A C++ library for creating graphical applications in the terminal.
Introduction
FTXUI is a library for creating “graphical” applications for the terminal. It is available for GNU/Linux, Windows and macOS, as well as being able to create apps for WEB with WebAssembly.
We have some blog articles with publishing apps that were made with FTXUI:
First of all make sure you have the dependencies, which are: g++, make, cmake, ncurses and git .
For example installation in your distro we will use Ubuntu as a reference, example of installation of dependencies in Ubuntu:
Use ‘search’ in your distro’s package manager or operating system to find the corresponding package names.
Installation
The installation will only serve to facilitate the use of Intelissense from your IDE or easier local copies, we will see more details below. To install, first…
Understanding FTXUI
FTXUI has 3 Modules which are:
dom - This is the main module, mandatory even if it is a Hello, World! of life;
screen - Display the elements defined in the dom to display on the screen, also mandatory for any project;
component - This module is optional and it has components such as: user input, widgets, and so on.
Creating a basic project
Let’s create a simple project that will only print “Hello, World!” on the screen and let’s call it 01-ftxui:
Let’s add:
Example 01:
Basic Hello, World! with rounded corners.
Example of CMakeLists.txt:
Compiling and running
Optimizing repository clone when compiling
Note that the line: GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui it downloads from the repository on GitHub, but suppose you are offline, you can use the repository itself on your machine. Example:
First clone the repository to a system directory:
The installed directory won’t work because it doesn’t have a .git inside it!
If you want to save to your normal user, choose a location in /home/$USER and don’t use sudo .
Now change the corresponding line of your CMakeLists.txt and indicate the location of the repository you cloned:
To test from scratch, remove build/ and redo the process:
Another example with more than one box
If you want the box to take up the remaining space, send the output to ftxui::flex, examples:
Or all together!
Conclusion
You can still add colors, for example:
Note that for color() you can choose not to use the namespace, or if you want to specify you can also use it, in addition to also using bgcolor for inner padding.
And among several other resources such as: Button, Input, Checkbox and among many others that can be found in documentation, in addition to other examples .