FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
Example

border

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠します。
#include <stdlib.h> // for EXIT_SUCCESS
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = //
hbox({
vbox({
text("Line 1"),
text("Line 2"),
text("Line 3"),
}) | border,
vbox({
text("Line 4"),
text("Line 5"),
text("Line 6"),
}) | border,
vbox({
text("Line 7"),
text("Line 8"),
text("Line 9"),
}) | border,
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return EXIT_SUCCESS;
}
FTXUI ftxui:: 名前空間
Definition animation.hpp:9

border_colored

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードは、LICENSEファイルにあるMITライセンスの下で管理されています。
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, Fit, borderDouble, borderHeavy, borderLight, borderRounded, vbox
#include <ftxui/screen/screen.hpp> // for Screen
#include <iostream> // for endl, cout, ostream
#include <memory> // for allocator
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto make_boxed = [] {
return vbox({
text("borderLight") | borderStyled(LIGHT, Color::Red),
text("borderDashed") | borderStyled(DASHED, Color::Green),
text("borderHeavy") | borderStyled(HEAVY, Color::Blue),
text("borderDouble") | borderStyled(DOUBLE, Color::Yellow),
text("borderRounded") | borderStyled(ROUNDED, Color::Cyan),
});
};
auto document = hbox({
make_boxed(),
separator() | color(Color::Red),
make_boxed(),
separator() | color(Color::Red),
make_boxed(),
}) |
borderStyled(ROUNDED, Color::Red);
auto screen =
Screen::Create(Dimension::Fit(document), Dimension::Fit(document));
Render(screen, document);
screen.Print();
std::cout << std::endl;
}
Decorator borderStyled(BorderStyle style)
borderと同じですが、異なるスタイルを使用します。

border_style

Demo

// Copyright 2020 Arthur Sonzogni. 全著作権所有。
// このソースコードの使用は、以下にあるMITライセンスに準拠します。
// LICENSEファイル。
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, Fit, borderDouble, borderHeavy, borderLight, borderRounded, vbox
#include <ftxui/screen/screen.hpp> // for Screen
#include <iostream> // for endl, cout, ostream
#include <memory> // for allocator
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = vbox({
text("borderLight") | borderLight,
text("borderDashed") | borderDashed,
text("borderHeavy") | borderHeavy,
text("borderDouble") | borderDouble,
text("borderRounded") | borderRounded,
});
auto screen =
Screen::Create(Dimension::Fit(document), Dimension::Fit(document));
Render(screen, document);
screen.Print();
std::cout << std::endl;
}
Element borderDouble(Element child)
要素の周囲に二重線のボーダーを描画します。
Element borderDashed(Element child)
要素の周囲に破線のボーダーを描画します。
Element borderRounded(Element child)
要素の周囲に角の丸いボーダーを描画します。
Element borderHeavy(Element child)
要素の周囲に太いボーダーを描画します。
Element borderLight(Element child)
要素の周囲に細いボーダーを描画します。

canvas

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
#include <stdio.h> // for getchar
#include <cmath> // for cos
#include <ftxui/dom/elements.hpp> // for Fit, canvas, operator|, border, Element
#include <ftxui/screen/screen.hpp> // for Pixel, Screen
#include <vector> // for vector, allocator
#include "ftxui/dom/canvas.hpp" // for Canvas
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Blue, Color::Green, ftxui
int main() {
using namespace ftxui;
auto c = Canvas(100, 100);
c.DrawText(0, 0, "This is a canvas", [](Pixel& p) {
p.foreground_color = Color::Red;
p.underlined = true;
});
// 三角形:
c.DrawPointLine(10, 10, 80, 10, Color::Red);
c.DrawPointLine(80, 10, 80, 40, Color::Blue);
c.DrawPointLine(80, 40, 10, 10, Color::Green);
// 円(塗りつぶしなしと塗りつぶしあり):
c.DrawPointCircle(30, 50, 20);
c.DrawPointCircleFilled(40, 40, 10);
// 関数をプロット:
std::vector<int> ys(100);
for (int x = 0; x < 100; x++) {
ys[x] = int(80 + 20 * cos(x * 0.2));
}
for (int x = 0; x < 99; x++) {
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
}
auto document = canvas(&c) | border;
auto screen = Screen::Create(Dimension::Fit(document));
Render(screen, document);
screen.Print();
getchar();
return 0;
}
Element border(Element child)
要素の周囲にボーダーを描画します。
Canvasは、描画操作に関連付けられた描画可能なバッファです。
Definition canvas.hpp:36
Color foreground_color
Definition pixel.hpp:48
bool underlined
Definition pixel.hpp:32
Unicode文字とそれに関連付けられたスタイル。
Definition pixel.hpp:14

color_gallery

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
#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
#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
using namespace ftxui;
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D
int main() {
// clang-format off
auto basic_color_display =
vbox(
text("16色パレット:"),
separator(),
hbox(
vbox(
color(Color::Default, text("デフォルト")),
color(Color::Black, text("黒")),
color(Color::GrayDark, text("濃い灰色")),
color(Color::GrayLight, text("薄い灰色")),
color(Color::White, text("白")),
color(Color::Blue, text("青")),
color(Color::BlueLight, text("水色")),
color(Color::Cyan, text("シアン")),
color(Color::CyanLight, text("明るいシアン")),
color(Color::Green, text("緑")),
color(Color::GreenLight, text("明るい緑")),
color(Color::Magenta, text("マゼンタ")),
color(Color::MagentaLight, text("明るいマゼンタ")),
color(Color::Red, text("赤")),
color(Color::RedLight, text("明るい赤")),
color(Color::Yellow, text("黄")),
color(Color::YellowLight, text("明るい黄"))
),
vbox(
bgcolor(Color::Default, text("デフォルト")),
bgcolor(Color::Black, text("黒")),
bgcolor(Color::GrayDark, text("濃い灰色")),
bgcolor(Color::GrayLight, text("薄い灰色")),
bgcolor(Color::White, text("白")),
bgcolor(Color::Blue, text("青")),
bgcolor(Color::BlueLight, text("水色")),
bgcolor(Color::Cyan, text("シアン")),
bgcolor(Color::CyanLight, text("明るいシアン")),
bgcolor(Color::Green, text("緑")),
bgcolor(Color::GreenLight, text("明るい緑")),
bgcolor(Color::Magenta, text("マゼンタ")),
bgcolor(Color::MagentaLight, text("明るいマゼンタ")),
bgcolor(Color::Red, text("赤")),
bgcolor(Color::RedLight, text("明るい赤")),
bgcolor(Color::Yellow, text("黄")),
bgcolor(Color::YellowLight, text("明るい黄"))
)
)
);
// clang-format on
auto palette_256_color_display = text("256色パレット:");
{
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,
separator(),
vbox(columns),
});
}
// トゥルーカラー表示。
auto true_color_display = text("トゥルーカラー: 24ビット:");
{
const int max_value = 255;
const int value_increment = 8;
const int hue_increment = 6;
int saturation = max_value;
Elements array;
for (int value = 0; value < max_value; value += 2 * value_increment) {
Elements line;
for (int hue = 0; hue < max_value; hue += hue_increment) {
line.push_back(
text("▀") //
| color(Color::HSV(hue, saturation, value)) //
| bgcolor(Color::HSV(hue, saturation, value + value_increment)));
}
array.push_back(hbox(std::move(line)));
}
true_color_display = vbox({
true_color_display,
separator(),
vbox(std::move(array)),
});
}
auto terminal_info =
vbox({
Terminal::ColorSupport() >= Terminal::Color::Palette16
? text(" 16色パレット対応: はい")
: text(" 16色パレット対応: いいえ"),
Terminal::ColorSupport() >= Terminal::Color::Palette256
? text("256色パレット対応: はい")
: text("256色パレット対応: いいえ"),
Terminal::ColorSupport() >= Terminal::Color::TrueColor
? text(" トゥルーカラー対応: はい")
: text(" トゥルーカラー対応: いいえ"),
}) |
border;
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;
}
std::vector< std::vector< ftxui::ColorInfo > > ColorInfoSorted2D()
Colorは、ターミナルユーザーインターフェースにおける色を表すクラスです。
Definition color.hpp:25
FTXUI ftxui::Terminal::名前空間
std::vector< Element > Elements
Definition elements.hpp:22

color_info_palette256

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
#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 Full, Screen
#include <utility> // for move
#include <vector> // for vector, allocator
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Palette256, ftxui
using namespace ftxui;
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D
int main() {
std::vector<std::vector<ColorInfo>> info_columns = ColorInfoSorted2D();
// すべての列を描画
Elements columns_elements;
for (auto& column : info_columns) {
Elements column_elements;
for (auto& it : column) {
column_elements.push_back(hbox({
text(" ") | bgcolor(Color(Color::Palette256(it.index_256))),
text(it.name),
}));
}
columns_elements.push_back(vbox(std::move(column_elements)));
}
auto document = hbox(std::move(columns_elements));
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

color_truecolor_HSV

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSE ファイルに記載されている MIT ライセンスに従います。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, ftxui
int main() {
using namespace ftxui;
int saturation = 255;
Elements array;
for (int value = 0; value < 255; value += 20) {
Elements line;
for (int hue = 0; hue < 255; hue += 2) {
line.push_back(text("▀") //
| color(Color::HSV(hue, saturation, value)) //
| bgcolor(Color::HSV(hue, saturation, value + 10)));
}
array.push_back(hbox(std::move(line)));
}
auto document = vbox(std::move(array));
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

color_truecolor_RGB

Demo

// Copyright 2020 Arthur Sonzogni. 全著作権所有。
// このソースコードの使用は、
// LICENSEファイルにあるMITライセンスに準拠します。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, ftxui
int main() {
using namespace ftxui;
Elements red_line;
Elements green_line;
Elements blue_line;
Elements cyan_line;
Elements magenta_line;
Elements yellow_line;
for (int value = 0; value < 255; value += 3) {
int v = value * value / 255;
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("原色"),
vbox({
hbox({text("赤色線 :"), hbox(std::move(red_line))}),
hbox({text("緑色線 :"), hbox(std::move(green_line))}),
hbox({text("青色線 :"), hbox(std::move(blue_line))}),
})),
window(text("二次色"),
vbox({
hbox({text("シアン線 :"), hbox(std::move(cyan_line))}),
hbox({text("マゼンタ線:"), hbox(std::move(magenta_line))}),
hbox({text("黄色線 :"), hbox(std::move(yellow_line))}),
})),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}
Element window(Element title, Element content, BorderStyle border)
要素の周囲にタイトルとボーダーを持つウィンドウを描画します。

dbox

Demo

// 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 <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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = dbox({
vbox({
text("line_1"),
text("line_2"),
text("line_3"),
text("line_4"),
text("line_5"),
}) | border,
text("overlay") | border | center,
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

gauge

Demo

// Copyright 2020 Arthur Sonzogni. 無断転載を禁じます。
// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
#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, char_traits, operator+, operator<<, string, to_string, basic_string
#include <thread> // for sleep_for
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
using namespace std::chrono_literals;
std::string reset_position;
for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) {
std::string data_downloaded =
std::to_string(int(percentage * 5000)) + "/5000";
auto document = hbox({
text("downloading:"),
gauge(percentage) | flex,
text(" " + data_downloaded),
});
auto screen = Screen(100, 1);
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
std::this_thread::sleep_for(0.01s);
}
std::cout << std::endl;
}
ピクセルの長方形グリッド。
Definition screen.hpp:25

gauge_direction

Demo

// Copyright 2022 Arthur Sonzogni. All rights reserved. (日本語訳: 無断転載を禁じます。)
// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスによって管理されています。
// (Use of this source code is governed by the MIT license that can be found in the LICENSE file.)
#include <chrono> // operator""s, chrono_literals のため
#include <ftxui/dom/elements.hpp> // filler, operator|, separator, text, border, Element, vbox, vtext, hbox, center, gaugeDown, gaugeLeft, gaugeRight, gaugeUp のため
#include <ftxui/screen/screen.hpp> // Screen のため
#include <iostream> // cout, endl, ostream のため
#include <string> // allocator, operator+, operator<<, string, to_string のため
#include <thread> // sleep_for のため
#include "ftxui/dom/node.hpp" // Render のため
#include "ftxui/screen/color.hpp" // ftxui のため
int main() {
using namespace ftxui;
using namespace std::chrono_literals;
std::string reset_position;
for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) {
std::string data_downloaded =
std::to_string(int(percentage * 5000)) + "/5000";
auto gauge_up = //
hbox({
vtext("gauge vertical"),
separator(),
gaugeUp(percentage),
}) |
border;
auto gauge_down = //
hbox({
vtext("gauge vertical"),
separator(),
gaugeDown(percentage),
}) |
border;
auto gauge_right = //
vbox({
text("gauge horizontal"),
separator(),
gaugeRight(percentage),
}) |
border;
auto gauge_left = //
vbox({
text("gauge horizontal"),
separator(),
gaugeLeft(percentage),
}) |
border;
auto document = hbox({
gauge_up,
filler(),
vbox({
gauge_right,
filler(),
text(data_downloaded) | border | center,
filler(),
gauge_left,
}),
filler(),
gauge_down,
});
auto screen = Screen(32, 16);
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
std::this_thread::sleep_for(0.01s);
}
std::cout << std::endl;
}

graph

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠します。
#include <chrono> // for operator""s, chrono_literals
#include <cmath> // for sin
#include <ftxui/dom/elements.hpp> // for graph, operator|, separator, color, Element, vbox, flex, inverted, operator|=, Fit, hbox, size, border, GREATER_THAN, HEIGHT
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <functional> // for ref, reference_wrapper
#include <iostream> // for cout, ostream
#include <memory> // for shared_ptr
#include <string> // for operator<<, string
#include <thread> // for sleep_for
#include <utility> // for ignore
#include <vector> // for vector
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::BlueLight, Color::RedLight, Color::YellowLight, ftxui
class Graph {
public:
std::vector<int> operator()(int width, int height) const {
std::vector<int> output(width);
for (int i = 0; i < width; ++i) {
float v = 0;
v += 0.1f * sin((i + shift) * 0.1f); // NOLINT
v += 0.2f * sin((i + shift + 10) * 0.15f); // NOLINT
v += 0.1f * sin((i + shift) * 0.03f); // NOLINT
v *= height; // NOLINT
v += 0.5f * height; // NOLINT
output[i] = static_cast<int>(v);
}
return output;
}
int shift = 0;
};
std::vector<int> triangle(int width, int height) {
std::vector<int> output(width);
for (int i = 0; i < width; ++i) {
output[i] = i % (height - 4) + 2;
}
return output;
}
int main() {
using namespace ftxui;
using namespace std::chrono_literals;
Graph my_graph;
std::string reset_position;
for (int i = 0;; ++i) {
std::ignore = i;
auto document = hbox({
vbox({
graph(std::ref(my_graph)),
separator(),
graph(triangle) | inverted,
}) | flex,
separator(),
vbox({
graph(std::ref(my_graph)) | color(Color::BlueLight),
separator(),
graph(std::ref(my_graph)) | color(Color::RedLight),
separator(),
graph(std::ref(my_graph)) | color(Color::YellowLight),
}) | flex,
});
document |= border;
const int min_width = 40;
document |= size(HEIGHT, GREATER_THAN, min_width);
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
const auto sleep_time = 0.03s;
std::this_thread::sleep_for(sleep_time);
my_graph.shift++;
}
return 0;
}
std::vector< int > triangle(int width, int height)
return size
Definition string.cpp:1516

gridbox

Demo

// Copyright 2021 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスによって管理されています。
#include <stdio.h> // for getchar
#include <ftxui/dom/elements.hpp> // for Elements, gridbox, Fit, operator|, text, border, Element
#include <ftxui/screen/screen.hpp> // for Screen
#include <memory> // for allocator, shared_ptr
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto cell = [](const char* t) { return text(t) | border; };
auto document = //
gridbox({
{
cell("north-west"),
cell("north"),
cell("north-east"),
},
{
cell("center-west"),
gridbox({
{
cell("center-north-west"),
cell("center-north-east"),
},
{
cell("center-south-west"),
cell("center-south-east"),
},
}),
cell("center-east"),
},
{
cell("south-west"),
cell("south"),
cell("south-east"),
},
});
auto screen = Screen::Create(Dimension::Fit(document));
Render(screen, document);
screen.Print();
getchar();
return 0;
}

hflow

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
// LICENSEファイルに記載されているMITライセンスの条件に従って使用されます。
#include <stdio.h> // getcharのため
#include <ftxui/dom/elements.hpp> // operator|, size, Element, text, hcenter, Decorator, Fit, WIDTH, hflow, window, EQUAL, GREATER_THAN, HEIGHT, bold, border, dim, LESS_THAN のため
#include <ftxui/screen/screen.hpp> // Full, Screen のため
#include <string> // allocator, char_traits, operator+, to_string, string のため
#include "ftxui/dom/node.hpp" // Renderのため
#include "ftxui/screen/color.hpp" // ftxuiのため
int main() {
using namespace ftxui;
auto make_box = [](int dimx, int dimy) {
std::string title = std::to_string(dimx) + "x" + std::to_string(dimy);
return window(text(title) | hcenter | bold,
text("content") | hcenter | dim) |
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy);
};
auto style = size(WIDTH, GREATER_THAN, 20) | border |
size(HEIGHT, GREATER_THAN, 30) | size(WIDTH, LESS_THAN, 50);
auto document = hflow({
make_box(7, 7),
make_box(7, 5),
make_box(5, 7),
make_box(10, 4),
make_box(10, 4),
make_box(10, 4),
make_box(10, 4),
make_box(11, 4),
make_box(11, 4),
make_box(11, 4),
make_box(11, 4),
make_box(12, 4),
make_box(12, 5),
make_box(12, 4),
make_box(13, 4),
make_box(13, 3),
make_box(13, 3),
make_box(10, 3),
}) |
style;
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
getchar();
return 0;
}
Element make_box(int x, int y)

