━━━━━━━━━━━━ c o d e c h u · t e r m ━━━━━━━━━━━━
>>> capabilities(sys.stdout)
{
'color': True, 'truecolor': True,
'unicode': True, 'emoji': True,
'mouse': True, 'alt_buffer': True,
}
$ _ ← raw mode · alt buffer · cursor control · resize
━━━━━ "what can this terminal actually do?" ━━━━━━
Terminal capability detection and low-level control, stdlib-only.
Stdlib-only terminal-capability detection and low-level terminal control. The "what can this terminal actually do?" question answered as a dictionary, plus the context managers you reach for when you need full-screen mode, raw input, or resize handling.
pip install codechu-termPython 3.10+. POSIX-first; no external dependencies.
import os, sys
from codechu_term import capabilities, with_alt_buffer, with_raw_mode, on_resize
caps = capabilities(sys.stdout, env=os.environ)
if caps["alt_buffer"]:
with with_alt_buffer() as out:
out.write("full-screen view\n")
out.flush()
with with_raw_mode() as fd:
ch = os.read(fd, 1) # char-by-char input
unsubscribe = on_resize(lambda: print("resized"))
unsubscribe()is_tty(stream)/terminal_size()— the basic facts about the current stream.capabilities(stream, env)— color, truecolor, unicode, emoji, mouse, alt-buffer support, returned as one dict.with_alt_buffer()— context manager for full-screen mode.with_raw_mode(fd)— context manager for char-by-char input.on_resize(callback)— SIGWINCH subscription with anunsubscribe()return.- Cursor + line helpers —
hide_cursor/show_cursor/clear_line/clear_screenfor the small ANSI tasks that always come up.
- API reference — every public symbol with full signatures and detection rules.
- Changelog
| Library | Purpose |
|---|---|
| codechu-cli | CLI primitives — colors, progress, spinners, prompts |
| codechu-color | Color palettes, WCAG contrast, color-blind variants |
| codechu-spark | Unicode sparklines, mini bar charts, heatmaps |
| codechu-fmt | Human-readable sizes, durations, rates |
| codechu-meter | Timing — stopwatch, ETA, rate, histogram |
Full ecosystem: github.com/codechu.
- Capability detection rules informed by supports-color and chalk.
- ANSI escape conventions per ECMA-48 and the
xtermcontrol sequence documentation.
MIT — see LICENSE.
Part of Codechu.