FTXUI  5.0.0
C++ functional terminal UI.
examples/dom/html_like.cpp
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/screen/screen.hpp> // for Screen
#include <iostream> // for cout, ostream
#include <string> // for allocator, operator<<, string
#include <thread> // for sleep_for
#include "ftxui/dom/elements.hpp" // for paragraph, text, operator|, Element, border, Fit, 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
int main() {
using namespace ftxui;
using namespace std::chrono_literals;
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 = //
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(),
"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)) |
auto screen = Screen::Create(Dimension::Fit(document));
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
std::this_thread::sleep_for(0.01s);
}
return 0;
}
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition: screen.cpp:388
Dimensions Fit(Element &)
Definition: util.cpp:93
Element bold(Element)
Use a bold font, for elements with more emphasis.
Definition: bold.cpp:33
Element spinner(int charset_index, size_t image_index)
Useful to represent the effect of time and/or events. This display an ASCII art "video".
Definition: spinner.cpp:282
Element underlined(Element)
Make the underlined element to be underlined.
Definition: underlined.cpp:33
Elements paragraph(std::wstring text)
Element text(std::wstring text)
Display a piece of unicode text.
Definition: text.cpp:119
Element dim(Element)
Use a light font, for elements with less emphasis.
Definition: dim.cpp:33
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition: node.cpp:47
Element hflow(Elements)
Element border(Element)
Draw a border around the element.
Definition: border.cpp:228
Decorator color(Color)
Decorate using a foreground color.
Definition: color.cpp:110
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition: vbox.cpp:83