Termpaint — Termpaint 0.3.0 documentation (original) (raw)

Termpaint is a low level terminal interface library for character-cell terminals in the tradition of VT1xx (like xterm, etc).

It’s designed to be portable and flexible to integrate. It covers event handling and rendering.

Features

Does not contain:

Termpaint is meant as a basic building block to build more specific libraries upon. There are a lot of different higher layer styles, so it’s cleaner to have separate libraries for this.

Minimal example

A “hello world”, using the internal default operating system integration and opinionated default setup.

See Getting started for full source.

main code

termpaint_integration *integration;
termpaint_terminal *terminal;
termpaint_surface *surface;

bool quit = false;

integration = termpaintx_full_integration_setup_terminal_fullscreen(
            "+kbdsig +kbdsigint",
            event_callback, &quit,
            &terminal);
surface = termpaint_terminal_get_surface(terminal);
termpaint_surface_clear(surface,
            TERMPAINT_DEFAULT_COLOR, TERMPAINT_DEFAULT_COLOR);
termpaint_surface_write_with_colors(surface,
            0, 0,
            "Hello World",
            TERMPAINT_DEFAULT_COLOR, TERMPAINT_DEFAULT_COLOR);

termpaint_terminal_flush(terminal, false);

while (!quit) {
    if (!termpaintx_full_integration_do_iteration(integration)) {
        // some kind of error
        break;
    }
}

termpaint_terminal_free_with_restore(terminal);

event callback

void event_callback(void *userdata, termpaint_event *event) { bool *quit = userdata; if (event->type == TERMPAINT_EV_CHAR) { if (event->c.length == 1 && event->c.string[0] == 'q') { *quit = true; } } if (event->type == TERMPAINT_EV_KEY) { if (event->key.atom == termpaint_input_escape()) { *quit = true; } } }

Support

It’s known to work on

The core library (but not the OS integration and the meson build system) only depend on C11 (plus a few common string functions like strdup).

Contents: