Coder Social home page Coder Social logo

arthursonzogni / ftxui Goto Github PK

View Code? Open in Web Editor NEW
6.1K 64.0 372.0 18.16 MB

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

License: MIT License

CMake 2.31% C++ 97.31% Shell 0.08% Nix 0.30%
ui terminal terminal-based ascii ascii-art cpp curse xterm user-interface simple

ftxui's Introduction

Demo image

latest packaged version(s)
Documentation · Report a Bug · Examples . Request Feature · Send a Pull Request

FTXUI

Functional Terminal (X) User interface

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

Feature

  • Functional style. Inspired by [1] and React
  • Simple and elegant syntax (in my opinion)
  • Keyboard & mouse navigation.
  • Support for UTF8 and fullwidth chars (→ 测试)
  • Support for animations. Demo 1, Demo 2
  • Support for drawing. Demo
  • No dependencies
  • Cross platform: Linux/MacOS (main target), WebAssembly, Windows (Thanks to contributors!).
  • Learn by examples, and tutorials
  • Multiple packages: CMake FetchContent (preferred), vcpkg, pkgbuild, conan.
  • Good practises: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc...

Documentation

Example

    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),
    });

image

Short gallery

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>

Layout

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 the flex decorator.

Example using hbox, vbox and filler.

image

Example using gridbox:

image

Example using flexbox:

image

See also this demo.

Style

An element can be decorated using the functions:

  • bold
  • 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.

Colors

FTXUI support every color palette:

Color gallery: image

Border and separator

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

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

Demo:

image

Text and paragraph

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

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

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

Paragraph example

ezgif com-gif-maker (4)

Table

A class to easily style a table of data.

Example:

image

Canvas

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

Gallery of multiple components. (demo)

image

Radiobox

Example:

image

Checkbox

Example:

image

Input

Example:

image

Toggle

Example:

image

Slider

Example:

image

Menu

Example:

image

ResizableSplit

Example:

ezgif com-gif-maker

Dropdown

Example:

youtube-video-gif (3)

Tab

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:

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

Utilization

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 v5.0.0
)

FetchContent_GetProperties(ftxui)
if(NOT ftxui_POPULATED)
  FetchContent_Populate(ftxui)
  add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

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 . . .

Contributors

ftxui's People

Contributors

arthursonzogni avatar beiklive avatar burningenlightenment avatar clement-roblot avatar cmorganbe avatar giuseppecesarano avatar hunter-zolomon avatar hzeller avatar jansende avatar jarekpelczar avatar jdfa avatar jubalh avatar lanza avatar lefticus avatar lostincompilation avatar mauve avatar mingsheng13 avatar mr-mocap avatar nikoladucak avatar robinlinden avatar ruebled avatar scaryrawr avatar spaceim avatar stefanrvo avatar stephanroslen avatar tchaikov avatar tusharpm avatar vedantparanjape avatar vnepogodin avatar yuzukitsuru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ftxui's Issues

No option to use keyboard modifiers

Usually keyboard events are handled with keyboard modifiers (Ctrl, Alt, Shilt, their combinations, system specific modifiers).
Current keyboard event system doesn't support that, only limited amount of events with Shift modifier can be distinguished.

AFAIK there is no platform independent solution for this, but there are some platform specific ones (GetKeyState for Windows).

P.S. I can provide specialization for Windows platform if there will be specialization for any other platform.

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

Feature request: A menu of components?

It would be nice adding a Menu of components, instead of being a menu of focusable text.

This would be useful for beagle-config, which was using a group of 3 submenu.

How create the library

How do I create statistical libraries from your project files? I really want to start writing programs using your wonderful library, but I do not know how to connect it to the code as in the examples. I use VS code and OS Windows 64x

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.

Shutting down via the window X (or any other signal) doesn't allow for clean exit