html_like

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスに従って行われます。
#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 = //
hflow(
paragraph("こんにちは世界!ここに画像があります:"), img1(),
paragraph(" ここにテキストがあります "), text("underlined ") | underlined,
paragraph(" ここにテキストがあります "), text("bold ") | bold,
paragraph("こんにちは世界!ここに画像があります:"), img2(),
paragraph(
"Lorem Ipsumは、印刷前の組版とレイアウトに使用される単なるダミーテキストです。Lorem Ipsumは、1500年代に匿名の印刷業者が活字見本帳を作成するためにテキストの断片を組み合わせて以来、印刷業界の標準ダミーテキストです。それは5世紀以上にわたって生き残っただけでなく、その内容が変更されることなく、電子組版にも適応しました。1960年代には、Lorem Ipsumのパッセージを含むLetrasetシートのリリースによって普及し、さらに最近では、Aldus PageMakerのようなデスクトップパブリッシングアプリケーションにそのバージョンが組み込まれています。"),
paragraph(" ここにテキストがあります "), text("dim ") | dim,
paragraph("こんにちは世界!ここに画像があります:"), img1(),
paragraph(" ここにテキストがあります "), text("red ") | color(Color::Red),
paragraph(" スピナー "), 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;
}

linear_gradient

Demo

// Copyright 2023 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスによって管理されています。
#include <ftxui/dom/elements.hpp> // for bgcolor, operator|, operator|=, text, center, Element
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator, shared_ptr
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::DeepPink1, Color::DeepSkyBlue1, Color::Yellow, ftxui
int main() {
using namespace ftxui;
auto document = text("gradient") | center;
document |= bgcolor(LinearGradient()
.Angle(45)
.Stop(Color::DeepPink1)
.Stop(Color::DeepSkyBlue1));
auto screen = Screen::Create(Dimension::Full(), Dimension::Full());
Render(screen, document);
screen.Print();
return 0;
}
線形グラデーションカラー効果の設定を表すクラスです。

