Skip to main content

cozy_tui

CI (Windows · macOS · Linux) PyPI version Python versions GitHub stars

A lightweight, cross-platform Python TUI (Terminal User Interface) library. Build keyboard-driven terminal apps with widgets, focus management, mouse support, and smooth cursor blinking — all rendered through raw VT sequences. Runs on Windows (Console API) and POSIX (Linux/macOS via termios).


Documentation

Full documentation lives in docs/ (GitHub) directory:

  • Core Concepts — the render loop, coordinate system, and widget lifecycle.
  • Widgets — every widget: App, Box, Label, Hyperlink, Bindings, Text, Input, Button, Checkbox, MarkdownInput, DropFilesArea, ListView, CheckList, RadioSet, Dropdown, RightClickMenu, ProgressBar, Spinner, Toast, Table, Tabs, ScrollView, Collapsible, Tree, AnimatedLabel, TracebackView.
  • Layouts, Dock & OverlaysVBox/HBox/Grid, app.dock(...), and the overlay/modal layer (open_overlay, app.prompt).
  • StylingStyle, colors, and text attributes.
  • Input & Interaction — key bindings, mouse support, focus, and scrolling.
  • Examples — runnable demos in examples/.

Features

  • Cross-platform — runs on Windows (Console API) and POSIX (Linux/macOS via termios); the backend is chosen automatically.
  • Very few dependencies — the clipboard is built in (no pyperclip); the only third-party dependency is rich, used to render Markdown/MarkdownInput and to syntax-highlight TracebackView/show_traceback. Everything else is the standard library.
  • Built-in clipboardcozy_tui.clipboard.copy/paste with native backends per platform (Win32 API, pbcopy/pbpaste, wl-clipboard/xclip/xsel, or OSC 52 fallback).
  • Unicode-aware rendering — a built-in wcwidth-style width layer keeps CJK/emoji (double-width) and combining marks (zero-width) aligned in the cell grid.
  • Widgets: Button, Checkbox, Input, Label, Hyperlink, Bindings, AnimatedLabel, Text, Box, MarkdownInput, DropFilesArea, ListView, CheckList, RadioSet, Dropdown, RightClickMenu, ProgressBar, Spinner, Toast, Table, Tabs, ScrollView, Collapsible, Tree, TracebackView
  • Crash screens: unhandled exceptions in app.run() automatically show a full-screen, scrollable, syntax-highlighted TracebackView with one-key clipboard copy (App(catch_errors=False) to get a plain propagating exception instead); call cozy_tui.crash_screen.show_traceback(exc) directly to get the same screen outside of run()
  • Context menus: RightClickMenu with icons, shortcut labels, and submenus — pop it up from app.on_right_click(...)
  • Layouts: VBox, HBox, Grid — auto-position children without manual x/y
  • Dock layout: app.dock(widget, "top"/"bottom"/"left"/"right"/"fill") — edge-anchored regions that re-flow on resize
  • Overlays & modals: app.open_overlay(widget) floats a widget above the UI, dims the background, and confines focus/input — the basis for dialogs, menus, and tooltips
  • Multi-line Input: Enter or Shift+Enter to insert newlines, UP/DOWN to navigate lines
  • Markdown preview: MarkdownInput renders live Rich Markdown when unfocused
  • Focus system: Tab / Shift+Tab to cycle focus, click to focus with mouse
  • Cursor blinking: Uses the real terminal cursor — smooth blink with no character replacement
  • Mouse support: Click to focus widgets, click to activate buttons, scroll wheel to scroll
  • Scrolling: Long content scrolls vertically; single-line inputs scroll horizontally
  • Global key handlers: Register app-wide shortcuts with app.on_key()
  • Flexible styling: Per-widget foreground, background, and text styles (bold, dim, underline)


Requirements

  • Python 3.10+
  • A VT-capable terminal on Windows (Windows Console API) or POSIX (Linux/macOS, via termios/tty). The console backend is selected automatically at import.


Installation

pip install cozy-tui

That's it — rich (used to render Markdown/MarkdownInput and to syntax-highlight TracebackView) is pulled in automatically.

Take it for a spin with the built-in demo:

cozy-tui              # or: python -m cozy_tui

Command-line

Installing the package also provides a cozy-tui command (equivalently python -m cozy_tui):

cozy-tui              # launch the interactive demo (no subcommand)
cozy-tui demo         # launch the interactive demo
cozy-tui --version    # print the installed version
cozy-tui doctor       # check Python, imports, clipboard backend, color depth, PyPI version
cozy-tui doctor --offline   # skip the PyPI check
cozy-tui info         # version + detected terminal capabilities
cozy-tui run script.py           # run a script, like `python script.py`
cozy-tui run --debug script.py   # ...with App(debug=True) on, no code change needed

Then in your script:

from cozy_tui import App, Style
from cozy_tui.widgets import Box, Label, Input, Button

From source (for development)

git clone https://github.com/youssefahmed2017/cozy_tui.git
cd cozy_tui
pip install -e .            # add [dev] for the test suite (pytest)


Quick Start

from cozy_tui import App, Style
from cozy_tui.widgets import Box, Label, Input, Button, Checkbox
from cozy_tui.events import Key

app = App(full=True, size=None, style=Style(fg="white", bg="black"))

# Box size = virtual pixels ÷ App.SCALE (10) → "600x140" = 60 cols × 14 rows
box = Box(2, 1, "600x140", border="rounded", style=Style(fg="white", bg="black"), title="Sign Up")

box.add(Label(2, 2, "Username:"))
box.add(Input(12, 2, 20, placeholder="Enter username"))

box.add(Label(2, 4, "Bio:"))
box.add(Input(12, 4, 20, placeholder="Tell us about you", multiline=True))

box.add(Checkbox(2, 7, "Subscribe to newsletter"))
box.add(Checkbox(2, 9, "I agree to the terms", checked=True))

btn = Button(2, 11, "Submit", width=20, style=Style(fg="white", bg="blue"))
btn.on_click(lambda b: print("Submitted!"))
box.add(btn)

app.add(box)
app.focus(btn)
app.on_key(Key.ESC, lambda: "quit")
app.run()

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cozy_tui-0.4.0.tar.gz (133.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cozy_tui-0.4.0-py3-none-any.whl (123.7 kB view details)

Uploaded Python 3

File details

Details for the file cozy_tui-0.4.0.tar.gz.

File metadata

  • Download URL: cozy_tui-0.4.0.tar.gz
  • Upload date:
  • Size: 133.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for cozy_tui-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f457da67010a3572e563fd84a1d6ba5a6fcbdc1e790cf8546399032ace08fd35
MD5 d32b756ed0d1a0868eedf929e5a94f3b
BLAKE2b-256 e563808e4fc1c7ca4ef00f5b8d2dcfcf89c54110d6afb09caed7783f90bf0906

See more details on using hashes here.

File details

Details for the file cozy_tui-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: cozy_tui-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 123.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for cozy_tui-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b794b6d2666cbb0fc04f8765ffe8d2859b25d7cfb236e831727f49de476da10
MD5 8b2a35349fa21738624f0428eaa06f02
BLAKE2b-256 20615b98838aad2497c71fd523e520f4a129d55b7a09db576f4cc552f018c2b4

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.0

2 files

0.4.2

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page