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.
- 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::atomicwithin 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.
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)
├── 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
The program orchestrates three distinct operational scopes:
- Main Thread: Initializes the shared atomic state, spawns the UI thread, and handles high-level application lifecycle monitoring.
- UI Thread (
RunUIThread): Drives the main FTXUIScreenInteractiveloop, captures user keyboard/mouse events, and renders the layout. - Timer Thread: A background worker spawned inside the UI block that increments a value every 5 seconds without bottlenecking frame renders or input detection.
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.
Run the configuration step using the included Windows preset:
cmake --preset windows-base
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.
- 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.
This project is licensed under the MIT License - see the LICENSE file for details.