tuibox is a lightweight, dependency-free library designed for building mouse-driven interactive applications in the terminal. With its easy-to-use components and event-driven architecture, tuibox allows you to create engaging terminal UIs without any hassle, leveraging just ANSI escape sequences.
Introducing tuibox – a powerful, single-header terminal UI (TUI) library that allows developers to create mouse-driven, interactive applications directly from the command line. With tuibox, you can bring your terminal applications to life using simple and elegant ANSI escape sequences, making it completely dependency-free and lightweight.
Key Features:
- Event-Driven Architecture: tuibox features a sophisticated event-driven rendering loop that makes it easy to manage user interactions.
- Mouse Interactivity: Engage your users with mouse click and hover capabilities on UI elements.
- Keyboard Support: Handle various keyboard events, including escape sequences like arrow keys, for seamless navigation.
- Render Caching: Optimize performance with render caching, controlled by a user-defined dirty bit.
- Modular Design: Each component of tuibox operates independently, allowing you to adopt rendering, events, and loops gradually as needed.
Easy-to-Use UI Hierarchy:
The intuitive structure of tuibox helps you build complex UIs with ease:
- UI: A collection of screens.
- Screen: A collection of boxes.
- Box: Represents any UI element with defined properties such as positions and dimensions, rendering functions, and event functions for clicks and hovers.
- Screen: A collection of boxes.
Example Usage:
Utilizing tuibox is straightforward. Here’s a quick example demonstrating how to interact with UI elements in your application:
/* 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;
}
With tuibox, you have the freedom to create interactive command-line applications without any cumbersome dependencies. Embrace the ease of building your next terminal UI with this innovative library!