Skip to content
skhelladiPublic

About

TUIKit is a C++ framework designed to build rich and interactive Terminal/Text User Interfaces (TUIs).

Topics

Resources

Stars

56 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

59 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TUIKit: A Qt-like Terminal User Interface Framework for C++

๐Ÿš€ Project Overview

Based on FTXUI, TUIKit is a modern C++ framework designed to build rich and interactive Terminal User Interfaces (TUIs). Inspired by the simplicity and power of the Qt framework, TUIKit aims to provide a familiar development experience for creating command-line applications, especially suited for scientific and engineering projects.

Demo of TUIKit in action
See example_1.cpp

Demo of TUIPlot in action
See example_plot.cpp

๐Ÿงฉ Core Principles (Qt-like Philosophy)

  • Hierarchical Widgets: Utilize a structured hierarchy of UI components (TUIWidget, TUIForm, TUIMenu, etc.).
  • Event Handling: Manage user interactions through a signal/slot-like mechanism or callbacks.
  • Automatic Layouts: Employ flexible layout managers (TUIVBox, TUIHBox) for responsive UI design.
  • Advanced Theming: Customize colors, borders, and styles to create visually appealing interfaces.
  • UI Definition Files: Support for defining UI layouts in JSON-like .tuik files, allowing dynamic loading and modification of interfaces.

โœจ Implemented Components (Current State)

The following core components are implemented and functional:

  • TUIApp: The entry point for the application.
  • TUIWidget: Base class for all UI components.
  • TUIButton: Interactive button with click events, icon and enable/disable support.
  • TUICheckBox: Simple toggle checkbox.
  • TUICollapsible: A collapsible container for widgets.
  • TUIComboBox: Dropdown list for selection.
  • TUIDoubleSpinBox: Spin box for double-precision floating-point values.
  • TUIFileDialog: Modal full-screen file/folder picker (open/save/directory modes, extension filters, hidden-files toggle).
  • TUIForm: Organizes input fields with labels (dynamic add/remove/rebuild supported).
  • TUIGroupBox: Groups related widgets with an optional title and border.
  • TUILabel: Displays static text.
  • TUIListView: A simple list of selectable string items.
  • TUILogConsole: High-performance scrolling log console (bounded ring buffer, follow-tail, per-line colors, filter, virtual rendering).
  • TUIMenu: Vertical list of selectable options.
  • TUIMenuBar: Horizontal menu bar with keyboard-navigable dropdown menus, icons, separators and shortcuts.
  • TUIProgressBar: A widget to show progress.
  • TUIRadioBox: Group of exclusive radio buttons.
  • TUIResizableSplit: Splitter for resizable panels (horizontal/vertical).
  • TUIScrollableContainer: Scrollable area for any widget (with scrollbar, keyboard and mouse support).
  • TUISlider: Horizontal slider for continuous value selection.
  • TUISpinBox: Spin box for integer values.
  • TUIStatusBar: Displays status messages at the bottom of the application.
  • TUITableView: A widget for displaying data in a table.
  • TUITabWidget: Organizes content into multiple tabs.
  • TUITextArea: A multi-line text editing widget.
  • TUITextField: Editable single-line text input.
  • TUIToolbar: A bar for action buttons.
  • TUITreeView: Displays hierarchical data in a tree structure.
  • TUIPlot: Plots several curves (live or streamed from a CSV file) with fixed/auto ranges, major/minor grid, legend, crosshair, zoom and pan.

๐ŸŽจ Icon Catalog (TUIKIT::ICON)

All glyphs are const std::string in include/tuikit/core/TUIIcons.h, ready to be passed to button()->setIcon(...), toolbar items, tree nodes, etc.

