Small C terminal control library that builds as a shared library for reuse in other projects.
Really its very very simple to use. Anywhere you can link c.
vtk_clear()clear screen, cursor to 0,0vtk_goto(x, y)move cursor to columnx, rowyvtk_color(n)set foreground color (0..255)vtk_bg(n)set background color (0..255)vtk_reset()reset fg/bg to terminal defaultsvtk_hide_cursor()hide cursorvtk_show_cursor()show cursorvtk_raw_mode()enable non-blocking single-char inputvtk_restore_mode()restore normal terminal input modevtk_getch()returns keycodeintor-1if no key pressedvtk_get_width()current terminal column count (fallback 80)vtk_get_height()current terminal row count (fallback 24)vtk_buffer_init(width, height)initialize a generic back/front buffer pairvtk_buffer_free()release buffer memoryvtk_buffer_clear(ch, fg, bg)fill back buffervtk_buffer_put(x, y, ch, fg, bg)write one cell in back buffervtk_buffer_present()diff-render back buffer to terminal and update front buffervtk_buffer_hline(x, y, len, ch, fg, bg)draw a horizontal run of cellsvtk_buffer_vline(x, y, len, ch, fg, bg)draw a vertical run of cellsvtk_buffer_text(x, y, text, fg, bg)write a string left-to-rightvtk_buffer_rect(x, y, w, h, ch, fg, bg)fill a rectanglevtk_buffer_line(x, y, dx, dy, ch, fg, bg)draw a Bresenham line from(x,y)to(x+dx, y+dy)
Session helpers:
vtk_begin()clear screen and hide cursorvtk_end()show cursor and reset attributes
Color constants are provided in enum vtk_color_code:
VTK_BLACK,VTK_RED,VTK_GREEN,VTK_YELLOWVTK_BLUE,VTK_MAGENTA,VTK_CYAN,VTK_WHITE- Bright variants are provided as macros:
VTK_BRIGHT_BLACKthroughVTK_BRIGHT_WHITE - Any explicit color index in
0..255is accepted for both foreground and background
cmake -S . -B build
cmake --build buildThis produces:
- Linux/macOS:
libvtkit.soorlibvtkit.dylib - Windows:
term.dll(plus import library)
By default, a static library is also built:
- Linux/macOS:
libvtk_static.a - Windows:
vtk_static.lib
Disable static library build if desired:
cmake -S . -B build -DVTK_BUILD_STATIC=OFFcmake --install build --prefix ./installInstalls headers and CMake package files so other projects can use find_package(term CONFIG REQUIRED).
find_package(vtkit CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE vtkit::vtkit)To link the static variant (when built):
target_link_libraries(my_app PRIVATE term::vtk_static)Build examples (default enabled):
cmake -S . -B build
cmake --build buildRun simple API demo:
./build/vtk_demoRun lines/color demo (any key draws a new batch, Q to quit):
./build/vtk_linesRun boxes/rectangles demo (any key draws a new batch, Q to quit):
./build/vtk_rectRun animated Pong demo:
./build/vtk_pongControls for Pong demo:
W/S: move left paddle up/down+/-: adjust speed while runningQ: quit
Pong uses an internal key repeat controller for the player paddle, so initial hold delay and repeat interval can be tuned independently of your OS keyboard repeat settings.
The Pong renderer now uses the library's generic diff-rendered buffer and only redraws changed cells each frame to reduce flicker.



