libterm
libterm is a small C11 terminal UI library with a termbox2-compatible API. The same code drives POSIX terminals and the native Win32 console, with no POSIX shims and no #ifdef in your program.
The model
You never print straight to the terminal. You draw into an off-screen cell buffer, then call lt_present(). libterm compares that buffer with the last frame it displayed and emits only the cells that changed, inside a synchronized-update bracket so the terminal swaps frames atomically. There is no flicker because there is nothing half-drawn to see.
Every program has the same three beats:
lt_init()puts the terminal in raw mode and switches to the alternate screen.- Draw with
lt_set_cellorlt_print, show the frame withlt_present, and read events withlt_poll_event, in a loop. lt_shutdown()restores the terminal exactly as it was.
Modern terminal features are negotiated for you. On a kitty-capable terminal you get modifiers on every key and press, repeat and release actions. In a truecolor terminal you get 24-bit colour. Where a feature is missing, libterm falls back to legacy behaviour without a code change.
Conventions
- Every identifier starts with
lt_(functions and types) orLT_(macros and constants). - Functions return
LT_OK, which is 0, on success and a negativeLT_ERR_*code on failure.lt_strerrordescribes any code andlt_last_errnoholds theerrnobehind a failed system call. See Errors and return codes. - Coordinates are 0-based
(x, y)from the top-left corner.xgrows to the right andygrows downward. - libterm manages one terminal per process. Its state is process-global and not thread-safe, so drive it from one thread.
Where to go
| If you want to | Read |
|---|---|
| Build it and link it into a project | Install |
| Learn by writing small programs | Tutorials |
| Understand one area in depth | the guides, starting with Screen and rendering |
| Move existing termbox2 code over | Porting from termbox2 |
| Look up a function or constant | the API reference |
See what ships in examples/ | Examples |
The reference covers every public symbol in include/libterm/libterm.h. Per-symbol parity with termbox2 is tracked in the repository's ROADMAP.md.