Skip to content

codechu/term-py

━━━━━━━━━━━━ 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?" ━━━━━━

PyPI Python CI License: MIT

Terminal capability detection and low-level control, stdlib-only.

codechu-term

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.

Install

pip install codechu-term

Python 3.10+. POSIX-first; no external dependencies.

Quick example

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()

What you get

  • 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 an unsubscribe() return.
  • Cursor + line helpershide_cursor / show_cursor / clear_line / clear_screen for the small ANSI tasks that always come up.

Read more

Family

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.

Credits

  • Capability detection rules informed by supports-color and chalk.
  • ANSI escape conventions per ECMA-48 and the xterm control sequence documentation.

License

MIT — see LICENSE.

Part of Codechu.

About

Terminal capability detection, alt buffer, raw mode, SIGWINCH — pure stdlib

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages