Skip to main content

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.

ExampleDemonstrates
hellothe minimal init, draw, event loop, shutdown cycle
printlt_print and lt_printf, UTF-8, wide CJK characters, multi-line text
colorsthe eight named colours as foreground and background, and the attribute flags
truecolor24-bit gradients, LT_RGB, the LT_HI_BLACK sentinel, colour-depth detection
themelt_query_color and lt_is_dark_background choosing a light or dark panel, with the assume-dark fallback
resizea layout derived from lt_width and lt_height, redrawn on every LT_EVENT_RESIZE
keyboardtermbox2's on-screen keyboard demo, ported by renaming tb_ to lt_ plus LT_INPUT_COMPAT
kbdan on-screen keyboard and a live event inspector: keys, modifiers, ev.action, bare modifiers, and an indicator for the input model in use
mouseSGR mouse events: buttons, position, drag
editora 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.