package_manager

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスによって管理されています。
#include <chrono> // for operator""s, chrono_literals
#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 string, operator<<, to_string
#include <thread> // for sleep_for
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Green, Color::Red, Color::RedLight, ftxui
int main() {
using namespace ftxui;
struct Task {
std::string name;
int number_of_threads;
int downloaded;
int size;
};
std::list<Task> remaining_tasks = {
{"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;
int remaining_threads = 12;
int nb_queued = (int)remaining_tasks.size();
int nb_active = 0;
int nb_done = 0;
auto to_text = [](int number) {
return text(std::to_string(number)) | size(WIDTH, EQUAL, 3);
};
auto renderTask = [&](const Task& task) {
auto style = (task.downloaded == task.size) ? dim : bold;
return hbox({
text(task.name) | style,
separator(),
to_text(task.downloaded),
text("/"),
to_text(task.size),
separator(),
gauge(task.downloaded / float(task.size)),
});
};
auto renderSummary = [&]() {
auto summary = vbox({
hbox({
text("- done: "),
to_text(nb_done) | bold,
}) | color(Color::Green),
hbox({
text("- active: "),
to_text(nb_active) | bold,
}) | color(Color::RedLight),
hbox({
text("- queue: "),
to_text(nb_queued) | bold,
}) | color(Color::Red),
});
return window(text(" Summary "), summary);
};
auto render = [&]() {
std::vector<Element> entries;
for (auto& task : displayed_task) {
entries.push_back(renderTask(task));
}
return vbox({
// タスク一覧
window(text(" Task "), vbox(std::move(entries))),
// 概要
hbox({
renderSummary(),
filler(),
}),
});
};
auto updateModel = [&]() {
for (auto& task : displayed_task) {
if (task.downloaded != task.size) {
task.downloaded++;
} else if (task.number_of_threads) {
remaining_threads += task.number_of_threads;
task.number_of_threads = 0;
nb_active--;
nb_done++;
}
}
if (remaining_tasks.size() &&
remaining_tasks.front().number_of_threads <= remaining_threads) {
remaining_threads -= remaining_tasks.front().number_of_threads;
displayed_task.push_back(remaining_tasks.front());
remaining_tasks.pop_front();
nb_queued--;
nb_active++;
}
};
std::string reset_position;
for (;;) {
// 描画
auto document = render();
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
// 時間をシミュレート
using namespace std::chrono_literals;
std::this_thread::sleep_for(0.01s);
// 終了
if (nb_active + nb_queued == 0) {
break;
}
// 次のフレームのためにモデルを更新
updateModel();
}
std::cout << std::endl;
}
std::variant< Event, Closure, AnimationTask > Task
Definition task.hpp:13

paragraph

Demo

// Copyright 2020 Arthur Sonzogni. 全著作権所有。
// このソースコードの使用は、以下で見つけることができるMITライセンスによって管理されています。
// LICENSEファイル。
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <iostream> // for cout, ostream
#include <memory> // for allocator, shared_ptr
#include <string> // for string, operator<<
#include <thread> // for sleep_for
#include "ftxui/dom/elements.hpp" // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
using namespace std::chrono_literals;
int main() {
using namespace ftxui;
std::string p =
R"(確率論および統計学において、ベイズの定理(またはベイズの法則、ベイズの規則)は、ある事象に関連する可能性のある条件の事前知識に基づいて、その事象の確率を記述します。例えば、癌が年齢と関連している場合、ベイズの定理を使用することで、その人の年齢を知らない状態での癌の確率の評価と比較して、その人が癌である確率をより正確に評価するために年齢を使用できます。ベイズの定理の多くの応用の1つは、統計的推論への特定のアプローチであるベイズ推論です。適用される場合、ベイズの定理に含まれる確率は、異なる確率解釈を持つことがあります。ベイズ確率解釈では、この定理は、関連する証拠の入手可能性を考慮して、主観的な信頼度が合理的に変化すべき方法を表現します。ベイズ推論は、ベイズ統計学の基礎です。) ";
std::string reset_position;
while (true) {
auto document = vbox({
hflow(paragraph(p)),
separator(),
hflow(paragraph(p)),
separator(),
hbox({
hflow(paragraph(p)),
separator(),
hflow(paragraph(p)),
}),
}) |
border;
document = vbox(filler(), document);
// auto screen = Screen::Create(Dimension::Fit(document));
// Render(screen, document);
// screen.Print();
// getchar();
auto screen = Screen::Create(Dimension::Full());
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
std::this_thread::sleep_for(0.01s);
}
return 0;
}

separator

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = hbox({
text("left-column"),
separator(),
vbox({
center(text("top")) | flex,
separator(),
center(text("bottom")),
}) | flex,
separator(),
text("right-column"),
}) |
border;
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

separator_style

Demo

// Copyright 2020 Arthur Sonzogni. 全著作権所有。
// このソースコードの使用は、以下で見つけることができるMITライセンスによって管理されています。
// LICENSEファイル。
#include <ftxui/screen/screen.hpp> // for Screen
#include <iostream> // for endl, cout, ostream
#include <memory> // for allocator
#include "ftxui/dom/elements.hpp" // for text, hbox, separatorDouble, separatorHeavy, separatorLight, vbox, operator|, Element, Fit, borderDouble, borderHeavy, borderLight
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = vbox({
vbox({
text("separatorLight"),
separatorLight(),
hbox(text("left"), separatorLight(), text("right")),
}) | borderLight,
vbox({
text("separatorDashed"),
separatorDashed(),
hbox(text("left"), separatorDashed(), text("right")),
}) | borderDashed,
vbox({
text("separatorHeavy"),
separatorHeavy(),
hbox(text("left"), separatorHeavy(), text("right")),
}) | borderHeavy,
vbox({
text("separatorDouble"),
separatorDouble(),
hbox(text("left"), separatorDouble(), text("right")),
}) | borderDouble,
});
auto screen =
Screen::Create(Dimension::Fit(document), Dimension::Fit(document));
Render(screen, document);
screen.Print();
std::cout << std::endl;
}

size

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSE ファイルにあるMITライセンスに準拠しています。
#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 string, to_string
#include <utility> // for move
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto make_box = [](const std::string& title) {
return window(text(title) | hcenter | bold,
text("content") | hcenter | dim);
};
Elements content;
for (int x = 3; x < 30; ++x) {
content.push_back(make_box(std::to_string(x)) | size(WIDTH, EQUAL, x));
}
auto document = hbox(std::move(content));
auto screen = Screen::Create(Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

spinner

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
#include <chrono> // for operator""s, chrono_literals
#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 to_string, operator<<, string
#include <thread> // for sleep_for
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
using namespace std::chrono_literals;
std::string reset_position;
for (int index = 0; index < 200; ++index) {
std::vector<Element> entries;
for (int i = 0; i < 23; ++i) {
if (i != 0) {
entries.push_back(separator());
}
entries.push_back( //
hbox({
text(std::to_string(i)) | size(WIDTH, EQUAL, 2),
separator(),
spinner(i, index) | bold,
}));
}
auto document = hbox({
vbox(std::move(entries)) | border,
filler(),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
std::this_thread::sleep_for(0.1s);
}
std::cout << std::endl;
}

style_blink

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
// text, operator|, blink, Fit, hbox, Element のため
#include <ftxui/dom/elements.hpp> // for text, operator|, blink, Fit, hbox, Element
// Full, Screen のため
#include <ftxui/screen/screen.hpp> // for Full, Screen
// アロケータのため
#include <memory> // for allocator
// Render のため
#include "ftxui/dom/node.hpp" // for Render
// ftxui のため
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = //
hbox({
text("このテキストは"),
text("点滅します") | blink,
text("。気に入りましたか?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_bold

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに従います。
#include <ftxui/dom/elements.hpp> // text, operator|, bold, Fit, hbox, Element のために
#include <ftxui/screen/screen.hpp> // Full, Screen のために
#include <memory> // アロケータのために
#include "ftxui/dom/node.hpp" // Render のために
#include "ftxui/screen/color.hpp" // ftxui のために
int main() {
using namespace ftxui;
auto document = //
hbox({
text("このテキストは"),
text("太字") | bold,
text("です。気に入りましたか?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_color

Demo

// 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 <ftxui/dom/linear_gradient.hpp> // for LinearGradient
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, filler, Fit, hbox
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, operator""_rgb, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::DeepSkyBlue4, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::SkyBlue1, Color::White, Color::Yellow, Color::YellowLight, ftxui
int main() {
using namespace ftxui;
auto document = hbox({
vbox({
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")),
color(0x66ff66_rgb, text("Phosphor")),
color(LinearGradient(Color::SkyBlue1, Color::DeepSkyBlue4),
text("Skyblue to DeepSkyBlue")),
}),
vbox({
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")),
bgcolor(0x66ff66_rgb, text("Phosphor")),
bgcolor(LinearGradient(Color::SkyBlue1, Color::DeepSkyBlue4),
text("Skyblue to DeepSkyBlue")),
}),
filler(),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_dim

Demo

// Copyright 2020 Arthur Sonzogni. 全著作権所有。
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに従います。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = //
hbox({
text("This text is "),
text("dim") | dim,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_gallery

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルに記載されているMITライセンスに準拠しています。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, ftxui
int main() {
using namespace ftxui;
// clang-format off
auto document =
hbox({
text("normal") , text(" ") ,
text("bold") | bold , text(" ") ,
text("italic") | italic , text(" ") ,
text("dim") | dim , text(" ") ,
text("inverted") | inverted , text(" ") ,
text("underlined") | underlined , text(" ") ,
text("underlinedDouble") | underlinedDouble , text(" ") ,
text("blink") | blink , text(" ") ,
text("strikethrough") | strikethrough , text(" ") ,
text("color") | color(Color::Blue) , text(" ") ,
text("bgcolor") | bgcolor(Color::Blue) , text(" ") ,
text("hyperlink") | hyperlink("https://github.com/ArthurSonzogni/FTXUI"),
});
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_hyperlink

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = //
hbox({
text("This text is an "),
text("hyperlink") | hyperlink("https://www.google.com"),
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_inverted

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに従います。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = hbox({
text("This text is "),
text("inverted") | inverted,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_italic

Demo

// Copyright 2025 Arthur Sonzogni. 全著作権所有。
// このソースコードの使用は、以下に記載されているMITライセンスに準拠します。
// LICENSEファイル。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = hbox({
text("This text is "),
text("italic") | italic,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_strikethrough

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
#include <ftxui/dom/elements.hpp> // for text, operator|, strikethrough, Fit, hbox, Element
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = //
hbox({
text("This text is "),
text("strikethrough") | strikethrough,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_underlined

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
#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/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = //
hbox({
text("This text is "),
text("underlined") | underlined,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

style_underlined_double

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
#include <ftxui/dom/elements.hpp> // for text, operator|, underlinedDouble, Fit, hbox, Element
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto document = //
hbox({
text("This text is "),
text("underlinedDouble") | underlinedDouble,
text(". Do you like it?"),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}

table

Demo

// Copyright 2020 Arthur Sonzogni. 無断複写・転載を禁じます。
// このソースコードの使用は、
// LICENSEファイルに記載されているMITライセンスに準拠します。
#include <ftxui/dom/elements.hpp> // for color, Fit, LIGHT, align_right, bold, DOUBLE
#include <ftxui/dom/table.hpp> // for Table, TableSelection
#include <ftxui/screen/screen.hpp> // for Screen
#include <iostream> // for endl, cout, ostream
#include <string> // for basic_string, allocator, string
#include <vector> // for vector
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::White, ftxui
int main() {
using namespace ftxui;
auto table = Table({
{"Version", "Marketing name", "Release date", "API level", "Runtime"},
{"2.3", "Gingerbread", "February 9 2011", "10", "Dalvik 1.4.0"},
{"4.0", "Ice Cream Sandwich", "October 19 2011", "15", "Dalvik"},
{"4.1", "Jelly Bean", "July 9 2012", "16", "Dalvik"},
{"4.2", "Jelly Bean", "November 13 2012", "17", "Dalvik"},
{"4.3", "Jelly Bean", "July 24 2013", "18", "Dalvik"},
{"4.4", "KitKat", "October 31 2013", "19", "Dalvik and ART"},
{"5.0", "Lollipop", "November 3 2014", "21", "ART"},
{"5.1", "Lollipop", "March 9 2015", "22", "ART"},
{"6.0", "Marshmallow", "October 5 2015", "23", "ART"},
{"7.0", "Nougat", "August 22 2016", "24", "ART"},
{"7.1", "Nougat", "October 4 2016", "25", "ART"},
{"8.0", "Oreo", "August 21 2017", "26", "ART"},
{"8.1", "Oreo", "December 5 2017", "27", "ART"},
{"9", "Pie", "August 6 2018", "28", "ART"},
{"10", "10", "September 3 2019", "29", "ART"},
{"11", "11", "September 8 2020", "30", "ART"},
});
table.SelectAll().Border(LIGHT);
// 最初の列に罫線を追加します。
table.SelectColumn(0).Border(LIGHT);
// 最初の行を二重罫線で太字にします。
table.SelectRow(0).Decorate(bold);
table.SelectRow(0).SeparatorVertical(LIGHT);
table.SelectRow(0).Border(DOUBLE);
// 「Release date」列を右寄せにします。
table.SelectColumn(2).DecorateCells(align_right);
// 2行目から最終行までを選択します。
auto content = table.SelectRows(1, -1);
// 3つの色を交互に適用します。
content.DecorateCellsAlternateRow(color(Color::Blue), 3, 0);
content.DecorateCellsAlternateRow(color(Color::Cyan), 3, 1);
content.DecorateCellsAlternateRow(color(Color::White), 3, 2);
auto document = table.Render();
auto screen =
Screen::Create(Dimension::Fit(document, /*extend_beyond_screen=*/true));
Render(screen, document);
screen.Print();
std::cout << std::endl;
return 0;
}
void Border(BorderStyle border=LIGHT)
選択範囲に border を適用します。
TableSelection SelectAll()
テーブル全体を選択します。
Tableは、テーブルを描画するためのユーティリティです。
Definition table.hpp:35

vbox_hbox

Demo

// Copyright 2020 Arthur Sonzogni. 無断複写・転載を禁じます。
// このソースコードの使用は、
// LICENSEファイルにあるMITライセンスによって管理されています。
#include <stdio.h> // getcharのため
#include <ftxui/dom/elements.hpp> // filler, text, hbox, vboxのため
#include <ftxui/screen/screen.hpp> // Full, Screenのため
#include <memory> // アロケータのため
#include "ftxui/dom/node.hpp" // Renderのため
#include "ftxui/screen/color.hpp" // ftxuiのため
int main() {
using namespace ftxui;
auto document = //
vbox({
hbox({
text("north-west"),
filler(),
text("north-east"),
}),
filler(),
hbox({
filler(),
text("center"),
filler(),
}),
filler(),
hbox({
text("south-west"),
filler(),
text("south-east"),
}),
});
auto screen = Screen::Create(Dimension::Full());
Render(screen, document);
screen.Print();
getchar();
return 0;
}

vflow

Demo

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
#include <stdio.h> // for getchar
#include <ftxui/dom/elements.hpp> // for operator|, Element, size, text, hcenter, Fit, vflow, window, EQUAL, bold, border, dim, HEIGHT, WIDTH
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <string> // for allocator, char_traits, operator+, to_string, string
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
int main() {
using namespace ftxui;
auto make_box = [](int dimx, int dimy) {
std::string title = std::to_string(dimx) + "x" + std::to_string(dimy);
return window(text(title) | hcenter | bold,
text("content") | hcenter | dim) |
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy);
};
auto document = vflow({
make_box(7, 7),
make_box(7, 5),
make_box(5, 7),
make_box(10, 4),
make_box(10, 4),
make_box(10, 4),
make_box(10, 4),
make_box(11, 4),
make_box(11, 4),
make_box(11, 4),
make_box(11, 4),
make_box(12, 4),
make_box(12, 5),
make_box(12, 4),
make_box(13, 4),
make_box(13, 3),
make_box(13, 3),
make_box(10, 3),
}) |
border;
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
getchar();
return 0;
}