A lightweight, dependency-light Python TUI library with a cell-grid renderer and VT input.
Project description
cozy_tui
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,ListView,CheckList,Dropdown,ProgressBar,Table,Collapsible,Tree,AnimatedLabel. - Layouts, Dock & Overlays —
VBox/HBox/Grid,app.dock(...), and the overlay/modal layer (open_overlay,app.prompt). - Styling —
Style, 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 isrich, used to renderMarkdown/MarkdownInput. Everything else is the standard library. - Built-in clipboard —
cozy_tui.clipboard.copy/pastewith 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,ListView,CheckList,Dropdown,ProgressBar,Table,Collapsible,Tree - 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:
MarkdownInputrenders 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) is pulled in automatically.
Take it for a spin with the built-in demo:
python -m cozy_tui
Then in your script:
from cozy_tui import App, Box, Label, Input, Button, Style
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, Box, Label, Input, Button, Checkbox, Style
from cozy_tui.events import Key
app = App(full=True, size=None, style=Style(fg="white", bg="black"))
# Box size = virtual pixels ÷ 30 → "1800x420" = 60 cols × 14 rows
box = Box(2, 1, "1800x420", 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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cozy_tui-0.2.0.tar.gz.
File metadata
- Download URL: cozy_tui-0.2.0.tar.gz
- Upload date:
- Size: 64.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8233c34326f9cad950761a38841bed3f30b65165a3b35734bd7c599e73eb11d6
|
|
| MD5 |
0f04d20f215c48474b1d95038badd049
|
|
| BLAKE2b-256 |
73c4abc9bec2b9a78a49cdfc1c5ccb123966a60642ce534c79976294d045d504
|
File details
Details for the file cozy_tui-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cozy_tui-0.2.0-py3-none-any.whl
- Upload date:
- Size: 70.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e30bc7356770c5030450b0cc059e22410e48403cfa87efe1ad70e57d14977625
|
|
| MD5 |
ad6161836a30576ca83add109c9a4a49
|
|
| BLAKE2b-256 |
f55e6f906a69293658243f0367630ea751c0d69cace8af8b160fcb385f9d919c
|