Skip to content

JayTwoLab/FTXUI_Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FTXUI Demo Project

A lightweight, cross-platform C++ Terminal User Interface (TUI) application demonstrating asynchronous thread management and event handling using the FTXUI library.

This project showcases how to safely separate the main application logic, the UI rendering loop, and background worker tasks (such as timers) using atomic variables.

Features

  • Thread Separation: Run UI rendering, background timers, and main application processes on independent threads without blocking each other.
  • Asynchronous State Shared via Atomics: Safe communication between threads using std::atomic within a structured payload (ThreadArgs).
  • Interactive TUI: Features a clickable button, dynamic counters, and a conditional confirmation modal layout.
  • Smooth Exit Sequence: Custom input handling to prompt a modern "Do you want to exit?" overlay before gracefully joining all threads.
  • Cross-Platform & UTF-8 Ready: Built-in Windows console code page configurations for clean UTF-8 text rendering.

Prerequisites

Before building the project, ensure you have the following installed:

  • C++17 Compiler (MSVC, GCC, or Clang)
  • CMake (version 3.26 or higher)
  • Ninja (Recommended build generator)
  • vcpkg (C++ Package Manager)

Project Structure

├── CMakeLists.txt        # Core CMake build configuration
├── CMakePresets.json     # Configuration presets for Ninja & vcpkg toolchain
├── vcpkg.json            # Project dependencies declaration (FTXUI)
├── main.cpp              # Application entry point & thread architecture
├── .gitignore            # Git ignore rules for modern C++ IDEs
└── LICENSE               # MIT License


How it Works (Architecture)

The program orchestrates three distinct operational scopes:

  1. Main Thread: Initializes the shared atomic state, spawns the UI thread, and handles high-level application lifecycle monitoring.
  2. UI Thread (RunUIThread): Drives the main FTXUI ScreenInteractive loop, captures user keyboard/mouse events, and renders the layout.
  3. Timer Thread: A background worker spawned inside the UI block that increments a value every 5 seconds without bottlenecking frame renders or input detection.

Building and Running

The project leverages CMake Presets combined with vcpkg manifest mode to automate dependency installation.

Note

Update the "CMAKE_TOOLCHAIN_FILE" path inside CMakePresets.json to match your local vcpkg directory before configuring.

1. Configure the Project

Run the configuration step using the included Windows preset:

cmake --preset windows-base

2. Build the Executable

Compile the binary using the generated build files:

cmake --build --preset windows-base

The compiled executable will be located in the out/build/windows-base/ directory as ftxui_demo.


Controls

  • Mouse Click: Click the "Click me!" button to increment the click counter.
  • Ctrl + Q: Trigger the exit confirmation overlay.
  • Y / y: (Inside Modal) Confirm exit and safely close the application.
  • N / n / ESC: (Inside Modal) Cancel exit and return to the main dashboard.

License

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

About

FTXUI Demo

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors