FTXUI  0.8.1
C++ functional terminal UI.
examples/dom/color_gallery.cpp
#include <ftxui/screen/color_info.hpp> // for ColorInfo
#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/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
int main(int argc, const char* argv[]) {
// clang-format off
auto basic_color_display =
text("16 color palette:"),
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"))
),
bgcolor(Color::Default, text("Default")),
bgcolor(Color::GrayDark, text("GrayDark")),
bgcolor(Color::GrayLight, text("GrayLight")),
bgcolor(Color::BlueLight, text("BlueLight")),
bgcolor(Color::CyanLight, text("CyanLight")),
bgcolor(Color::GreenLight, text("GreenLight")),
bgcolor(Color::Magenta, text("Magenta")),
bgcolor(Color::MagentaLight, text("MagentaLight")),
bgcolor(Color::RedLight, text("RedLight")),
bgcolor(Color::Yellow, text("Yellow")),
bgcolor(Color::YellowLight, text("YellowLight"))
)
)
);
// clang-format on
auto palette_256_color_display = text("256 colors palette:");
{
std::vector<std::vector<ColorInfo>> info_columns = ColorInfoSorted2D();
Elements columns;
for (auto& column : info_columns) {
Elements column_elements;
for (auto& it : column) {
column_elements.push_back(
text(" ") | bgcolor(Color(Color::Palette256(it.index_256))));
}
columns.push_back(hbox(std::move(column_elements)));
}
palette_256_color_display = vbox({
palette_256_color_display,
vbox(columns),
});
}
// True color display.
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("▀") //
| color(Color::HSV(hue, saturation, value)) //
| bgcolor(Color::HSV(hue, saturation, value + 8)));
}
array.push_back(hbox(std::move(line)));
}
true_color_display = vbox({
true_color_display,
vbox(std::move(array)),
});
}
auto terminal_info =
vbox({
? text(" 16 color palette support : Yes")
: text(" 16 color palette support : No"),
? text("256 color palette support : Yes")
: text("256 color palette support : No"),
? text(" True color support : Yes")
: text(" True color support : No"),
}) |
auto document = vbox({hbox({
basic_color_display,
text(" "),
palette_256_color_display,
text(" "),
true_color_display,
}),
terminal_info});
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}
// 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.
ftxui::Terminal::ColorSupport
Color ColorSupport()
Definition: terminal.cpp:81
ftxui::border
Element border(Element)
Draw a border around the element.
Definition: border.cpp:138
ftxui::Color::Green
@ Green
Definition: color.hpp:42
ftxui::Terminal::Palette16
@ Palette16
Definition: terminal.hpp:15
ftxui::Color::Red
@ Red
Definition: color.hpp:41
ftxui
Definition: captured_mouse.hpp:6
node.hpp
ftxui::Terminal::TrueColor
@ TrueColor
Definition: terminal.hpp:17
ftxui::color
Decorator color(Color)
Decorate using a foreground color.
Definition: color.cpp:86
ftxui::Color::Magenta
@ Magenta
Definition: color.hpp:45
ftxui::Color::MagentaLight
@ MagentaLight
Definition: color.hpp:53
ftxui::Color::Palette256
Palette256
Definition: color.hpp:58
ftxui::hbox
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition: hbox.cpp:75
terminal.hpp
ftxui::Color::Yellow
@ Yellow
Definition: color.hpp:43
ftxui::separator
Element separator(void)
Definition: separator.cpp:54
ftxui::Color::YellowLight
@ YellowLight
Definition: color.hpp:51
ftxui::Color::GrayDark
@ GrayDark
Definition: color.hpp:48
ftxui::Elements
std::vector< Element > Elements
Definition: elements.hpp:16
ftxui::Color::CyanLight
@ CyanLight
Definition: color.hpp:54
elements.hpp
ftxui::Color::RedLight
@ RedLight
Definition: color.hpp:49
ftxui::Color::GreenLight
@ GreenLight
Definition: color.hpp:50
ftxui::Color::Blue
@ Blue
Definition: color.hpp:44
ftxui::Dimension::Fit
Dimensions Fit(Element &)
Definition: util.cpp:71
ftxui::Color::HSV
static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value)
Build a Color from its HSV representation. https://en.wikipedia.org/wiki/HSL_and_HSV.
Definition: color.cpp:122
ftxui::bgcolor
Decorator bgcolor(Color)
Decorate using a background color.
Definition: color.cpp:100
ftxui::Terminal::Color
Color
Definition: terminal.hpp:13
ftxui::Color::Black
@ Black
Definition: color.hpp:40
ftxui::vbox
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition: vbox.cpp:76
ftxui::Screen::Create
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition: screen.cpp:115
ftxui::Color::GrayLight
@ GrayLight
Definition: color.hpp:47
color.hpp
ftxui::Terminal::Palette256
@ Palette256
Definition: terminal.hpp:16
ftxui::Dimension::Full
Dimensions Full()
Definition: screen.cpp:103
ftxui::Render
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
Definition: node.cpp:34
ftxui::Color::BlueLight
@ BlueLight
Definition: color.hpp:52
ftxui::Color::Default
@ Default
Definition: color.hpp:36
color_info.hpp
screen.hpp
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition: text.cpp:106
ftxui::Color::Cyan
@ Cyan
Definition: color.hpp:46
ftxui::Color::White
@ White
Definition: color.hpp:55