Cross-platform, native, modern terminal UI library
termbox2-compatible API on POSIX and native Windows (Win32 Console API).
cmake -B build && cmake --build buildC11, no dependencies, MIT.
libterm keyboard demo - press keys to light them up - Ctrl+C to quit ╭───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───╮ │Esc│F1 │F2 │F3 │F4 │F5 │F6 │F7 │F8 │F9 │F10│F11│F12│ ╰───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───╯ ╭───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬────╮ │ ` │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 0 │ - │ = │Bksp│ ╰───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴────╯ ╭────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───╮ │Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │ [ │ ] │ \ │ ╰────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───╯ ╭────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬─────╮ │Caps│ A │ S │ D │ F │ G │ H │ J │ K │ L │ ; │ ' │Enter│ ╰────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────╯ ╭─────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬─────╮ ╭───╮ │Shift│ Z │ X │ C │ V │ B │ N │ M │ , │ . │ / │Shift│ │ ↑ │ ╰─────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────╯ ╰───╯ ╭────┬───┬─────────────────────────────┬───┬────╮ ╭───╮ ╭───╮ ╭───╮ │Ctrl│Alt│ Space │Alt│Ctrl│ │ ← │ │ ↓ │ │ → │ ╰────┴───┴─────────────────────────────┴───┴────╯ ╰───╯ ╰───╯ ╰───╯ last libterm event (raw lt_peek_event fields): type=KEY key=0xFFFF LT_KEY_F1 ch=0x00 '.' mod=0x02 CTRL action=PRESS input model: modern (kitty negotiated) - unconfirmed; press Shift+a letter
After Ctrl+F1: the inspector reads F1 with LT_MOD_CTRL.
One header, four calls
Init, draw, present, shutdown.
- lt_print, lt_set_cellwrite to the back buffer
- lt_presentemits the changed cells once
- lt_poll_eventa key, a click or a resize
#include "libterm/libterm.h"
int main(void) {
if (lt_init() != LT_OK)
return 1;
lt_print(2, 1, LT_GREEN, LT_DEFAULT, "hello, libterm");
lt_present();
struct lt_event ev;
lt_poll_event(&ev); /* any key */
return lt_shutdown();
}Three examples, caught mid-run
Each picture is the program’s own cells, captured on a pseudo terminal.
Text lands where you put it
lt_print decodes UTF-8 and advances columns the way the terminal does: a CJK glyph takes two cells, a combining mark none, a newline returns to the starting column.
lt_print: red on default
UTF-8: € é 😀
lt_printf: 2 + 40 = 42
multi-line:
second line
third line
wide: 你 好 (CJK = 2 cols)
press any key to quit
termbox2 code builds unchanged
This editor is written against compat/termbox2.h with tb_ names only. One line after init keeps its Ctrl+letter bindings working.
Shopping
- bread
- coffee beans
- a new USB-C cable
Call the dentist on Thursday.
notes.txt | Ctrl-S save Ctrl-Q quit
Eight names, or sixteen million
Named colours, palettes and 24-bit RGB share one lt_attr. lt_detect_color_depth picks the richest mode the terminal reports.
libterm truecolor demo [truecolor detected] (press q or Esc to quit)
24-bit gradient:
LT_RGB swatches:
orange teal purple
HI_BLACK vs default:
default-bg real-black
truecolor + bold
lt_print: red on default UTF-8: € é 😀 lt_printf: 2 + 40 = 42 multi-line: second line third line wide: 你 好 (CJK = 2 cols) press any key to quit
Shopping - bread - coffee beans - a new USB-C cable Call the dentist on Thursday. notes.txt | Ctrl-S save Ctrl-Q quit
libterm truecolor demo [truecolor detected] (press q or Esc to quit) 24-bit gradient: LT_RGB swatches: orange teal purple HI_BLACK vs default: default-bg real-black truecolor + bold
One event struct, two backends
What each platform does behind the same lt_event.
| Area | POSIX | Windows |
|---|---|---|
| Terminal | /dev/tty, termios raw mode | Win32 console API |
| Keys | kitty protocol when negotiated, else legacy decoding | ReadConsoleInputW records |
| Modifiers on letters | kitty terminals only | every key |
| Mouse | SGR 1006 reports | console mouse events |
| Colour query | OSC 10, 11 and 4 round-trip | console colour table, 16 entries |
| Own event loop | lt_get_fds | not available |
Before you link it
Is it a drop-in for termbox2?
Include
compat/termbox2.hand keep the tb_ names. The one difference, Ctrl+letter, is covered in the porting guide.Which terminals get the modern input model?
kitty, foot, ghostty and recent xterm. Everything else falls back to legacy decoding with no code change.
Is it thread-safe?
No. One terminal per process, driven from one thread.
What does it depend on?
Only the C library. CMake 3.32 for the SIMD build, or one cc command for the scalar one.
git clone https://github.com/rizukirr/libterm.git
cd libterm
cmake -B build
cmake --build build
./build/examples/hello