Skip to content

lib_tsi

pf4 edited this page Jun 21, 2024 · 3 revisions

libtsi

The Terminal based scrollable interface library is a dynamic library to create a simple interface in the terminal.

Related files

Index

Compilation

To compile a file with the library with make disk, add the following line to the file:

// @LINK SHARED: libtsi

To compile a file with the library in profanOS use -ltsi:

tcc -o file file.c -ltsi

The interface

Controls

After the function call, the terminal will be cleared and the interface will be displayed. The interface is scrollable and the user can navigate with the arrow keys or P/M (page up/page down) keys. The user can exit the interface by pressing q or ESC. The terminal will be restored to its previous state.

ANSI support

The library uses ANSI escape codes to color the interface. Only foreground colors are supported:

  • \033[0m - Reset text color
  • \033[3*m - Set text color (* is the color)
  • \033[9*m - Set text bright color (* is the color)

Functions

tsi_start

Open a new TSI interface with the given title and string. The string is the data to be displayed on the interface. Lines are separated by '\n' and the string must be null-terminated. Function only returns after the user exits the interface.

int tsi_start (
    const char *title,
    const char *string
);
  • title: The title of the interface.
  • string: The data to be displayed on the interface.
  • Returns: 0 on success, 1 on failure.

tsi_start_array

Open a new TSI interface with the given title and array of strings. The array must represent the lines of the interface and must be null-terminated. Each line must be null-terminated or terminated by '\n'. If a line is greater than the maximum width of the interface, it will be truncated. Function only returns after the user exits the interface.

int tsi_start_array (
    const char *title,
    const char **lines
);
  • title: The title of the interface.
  • lines: The lines of the interface.
  • Returns: 0 on success, 1 on failure.

Example

// @LINK SHARED: libtsi

#include <profan/libtsi.h>
#include <stdio.h>

int main (int argc, char **argv) {
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <string>\n", argv[0]);
        return 1;
    }

    tsi_start("Example", argv[1]);

    return 0;
}

profanOS Wiki

Clone this wiki locally