Category Icons
General / application Rocket ๐Ÿš€, Home ๐Ÿ , Settings โš™๏ธ, Search ๐Ÿ”, Clock ๐Ÿ•, Link ๐Ÿ”—, Lock ๐Ÿ”’, Unlock ๐Ÿ”“, User ๐Ÿ‘ค, Terminal ๐Ÿ–ฅ๏ธ, Book ๐Ÿ“–, Help โ“
Files and edition NewFile ๐Ÿ“„, File ๐Ÿ“ƒ, Folder ๐Ÿ“, Open ๐Ÿ“‚, Save ๐Ÿ’พ, SaveAs ๐Ÿ’ฝ, Edit โœ๏ธ, Delete ๐Ÿ—‘๏ธ, Copy ๐Ÿ“‹, Paste ๐Ÿ“Œ, Import ๐Ÿ“ฅ, Export ๐Ÿ“ค
Execution controls Play โ–ถ๏ธ, Stop โน๏ธ, Pause โธ๏ธ, Refresh ๐Ÿ”„, Calculate ๐Ÿงฎ, Solver ๐ŸŒ€
Status / severity Tasks โœ…, Quit โŒ, Close โœ–๏ธ, Info โ„น๏ธ, Warning โš ๏ธ, Error โ—, Success โœ”๏ธ
Navigation Collapsible โ†•๏ธ, ArrowUp โฌ†๏ธ, ArrowDown โฌ‡๏ธ, ArrowLeft โฌ…๏ธ, ArrowRight โžก๏ธ, ChevronUp โ–ฒ, ChevronDown โ–ผ, ChevronLeft โ—€, ChevronRight โ–ถ, Back โ†ฉ๏ธ, Forward โ†ช๏ธ, Plus โž•, Minus โž–
Project / engineering ProjectTree ๐ŸŒณ, Themes ๐ŸŽจ, Chart ๐Ÿ“Š, Domain ๐ŸŒ, Mesh ๐Ÿ•ธ๏ธ, Boundary ๐Ÿงฑ

๐Ÿ› ๏ธ Getting Started

Prerequisites

  • C++17/20 Compiler: A compiler that supports C++17/20 (e.g., GCC, Clang, MSVC).
  • CMake: Version 3.15 or higher.
  • FTXUI: A terminal UI library that TUIKit is built upon.
  • nlohmann/json: For JSON parsing, used in .tuik file handling.

Building the Project

  1. Clone the repository:

    git clone https://github.com/skhelladi/TUIKit.git
    cd TUIKit
  2. Install dependencies:

    You can install all dependencies and build the project in one step using the provided script:

    ./install.sh

    Or manually:

    • Install FTXUI: You need to clone it into the external/ftxui directory:
    git clone https://github.com/ArthurSonzogni/FTXUI.git external/ftxui
    • Install nolmann/json for JSON parsing into external/json:
    wget https://github.com/nlohmann/json/releases/download/v3.12.0/json.hpp -P external/json
  3. Create a build directory and configure CMake:

    mkdir build
    cd build
    cmake ..
  4. Build the project:

    cmake --build .

Running the Example

After a successful build, you can run the examples provided in the examples directory. The build process will generate executables in the build directory.:

./build/example_1

and

./build/example_2

and the plotting demo (live curves, CSV tail, fixed ranges):

./build/example_plot

๐Ÿงช Usage Example

Here's a minimal example demonstrating how to create a simple TUI application with TUIKit, showcasing factory functions and the connect mechanism for event handling.

#include "tuikit.h"

using namespace TUIKIT;

int main() {
    TUIApp app("My Simple TUI App");

    auto main_layout = vbox();
    
    auto my_label = label("Hello from TUIKit!");
    main_layout->addWidget(my_label);

    auto my_button = button("Click Me!");
    connect(my_button, [&] {
        my_label->setText("Button Clicked!");
    });
    
    // or you can use a lambda function directly
    // my_button->onClick([]() {
    //     my_label->setText("Button Clicked!");
    // });

    main_layout->addWidget(my_button);

    app.setMainWidget(main_layout);
    return app.exec();
}

๐Ÿ“ˆ Plotting with TUIPlot

TUIPlot draws several curves on one graph, from live data (solver running) or from a CSV file read while it grows.

  • Series: addSeries(name) returns a TUIPlotSeries. Push points with append(x, y) from any thread, then call app.PostEvent(ftxui::Event::Custom) to request a repaint.
  • Curve style: setColor, setLineStyle (None, Solid, Dashed, Dotted), setLineWidth (1 to 3), setMarker (Circle, Square, Triangle, Diamond, Plus, Cross), setMarkerStride.
  • Axes: xAxis() / yAxis() with setRange(min, max) (fixed), setAutoRange() (default: data extent + 5 %), setFollowTail(width) (sliding window), setAutoLimits, setLabel, setTickFormat, setTickStep, setMajorGrid, setMinorGrid.
  • Keys, on the graph having the focus: + / - zoom, , / . pan, z reset, c crosshair then left/right, l legend, g grid.
