Examples
The examples/ directory builds into build/examples/. Each program is small and self-contained, and each is the best reference for one part of the API.
| Example | Demonstrates |
|---|---|
hello | the minimal init, draw, event loop, shutdown cycle |
print | lt_print and lt_printf, UTF-8, wide CJK characters, multi-line text |
colors | the eight named colours as foreground and background, and the attribute flags |
truecolor | 24-bit gradients, LT_RGB, the LT_HI_BLACK sentinel, colour-depth detection |
theme | lt_query_color and lt_is_dark_background choosing a light or dark panel, with the assume-dark fallback |
resize | a layout derived from lt_width and lt_height, redrawn on every LT_EVENT_RESIZE |
keyboard | termbox2's on-screen keyboard demo, ported by renaming tb_ to lt_ plus LT_INPUT_COMPAT |
kbd | an on-screen keyboard and a live event inspector: keys, modifiers, ev.action, bare modifiers, and an indicator for the input model in use |
mouse | SGR mouse events: buttons, position, drag |
editor | a small text editor written against compat/termbox2.h: open a file, edit, save as, Ctrl-S and Ctrl-Q |
Running them
cmake -B build && cmake --build build
./build/examples/hello
./build/examples/kbd
./build/examples/editor examples/hello.c
Most quit on q or Esc. kbd quits on Ctrl+C, keyboard on Ctrl+X then Ctrl+Q, and editor on Ctrl+Q. The mouse demo prints event details to stderr while it runs, so redirect them to a file if you want to read them:
./build/examples/mouse 2> events.log
Adding your own
Create examples/playground.c, add libterm_add_example(playground) to examples/CMakeLists.txt, and run cmake --build build. The tutorials use this recipe for every program.