FTXUI

ArthurSonzogniMIT活跃维护

用 C++ 函数式风格写终端界面,像搭积木一样组合组件,省去手写 ANSI 转义和 curses 的麻烦。

:computer: C++ Functional Terminal User Interface. :heart:

v7.0.3发布于 2026-08-06 07:35 UTC10,880star +6 / 7 天626fork同步于 2026-11-10 17:29 UTC

怎么上手

由 README 提炼,执行前请确认
include(FetchContent)
FetchContent_Declare(ftxui
  GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
  GIT_TAG v7.0.3
)
FetchContent_MakeAvailable(ftxui)
target_link_libraries(your_target PRIVATE ftxui::ftxui)
硬件要求按 README 说明

README 未说明,纯终端库无 GPU/显存要求;支持 Linux/MacOS、Windows 与 WebAssembly。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

跨平台 C++ 终端 UI 库,用函数式风格快速搭建带交互的 TUI 界面

用 C++ 函数式风格写终端界面,像搭积木一样组合组件,省去手写 ANSI 转义和 curses 的麻烦。

核心能力

  • 用 hbox/vbox/gridbox/flexbox 组合式布局构建界面
  • 提供 screen、dom、component 三层模块,含组件与事件主循环
  • 支持键盘与鼠标导航
  • 支持 UTF8 与全角字符渲染
  • 支持动画与 Canvas 绘制,且无第三方依赖

容易踩的坑