When the framerwork enters the Loop, it tales over signal handlers. This would be fine if it handled them by alerting the main process loop to exit. Instead it calls some cleanup code and exits from the exception thread. We've got COM initialization and objects created on the main thread that we'd like to be able to cleanup.

Key strokes with modifiers

Hey there!
First of all, in the past three hours, upon discovering this project, I started to fall in love with it and its design. ❤️
Well done!

For my project I'd like to open a modal upon pressing CTRL-P. The modal is pretty much what you expect: A fuzzy finder for commands.

However, I failed to determine which event to check for when processing events. The example print_key_press only prints:

( 16 ) -> (special)

How can I detect that CTRL-P is being pressed?

While I am at it; how about the other modifier keys?

  • Meta (I.e. Windows-Key or Command Key on macOS)
  • Alt
  • Can we distinguish between right and left modifiers?

Support for RGB Colors

Hi !

From what I understand there's only 16 colors available in FTXUI for now. Some terminals are able to display a lot more than 16 colors though and it would be great if FTXUI could also support.

I imagine you already now much more than I do about terminal color handling but I'm putting those two link as a reference purpose.
http://jafrog.com/2013/11/23/colors-in-terminal.html
https://tforgione.fr/posts/ansi-escape-codes/
Since I didn't knew how to handle color on a terminal before reading them I figure they can also be useful to somebody else looking at this issue.

Suggested implementation :
Transforming the Color enum into a class.
Creating an enum for the color mode. So the Color instance can know if it is a basic color, a 256 color or an RGB color and print the corresponding escape code. (Only supporting RGB colors would be more elegant but I'm not certain it would work the same on every terminal)
Then, depending on how much you want the library to support older code, I can think of two ways to ensure the least amount of external code would have to be rewritten. Either having constructors for the 16 colors already available or having a static instance for each of these colors in the class.

I'd love to work on a pull request for this feature if you're okay with that !

Have a nice day !
Damien.

ps : I've began using FTXUI for a personal project and I like it a lot ! Thank you for creating it :)

character ghosting

I've noticed a behavior wherein text elements retain their prior contents across render passes.

Example

    std::string a = "this is a test of the emergency broadcast system";
    std::string b = "####";
    std::string& activeMessage = a;

    auto screen = Screen::Create(
        Dimension::Full(),
        Dimension::Full()
    );
    std::string reset_position = screen.ResetPosition();

    for(int x=0;x<2;++x) {
        auto document = vbox({
            hbox({
                text(std::wstring(activeMessage.begin(),activeMessage.end()))
            })
        });
        Render(screen, document);
        std::cout << reset_position << screen.ToString() << std::flush;
        std::this_thread::sleep_for(1s);
        activeMessage = b;
    }

This will first render

this is a test of the emergency broadcast system

and then 1 second later it will render

#### is a test of the emergency broadcast system

when I expected it to just render ####

This came to light while I was implementing a log output system inspired by #14 where I noticed the ghosting in my log output.

What am I missing here?

Unicode combining characters do not show up

It looks like unicode combining characters such as https://www.fileformat.info/info/unicode/char/0303/index.htm do not render correctly.

Modifying the example starter project as a test (see https://gist.github.com/retupmoca/68a4852a28b7cf6d2c39a90d7670212f for the full modified file), I added:

  // plain UTF-8 output of a random combining character:
  // https://www.fileformat.info/info/unicode/char/0303/index.htm
  std::cout << "done\xcc\x83:\n";

  auto summary = [&] {
    auto content = vbox({
        // converted UTF-8
        hbox({text(to_wstring(std::string("- done\xcc\x83:   "))), text(L"3") | bold}) | color(Color::Green),
        // UTF-16 / UCS-2
        hbox({text(L"- active\x0303: "), text(L"2") | bold}) | color(Color::RedLight),
        hbox({text(L"- queue:  "), text(L"9") | bold}) | color(Color::Red),
    });
    return window(text(L" Summary "), content);
  };

When I run the modified program, I see:
image

That is, the combining character renders correctly in my terminal if I directly output it, but displaying it via FTXUI does not appear to work.

Scroll a Vertical Container

I want to be able to scroll through a Vertical container during runtime. I have ideas to populate the container with messages and other various strings. With the strings being dynamically added during runtime I can't seem to figure out how to scroll the container's history after it has filled passed the screen height.

auto message_container {ftxui::Container::Vertical({})};
auto message_view_renderer {Renderer(layout, [&] {
  return vbox({
    text(L"Basic Message Viewer") | center,
      vbox({ message_container->Render() | yflex }) | border | flex
  });
})};

I would then have another process running in another thread adding new lines as they arrive.

message_container->Add(ftxui::Renderer([] {}));

Is it possible to scroll the contents of the container?

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;

handle terminal resize (SIGWINCH)

image
when I resize the terminal..
but It will redraw when new character was typed

possible fix: just add a SIGWINCH signal handler that clear the content and redraw

CMakeLists.txt issue when git is not installed or master.zip from github is used

The supplied CMakeLists.txt fails if either git is not installed or the master.zip from github is used (and therefore the unpacked source does not contain a git repository).
Change the top to:

find_package(git QUIET)
if (git_FOUND)
  execute_process(
  COMMAND git rev-list --count HEAD
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  OUTPUT_VARIABLE git_version
  OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
  set(git_version 0)
endif()

Setting git_version to 0 may not be the best solution, but at least it works.

Esc-key doesn't trigger on single press?

I'm loving FTXUI, but I'm noticing that when I try to do something like:

bool CustomComponent::OnEvent(Event event)
{
    if (Event::Escape == event)
    {
        // Never hit.
        on_exit();
        return true;
    }
}

It looks like there's a ParseESC that waits for other possible combinations with the escape key.

I'm also wondering if I just have it set up wrong...

My main loop (I'm making a launcher...):

	auto screen = ftxui::ScreenInteractive::TerminalOutput();

	tofi::Modes modes;
	modes.emplace_back(std::make_unique<tofi::modes::drun>());
	modes.emplace_back(std::make_unique<tofi::modes::run>());

	tofi::Tofi tofi{std::move(modes)};
	int exit{};
	tofi.on_exit = [&exit, &screen](int code) {
		exit = code;
		screen.ExitLoopClosure()();
	};

	screen.Loop(&tofi);

I see if I hit Esc 3 times I'll get an input of "\033\033\033", but I can't seem to get "\033".

Thanks!

on_change event does nothing in Toggle

Toggle pru_start_top;
...

pru_start_top.on_change = [this] {
    started = pru_start_top.selected;
};

Value of started doesnot change.
Does Toggle component have a on_enter event ?

I think issue is in this function definition:

bool Toggle::OnEvent(Event event) {

You forgot to call the on_change function in OnEvent function based on type of event received. Is this a mistake or design choice ?

Multipe bugs introduced with last commit

If i compile my project with cccbe5b, the produced binary starts its UI misaligned with the terminal using st terminal, in kitty terminal the UI works fine, however it crashes after handling some keyboard events

Sharing data across Tabs

I'm having trouble trying to share a variable between different tabs, once they are different classes is there a fair enough way to accomplish this?

I've tried to create a class for the data and instantiate, then assign to each class that will need it. Yet still it doesn't work.

...
Routes routes;
Checkout checkout;

Tab () {
   auto data = std::make_shared<RoutesData>();
   Add(&mainContainer);
   ...
   routes.data = &data;
   checkout.data = &data;   
}

PKGBUILD for building and installing on Arch Linux

I wrote a PKGBUILD for managing the updating and installation management from pacman on Arch Linux.

Since the build is only CMake .. and CMake --build so it is quite simple.
What is Added: Having pacman handle where they are stored, and uninstalling and updating too

The PKGBUILD -

https://github.com/adig-pkgs/ftxui-git/blob/09a3c65df13fe4cb7a2320f86b2100b936d721d4/PKGBUILD#L1-L45

It can also be pushed to the Arch User Repository, which is a community repo for packages for easy use by everyone. [*considering the repo is not just for a single person]

The https://github.com/adig-pkgs/ftxui-git can be directly pushed to AUR too, so it can be directly searched and installed with Arch's official package manager, pacman. You may push it yourself under your account if you like 😃 👍

2021-06-10_20-08

Add a grid control?

It would be great to have a control that lets you have a fixed set of rows and columns fit to a space.

Document how to enable truecolor on Windows

The code looks for the environment variable

COLORTERM

to enable true color.

Windows 10 has supported true color in the console for a while now, but FTXUI doesn't do the right thing without the environment variable set:

image

FTXUI multiple logging windows

Hi, thanks a lot for the library.
I was looking at the examples and wonder if it's possible to create multiple windows which are used solely show log information.

In short, I want to log multiple information in different windows. Is there an optimal design using this library to achieve that?

The maximum I could find is two use two windows, each one having a generic element inside which I have to keep updating the text:

Elements line;
line.push_back(text(L"possibly string stream here") | bold);

However, "text" element doesn't seem to support multiple lines with "\n".
Is there a suggestion on how to do that?

Regards.

Windows build error using msvc 142

D:\include\ftxui/screen/color.hpp(22): error C2059: syntax error: "("
D:\include\ftxui/screen/color.hpp(22): error C2091: function return function
D:\include\ftxui/screen/color.hpp(22): error C2143: syntax error: missing "," (before "|")
D:\include\ftxui/screen/color.hpp(22): error C2535: "ftxui::Color::Color(void)": Member function has been defined or declared
D:\include\ftxui/screen/color.hpp(17): note: see the declaration of "ftxui::Color::Color"
D:\include\ftxui/screen/color.hpp(22): error C2059: syntax error: "|"
D:\include\ftxui/screen/color.hpp(22): error C2059: syntax error: ")"
D:\include\ftxui/screen/color.hpp(22): error C2238: Unexpected mark is located before ";"

Add alert widget

Hey Arthur,
It would be great if there would be a alert widget, on the lines of flash() in JS. It pops up in the center of screen and alerts user and disappears on pressing a key.
If this hasn't been implemented yet and if you approve, I would like to contribute this !

Regards,
Vedant Paranjape

to_wstring may get invalid UTF-8 string sent by user intentionally

Hi, we recently tested the library through fuzzing rgb-tui, and we found out there are crashes when feeding into non-UTF8 string. I think it would be great to check it first before std::wstring to_wstring(const std::string& s).

terminate called after throwing an instance of 'std::range_error'
what(): wstring_convert::from_bytes
[1] 3142 abort (core dumped) ./rgb-tui <
m35:113;34m35;115;35m35;116;35

Make Element to be a function.

Currently we have:

using Element = std::unique_ptr<Node>();

It means an Element is not copyable. It can't be put in an initializer list either.
Instead, I think we should have used:

using Element = std::function<std::unique_ptr<Node>()>;

If we do this, then every Element become copyable. This would allow users to do:

  // old
  return window(L"window", std::move(renderWindow()));

  // new
  return window(L"window", renderWindow());

and

  // old
  return vbox(
    text("L upper"),
    text("L lower"),
  );

  // new
  return vbox({
    text("L upper"),
    text("L lower")
  });

Benefits:

  • Being able to use initializer list would make tool like clang-format able to properly format the C++ Code.
  • Not being forced to use std::move()

+CC users of the projects I know using FTXUI. (@AnisBdz, @mibli, @GiuseppeCesarano) If you have some comments, please let me know.

Note: This shouldn't break most of the users. Only the one that have defined their own Elements.
I think only https://github.com/AnisBdz/CPU will be slightly broken. I will prepare a fix for you.

Blinking in windows terminal

Thank you for the library. I use WSL and windows terminal. In this terminal, many of the examples blink excessively. For example:

issue

I think that this issue could be avoided by updating only the characters that have changed between frames. Unless this is already the case? It could also lead to better performance in other terminals. I suspect that using std::cout for the drawing might be slow. Although I haven't tested its performance compared to other standard methods.

Resizing not working on Windows Terminal, Powershell and CMD

Element document =
        hbox({
           text(L"|") | border, text(L"Welcome To Axzil V1.0") | color(Color::BlueViolet) | border | flex, text(L"|") | border
        });

auto screen = Screen::Create(
        Dimension::Full(),
        Dimension::Fit(document)
        );
Render(screen, document);
std::cout << screen.ToString() << std::endl;

Basic example code, when resizing turns into garbled text.
Is there already a fix for it or am I doing something wrong?

Build fails if this library is used in a non-git folder

So, If this library is used in a folder which is not a git repository build will fail

CMakeLists.txt

# Specify minimum cmake version required
cmake_minimum_required(VERSION 3.4)

# Download ftxui library
include(FetchContent)

set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
FetchContent_Declare(ftxui
  GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
)

FetchContent_GetProperties(ftxui)
if(NOT ftxui_POPULATED)
  FetchContent_Populate(ftxui)
  add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

# Find Threads Library
find_package( Threads )

# CMake project description and project specific settings
project(simppru-console
        VERSION 1.0
        DESCRIPTION "Console for simpPRU"
        HOMEPAGE_URL "https://github.com/VedantParanjape/simpPRU/")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")

# Set pru-gcc as the compiler

# Specify Build type
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()
  
######## SOURCES ########
# Add source files and header files
file(GLOB PROJECT_HEADERS *.hpp)
file(GLOB PROJECT_SOURCES *.cpp)
set(PROJECT_FILES
    ${PROJECT_HEADERS}
    ${PROJECT_SOURCES})

######## TARGETS ########
# Add executables
add_executable(${PROJECT_NAME}-${CMAKE_PROJECT_VERSION} ${PROJECT_FILES})
set_target_properties(${PROJECT_NAME}-${CMAKE_PROJECT_VERSION} PROPERTIES CXX_STANDARD 17)
target_include_directories(${PROJECT_NAME}-${CMAKE_PROJECT_VERSION} PUBLIC 
  $<BUILD_INTERFACE:${simppru_SOURCE_DIR}/include/console>
  $<BUILD_INTERFACE:${ftxui_SOURCE_DIR}/include>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

# Link ftxui and Thread library
target_link_libraries(${PROJECT_NAME}-${CMAKE_PROJECT_VERSION}
PRIVATE ftxui::screen
PRIVATE ftxui::dom
PRIVATE ftxui::component
${CMAKE_THREAD_LIBS_INIT}
)

Output message:

fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
CMake Error at build/_deps/ftxui-src/CMakeLists.txt:10 (project):
  VERSION "0.3." format invalid.


-- Configuring incomplete, errors occurred!

Issue is with the following line:

VERSION 0.3.${git_version}

NMAKE : fatal error U1073: don't know how to make 'lib\screen.lib'

Hello,
I am trying to build the below example with the latest MSVC but I get into this error.
Anyone knows how to fix it (full cmake and build logs below)?

[ 72%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/vbox.cpp.obj
vbox.cpp
NMAKE : fatal error U1073: don't know how to make 'lib\screen.lib'

https://arthursonzogni.com/FTXUI/doc/_2examples_2component_2homescreen_8cpp-example.html

C:\Users\snoof\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\211.7142.21\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" D:\project\crypto_amm
-- No colored compiler diagnostic set for 'MSVC' compiler.
-- ccache found and enabled
-- Conan: Automatic detection of conan settings from cmake
-- Conan: Detected VS runtime: MDd
-- Conan: Settings= -s;arch=x86_64;-s;build_type=Debug;-s;compiler=Visual Studio;-s;compiler.version=16;-s;compiler.runtime=MDd
-- Conan: checking conan executable
-- Conan: Found program C:/Users/snoof/anaconda3/Scripts/conan.exe
-- Conan: Version found Conan version 1.36.0

-- Conan executing: C:/Users/snoof/anaconda3/Scripts/conan.exe install . -s arch=x86_64 -s build_type=Debug -s compiler=Visual Studio -s compiler.version=16 -s compiler.runtime=MDd -g=cmake --build=missing -o=boost:header_only=True
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MDd
compiler.version=16
os=Windows
os_build=Windows
[options]
boost:header_only=True
[build_requires]
[env]

conanfile.txt: Installing package
Requirements
    boost/1.76.0 from 'conan-center' - Cache
    catch2/2.13.6 from 'conan-center' - Cache
    cpr/1.6.0 from 'conan-center' - Cache
    fmt/7.1.3 from 'conan-center' - Cache
    libcurl/7.69.1 from 'conan-center' - Cache
    openssl/1.1.1k from 'conan-center' - Cache
    rapidjson/1.1.0 from 'conan-center' - Cache
    spdlog/1.8.5 from 'conan-center' - Cache
    websocketpp/0.8.2 from 'conan-center' - Cache
    zlib/1.2.11 from 'conan-center' - Cache
Packages
    boost/1.76.0:524ea35a8120baabdde02483add58d81bf541327 - Cache
    catch2/2.13.6:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    cpr/1.6.0:17e89a7d9a71d16eda694469d0feeadabd149615 - Cache
    fmt/7.1.3:d057732059ea44a47760900cb5e4855d2bea8714 - Cache
    libcurl/7.69.1:0a15b3554d54d89968fdd6ac216f2471a295beb6 - Cache
    openssl/1.1.1k:d057732059ea44a47760900cb5e4855d2bea8714 - Cache
    rapidjson/1.1.0:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    spdlog/1.8.5:55db45024bed1a2d40f24c02c050b7ca72eeccf4 - Cache
    websocketpp/0.8.2:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    zlib/1.2.11:d057732059ea44a47760900cb5e4855d2bea8714 - Cache

Installing (downloading, building) binaries...
boost/1.76.0: Already installed!
catch2/2.13.6: Already installed!
fmt/7.1.3: Already installed!
openssl/1.1.1k: Already installed!
rapidjson/1.1.0: Already installed!
zlib/1.2.11: Already installed!
libcurl/7.69.1: Already installed!
spdlog/1.8.5: Already installed!
websocketpp/0.8.2: Already installed!
cpr/1.6.0: Already installed!
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generator cmake created conanbuildinfo.cmake
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
WARN: websocketpp/0.8.2: requirement openssl/1.1.1h overridden by your conanfile to openssl/1.1.1k 
WARN: websocketpp/0.8.2: requirement boost/1.74.0 overridden by your conanfile to boost/1.76.0 
-- Conan: Loading conanbuildinfo.cmake
-- Conan: Adjusting output directories
-- Conan: Using cmake targets configuration
-- Library spdlogd found C:/Users/snoof/.conan/data/spdlog/1.8.5/_/_/package/55db45024bed1a2d40f24c02c050b7ca72eeccf4/lib/spdlogd.lib
-- Library cpr found C:/Users/snoof/.conan/data/cpr/1.6.0/_/_/package/17e89a7d9a71d16eda694469d0feeadabd149615/lib/cpr.lib
-- Library fmtd found C:/Users/snoof/.conan/data/fmt/7.1.3/_/_/package/d057732059ea44a47760900cb5e4855d2bea8714/lib/fmtd.lib
-- Library libcurl found C:/Users/snoof/.conan/data/libcurl/7.69.1/_/_/package/0a15b3554d54d89968fdd6ac216f2471a295beb6/lib/libcurl.lib
-- Library libssld found C:/Users/snoof/.conan/data/openssl/1.1.1k/_/_/package/d057732059ea44a47760900cb5e4855d2bea8714/lib/libssld.lib
-- Library libcryptod found C:/Users/snoof/.conan/data/openssl/1.1.1k/_/_/package/d057732059ea44a47760900cb5e4855d2bea8714/lib/libcryptod.lib
-- Library zlib found C:/Users/snoof/.conan/data/zlib/1.2.11/_/_/package/d057732059ea44a47760900cb5e4855d2bea8714/lib/zlib.lib
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: D:/project/crypto_amm/cmake-build-debug-msvc
Building Tests. Be sure to check out test/constexpr_tests for constexpr testing
git found
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
Doxygen need to be installed to generate the doxygen documentation
-- Configuring done
-- Generating done
-- Build files have been written to: D:/project/crypto_amm/cmake-build-debug-msvc

[Finished]
====================[ Clean | Debug-MSVC ]======================================
C:\Users\snoof\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\211.7142.21\bin\cmake\win\bin\cmake.exe --build D:\project\crypto_amm\cmake-build-debug-msvc --target clean

Clean finished

====================[ Build | all | Debug-MSVC ]================================
C:\Users\snoof\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\211.7142.21\bin\cmake\win\bin\cmake.exe --build D:\project\crypto_amm\cmake-build-debug-msvc --target all
[  2%] Building CXX object test/CMakeFiles/catch_main.dir/cmake_pch.cxx.obj
cmake_pch.cxx
[  4%] Building CXX object test/CMakeFiles/catch_main.dir/catch_main.cpp.obj
catch_main.cpp
[  4%] Linking CXX static library ..\lib\catch_main.lib
[  4%] Built target catch_main
[  6%] Building CXX object test/CMakeFiles/tests.dir/cmake_pch.cxx.obj
cmake_pch.cxx
[  9%] Building CXX object test/CMakeFiles/tests.dir/tests.cpp.obj
tests.cpp
[  9%] Linking CXX executable ..\bin\tests.exe
LINK : ..\bin\tests.exe not found or not built by the last incremental link; performing full link
[  9%] Built target tests
[  9%] Building CXX object test/CMakeFiles/constexpr_tests.dir/cmake_pch.cxx.obj
cmake_pch.cxx
[ 11%] Building CXX object test/CMakeFiles/constexpr_tests.dir/constexpr_tests.cpp.obj
constexpr_tests.cpp
[ 13%] Linking CXX executable ..\bin\constexpr_tests.exe
LINK : ..\bin\constexpr_tests.exe not found or not built by the last incremental link; performing full link
[ 13%] Built target constexpr_tests
[ 13%] Building CXX object test/CMakeFiles/relaxed_constexpr_tests.dir/cmake_pch.cxx.obj
cmake_pch.cxx
[ 16%] Building CXX object test/CMakeFiles/relaxed_constexpr_tests.dir/constexpr_tests.cpp.obj
constexpr_tests.cpp
[ 18%] Linking CXX executable ..\bin\relaxed_constexpr_tests.exe
LINK : ..\bin\relaxed_constexpr_tests.exe not found or not built by the last incremental link; performing full link
[ 18%] Built target relaxed_constexpr_tests
[ 20%] Building CXX object _deps/ftxui-build/CMakeFiles/screen.dir/src/ftxui/screen/box.cpp.obj
box.cpp
[ 20%] Building CXX object _deps/ftxui-build/CMakeFiles/screen.dir/src/ftxui/screen/color.cpp.obj
color.cpp
[ 23%] Building CXX object _deps/ftxui-build/CMakeFiles/screen.dir/src/ftxui/screen/color_info.cpp.obj
color_info.cpp
[ 25%] Building CXX object _deps/ftxui-build/CMakeFiles/screen.dir/src/ftxui/screen/screen.cpp.obj
screen.cpp
[ 25%] Building CXX object _deps/ftxui-build/CMakeFiles/screen.dir/src/ftxui/screen/string.cpp.obj
string.cpp
[ 27%] Building CXX object _deps/ftxui-build/CMakeFiles/screen.dir/src/ftxui/screen/terminal.cpp.obj
terminal.cpp
[ 30%] Building CXX object _deps/ftxui-build/CMakeFiles/screen.dir/src/ftxui/screen/wcwidth.cpp.obj
wcwidth.cpp
[ 30%] Linking CXX shared library ..\..\bin\screen.dll
LINK : ..\..\bin\screen.dll not found or not built by the last incremental link; performing full link
[ 30%] Built target screen
[ 32%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/blink.cpp.obj
blink.cpp
[ 32%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/bold.cpp.obj
bold.cpp
[ 34%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/border.cpp.obj
border.cpp
[ 37%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/clear_under.cpp.obj
clear_under.cpp
[ 37%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/color.cpp.obj
color.cpp
[ 39%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/composite_decorator.cpp.obj
composite_decorator.cpp
[ 41%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/dbox.cpp.obj
dbox.cpp
[ 44%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/dim.cpp.obj
dim.cpp
[ 44%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/flex.cpp.obj
flex.cpp
[ 46%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/frame.cpp.obj
frame.cpp
[ 48%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/gauge.cpp.obj
gauge.cpp
[ 48%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/graph.cpp.obj
graph.cpp
[ 51%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/hbox.cpp.obj
hbox.cpp
[ 53%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/hflow.cpp.obj
hflow.cpp
[ 53%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/inverted.cpp.obj
inverted.cpp
[ 55%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/node.cpp.obj
node.cpp
[ 58%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/node_decorator.cpp.obj
node_decorator.cpp
[ 58%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/paragraph.cpp.obj
paragraph.cpp
[ 60%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/reflect.cpp.obj
reflect.cpp
[ 62%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/separator.cpp.obj
separator.cpp
[ 65%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/size.cpp.obj
size.cpp
[ 65%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/spinner.cpp.obj
spinner.cpp
[ 67%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/text.cpp.obj
text.cpp
[ 69%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/underlined.cpp.obj
underlined.cpp
[ 69%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/util.cpp.obj
util.cpp
[ 72%] Building CXX object _deps/ftxui-build/CMakeFiles/dom.dir/src/ftxui/dom/vbox.cpp.obj
vbox.cpp
NMAKE : fatal error U1073: don't know how to make 'lib\screen.lib'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.

[question] render only changed component

Hi, I came across this good library. I am thinking to write a coinwatch tui. mostly data source will be websocket. something like fx dashboard. is it possible to render the only box instead of whole laytout from other thread ? I see screen.Post(...) seems to render everything.

Please correct me If I am wrong, asking for suggestion best way to layout this fast ticking data.

Struggling with custom event

Hi, first of all thank you for making this amazing library !

My problem is that I can't find any example on how to trigger an screen update from an external event. My program gets json messages through a socket and my goal is to get to update the contents on the screen once a new message arrives. Right now, I have this socket receiving messages on a thread that returns a future, and to test it I'm passing the result to a paragraph. but I can't seem to be able to trigger an screen update following this example : https://arthursonzogni.com/FTXUI/doc/_2examples_2component_2homescreen_8cpp-example.html

The update seems to be triggered here. In my code I have removed the shift references since I'm not using a graph yet.

  std::thread update([&screen, &shift]() {
    for (;;) {
      using namespace std::chrono_literals;
      std::this_thread::sleep_for(0.05s);
      shift++;
      screen.PostEvent(Event::Custom);
    }
  });

Any guidance or help will be much appreciated

WideChar on GNOME Terminal

I faced a issue with text output where all text was being displayed in chinese. I could fix the problem locally by changing wstring converter to <std::codecvt_utf8<wchar_t>> in string.cpp . May i know if this is the correct way ? Thanks.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.