FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/dom/table.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <ftxui/dom/elements.hpp> // for color, Fit, LIGHT, align_right, bold, DOUBLE
5#include <ftxui/dom/table.hpp> // for Table, TableSelection
6#include <ftxui/screen/screen.hpp> // for Screen
7#include <iostream> // for endl, cout, ostream
8#include <string> // for basic_string, allocator, string
9#include <vector> // for vector
10
11#include "ftxui/dom/node.hpp" // for Render
12#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::White, ftxui
13
14int main() {
15 using namespace ftxui;
16
17 auto table = Table({
18 {"Version", "Marketing name", "Release date", "API level", "Runtime"},
19 {"2.3", "Gingerbread", "February 9 2011", "10", "Dalvik 1.4.0"},
20 {"4.0", "Ice Cream Sandwich", "October 19 2011", "15", "Dalvik"},
21 {"4.1", "Jelly Bean", "July 9 2012", "16", "Dalvik"},
22 {"4.2", "Jelly Bean", "November 13 2012", "17", "Dalvik"},
23 {"4.3", "Jelly Bean", "July 24 2013", "18", "Dalvik"},
24 {"4.4", "KitKat", "October 31 2013", "19", "Dalvik and ART"},
25 {"5.0", "Lollipop", "November 3 2014", "21", "ART"},
26 {"5.1", "Lollipop", "March 9 2015", "22", "ART"},
27 {"6.0", "Marshmallow", "October 5 2015", "23", "ART"},
28 {"7.0", "Nougat", "August 22 2016", "24", "ART"},
29 {"7.1", "Nougat", "October 4 2016", "25", "ART"},
30 {"8.0", "Oreo", "August 21 2017", "26", "ART"},
31 {"8.1", "Oreo", "December 5 2017", "27", "ART"},
32 {"9", "Pie", "August 6 2018", "28", "ART"},
33 {"10", "10", "September 3 2019", "29", "ART"},
34 {"11", "11", "September 8 2020", "30", "ART"},
35 });
36
37 table.SelectAll().Border(LIGHT);
38
39 // Add border around the first column.
40 table.SelectColumn(0).Border(LIGHT);
41
42 // Make first row bold with a double border.
43 table.SelectRow(0).Decorate(bold);
44 table.SelectRow(0).SeparatorVertical(LIGHT);
45 table.SelectRow(0).Border(DOUBLE);
46
47 // Align right the "Release date" column.
48 table.SelectColumn(2).DecorateCells(align_right);
49
50 // Select row from the second to the last.
51 auto content = table.SelectRows(1, -1);
52 // Alternate in between 3 colors.
53 content.DecorateCellsAlternateRow(color(Color::Blue), 3, 0);
54 content.DecorateCellsAlternateRow(color(Color::Cyan), 3, 1);
55 content.DecorateCellsAlternateRow(color(Color::White), 3, 2);
56
57 auto document = table.Render();
58 auto screen =
59 Screen::Create(Dimension::Fit(document, /*extend_beyond_screen=*/true));
60 Render(screen, document);
61 screen.Print();
62 std::cout << std::endl;
63
64 return 0;
65}
void Border(BorderStyle border=LIGHT)
Apply a border around the selection.
int main()
TableSelection SelectAll()
Select all the table.
Table is a utility to draw tables.
Definition table.hpp:36
The FTXUI ftxui:: namespace.
Definition animation.hpp:10