手动链接时 ftxui-component 必须排在其他 FTXUI 库之前;README 推荐用 CMake FetchContent 并锁定具体 tag 版本;C++20 Modules 与单头文件(Amalgamated)用法需另查专门文档。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v7.0.3
  1. v7.0.3最新正式版2026-08-06 · 2026-08-06 07:35 UTC

    Component

    • Bugfix: Fix incorrect mouse position in non-alternate-screen modes. The cursor position request (used to convert mouse coordinates from screen space to frame space) could be sent asynchronously, after the cursor had already moved away from the frame's origin, causing the terminal's reply to be misread as the wrong offset. Regressed by the 7.0.2 throttle fix, which made the request's 500ms throttle actually engage for the first time. See #1310.
  2. v7.0.22026-08-01 · 2026-08-01 16:40 UTC
    查看更新说明

    Component

    • Bugfix: Fix high CPU usage (app and terminal emulator, e.g. tmux) caused by a cursor position request/reply feedback loop redrawing the screen at ~60fps in the non-alternate-screen modes. See #1302.
    • Animation frames are now produced only when requested via animation::RequestAnimationFrame() (e.g. by animation::Animator), as in FTXUI 6. Receiving an event no longer implicitly triggers an animation frame.
    • Bugfix: App::PostEvent is now thread safe again, as documented. Since the 7.0.0 event loop rework it pushed into an unsynchronized buffer, racing with the main loop when called from another thread.
    • Bugfix: Fix unbounded memory growth in the event buffer. A receiver used during terminal setup was kept for the whole App lifetime, retaining every subsequent event (including every mouse move).

    Dom

    • Performance: text computes its requirement once and renders only the visible lines. This makes scrolling a large text inside a frame significantly faster. Thanks @patlefort. See #1309.
    • Performance: text selection now only visits and stores the selected line range, instead of scanning and allocating one entry per line of the whole text on every frame.
  3. v7.0.12026-07-14 · 2026-07-14 12:12 UTC
    查看更新说明

    Minor release to fix bugs introduced by v7.0.0

    Screen

    • Bugfix: Restore TrueColor support on Windows Terminal (default to TrueColor on Windows and check WT_SESSION environment variable for WSL compatibility). See #1305.
    • Feature: Honor the NO_COLOR environment variable (https://no-color.org). When set and non-empty, colors degrade to the terminal's default colors.
    • Bugfix: Apple's Terminal.app (TERM_PROGRAM=Apple_Terminal) is now reported as Palette256 instead of TrueColor; it does not support 24bit colors.
    • Bugfix: An empty terminal name or terminal emulator name is now treated as unidentified by Terminal::ComputeColorSupport, instead of implying TrueColor support.
    • Bugfix (Windows): Downgrade color support when the console rejects VT processing (legacy consoles), instead of emitting TrueColor escape sequences.
    • Bugfix: Avoid segmentation fault / crash during static initialization if Color::RGB or other color constants are constructed globally/statically before main(). See #1303.

    Build

    • Bugfix: Fix build failure when an older FTXUI is installed in a system include path (e.g. MacPorts upgrade). A CMake deduplication quirk was promoting the project's own -I include/ to -isystem, causing package managers' -I/opt/local/include (which may contain stale headers) to win. See #1299, #1300.
  4. v7.0.02026-06-13 · 2026-06-13 21:50 UTC
    查看更新说明

    7.0.0 (2026-06-13)

    Doc

    • Fix broken Doxygen output. See @markmandel in #1029.
    • Use Doxygen awesome. Add our own theme.
    • Break the documentation into several pages.

    Build

    • Feature: Support amalgamated version. This provides a single-header (ftxui.hpp) and single-source (ftxui.cpp) version of the library, as well as a truly single-file header-only version (ftxui_all.hpp). This is the easiest way to vendor FTXUI into your project. See #1252.
    • Feature: Support umbrella header and target. Usage:
      #include <ftxui/ftxui.hpp>
      
      CMake: target_link_libraries(your_target PRIVATE ftxui::ftxui) Bazel: deps = ["@ftxui//:ftxui"] See #1252.
    • Feature: Support C++20 modules. This requires:
      • Using the Ninja or MSVC generator
      • A recent Clang/GCC/MSVC compiler.
      • Cmake 3.28 or higher. Usage:
      import ftxui;
      import ftxui.component;
      import ftxui.dom;
      import ftxui.screen;
      import ftxui.util;
      
      Thanks @mikomikotaishi for PR #1015.
    • Consolidate C++20 code into named modules to reduce compile times and improve flexibility. Thanks @mikomikotaishi in #1221.
    • Feature: Support Meson build system. Thanks @mintonmu in #1259.
    • Remove dependency on 'pthread'.
    • Bugfix: Bazel target @ftxui is now visible. Thanks @dskkato in #1157.
    • ABI: Explicitly size all public enums to uint8_t for ABI layout stability.
    • ABI: Add reserved virtual methods to Screen and Node for future extensibility without breaking ABI.

    General

    • Breaking (Renames):

      • Pixel is renamed to Cell.
      • Image is renamed to Surface.
      • ScreenInteractive is renamed to App.
      • PixelAt method is renamed to CellAt. Compatibility aliases and headers are provided to avoid breaking existing code.
    • Breaking. Move to std::string_view instead of const std::string& where applicable. This yields better interoperability with string literals and avoids unnecessary copies. Thanks @mikomikotaishi for PR #1154

    Component

    • Feature: Improved signal handling. Upgrade signal interception to use POSIX sigaction for robust signal masking and cleanup handler preservation. Protect against double terminal restoration on exit using atomic raw-state tracking. Add support for additional POSIX signals (SIGBUS, SIGSYS as crash signals, and SIGQUIT, SIGHUP as deferred termination signals) and fix async-signal-safety issues in crash paths.
    • Bugfix: Fix Input cursor visibility when using a custom Renderer on nested containers. See #1220. Thanks @nmarks99.
    • Fix Input cursor positioning and scroll stability. See #1196. Thanks @739C1AE2.
    • Fix Input support for non-ASCII characters in password mode. See #1196. Thanks @739C1AE2.
    • Performance: Mitigate cursor flickering during redraw in App. See #1196. Thanks @739C1AE2.
    • Feature: POSIX Piped Input Handling.
      • Allows FTXUI applications to read data from stdin (when piped) while still receiving keyboard input from the terminal.
      • Enabled by default.
      • Can be disabled using App::HandlePipedInput(false).
      • Only available on Linux and macOS. Thanks @HarryPehkonen for PR #1094.
    • Fix App::FixedSize screen stomps on the preceding terminal output. Thanks @zozowell in #1064.
    • Fix vertical ftxui::Slider. The "up" key was previously decreasing the value. Thanks @its-pablo in #1093 for reporting the issue.
    • Fix Windows UTF-16 key input handling. Emoji and other code points outside the Basic Multilingual Plane (BMP) are now correctly processed. Thanks @739C1AE2 in #1160 for fixing the issue.
    • Fix Input style is now colorschem agnostic. Thanks @Smail in #1170 for reporting and fixing the issue.
    • Fix App::Post(..) is now thread safe. Thanks @739C1AE2 in ~1183 for reporting the issue. This regressed in non released versions.

    Dom

    • Feature: Support newline \n within text() and vtext(). Thanks
  5. v6.1.92025-05-07 · 2025-05-07 20:49 UTC
    查看更新说明

    Build

    If all goes well (pending), ftxui should appear in the Bazel central repository. It can be imported into your project using the following lines:

    MODULE.bazel

    bazel_dep(name = "ftxui", version = "6.1.9")
    

    Thanks @robinlinden and @kcc for the reviews.

    dom

    • Bugfix: Restore the dbox behavior from ftxui 5.0.0. To apply bgcolor blending between the two layers, a new dboxBlend will be added.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    FTXUI

    Functional Terminal (X) User interface

    A simple cross-platform C++ library for terminal based user interfaces!

    [!TIP] Check out RTXUI, my other project. It is a different, experimental TUI library based on reactive HTML/CSS/C++: structure with semantic HTML, style with real CSS (flexbox, grid, transitions), and bind plain C++ state. Live demo.

    Feature

    Documentation

    Example

    #include <ftxui/ftxui.hpp>
    using namespace ftxui;
    
    int main() {
      auto document =
        vbox({
          hbox({
            text("one") | border,
            text("two") | border | flex,
            text("three") | border | flex,
          }),
    
          gauge(0.25) | color(Color::Red),
          gauge(0.50) | color(Color::White),
          gauge(0.75) | color(Color::Blue),
        });
    
      auto screen = Screen::Create(Dimension::Full());
      Render(screen, document);
      screen.Print();
    
      return 0;
    }
    

    image

    Short gallery

    FTXUI is organized into three modules:

    1. screen: Low-level rendering (colors, pixels, terminal)
    2. dom: Layout and composition (hierarchical elements)
    3. component: User interaction (widgets, events, main loop)

    For most users, including everything at once is the simplest way to start:

    • Header: #include <ftxui/ftxui.hpp>
    • CMake target: ftxui::ftxui
    • Bazel target: @ftxui//:ftxui
    DOM

    This module defines a hierarchical set of Element. An Element manages layout and can be responsive to the terminal dimensions.

    They are declared in <ftxui/dom/elements.hpp>

    Element can be arranged together:

    • horizontally with hbox
    • vertically with vbox
    • inside a grid with gridbox
    • wrap along one direction using the flexbox.

    Element can become flexible using the flex decorator.

    Example using hbox, vbox and filler.

    image

    Example using gridbox:

    image

    Example using flexbox:

    image

    See also this demo.

    An element can be decorated using the functions:

    • bold
    • italic
    • dim
    • inverted
    • underlined
    • underlinedDouble
    • blink
    • strikethrough
    • color
    • bgcolor
    • hyperlink

    Example

    image

    FTXUI supports the pipe operator. It means: decorator1(decorator2(element)) and element | decorator1 | decorator2 can be used.

    FTXUI supports every color palette:

    Color gallery: image

    Use decorator border and element separator() to subdivide your UI:

    Element document = vbox({
        text("top"),
        separator(),
        text("bottom"),
    }) | border;
    
    

    Demo:

    image

    A simple piece of text is represented using text("content").

    To support text wrapping following spaces the following functions are provided:

    Element paragraph(string text);
    Element paragraphAlignLeft(string text);
    Element paragraphAlignRight(string text);
    Element paragraphAlignCenter(string text);
    Element paragraphAlignJustify(string text);
    

    Paragraph example

    ezgif com-gif-maker (4)

    A class to easily style a table of data.

    Example:

    image

    Drawing can be made on a Canvas, using braille, block, or simple characters:

    Simple example:

    image

    Complex examples:

    ezgif com-gif-maker (3)

    Component

    ftxui/component produces dynamic UI, reactive to the user's input. It defines a set of ftxui::Component. A component reacts to Events (keyboard, mouse, resize, ...) and Renders as an Element (see previous section).

    Prebuilt components are declared in <ftxui/component/component.hpp>

    Gallery of multiple components. (demo)

    image

    Example:

    image

    Example:

    image

    Example:

    image

    Example:

    image

    Example:

    image

    Example:

    image

    Example:

    ezgif com-gif-maker

    Example:

    youtube-video-gif (3)

    Vertical:

    ezgif com-gif-maker (1)

    Horizontal:

    ezgif com-gif-maker (2)

    Libraries for FTXUI

    Project using FTXUI

    Feel free to add your projects here:


    cpp-best-practices/game_jam

    Several games using the FTXUI have been made during the Game Jam:

    Build using CMake

    It is highly recommended to use CMake FetchContent to depend on FTXUI so you may specify which commit you would like to depend on.

    include(FetchContent)
    FetchContent_Declare(ftxui
      GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
      GIT_TAG v7.0.3
    )
    FetchContent_MakeAvailable(ftxui)
    
    target_link_libraries(your_target PRIVATE
        # Use the umbrella target (recommended)
        ftxui::ftxui
    
        # Or chose a submodule
        # ftxui::component
        # ftxui::dom
        # ftxui::screen
    )
    

    Build using Bazel

    MODULE.bazel

    bazel_dep(
        name = "ftxui",
        version = "7.0.3",
    )
    

    BUILD.bazel

    cc_binary(
        name = "your_target",
        srcs = ["your_source.cc"],
        deps = [
            # Choose submodules
            "@ftxui//:component",
            "@ftxui//:dom",
            "@ftxui//:screen",
            
            # Or use the single ftxui target (includes all modules)
            # "@ftxui//:ftxui",
        ],
    )
    

    Build using Meson

    FTXUI can also be built using Meson. See doc/installation_meson.md for detailed instructions.

    meson setup builddir
    ninja -C builddir
    

    To use FTXUI as a subproject in your Meson project, create a subprojects/ftxui.wrap file or use it as a dependency:

    ftxui_dep = dependency('ftxui-component')
    

    Build with something else:

    If you don't, FTXUI may be used from the following packages:

    Packaging status

    If you choose to build and link FTXUI yourself, ftxui-component must be first in the linking order relative to the other FTXUI libraries, i.e.

    g++ . . . -lftxui-component -lftxui-dom -lftxui-screen . . .
    

    To build FTXUI with modules, check documentation

    Contributors