Update examples to use std::string. (#182)

In examples and tests, use std::string.

In addtion:
1. Address follow-up from:
https://github.com/ArthurSonzogni/FTXUI/pull/179
2. Fix a bug when Input is used with std::string.
This commit is contained in:
Arthur Sonzogni
2021-08-09 00:27:37 +02:00
committed by GitHub
parent 3b4ab618a3
commit 9a54528bca
60 changed files with 817 additions and 836 deletions

View File

@@ -1,31 +1,30 @@
#include <ftxui/dom/elements.hpp> // for operator|, vbox, border, Element, hbox
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, operator|, vbox, border, Element, Fit, hbox
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = //
hbox({
vbox({
text(L"Line 1"),
text(L"Line 2"),
text(L"Line 3"),
text("Line 1"),
text("Line 2"),
text("Line 3"),
}) | border,
vbox({
text(L"Line 4"),
text(L"Line 5"),
text(L"Line 6"),
text("Line 4"),
text("Line 5"),
text("Line 6"),
}) | border,
vbox({
text(L"Line 7"),
text(L"Line 8"),
text(L"Line 9"),
text("Line 7"),
text("Line 8"),
text("Line 9"),
}) | border,
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));

View File

@@ -1,14 +1,13 @@
#include <ftxui/screen/color_info.hpp> // for ColorInfo
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/screen/terminal.hpp> // for Terminal, Terminal::Color, Terminal::Palette16, Terminal::Palette256, Terminal::TrueColor
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <ftxui/screen/terminal.hpp> // for ColorSupport, Color, Palette16, Palette256, TrueColor
#include <memory> // for allocator, shared_ptr
#include <utility> // for move
#include <vector> // for vector
using namespace ftxui;
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for bgcolor, color, vbox, hbox, separator, operator|, Elements, Element, border
#include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, hbox, separator, operator|, Elements, Element, Fit, border
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::White, Color::Yellow, Color::YellowLight, Color::Palette256, ftxui
@@ -16,52 +15,52 @@ int main(int argc, const char* argv[]) {
// clang-format off
auto basic_color_display =
vbox(
text(L"16 color palette:"),
text("16 color palette:"),
separator(),
hbox(
vbox(
color(Color::Default, text(L"Default")),
color(Color::Black, text(L"Black")),
color(Color::GrayDark, text(L"GrayDark")),
color(Color::GrayLight, text(L"GrayLight")),
color(Color::White, text(L"White")),
color(Color::Blue, text(L"Blue")),
color(Color::BlueLight, text(L"BlueLight")),
color(Color::Cyan, text(L"Cyan")),
color(Color::CyanLight, text(L"CyanLight")),
color(Color::Green, text(L"Green")),
color(Color::GreenLight, text(L"GreenLight")),
color(Color::Magenta, text(L"Magenta")),
color(Color::MagentaLight, text(L"MagentaLight")),
color(Color::Red, text(L"Red")),
color(Color::RedLight, text(L"RedLight")),
color(Color::Yellow, text(L"Yellow")),
color(Color::YellowLight, text(L"YellowLight"))
color(Color::Default, text("Default")),
color(Color::Black, text("Black")),
color(Color::GrayDark, text("GrayDark")),
color(Color::GrayLight, text("GrayLight")),
color(Color::White, text("White")),
color(Color::Blue, text("Blue")),
color(Color::BlueLight, text("BlueLight")),
color(Color::Cyan, text("Cyan")),
color(Color::CyanLight, text("CyanLight")),
color(Color::Green, text("Green")),
color(Color::GreenLight, text("GreenLight")),
color(Color::Magenta, text("Magenta")),
color(Color::MagentaLight, text("MagentaLight")),
color(Color::Red, text("Red")),
color(Color::RedLight, text("RedLight")),
color(Color::Yellow, text("Yellow")),
color(Color::YellowLight, text("YellowLight"))
),
vbox(
bgcolor(Color::Default, text(L"Default")),
bgcolor(Color::Black, text(L"Black")),
bgcolor(Color::GrayDark, text(L"GrayDark")),
bgcolor(Color::GrayLight, text(L"GrayLight")),
bgcolor(Color::White, text(L"White")),
bgcolor(Color::Blue, text(L"Blue")),
bgcolor(Color::BlueLight, text(L"BlueLight")),
bgcolor(Color::Cyan, text(L"Cyan")),
bgcolor(Color::CyanLight, text(L"CyanLight")),
bgcolor(Color::Green, text(L"Green")),
bgcolor(Color::GreenLight, text(L"GreenLight")),
bgcolor(Color::Magenta, text(L"Magenta")),
bgcolor(Color::MagentaLight, text(L"MagentaLight")),
bgcolor(Color::Red, text(L"Red")),
bgcolor(Color::RedLight, text(L"RedLight")),
bgcolor(Color::Yellow, text(L"Yellow")),
bgcolor(Color::YellowLight, text(L"YellowLight"))
bgcolor(Color::Default, text("Default")),
bgcolor(Color::Black, text("Black")),
bgcolor(Color::GrayDark, text("GrayDark")),
bgcolor(Color::GrayLight, text("GrayLight")),
bgcolor(Color::White, text("White")),
bgcolor(Color::Blue, text("Blue")),
bgcolor(Color::BlueLight, text("BlueLight")),
bgcolor(Color::Cyan, text("Cyan")),
bgcolor(Color::CyanLight, text("CyanLight")),
bgcolor(Color::Green, text("Green")),
bgcolor(Color::GreenLight, text("GreenLight")),
bgcolor(Color::Magenta, text("Magenta")),
bgcolor(Color::MagentaLight, text("MagentaLight")),
bgcolor(Color::Red, text("Red")),
bgcolor(Color::RedLight, text("RedLight")),
bgcolor(Color::Yellow, text("Yellow")),
bgcolor(Color::YellowLight, text("YellowLight"))
)
)
);
// clang-format on
auto palette_256_color_display = text(L"256 colors palette:");
auto palette_256_color_display = text("256 colors palette:");
{
std::vector<std::vector<ColorInfo>> info_columns = ColorInfoSorted2D();
Elements columns;
@@ -69,7 +68,7 @@ int main(int argc, const char* argv[]) {
Elements column_elements;
for (auto& it : column) {
column_elements.push_back(
text(L" ") | bgcolor(Color(Color::Palette256(it.index_256))));
text(" ") | bgcolor(Color(Color::Palette256(it.index_256))));
}
columns.push_back(hbox(std::move(column_elements)));
}
@@ -81,14 +80,14 @@ int main(int argc, const char* argv[]) {
}
// True color display.
auto true_color_display = text(L"TrueColors: 24bits:");
auto true_color_display = text("TrueColors: 24bits:");
{
int saturation = 255;
Elements array;
for (int value = 0; value < 255; value += 16) {
Elements line;
for (int hue = 0; hue < 255; hue += 6) {
line.push_back(text(L"") //
line.push_back(text("") //
| color(Color::HSV(hue, saturation, value)) //
| bgcolor(Color::HSV(hue, saturation, value + 8)));
}
@@ -104,22 +103,22 @@ int main(int argc, const char* argv[]) {
auto terminal_info =
vbox({
Terminal::ColorSupport() >= Terminal::Color::Palette16
? text(L" 16 color palette support : Yes")
: text(L" 16 color palette support : No"),
? text(" 16 color palette support : Yes")
: text(" 16 color palette support : No"),
Terminal::ColorSupport() >= Terminal::Color::Palette256
? text(L"256 color palette support : Yes")
: text(L"256 color palette support : No"),
? text("256 color palette support : Yes")
: text("256 color palette support : No"),
Terminal::ColorSupport() >= Terminal::Color::TrueColor
? text(L" True color support : Yes")
: text(L" True color support : No"),
? text(" True color support : Yes")
: text(" True color support : No"),
}) |
border;
auto document = vbox({hbox({
basic_color_display,
text(L" "),
text(" "),
palette_256_color_display,
text(L" "),
text(" "),
true_color_display,
}),
terminal_info});

View File

@@ -1,15 +1,12 @@
#include <ftxui/dom/elements.hpp> // for bgcolor, hbox, operator|, Elements, vbox, Element
#include <ftxui/dom/elements.hpp> // for text, bgcolor, hbox, operator|, Elements, Fit, vbox, Element
#include <ftxui/screen/color_info.hpp> // for ColorInfo
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <string> // for allocator, string
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <utility> // for move
#include <vector> // for vector
#include <vector> // for vector, allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Palette256
#include "ftxui/screen/string.hpp" // for to_wstring
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Palette256
using namespace ftxui;
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D
@@ -23,8 +20,8 @@ int main(int argc, const char* argv[]) {
Elements column_elements;
for (auto& it : column) {
column_elements.push_back(hbox({
text(L" ") | bgcolor(Color(Color::Palette256(it.index_256))),
text(to_wstring(std::string(it.name))),
text(" ") | bgcolor(Color(Color::Palette256(it.index_256))),
text(it.name),
}));
}
columns_elements.push_back(vbox(std::move(column_elements)));

View File

@@ -1,12 +1,11 @@
#include <ftxui/dom/elements.hpp> // for operator|, Elements, bgcolor, color, hbox, vbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for operator|, Elements, Fit, bgcolor, color, hbox, text, vbox, Element
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include <utility> // for move
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color
int main(int argc, const char* argv[]) {
using namespace ftxui;
@@ -16,7 +15,7 @@ int main(int argc, const char* argv[]) {
for (int value = 0; value < 255; value += 20) {
Elements line;
for (int hue = 0; hue < 255; hue += 2) {
line.push_back(text(L"") //
line.push_back(text("") //
| color(Color::HSV(hue, saturation, value)) //
| bgcolor(Color::HSV(hue, saturation, value + 10)));
}

View File

@@ -1,12 +1,11 @@
#include <ftxui/dom/elements.hpp> // for hbox, bgcolor, operator|, vbox, Elements, window, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for hbox, text, bgcolor, operator|, vbox, Elements, window, Element, Fit
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include <utility> // for move
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color
int main(int argc, const char* argv[]) {
using namespace ftxui;
@@ -21,26 +20,26 @@ int main(int argc, const char* argv[]) {
for (int value = 0; value < 255; value += 3) {
int v = value * value / 255;
red_line.push_back(text(L" ") | bgcolor(Color::RGB(v, 0, 0)));
green_line.push_back(text(L" ") | bgcolor(Color::RGB(0, v, 0)));
blue_line.push_back(text(L" ") | bgcolor(Color::RGB(0, 0, v)));
cyan_line.push_back(text(L" ") | bgcolor(Color::RGB(0, v, v)));
magenta_line.push_back(text(L" ") | bgcolor(Color::RGB(v, 0, v)));
yellow_line.push_back(text(L" ") | bgcolor(Color::RGB(v, v, 0)));
red_line.push_back(text(" ") | bgcolor(Color::RGB(v, 0, 0)));
green_line.push_back(text(" ") | bgcolor(Color::RGB(0, v, 0)));
blue_line.push_back(text(" ") | bgcolor(Color::RGB(0, 0, v)));
cyan_line.push_back(text(" ") | bgcolor(Color::RGB(0, v, v)));
magenta_line.push_back(text(" ") | bgcolor(Color::RGB(v, 0, v)));
yellow_line.push_back(text(" ") | bgcolor(Color::RGB(v, v, 0)));
}
auto document = vbox({
window(text(L"Primary colors"),
window(text("Primary colors"),
vbox({
hbox({text(L"Red line :"), hbox(std::move(red_line))}),
hbox({text(L"Green line :"), hbox(std::move(green_line))}),
hbox({text(L"Blue line :"), hbox(std::move(blue_line))}),
hbox({text("Red line :"), hbox(std::move(red_line))}),
hbox({text("Green line :"), hbox(std::move(green_line))}),
hbox({text("Blue line :"), hbox(std::move(blue_line))}),
})),
window(text(L"Secondary colors"),
window(text("Secondary colors"),
vbox({
hbox({text(L"cyan line :"), hbox(std::move(cyan_line))}),
hbox({text(L"magenta line:"), hbox(std::move(magenta_line))}),
hbox({text(L"Yellow line :"), hbox(std::move(yellow_line))}),
hbox({text("cyan line :"), hbox(std::move(cyan_line))}),
hbox({text("magenta line:"), hbox(std::move(magenta_line))}),
hbox({text("Yellow line :"), hbox(std::move(yellow_line))}),
})),
});

View File

@@ -1,22 +1,21 @@
#include <ftxui/dom/elements.hpp> // for operator|, border, Element, vbox, center, dbox
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, operator|, border, Element, vbox, center, Fit, dbox
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = dbox({
vbox({
text(L"line_1"),
text(L"line_2"),
text(L"line_3"),
text(L"line_4"),
text(L"line_5"),
text("line_1"),
text("line_2"),
text("line_3"),
text("line_4"),
text("line_5"),
}) | border,
text(L"overlay") | border | center,
text("overlay") | border | center,
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);

View File

@@ -1,13 +1,12 @@
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/dom/elements.hpp> // for gauge, operator|, flex, hbox, Element
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/dom/elements.hpp> // for text, gauge, operator|, flex, hbox, Element
#include <ftxui/screen/screen.hpp> // for Screen
#include <iostream> // for cout, endl, ostream
#include <string> // for allocator, operator+, char_traits, operator<<, to_wstring, basic_string, string, wstring
#include <string> // for allocator, operator+, char_traits, operator<<, string, to_string, basic_string
#include <thread> // for sleep_for
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
@@ -15,12 +14,12 @@ int main(int argc, const char* argv[]) {
std::string reset_position;
for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) {
std::wstring data_downloaded =
std::to_wstring(int(percentage * 5000)) + L"/5000";
std::string data_downloaded =
std::to_string(int(percentage * 5000)) + "/5000";
auto document = hbox({
text(L"downloading:"),
text("downloading:"),
gauge(percentage) | flex,
text(L" " + data_downloaded),
text(" " + data_downloaded),
});
auto screen = Screen(100, 1);
Render(screen, document);

View File

@@ -1,20 +1,18 @@
#include <stddef.h> // for size_t
#include <ftxui/dom/elements.hpp> // for operator|, size, Element, hcenter, Decorator, WIDTH, hflow, window, EQUAL, GREATER_THAN, HEIGHT, bold, border, dim, LESS_THAN
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/screen/string.hpp> // for to_wstring
#include <ftxui/dom/elements.hpp> // for operator|, size, Element, text, hcenter, Decorator, Fit, WIDTH, hflow, window, EQUAL, GREATER_THAN, HEIGHT, bold, border, dim, LESS_THAN
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator, shared_ptr
#include <string> // for operator+, char_traits, wstring
#include <string> // for operator+, to_string, char_traits, string
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto make_box = [](size_t dimx, size_t dimy) {
std::wstring title = to_wstring(dimx) + L"x" + to_wstring(dimy);
std::string title = std::to_string(dimx) + "x" + std::to_string(dimy);
return window(text(title) | hcenter | bold,
text(L"content") | hcenter | dim) |
text("content") | hcenter | dim) |
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy);
};

View File

@@ -1,12 +1,11 @@
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <iostream> // for cout, ostream
#include <memory> // for allocator, shared_ptr
#include <string> // for operator<<, string
#include <thread> // for sleep_for
#include "ftxui/dom/deprecated.hpp" // for paragraph, text
#include "ftxui/dom/elements.hpp" // for operator|, Element, border, color, hflow, spinner, vbox, bold, dim, underlined
#include "ftxui/dom/elements.hpp" // for paragraph, text, operator|, Element, border, color, hflow, spinner, vbox, bold, dim, underlined
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Red
@@ -15,34 +14,34 @@ int main(int argc, const char* argv[]) {
using namespace ftxui;
using namespace std::chrono_literals;
auto img1 = []() { return text(L"img") | border; };
auto img2 = []() { return vbox({text(L"big"), text(L"image")}) | border; };
auto img1 = []() { return text("img") | border; };
auto img2 = []() { return vbox({text("big"), text("image")}) | border; };
std::string reset_position;
for (int i = 0;; ++i) {
auto document = //
hflow(
paragraph(L"Hello world! Here is an image:"), img1(),
paragraph(L" Here is a text "), text(L"underlined ") | underlined,
paragraph(L" Here is a text "), text(L"bold ") | bold,
paragraph(L"Hello world! Here is an image:"), img2(),
paragraph("Hello world! Here is an image:"), img1(),
paragraph(" Here is a text "), text("underlined ") | underlined,
paragraph(" Here is a text "), text("bold ") | bold,
paragraph("Hello world! Here is an image:"), img2(),
paragraph(
L"Le Lorem Ipsum est simplement du faux texte employé dans la "
L"composition et la mise en page avant impression. Le Lorem "
L"Ipsum est le faux texte standard de l'imprimerie depuis les "
L"années 1500, quand un imprimeur anonyme assembla ensemble "
L"des morceaux de texte pour réaliser un livre spécimen de "
L"polices de texte. Il n'a pas fait que survivre cinq siècles, "
L"mais s'est aussi adapté à la bureautique informatique, sans "
L"que son contenu n'en soit modifié. Il a été popularisé dans "
L"les années 1960 grâce à la vente de feuilles Letraset "
L"contenant des passages du Lorem Ipsum, et, plus récemment, "
L"par son inclusion dans des applications de mise en page de "
L"texte, comme Aldus PageMaker."),
paragraph(L" Here is a text "), text(L"dim ") | dim,
paragraph(L"Hello world! Here is an image:"), img1(),
paragraph(L" Here is a text "), text(L"red ") | color(Color::Red),
paragraph(L" A spinner "), spinner(6, i / 10)) |
"Le Lorem Ipsum est simplement du faux texte employé dans la "
"composition et la mise en page avant impression. Le Lorem "
"Ipsum est le faux texte standard de l'imprimerie depuis les "
"années 1500, quand un imprimeur anonyme assembla ensemble "
"des morceaux de texte pour réaliser un livre spécimen de "
"polices de texte. Il n'a pas fait que survivre cinq siècles, "
"mais s'est aussi adapté à la bureautique informatique, sans "
"que son contenu n'en soit modifié. Il a été popularisé dans "
"les années 1960 grâce à la vente de feuilles Letraset "
"contenant des passages du Lorem Ipsum, et, plus récemment, "
"par son inclusion dans des applications de mise en page de "
"texte, comme Aldus PageMaker."),
paragraph(" Here is a text "), text("dim ") | dim,
paragraph("Hello world! Here is an image:"), img1(),
paragraph(" Here is a text "), text("red ") | color(Color::Red),
paragraph(" A spinner "), spinner(6, i / 10)) |
border;
auto screen = Screen::Create(Dimension::Full());

View File

@@ -1,43 +1,41 @@
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/dom/elements.hpp> // for operator|, Element, hbox, bold, color, filler, separator, vbox, window, gauge, size, dim, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <ftxui/screen/string.hpp> // for to_wstring
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, hbox, bold, color, filler, separator, vbox, window, gauge, Fit, size, dim, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <iostream> // for cout, endl, ostream
#include <list> // for list, operator!=, _List_iterator, _List_iterator<>::_Self
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
#include <string> // for wstring, operator<<, string
#include <string> // for string, operator<<, to_string
#include <thread> // for sleep_for
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Green, Color::Red, Color::RedLight
int main(int argc, const char* argv[]) {
using namespace ftxui;
struct Task {
std::wstring name;
std::string name;
int number_of_threads;
int downloaded;
int size;
};
std::list<Task> remaining_tasks = {
{L"contact server ", 10, 0, 6 * 25},
{L"download index.html ", 10, 0, 9 * 25},
{L"download script.js ", 1, 0, 3 * 25},
{L"download style.js ", 1, 0, 4 * 25},
{L"download image.png ", 1, 0, 5 * 25},
{L"download big_1.png ", 1, 0, 30 * 25},
{L"download icon_1.png ", 1, 0, 7 * 25},
{L"download icon_2.png ", 1, 0, 8 * 25},
{L"download big_2.png ", 1, 0, 30 * 25},
{L"download small_1.png ", 1, 0, 10 * 25},
{L"download small_2.png ", 1, 0, 11 * 25},
{L"download small_3.png ", 1, 0, 12 * 25},
{"contact server ", 10, 0, 6 * 25},
{"download index.html ", 10, 0, 9 * 25},
{"download script.js ", 1, 0, 3 * 25},
{"download style.js ", 1, 0, 4 * 25},
{"download image.png ", 1, 0, 5 * 25},
{"download big_1.png ", 1, 0, 30 * 25},
{"download icon_1.png ", 1, 0, 7 * 25},
{"download icon_2.png ", 1, 0, 8 * 25},
{"download big_2.png ", 1, 0, 30 * 25},
{"download small_1.png ", 1, 0, 10 * 25},
{"download small_2.png ", 1, 0, 11 * 25},
{"download small_3.png ", 1, 0, 12 * 25},
};
std::list<Task> displayed_task;
@@ -49,7 +47,7 @@ int main(int argc, const char* argv[]) {
int nb_done = 0;
auto to_text = [](int number) {
return text(to_wstring(number)) | size(WIDTH, EQUAL, 3);
return text(std::to_string(number)) | size(WIDTH, EQUAL, 3);
};
auto renderTask = [&](const Task& task) {
@@ -58,7 +56,7 @@ int main(int argc, const char* argv[]) {
text(task.name) | style,
separator(),
to_text(task.downloaded),
text(L"/"),
text("/"),
to_text(task.size),
separator(),
gauge(task.downloaded / float(task.size)),
@@ -68,20 +66,20 @@ int main(int argc, const char* argv[]) {
auto renderSummary = [&]() {
auto summary = vbox({
hbox({
text(L"- done: "),
text("- done: "),
to_text(nb_done) | bold,
}) | color(Color::Green),
hbox({
text(L"- active: "),
text("- active: "),
to_text(nb_active) | bold,
}) | color(Color::RedLight),
hbox({
text(L"- queue: "),
text("- queue: "),
to_text(nb_queued) | bold,
}) | color(Color::Red),
});
return window(text(L" Summary "), summary);
return window(text(" Summary "), summary);
};
auto render = [&]() {
@@ -91,7 +89,7 @@ int main(int argc, const char* argv[]) {
return vbox({
// List of tasks.
window(text(L" Task "), vbox(std::move(entries))),
window(text(" Task "), vbox(std::move(entries))),
// Summary.
hbox({

View File

@@ -1,16 +1,15 @@
#include <stdio.h> // for getchar
#include <ftxui/dom/elements.hpp> // for operator|, hflow, border, Element, hbox, flex, vbox
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <string> // for allocator, wstring
#include <stdio.h> // for getchar
#include <ftxui/dom/elements.hpp> // for operator|, hflow, paragraph, border, Element, hbox, flex, vbox
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <string> // for allocator, string
#include "ftxui/dom/deprecated.hpp" // for paragraph
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
std::wstring p =
LR"(In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule) describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if cancer is related to age, then, using Bayes' theorem, a person's age can be used to more accurately assess the probability that they have cancer, compared to the assessment of the probability of cancer made without knowledge of the person's age. One of the many applications of Bayes' theorem is Bayesian inference, a particular approach to statistical inference. When applied, the probabilities involved in Bayes' theorem may have different probability interpretations. With the Bayesian probability interpretation the theorem expresses how a subjective degree of belief should rationally change to account for availability of related evidence. Bayesian inference is fundamental to Bayesian statistics.)";
std::string p =
R"(In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule) describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if cancer is related to age, then, using Bayes' theorem, a person's age can be used to more accurately assess the probability that they have cancer, compared to the assessment of the probability of cancer made without knowledge of the person's age. One of the many applications of Bayes' theorem is Bayesian inference, a particular approach to statistical inference. When applied, the probabilities involved in Bayes' theorem may have different probability interpretations. With the Bayesian probability interpretation the theorem expresses how a subjective degree of belief should rationally change to account for availability of related evidence. Bayesian inference is fundamental to Bayesian statistics.)";
auto document = vbox({
hbox({

View File

@@ -1,23 +1,22 @@
#include <ftxui/dom/elements.hpp> // for center, separator, operator|, flex, Element, vbox, hbox, border
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, center, separator, operator|, flex, Element, vbox, Fit, hbox, border
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = hbox({
text(L"left-column"),
text("left-column"),
separator(),
vbox({
center(text(L"right-top")) | flex,
center(text("right-top")) | flex,
separator(),
center(text(L"bottom-bottom")),
center(text("bottom-bottom")),
}) | flex,
separator(),
text(L"right-column"),
text("right-column"),
}) |
border;
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));

View File

@@ -1,24 +1,22 @@
#include <ftxui/dom/elements.hpp> // for operator|, Element, hcenter, hbox, size, window, Elements, bold, dim, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <ftxui/screen/string.hpp> // for to_wstring
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, hcenter, Fit, hbox, size, window, Elements, bold, dim, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Screen
#include <memory> // for allocator, shared_ptr
#include <string> // for wstring
#include <string> // for string, to_string
#include <utility> // for move
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto make_box = [](const std::wstring title) {
auto make_box = [](const std::string& title) {
return window(text(title) | hcenter | bold,
text(L"content") | hcenter | dim);
text("content") | hcenter | dim);
};
Elements content;
for (int x = 3; x < 30; ++x) {
content.push_back(make_box(to_wstring(x)) | size(WIDTH, EQUAL, x));
content.push_back(make_box(std::to_string(x)) | size(WIDTH, EQUAL, x));
}
auto document = hbox(std::move(content));

View File

@@ -1,16 +1,14 @@
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/dom/elements.hpp> // for Element, operator|, separator, filler, hbox, size, spinner, vbox, bold, border, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <ftxui/screen/string.hpp> // for to_wstring
#include <ftxui/dom/elements.hpp> // for Element, operator|, separator, filler, hbox, size, spinner, text, vbox, bold, border, Fit, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <iostream> // for cout, endl, ostream
#include <string> // for operator<<, string
#include <string> // for to_string, operator<<, string
#include <thread> // for sleep_for
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
@@ -24,7 +22,7 @@ int main(int argc, const char* argv[]) {
entries.push_back(separator());
entries.push_back( //
hbox({
text(to_wstring(i)) | size(WIDTH, EQUAL, 2),
text(std::to_string(i)) | size(WIDTH, EQUAL, 2),
separator(),
spinner(i, index) | bold,
}));

View File

@@ -1,18 +1,17 @@
#include <ftxui/dom/elements.hpp> // for operator|, blink, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, operator|, blink, Fit, hbox, Element
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = //
hbox({
text(L"This text is "),
text(L"blink") | blink,
text(L". Do you like it?"),
text("This text is "),
text("blink") | blink,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);

View File

@@ -1,18 +1,17 @@
#include <ftxui/dom/elements.hpp> // for operator|, bold, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, operator|, bold, Fit, hbox, Element
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = //
hbox({
text(L"This text is "),
text(L"bold") | bold,
text(L". Do you like it?"),
text("This text is "),
text("bold") | bold,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);

View File

@@ -1,10 +1,9 @@
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for bgcolor, color, vbox, filler, hbox
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, Fit, filler, hbox
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::White, Color::Yellow, Color::YellowLight
int main(int argc, const char* argv[]) {
@@ -13,42 +12,42 @@ int main(int argc, const char* argv[]) {
auto document =
hbox(
vbox(
color(Color::Default, text(L"Default")),
color(Color::Black, text(L"Black")),
color(Color::GrayDark, text(L"GrayDark")),
color(Color::GrayLight, text(L"GrayLight")),
color(Color::White, text(L"White")),
color(Color::Blue, text(L"Blue")),
color(Color::BlueLight, text(L"BlueLight")),
color(Color::Cyan, text(L"Cyan")),
color(Color::CyanLight, text(L"CyanLight")),
color(Color::Green, text(L"Green")),
color(Color::GreenLight, text(L"GreenLight")),
color(Color::Magenta, text(L"Magenta")),
color(Color::MagentaLight, text(L"MagentaLight")),
color(Color::Red, text(L"Red")),
color(Color::RedLight, text(L"RedLight")),
color(Color::Yellow, text(L"Yellow")),
color(Color::YellowLight, text(L"YellowLight"))
color(Color::Default, text("Default")),
color(Color::Black, text("Black")),
color(Color::GrayDark, text("GrayDark")),
color(Color::GrayLight, text("GrayLight")),
color(Color::White, text("White")),
color(Color::Blue, text("Blue")),
color(Color::BlueLight, text("BlueLight")),
color(Color::Cyan, text("Cyan")),
color(Color::CyanLight, text("CyanLight")),
color(Color::Green, text("Green")),
color(Color::GreenLight, text("GreenLight")),
color(Color::Magenta, text("Magenta")),
color(Color::MagentaLight, text("MagentaLight")),
color(Color::Red, text("Red")),
color(Color::RedLight, text("RedLight")),
color(Color::Yellow, text("Yellow")),
color(Color::YellowLight, text("YellowLight"))
),
vbox(
bgcolor(Color::Default, text(L"Default")),
bgcolor(Color::Black, text(L"Black")),
bgcolor(Color::GrayDark, text(L"GrayDark")),
bgcolor(Color::GrayLight, text(L"GrayLight")),
bgcolor(Color::White, text(L"White")),
bgcolor(Color::Blue, text(L"Blue")),
bgcolor(Color::BlueLight, text(L"BlueLight")),
bgcolor(Color::Cyan, text(L"Cyan")),
bgcolor(Color::CyanLight, text(L"CyanLight")),
bgcolor(Color::Green, text(L"Green")),
bgcolor(Color::GreenLight, text(L"GreenLight")),
bgcolor(Color::Magenta, text(L"Magenta")),
bgcolor(Color::MagentaLight, text(L"MagentaLight")),
bgcolor(Color::Red, text(L"Red")),
bgcolor(Color::RedLight, text(L"RedLight")),
bgcolor(Color::Yellow, text(L"Yellow")),
bgcolor(Color::YellowLight, text(L"YellowLight"))
bgcolor(Color::Default, text("Default")),
bgcolor(Color::Black, text("Black")),
bgcolor(Color::GrayDark, text("GrayDark")),
bgcolor(Color::GrayLight, text("GrayLight")),
bgcolor(Color::White, text("White")),
bgcolor(Color::Blue, text("Blue")),
bgcolor(Color::BlueLight, text("BlueLight")),
bgcolor(Color::Cyan, text("Cyan")),
bgcolor(Color::CyanLight, text("CyanLight")),
bgcolor(Color::Green, text("Green")),
bgcolor(Color::GreenLight, text("GreenLight")),
bgcolor(Color::Magenta, text("Magenta")),
bgcolor(Color::MagentaLight, text("MagentaLight")),
bgcolor(Color::Red, text("Red")),
bgcolor(Color::RedLight, text("RedLight")),
bgcolor(Color::Yellow, text("Yellow")),
bgcolor(Color::YellowLight, text("YellowLight"))
),
filler()
);

View File

@@ -1,18 +1,17 @@
#include <ftxui/dom/elements.hpp> // for operator|, dim, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, operator|, dim, Fit, hbox, Element
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = //
hbox({
text(L"This text is "),
text(L"dim") | dim,
text(L". Do you like it?"),
text("This text is "),
text("dim") | dim,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);

View File

@@ -1,25 +1,24 @@
#include <ftxui/dom/elements.hpp> // for operator|, Element, bgcolor, color, blink, bold, dim, inverted, underlined, hbox
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, operator|, Element, bgcolor, color, blink, bold, dim, inverted, underlined, Fit, hbox
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Blue
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Blue
int main(int argc, const char* argv[]) {
using namespace ftxui;
// clang-format off
auto document =
hbox({
text(L"normal") , text(L" ") ,
text(L"bold") | bold , text(L" ") ,
text(L"dim") | dim , text(L" ") ,
text(L"inverted") | inverted , text(L" ") ,
text(L"underlined")| underlined , text(L" ") ,
text(L"blink") | blink , text(L" ") ,
text(L"color") | color(Color::Blue) , text(L" ") ,
text(L"bgcolor") | bgcolor(Color::Blue),
text("normal") , text(" ") ,
text("bold") | bold , text(" ") ,
text("dim") | dim , text(" ") ,
text("inverted") | inverted , text(" ") ,
text("underlined")| underlined , text(" ") ,
text("blink") | blink , text(" ") ,
text("color") | color(Color::Blue) , text(" ") ,
text("bgcolor") | bgcolor(Color::Blue),
});
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));

View File

@@ -1,17 +1,16 @@
#include <ftxui/dom/elements.hpp> // for operator|, inverted, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, operator|, inverted, Fit, hbox, Element
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = hbox({
text(L"This text is "),
text(L"inverted") | inverted,
text(L". Do you like it?"),
text("This text is "),
text("inverted") | inverted,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);

View File

@@ -1,18 +1,17 @@
#include <ftxui/dom/elements.hpp> // for operator|, underlined, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/dom/elements.hpp> // for text, operator|, underlined, Fit, hbox, Element
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = //
hbox({
text(L"This text is "),
text(L"underlined") | underlined,
text(L". Do you like it?"),
text("This text is "),
text("underlined") | underlined,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);

View File

@@ -1,32 +1,31 @@
#include <stdio.h> // for getchar
#include <ftxui/dom/elements.hpp> // for filler, hbox, vbox
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <ftxui/dom/elements.hpp> // for filler, text, hbox, vbox
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto document = //
vbox({
hbox({
text(L"north-west"),
text("north-west"),
filler(),
text(L"north-east"),
text("north-east"),
}),
filler(),
hbox({
filler(),
text(L"center"),
text("center"),
filler(),
}),
filler(),
hbox({
text(L"south-west"),
text("south-west"),
filler(),
text(L"south-east"),
text("south-east"),
}),
});
auto screen = Screen::Create(Dimension::Full());