$ show dankamongmen/notcurses
Notcurses is a C library for building rich terminal user interfaces (TUIs) with full pixel graphics, multimedia support, and a widget toolkit. It provides both a full-screen rendered mode and a direct mode for simple output. The library abstracts terminal capabilities (terminfo, escape sequences, pixel protocols like Sixel and Kitty) and offers a composable plane system with z-ordering, transparency, scrolling, and damage-based rendering. It includes built-in widgets such as reels, selectors, menus, progress bars, plots, trees, and tabbed containers, as well as a multimedia backend (FFmpeg/OpenImageIO) for image/video decoding and streaming. The architecture is centered around a core C library with official C++ and Python bindings, plus command-line tools (ncplayer, nctetris, notcurses-demo, notcurses-info, etc.) that demonstrate its capabilities. Input handling uses an automaton-based parser for escape sequences and mouse protocols. The codebase is substantial and well-tested, though some areas show incomplete features and platform-specific complexity.
The LLM identified 5 files worth highlighting for reuse:
Implements a generic trie-based automaton for parsing terminal escape sequences, mouse events, and response strings. The automaton is built with a trie of nodes supporting character, numeric, string, and Kleene star transitions, and dispatches matched sequences to callback functions. This pattern is reusable for any protocol parsing that requires matching variable-length sequences efficiently.
A lock-free memory pool for storing variable-length extended grapheme clusters (UTF-8 strings) associated with cells. It uses a slab allocator with linked free lists and supports O(1) insertion and removal. This component is self-contained (only depends on standard C) and can be reused in any application needing efficient storage of small-to-medium variable-length blobs.
Provides functions for converting numeric values (bytes, counts) into human-readable strings with metric or binary prefixes (K, M, G, etc.) and locale-aware formatting. It includes fixed-width formatting (ncnmetric) for aligned output. This is a standalone utility that can be extracted and reused in any C project requiring SI/binary prefix formatting.
Defines a flexible buffer (fbuf) structure with mmap/mremap-backed growth for efficient appending of byte sequences. Designed for assembling terminal escape sequences, it supports reset, rewind, and direct output. On Linux it uses mremap for low-overhead reallocation; fallbacks are provided. This pattern is reusable for any application needing a high-performance growable byte buffer.
Manages UNIX signal handling for terminal applications, setting up an alternate signal stack and handlers for SIGSEGV, SIGABRT, SIGBUS, etc. to allow graceful cleanup (restoring terminal state). Provides setup_signals()/drop_signals() functions. This component is small, self-contained, and reusable for any terminal-based application that needs robust signal recovery.