跪拜 Guibai
← All articles
Backend

A Terminal Stock Ticker That Disguises Itself as a Docker Build

By 寒蝉128 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

The tool solves a specific social-signaling problem in open-plan offices: switching to a browser or GUI app to check stock prices visibly signals "not working." By embedding live quotes inside a terminal and adding a one-key disguise, it removes that signal without changing the underlying behavior. The termios-based single-threaded input handling is also a reusable pattern for any terminal app that needs both real-time updates and instant keystroke response without pulling in curses.

Summary

BossKey-Stock pulls real-time Chinese A-share quotes from the free Sina Finance API and renders them inside a terminal UI built with Python's Rich library. The defining feature is a boss-key mode: pressing `b` instantly swaps the stock table for a procedurally generated Docker build log, complete with step numbers, occasional warnings, and a running timer. The tool requires no API keys or registration and runs entirely in a single thread using direct termios manipulation for non-blocking keystroke detection.

Version 0.2.1 adds position tracking with cost-basis and P&L columns, a Chinese/English UI toggle that defaults to English to strengthen the disguise, and an on-demand shortcut hint bar. The data layer handles trading-session detection, offline resilience, and automatic conversion of share counts to standard lots.

The project is a modern take on the classic boss key, addressing the social friction of visibly checking stock prices in an open office by embedding the entire workflow inside a terminal that always looks like work.

Takeaways
Pressing `b` toggles between a live stock table and a scrolling fake Docker build log with step numbers, warnings, and a timer.
Stock data comes from Sina Finance's free HTTP API, which requires no key and returns GBK-encoded JavaScript variable assignments.
Non-blocking single-key input is achieved by disabling ICANON, ECHO, and ISIG via termios, then polling with select at a 0.5-second timeout — no curses, no background threads.
The ICRNL flag must be explicitly disabled on some terminal emulators to prevent Enter (\r) from being converted to newline (\n) and breaking key detection.
Position management supports adding stocks interactively with share count and cost basis, then displays position P&L and today's P&L with independent red/green coloring.
The UI defaults to English because Chinese characters like 持仓 and 收益 are instantly readable to colleagues, whereas English text blends into a coding environment.
Trading-session detection suppresses data fetching outside market hours (Mon–Fri, 9:30–11:30 and 13:00–15:00) and shows an [After Hours] indicator.
Network failures display a yellow [Offline] indicator while preserving the last successfully fetched data rather than clearing the screen.
Conclusions

The project reframes a workplace taboo — checking stocks during work hours — as a UI problem: the issue isn't the activity itself but the visible signal it sends in an open office.

Defaulting the interface to English is a subtle but effective disguise tactic; it exploits the fact that non-native text takes longer to parse, making a quick glance over someone's shoulder far less revealing.

The termios approach sidesteps a common terminal-UI conflict: Rich and curses both want control of the terminal, but by only modifying input flags and leaving output alone, the two concerns stay decoupled.

Many 'slacking off' tools are really responses to environments that conflate visible screen content with productivity, and the boss-key pattern persists precisely because that conflation hasn't gone away.

Concepts & terms
Boss Key
A keyboard shortcut, dating back to early PC games, that instantly replaces the current screen with something innocuous — originally a fake spreadsheet — to hide non-work activity from a passing supervisor.
termios ICANON / ECHO / ISIG
Terminal input flags on Unix-like systems. ICANON enables line-buffered input (waits for Enter); disabling it allows reading one character at a time. ECHO controls whether typed characters are displayed. ISIG enables signal generation (e.g., Ctrl+C). Disabling all three gives a program raw, unbuffered keystroke access.
ICRNL
A termios input flag that, when enabled, translates carriage return (\r) into newline (\n). On some terminal emulators this can corrupt single-byte key reads, so it must be explicitly disabled for raw input handling.
Rich Live
A component of the Python Rich library that maintains a dynamically updating region in the terminal using the alternate screen buffer, similar to how vim or top redraw the screen without scrolling the terminal history.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