Easily Create Tables in Terminal with C++
A C++ library that facilitates the development of your TUI applications.
TUI (Terminal User Interface) applications are growing day by day. And for you to display table data in the terminal with colors and other features, for C++ developers there is one more library that is very simple to use: Tabulate .
Installation
To use Tabulate in your applications, just install it on your system and for that you will need the following dependencies:
Usually C++ programmers already have them all installed, but just in case… 😃
After that, just clone and install with the following commands:
Usage
There are several ways to apply Tabulate in your code, however, the most basic way would be:
- Include library:
#include <tabulate/table.hpp>
- Use namespace directly or with using:
using namespace tabulate;
- Instantiate the class:
Table table;
- And use the code as needed.
In this basic example we print two cells with predefined widths as desired:
vim main.cpp
To compile you don’t need any additional flag, example:
Possible output:
Note that to print the table you must use std::cout << table_name << '\n';
. And to add features, formatting, colors and others you can do union in your class instance, for example adding color would be: table[0][0].format().font_color(Color::yellow);
, in this case according to the example above the [0][0]
indicates that the output of the cell on the left will now be colored yellow .
More examples
For a more detailed example you can use the samples/ directory, example:
The possible output will be:
If you want to uninstall Tabulate, run:
For more examples and information visit the official repository .
Comments