Tuibox - A single-header terminal UI (TUI) library, capable of creating mouse-driven, interactive applications on the command line.

Related tags

Miscellaneous tuibox
Overview

tuibox

tuibox ("toybox") is a single-header terminal UI library, capable of creating mouse-driven, interactive applications on the command line.

It is completely dependency-free, using nothing other than ANSI escape sequences to handle parsing input and rendering the screen. Additionally, its individual parts work largely independently, meaning as much (or as little) of the library as is necessary can be used.

Demos

demo_basic.c: Basic button demo w/ truecolor background

  • (Note: Ugly color banding is from GIF compression)

demo_basic.gif

demo_bounce.c: Bouncing box using custom render loop

demo_bounce.gif

demo_drag.c: Click and drag

demo_drag.gif

bdfedit, a bitmap font editor built using tuibox:

demo_bdfedit.gif

Features

tuibox currently contains the following:

  • Event-driven terminal render loop
  • Mouse click and hover events on individual UI elements
  • Keyboard events (including escape sequence events, such as arrow keys)
  • Render caching (controlled by a user-defined dirty bit)
  • Completely dependency-free, using pure ANSI escape sequences (no ncurses)
  • Incrementally-adoptable -- rendering, events, and loops can all be used independently

Design Overview

The basic hierarchy of a UI looks like this:

  • UI: A collection of screens
    • Screen: A collection of boxes
      • Box: Any UI element
        • X/Y, width/height
        • Render function
        • Click event function (optional)
        • Hover event function (optional)
        • Arbitrary user data (see below example)
  • Main loop: Infinite read() loop gathering user input
    • Update: Parses user input and fires events (if applicable)

Example Code

A complete example is as follows:

/* Global UI struct */
ui_t u;

/* Function that runs on box click */
void click(ui_box_t *b, int x, int y){
  b->data1 = "you clicked me!";
  ui_draw(&u);
}

/* Function that runs on box hover */
void hover(ui_box_t *b, int x, int y, int down){
  b->data1 = "you hovered me!";
  ui_draw(&u);
}

void stop(){
  ui_free(&u);
  exit(0);
}

int main(){
  /* Initialize UI data structures */
  ui_new(0, &u);

  /* Add a new text box to screen 0 */
  ui_text(
    UI_CENTER_X, UI_CENTER_Y,
    "hello world!",
    0,
    click, hover,
    &u
  );

  /* Register an event on the q key */
  ui_key("q", stop, &u);

  /* Render the screen */
  ui_draw(&u);

  ui_loop(&u){
    /* Check for mouse/keyboard events */
    ui_update(&u);
  }

  return 0;
}

Compiling and Running Demos

To compile all demos in one go:

 $ make

 $ ./demo_basic
 $ ./demo_bounce
 $ ./demo_drag

Libraries/See Also

  • vec: Dynamic arrays used to store events and boxes
  • bdfedit: Bitmap font editor written alongside tuibox
You might also like...
Command line C++ and Python VSTi Host library with MFCC, FFT, RMS and audio extraction and .wav writing.
Command line C++ and Python VSTi Host library with MFCC, FFT, RMS and audio extraction and .wav writing.

______ _ ___ ___ | ___ \ | | | \/ | | |_/ /___ _ __ __| | ___ _ __| . . | __ _ _ __

A C++ header-only library for creating, displaying, iterating and manipulating dates

The ASAP date/time library for beautiful C++ code ASAP is a small, header-only date-time library for C++11 and beyond. It is heavily inspired by my gr

a one header library for creating Lua bindings to C++

Description A C++ library for generating Lua bindings. Supported features: functions, constructors, inheritance, member functions, properties, standar

A Minimal, Header only Modern c++ library for terminal goodies 💄✨
A Minimal, Header only Modern c++ library for terminal goodies 💄✨

rang Colors for your Terminal. Windows Demo Example usage #include "rang.hpp" using namespace std; using namespace rang; int main() { cout "P

Lightweight C++ command line option parser

Release versions Note that master is generally a work in progress, and you probably want to use a tagged release version. Version 3 breaking changes I

The command line interface for Piccolo
The command line interface for Piccolo

Piccolo programming language A fun, easy to embed high-level programming language. This repo contains the code for the Piccolo CLI. The core Piccolo c

A simple DPDK application that calculates stats for dropped and forwarded packets depending on the command line.

The DPDK Stats Description A small DPDK application that increments a basic packet counter for TCP or UDP packets depending on what's specified in the

Simple command-line program for sharing the display image on a local network.

XCast is a simple server/client command line program for sharing screen under X. With XCast you have the ability to either pull the display from a rem

LKM Command Line Parsing - Parte 2
LKM Command Line Parsing - Parte 2

LKM-Command-Line-Parsing 👾 Hoje iremos falar sobre Command Line Parsing diretamente no LKM. Esse é a segunda parte da nossa série de estudos para Roo

Owner
Andrew
Ramblings in code. UCSD CS
Andrew
Educational Administration Platform Emulator(TUI)

Educational Administration Platform Emulator This is an simple emulator aim to implement Educational Administration Platform base on terminal user int

null 1 Dec 30, 2021
Gauss Stylization - Interactive tool for normal driven stylization

Interactive tool for normal driven stylization. A set of preferred normals can be chosen arbitrarily from the Gauss sphere, including semi-discrete sets to model preference for cylinder- or cone-like shapes.

Ugo Finnendahl 16 Dec 6, 2022
Interactive-hex-meshing - Source code for "Interactive All-Hex Meshing via Cuboid Decomposition [SIGGRAPH Asia 2021]".

Interactive All-Hex Meshing via Cuboid Decomposition Video demonstration This repository contains an interactive software to the PolyCube-based hex-me

Lingxiao Li 131 Dec 5, 2022
OpenMLDB is an open-source database particularly designed to efficiently provide consistent data for machine learning driven applications.

English version | 中文版 1. Introduction OpenMLDB is an open-source database particularly designed to efficiently provide consistent data for machine lea

4Paradigm 1.2k Jan 8, 2023
imGuIZMO.quat is a ImGui widget: like a trackball it provides a way to rotate models, lights, or objects with mouse, and graphically visualize their position in space, also around any single axis (Shift/Ctrl/Alt/Super)

imGuIZMO.quat v3.0 imGuIZMO.quat is a ImGui widget: like a trackball it provides a way to rotate models, lights, or objects with mouse, and graphicall

Michele Morrone 276 Dec 28, 2022
PoC capable of detecting manual syscalls from usermode.

syscall-detect PoC capable of detecting manual syscalls from usermode. More information available at: https://winternl.com/detecting-manual-syscalls-f

null 125 Dec 26, 2022
General purpose power controller, capable of driving soldering irons using different voltages and probe types.

All-purpose Power Micro Controller This general purpose power micro controller features: Wheatstone Bridge front-end New Texas Instruments INA823 inst

Tomasz Jastrzębski 30 Dec 3, 2022
A complete Javascript environment for creating homebrew applications and games on PlayStation 2.

AthenaEnv is a project that seeks to facilitate and at the same time brings a complete kit for users to create homebrew software for PlayStation 2 using the JavaScript language.

Daniel Santos 29 Nov 15, 2022
A single file, single function, header to make notifications on the PS4 easier

Notifi Synopsis Adds a single function notifi(). It functions like printf however the first arg is the image to use (NULL and any invalid input should

Al Azif 9 Oct 4, 2022
Wave Function Collapse library in C, plus a command-line tool

wfc Single-file Wave Function Collapse library in C, plus a command-line tool License: MIT Version: 0.01 This is an early version that supports the ov

krychu 314 Dec 29, 2022