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

Overview

FTXUI

travis issues license contributors

Functional Terminal (X) User interface

A simple C++ library for terminal based user interface.

Demo:

Demo image

Feature

  • Functional style. Inspired by [1] and React
  • Simple and elegant syntax (in my opinion).
  • Support for UTF8 and fullwidth chars (→ 测试)
  • No dependencies.
  • Cross platform (mostly). Linux (main target), Windows (experimental), Mac.

Example:

  vbox({
    hbox({
      text(L"left") | border,
      text(L"middle") | border | flex,
      text(L"right") | border,
    }),
    gauge(0.5) | border,
  });
┌────┐┌───────────────────────────────────────────────────────────────┐┌─────┐
│left││middle                                                         ││right│
└────┘└───────────────────────────────────────────────────────────────┘└─────┘
┌────────────────────────────────────────────────────────────────────────────┐
│██████████████████████████████████████                                      │
└────────────────────────────────────────────────────────────────────────────┘

Documentation:

Project using FTXUI

Feel free to add your projects here:

Hosted on:

Comments
  • [BUG] Input fields get random symbols like

    [BUG] Input fields get random symbols like "[B[AA1" or "B" and others pasted in on every action

    Input fields get random symbols like "[B[AA1" or "B" and others pasted in on every action like typing, using the arrow keys and moving the mouse

    opened by Creapermann 28
  • WIP: Port to Win32 and MSVC

    WIP: Port to Win32 and MSVC

    Hi,

    I really like your library, however I would like to use it for a project which currently requires windows support. So here is a quick WIP-version of a windows port.

    I am planning to do some more cleanup before this is ready to merge but sofar it looks good, however before I spend too much time cleaning up my branch I first wanted to check if you are willing to accept a windows port.

    The blocker for merging (IMHO) is that focus handling seems broken in the sense that I cannot move between checkboxes (or list items) in any of the examples. I ran the print_key_press example and pressed ⬅⬆➡⬇, this was the output I got for that:

    ( 27 91 68 ) -> (special)
    ( 27 91 65 ) -> (special)
    ( 27 91 67 ) -> (special)
    ( 27 91 66 ) -> (special)
    
    • [x] Refactor: event translation into separate file
      • currently the Console API event mapping is living inside the read_char thread lambda in screen_interactive.cpp, as this code is a bit longer than the original (which is just a oneliner) my plan is to move it to a separate function in a separate file or ifdef guarded inside event.cpp
    • [x] Bug: Focus handling not working
      • in the examples (e.g. checkbox.cpp) I can toggle the individual checkboxes but I cannot move between items, I tried to understand the focus implementation but am I unsure which keypresses would move focus between different components
    • [ ] Annoyance: Flickering
      • screen_interactive.cpp redraws the screen which causes the output to flicker (on Windows at least), I was thinking about only redrawing the screen if it has changed (i.e. dirty tracking)

    Screenshot:

    image

    opened by mauve 26
  • Feature request: Support multi-paragraph text layout

    Feature request: Support multi-paragraph text layout

    I was enjoying the amazing library when I got crazy to find out that...

    There is no proper way I can make two paragraphs (with word wrap) adjacent!

    I've tried... this:
    	auto si = ScreenInteractive::Fullscreen();
    	
    	auto ui = Renderer([]() {
    		return vbox({
    			text("... title goes here ..."),
    			hflow(paragraph("    To celebrate Dragon Boat Festival, an underwater dance performance titled Pray was aired on Henan TV last Saturday night, the first day of the holiday.")),
    			hflow(paragraph("    Featuring the goddess of Luo River – a mysterious beauty best known in the poetry of Cao Zhi during the Three Kingdoms period, the dancer Haohao He, a former synchronized swimmer, recreated the elegance of this ancient Chinese goddess.")),
    		});
    	});
    
    	si.Loop(ui);
    

    ... which spares the vertical space evenly for the two paragraphs, and this:

    	auto ui = Container::Vertical({
    		Renderer([]() { return text("... title goes here ..."); }),
    		Renderer([]() {
    			return vbox({
    				hflow(paragraph("    To celebrate Dragon Boat Festival, an underwater dance performance titled Pray was aired on Henan TV last Saturday night, the first day of the holiday.")),
    				hflow(paragraph("    Featuring the goddess of Luo River – a mysterious beauty best known in the poetry of Cao Zhi during the Three Kingdoms period, the dancer Haohao He, a former synchronized swimmer, recreated the elegance of this ancient Chinese goddess.")),
    			});
    		})
    	});
    

    ... where paragraphs collapse and only one line is visible, with a weird g at the top left corner:

    g.. title goes here ...                                                         
        To celebrate Dragon Boat Festival, an underwater dance performance titled   
        Featuring the goddess of Luo River – a mysterious beauty best known in the  
    

    And I notices this: https://github.com/ArthurSonzogni/FTXUI/issues/68#issuecomment-762807087

    So FTXUI is missing an important and very basic feature for displaying longer texts, and the solution seems not clear.

    I think a discussion about solution is needed here.

    enhancement help wanted 
    opened by Zjl37 24
  • Arrow keys not working they way they should on Microsoft terminal

    Arrow keys not working they way they should on Microsoft terminal

    When switching between input fields the arrow key sometimes paste in symbols (text doesnt anymore and mouse movement either, thats fixed). When switching between checkboxes and pressing ENTER while switching between them, the arrow keys dont work anymore either (or the switching functionallity doesnt work anymore)

    EDIT: When mouse selecting is enabled (When you can select stuff with your mouse e.g. buttons), symbols also get copied in. Just the text part was fixed in the previous fix

    opened by Creapermann 20
  • Window doesn't update on adding a element to Elements

    Window doesn't update on adding a element to Elements

    I am adding data to Elements output from a separate thread, data is added correctly, but the screen isn't updated on adding a new element, i need to move the focus area with arrow keys for the UI to update, how can i make it update everytime a new element is added to Elements output

    opened by VedantParanjape 20
  • Is it possible to have on_enter method for Toggle component?

    Is it possible to have on_enter method for Toggle component?

    Hey, is it possible to add on_enter() for toggle component? Since, this framework doesn't have buttons. Toggle is a pretty good way to emulate buttons.

    I am more than happy to contribute for this feature.

    good first issue 
    opened by VedantParanjape 13
  • on_enter callback doesn't work

    on_enter callback doesn't work

    Normally, it works well。 in ubuntu, when I use bind command to start my program based on FTXUI. the on_enter callback of input doesn,t work. like this. add "bind -x '"\C-g":<my_program>" to ~/.bashrc. so I can use 'ctrl+g' to start my program.

    opened by brokensword2018 12
  • Customize menu items

    Customize menu items

    Hello, and thanks for the lib again) Is there any built-in way to customize (i.e. change color ) particular item in menu ?

    First approach on my mind is to add MenuOptions for each entry, but it implies some changes in MenuBase. If it is a necessary feature I can later send code for review, of course if it is not already implemented.

    Thanks!

    enhancement 
    opened by MattBystrin 12
  • Windows can not be used normally

    Windows can not be used normally

    image

    std::string reset_position;
        auto document =
                ftxui::vbox({
                                    ftxui::text(L"GNU Affero General Public License v3.0") | ftxui::bold | color(ftxui::Color::Green) | ftxui::border,
                             hflow(
                                     ftxui::paragraph(L"The GNU Affero General Public License is a free, copyleft license for"
                                               L"software and other kinds of works, specifically designed to ensure"
                                               L"cooperation with the community in the case of network server software."
                                               L"The licenses for most software and other practical works are designed"
                                               L"to take away your freedom to share and change the works.  By contrast,"
                                               L"our General Public Licenses are intended to guarantee your freedom to"
                                               L"share and change all versions of a program--to make sure it remains free"
                                               L"software for all its users.\n"
                                               L"When we speak of free software, we are referring to freedom, not"
                                               L"price.  Our General Public Licenses are designed to make sure that you"
                                               L"have the freedom to distribute copies of free software (and charge for"
                                               L"them if you wish), that you receive source code or can get it if you"
                                               L"want it, that you can change the software or use pieces of it in new"
                                               L"free programs, and that you know you can do these things.  "
                                               L"Developers that use our General Public Licenses protect your rights"
                                               L"with two steps: (1) assert copyright on the software, and (2) offer"
                                               L"you this License which gives you legal permission to copy, distribute"
                                               L"and/or modify the software.")) |
                                     ftxui::border,
                     });
    
        auto screen = ftxui::Screen::Create(ftxui::Dimension::Full());
        Render(screen, document);
        std::cout << reset_position << screen.ToString() << std::flush;
        reset_position = screen.ResetPosition();
        getchar();
        return 0;
    
    opened by YuzukiTsuru 12
  • Errors when trying to build the lib

    Errors when trying to build the lib

    Hey, i m trying to build ftxui in a project(vs19) and then link the lib. Im getting unresolved external errors on the color class tho, saying smth like this: LNK2001 unresolved external symbol "class std::function<class std::shared_ptr __cdecl(class std::shared_ptr)> __cdecl ftxui::color(class ftxui::Color)" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@@[email protected]@@Z) Could this be due to the 2 files which are both named "color.cpp"?

    opened by Creapermann 11
  • Crash on exit

    Crash on exit

    Often, when exiting from main, I get this crash:

    AdminConsole.exe!std::_Iterator_base12::_Adopt_unlocked(std::_Container_proxy * _Parent_proxy=0xdddddddddddddddd) Line 1190 C++ Symbols loaded. AdminConsole.exe!std::_Iterator_base12::_Adopt_locked(std::_Container_proxy * _Parent_proxy=0xdddddddddddddddd) Line 1198 C++ Symbols loaded. AdminConsole.exe!std::_Iterator_base12::_Adopt(const std::_Container_base12 * _Parent=0x000002f48d016108) Line 1147 C++ Symbols loaded. AdminConsole.exe!std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::shared_ptrftxui::ComponentBase>>>::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::shared_ptrftxui::ComponentBase>>>(std::shared_ptrftxui::ComponentBase * _Parg=0xdddddddddddddddd, const std::_Container_base12 * _Pvector=0x000002f48d016108) Line 44 C++ Symbols loaded. AdminConsole.exe!std::_Vector_iterator<std::_Vector_val<std::_Simple_types<std::shared_ptrftxui::ComponentBase>>>::_Vector_iterator<std::_Vector_val<std::_Simple_types<std::shared_ptrftxui::ComponentBase>>>(std::shared_ptrftxui::ComponentBase *) C++ Symbols loaded. AdminConsole.exe!std::vector<std::shared_ptrftxui::ComponentBase,std::allocator<std::shared_ptrftxui::ComponentBase>>::end() Line 1486 C++ Symbols loaded. AdminConsole.exe!std::end<std::vector<std::shared_ptrftxui::ComponentBase,std::allocator<std::shared_ptrftxui::ComponentBase>>>(std::vector<std::shared_ptrftxui::ComponentBase,std::allocator<std::shared_ptrftxui::ComponentBase>> & _Cont={...}) Line 1927 C++ Symbols loaded. AdminConsole.exe!ftxui::ComponentBase::Detach() Line 139 C++ Symbols loaded. AdminConsole.exe!ftxui::ComponentBase::~ComponentBase() Line 23 C++ Symbols loaded. AdminConsole.exe!ftxui::ContainerBase::~ContainerBase() Line 23 C++ Symbols loaded. AdminConsole.exe!ftxui::ContainerBase::`scalar deleting destructor'(unsigned int) C++ Symbols loaded. AdminConsole.exe!std::_Destroy_in_placeftxui::ContainerBase(ftxui::ContainerBase & _Obj={...}) Line 313 C++ Symbols loaded. AdminConsole.exe!std::_Ref_count_obj2ftxui::ContainerBase::_Destroy() Line 2048 C++ Symbols loaded. AdminConsole.exe!std::_Ref_count_base::_Decref() Line 1110 C++ Symbols loaded. AdminConsole.exe!std::_Ptr_baseftxui::ComponentBase::_Decref() Line 1341 C++ Symbols loaded. AdminConsole.exe!std::shared_ptrftxui::ComponentBase::~shared_ptrftxui::ComponentBase() Line 1629 C++ Symbols loaded.

    opened by MichaelGoulding 11
  • Can not build with g++ 11.2

    Can not build with g++ 11.2

    After the fix in #510 I can not build with g++ 11.2, it seems to be caused by the extra braces around the map initializer. This is possibly a compiler bug, it obviously works with various other compilers. The exact version I am using is: g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)

    Anyway the extra braces are not needed as far as I can tell.

    --- src/ftxui/component/terminal_input_parser.cpp.orig	2022-11-23 11:24:10.374350457 +0100
    +++ src/ftxui/component/terminal_input_parser.cpp	2022-11-23 11:24:19.768526030 +0100
    @@ -13,7 +13,7 @@
     namespace ftxui {
     
     // NOLINTNEXTLINE
    -const std::map<std::string, std::string> g_uniformize = {{
    +const std::map<std::string, std::string> g_uniformize = {
         // Microsoft's terminal uses a different new line character for the return
         // key. This also happens with linux with the `bind` command:
         // See https://github.com/ArthurSonzogni/FTXUI/issues/337
    @@ -21,7 +21,7 @@
         {"\r", "\n"},
         // See: https://github.com/ArthurSonzogni/FTXUI/issues/508
         {std::string({8}), std::string({127})},
    -}};
    +};
     
     TerminalInputParser::TerminalInputParser(Sender<Task> out)
         : out_(std::move(out)) {}
    

    Originally posted by @megahallon in https://github.com/ArthurSonzogni/FTXUI/issues/510#issuecomment-1324839901

    opened by megahallon 2
  • Scrollable paragraph

    Scrollable paragraph

    Hello. I sincerely apologize for using issues as helpdesk but cannot figure out how to make a thing which looks trivial: scrollable paragraph frame. Meaning, I need to display quite a wall of text and want to let user to scroll it with arrows/mouse wheel. I checked the other issues and the code of git-tui and chrome-log-beautifier, but they seem to operate with lists, not paragraphs. Or there is no easy builtin way to do that, and I need to write a component for this purpose from scratch?

    image

    Thanks in advance, the library is very neat and handy!

    opened by archydragon 2
  • Improve UNIX signal handling of SIGWINCH

    Improve UNIX signal handling of SIGWINCH

    There exists a possibility of a signal occurring during a Receiver::Receive(), while a lock is held on its mutex. The lock is not released during the signal handler. If we then redraw the screen inside the signal handler via the same Sender, then we try to acquire a lock on that same mutex, which effectively halts the program.

    Let's move the code from inside the signal handler to outside of it. A simple boolean flag should be fine. We can then check for this flag in the ScreenInteractive's EventListener and perform the action there.

    NOTE: The only reason this was noticed is because I changed my project's use of FTXUI from muti-threaded to a single-threaded, custom event loop. Windows hasn't shown me this issue.

    opened by mr-mocap 3
  • Problem: Linux terminal app stops working after resizing

    Problem: Linux terminal app stops working after resizing

    Summary: Start up an FTXUI app and then begin resizing. You will quickly see that the terminal stops updating. In fact, the entire UI is now non-responsive.

    One Possible Reason: First of all, only have a single thread in your program. Second, it looks like a SIGWINCH can occur while the Receiver class is holding a lock on the mutex. If this happens, the OnResize() code tries to then Send() an Event, which ends up trying to acquire a lock on the same mutex (The original lock is still held during the signal). The process can then end up in the condition_variable's wait()... waiting on the same thread to unlock that other mutex (which, of course, it cannot).

    I've already found and implemented a solution for this, which is a rather small change.

    opened by mr-mocap 3
  • Braille and Box Characters Not Appearing

    Braille and Box Characters Not Appearing

    Hi, I was trying to run the "Canvas_Animated.cpp" file but Braille and Box characters appear as "?" blocks. Is there a solution to this?

    opened by ZclipseCode 2
  • Compiler warning triggered with -O3 flag

    Compiler warning triggered with -O3 flag

    Hello,

    FTXui has been working quite well so far. However, I just turned on -O3 and am receiving the following compilation error on Linux. Note that FTXui turns on -WError.

    ` inlined from ‘void ftxui::ScreenInteractive::SigStop()’ at /ftxui/src/ftxui/component/screen_interactive.cpp:661:7: /usr/local/include/c++/12.2.0/bits/cow_string.h:315:14: warning: ‘((std::basic_string<char, std::char_traits, std::allocator >::_Alloc_hider*)((char*)& + offsetof(std::Task, std::variant<ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::__detail::__variant::_Variant_base<ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::__detail::__variant::_Move_assign_base<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::__detail::__variant::_Copy_assign_base<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::__detail::__variant::_Move_ctor_base<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::__detail::__variant::_Copy_ctor_base<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::__detail::__variant::_Variant_storage<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::_M_u)))[4].std::basic_string::_Alloc_hider::_M_p’ may be used uninitialized [-Wmaybe-uninitialized] 315 | struct _Alloc_hider : _Alloc | ^~~~~~~~~~~~ .../ftxui/src/ftxui/component/screen_interactive.cpp: In member function ‘void ftxui::ScreenInteractive::SigStop()’: .../ftxui/src/ftxui/component/screen_interactive.cpp:661:7: note: ‘anonymous’ declared here

    661 | Post([&] { 662 | Uninstall(); 663 | std::cout << reset_cursor_position; 664 | reset_cursor_position = ""; 665 | std::cout << ResetPosition(/clear=/true); 666 | dimx_ = 0; 667 | dimy_ = 0; 668 | Flush(); 669 | std::raise(SIGTSTP); 670 | Install(); 671 | }); cc1plus: all warnings being treated as errors `

    I also note that CLion/GCC is showing an error on the lambda capture function as well ("Attempt to use a deleted function"):

    https://imgur.com/sgrRMMH.png

    bug 
    opened by WinstonPrivacy 2
Releases(v3.0.0)
Owner
Arthur Sonzogni
Love C++. - Image rendering / analysis. - Ascii art / TUI. - Games
Arthur Sonzogni
Spitfire is a basic terminal language that can exicute code via the terminal.

Spitfire is a basic terminal language that can exicute code via the terminal. It is easy to learn and runs fast, considering that its just a 300 line c++ file.

jhomas tefferson 0 Nov 18, 2021
Collection of human friendly terminal interface for git.

A collection of human friendly terminal user interface for git.

Arthur Sonzogni 73 Nov 25, 2022
ImTui: Immediate Mode Text-based User Interface

imtui ImTui is an immediate mode text-based user interface library. Supports 256 ANSI colors and mouse/keyboard input. Live demo in the browser Eventh

Georgi Gerganov 2k Nov 23, 2022
Fire for C++: Create fully functional CLIs using function signatures

Fire for C++ Fire for C++, inspired by python-fire, is a single header library that creates a command line interface from a function signature. Here's

Kristjan Kongas 439 Nov 29, 2022
A wrapper of C++ std::vector for functional programming

Say hello to functional C++ vectors A wrapper for C++ std::vector geared towards functional programming and fluent APIs. The primary focus is readabil

null 19 Jul 26, 2022
Small header only C++ library for writing multiplatform terminal applications

Terminal Terminal is small header only library for writing terminal applications. It works on Linux, macOS and Windows (in the native cmd.exe console)

Jupyter Xeus 263 Dec 1, 2022
A little UNIX-inspired terminal application for the Numworks Calculator (not using escher).

L.E. Terminal (let for short) is a little UNIX-inspired terminal for the Numworks Calculator.

Cacahuète Sans Sel 20 Aug 31, 2022
Draw sequence diagram in text from terminal.

sequence-diagram-cli Draw seqence diagram from terminal.

null 44 Nov 26, 2022
Terminal calculator made for programmers working with multiple number representations, sizes, and overall close to the bits

Programmer calculator The programmer calculator is a simple terminal tool designed to give maximum efficiency and flexibility to the programmer workin

romes 174 Nov 22, 2022
X terminal emulator rendering through OpenGL ES Compute Shaders

Zutty is a terminal emulator for the X Window System, functionally similar to several other X terminal emulators such as xterm, rxvt and countless others

Tom Szilagyi 252 Dec 3, 2022
The new Windows Terminal and the original Windows console host, all in the same place!

The new Windows Terminal and the original Windows console host, all in the same place!

Microsoft 86.2k Nov 28, 2022
n³ The unorthodox terminal file manager

n³ The unorthodox terminal file manager

Mischievous Meerkat 15.3k Nov 30, 2022
Graphs the activity of a chia harvester in a linux terminal.

Chia Harvest Graph Monitor for Chia Harvesting Introduction The chiaharvestgraph tool will graph Chia Harvesting activity in a linux terminal. Use a 2

Bram Stolk 216 Nov 10, 2022
a simple to use linux terminal

a simple to use linux terminal

notaweeb 7 Feb 17, 2022
Simple benchmark for terminal output

TermBench This is a simple timing utility you can use to see how slow your terminal program is at parsing escape-sequence-coded color output. It can b

Casey Muratori 176 Oct 19, 2022
tinytetris - 80x23 terminal tetris

tinytetris - 80x23 terminal tetris

Conor Taylor 2k Dec 1, 2022
Contour - A modern C++ Terminal Emulator

contour is a modern terminal emulator, for everyday use. It is aiming for power users with a modern feature mindset.

Contour Terminal Emulator 1k Nov 24, 2022
A C, C++ and Rust library to draw graphics with pixels in the terminal

A library to draw graphics with pixels in the terminal Who needs a GUI when you have a terminal ? Building To generate libpluto.a, run: $ make To ins

null 69 Nov 7, 2022
📺🗿 Terminal graphics for the 21st century.

???? Chafa is a command-line utility that converts all kinds of images, including animated GIFs, into sixel or ANSI/Unicode character output that can be displayed in a terminal.

Hans Petter Jansson 1.8k Nov 29, 2022