auto p = plot("Convergence");
p->xAxis().setLabel("iteration").setFollowTail(500);
p->yAxis().setLabel("residual");
auto residuals = p->addSeries("Ux");
residuals->setLineStyle(TUIPlotLineStyle::Dashed).setMarker(TUIPlotMarker::Circle);
layout->addWidget(p);

// From a worker thread:
residuals->append(iteration, value);
app.PostEvent(ftxui::Event::Custom);

Streaming a CSV file

TUICSVTailReader follows a CSV file as it grows. The first line is either a header with the column names or data (the columns are then named col1, col2, ...). Fields are separated by ,, by ; (a comma is then read as the decimal mark) or by whitespace.

TUICSVTailReader reader("monitor.csv");
reader.setColumns("Time", "CPU");  // or setColumns(0, 1)
std::vector<std::pair<double, double>> rows;
if (reader.poll(rows)) {  // call periodically
    for (const auto& [time, load] : rows) cpu_series->append(time, load);
}

See examples/example_plot.cpp above.


๐Ÿ†• Example: Embedding a .tuik UI file

TUIKit supports embedding JSON UI definitions (.tuik files) directly into your binary using CMake and xxd.
For each .tuik file listed in TUIKIT_UI, a header <name>_tuik.h is generated with a binary variable.

Example .tuik file (examples/simple_ui.tuik):

{
  "class": "TUIVBoxLayout",
  "children": [
    { "class": "TUILabel", "properties": { "text": "Hello from .tuik!" } },
    { "class": "TUIButton", "properties": { "text": "Click Me" }, "name": "btn" }
  ]
}

C++ usage:

#include "tuikit.h"
#include "examples/simple_ui_tuik.h"
#include <nlohmann/json.hpp>

using namespace TUIKIT;

int main() {
    TUIApp app("TUI .tuik Example");

    // Load UI from embedded binary resource
    std::string tuik_str(reinterpret_cast<const char*>(simple_ui_tuik), simple_ui_tuik_len);
    nlohmann::json tuik_json = nlohmann::json::parse(tuik_str);

    TUIKLoader loader;
    auto main_ui_widget = loader.createWidgetFromJson(tuik_json);
    app.setMainWidget(main_ui_widget);

    // Connect a slot to the button named "btn"
    auto btn = std::dynamic_pointer_cast<TUIButton>(loader.getWidget("btn"));
    if (btn) {
        connect(btn, [&] { /* action */ });
    }

    return app.exec();
}

CMake integration:

find_program(XXD_EXE xxd REQUIRED)
set(TUIKIT_UI "examples/simple_ui.tuik")
foreach(TUIK_FILE ${TUIKIT_UI})
    get_filename_component(TUIK_NAME ${TUIK_FILE} NAME_WE)
    get_filename_component(TUIK_DIR ${TUIK_FILE} DIRECTORY)
    set(VAR_NAME "${TUIK_NAME}_tuik")
    set(HEADER_FILE "${TUIK_DIR}/${TUIK_NAME}_tuik.h")
    add_custom_command(
        OUTPUT ${HEADER_FILE}
        COMMAND ${CMAKE_COMMAND} -E make_directory ${TUIK_DIR}
        COMMAND ${XXD_EXE} -i -n ${VAR_NAME} ${TUIK_FILE} > ${HEADER_FILE}
        DEPENDS ${TUIK_FILE}
        COMMENT "Generate ${HEADER_FILE} from ${TUIK_FILE} with variable ${VAR_NAME} (xxd required)"
        VERBATIM
    )
    list(APPEND EMBEDDED_HEADERS ${HEADER_FILE})
endforeach()
add_custom_target(generate_embedded_headers ALL DEPENDS ${EMBEDDED_HEADERS})

๐Ÿค Contributing

Contributions are welcome! Please refer to the CONTRIBUTING.md file (to be created) for guidelines on how to contribute to TUIKit.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

TUIKit is a C++ framework designed to build rich and interactive Terminal/Text User Interfaces (TUIs).

Topics

Resources

Stars

56 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages