Skip to main content

curses_components

A reusable Python terminal UI library built on curses. Provides a grid viewer for tabular data and a vi-like text editor popup. Both components focus purely on the user interface and accept data in a canonical format.

Components

GridComponent Displays tabular data (e.g. CSV, database result sets) in a scrollable, interactive grid. Supports filtering, sorting, searching, column navigation, and CSV export.

EditorPopup A vi-like modal text editor shown as a popup window. Suitable for editing small text files such as SQL scripts. Supports insert mode, normal mode commands, search, substitute, and sort.

ScrollablePopup Base class for bordered, scrollable popup windows. Subclass to build custom help screens or information panels.

Installation

Install as an editable local package (recommended for development):

pip install -e /path/to/curses_component

Or add as a git submodule in another project:

git submodule add <repo-url> libs/curses_component
pip install -e libs/curses_component

Usage

GridComponent:

import curses
from curses_components import GridComponent

data = [
    {'name': 'Alice', 'age': 30},
    {'name': 'Bob',   'age': 25},
]

def main(stdscr):
    grid = GridComponent(data, fg_color='green', bg_color='black')
    grid.display(stdscr)

curses.wrapper(main)

EditorPopup:

import curses
from curses_components import EditorPopup

def main(stdscr):
    editor = EditorPopup(stdscr, title='Edit', fg_color='green',
                         bg_color='black', bold=True)
    result = editor.edit(text='', filename='script.sql')
    if result is not None:
        print(result)

curses.wrapper(main)

See examples/ for runnable demos:

python examples/grid_editor.py
python examples/text_editor.py
python examples/text_editor.py <file>
python examples/text_editor.py --size 120x40 <file>

GridComponent key bindings

Grid extensions can display reusable popups through show_popup:

grid.show_popup('Messages', lines=['first line', 'second line'])
grid.show_popup('Results', rows=[('Name', 'Alice'), ('State', 'Active')])

The popup inherits the grid's configured colors.

Commands can be added with a handler that receives the grid and parsed arguments:

def show_current_column(grid, args):
    column = grid.columns[grid.col_idx]
    grid.show_popup(column, lines=[str(row.get(column, ''))
                                   for row in grid.data])

grid.register_command('values', show_current_column)

Navigation: j/k/h/l or arrow keys, Home/End, Page Up/Down, ^/$ Search: / (substring), r/

EditorPopup key bindings

Normal mode: h/j/k/l or arrow keys, w/b (word), 0/$ (line), gg/G (file) Editing: i/a (insert), o/O (new line), x (delete char), dw (delete word), dd (delete line), yy (yank), p (paste), u (undo) Search: / (enter), n/N (next/previous) Command mode: :w [file], :q, :q!, :wq, :x, : (jump to line) Substitute: :s/pat/rep[/g], :%s/pat/rep[/g] Sort: :sort[!][ u] Help: :help

Color options (both components)

Both GridComponent and EditorPopup accept fg_color, bg_color, and border_color as constructor arguments. Valid color names:

black  blue  cyan  green  magenta  red  white  yellow

EditorPopup also accepts bold=True (bright text) and bold_background=True.

Dependencies

  • Python 3.8+
  • pyperclip (for copy/copyrow commands in GridComponent)

License

MIT

Metadata

Release files for curses-components 26.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for curses-components 26.9.2
File Size Uploaded
curses_components-26.9.2.tar.gz 24.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for curses-components 26.9.2
File Interpreter ABI Platform
curses_components-26.9.2-py3-none-any.whl Python 3 none any Details

Total release size: 49.9 kB

Release files / curses_components-26.9.2.tar.gz

Download URL curses_components-26.9.2.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
06f7424af6ca9fe7d9e45cee3d1c24fc07d2981b582c1cb51cddc76341386ebc
BLAKE2b-256 checksum
How to use checksums
df39f3b5d3fb775cf34499b47c36c0dc4d4a6bded43062f4152aa0de1fc297cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / curses_components-26.9.2-py3-none-any.whl

Download URL curses_components-26.9.2-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
251bd80194d4ba30de7b8fd94eeeb974628aa8f889a753e4eb07517c095ca8a4
BLAKE2b-256 checksum
How to use checksums
c0e259d552ffae91a9bcc5d6c96afa7e7ccf5e8c2ad1bd6b2ff595eb3e060692
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

26.9.5

2 release files

26.9.4

2 release files

This release

26.9.2 This release

2 release files

26.7.2

2 release 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