38 auto my_graph = [&shift](
int width,
int height) {
39 std::vector<int> output(width);
40 for (
int i = 0; i < width; ++i) {
42 v += 0.1f * sin((i + shift) * 0.1f);
43 v += 0.2f * sin((i + shift + 10) * 0.15f);
44 v += 0.1f * sin((i + shift) * 0.03f);
52 auto frequency =
vbox({
66 auto utilization =
vbox({
110 const std::vector<std::string> compiler_entries = {
116 "ALGOL 60 compilers",
117 "ALGOL 68 compilers",
118 "Assemblers (Intel *86)",
119 "Assemblers (Motorola 68*)",
120 "Assemblers (Zilog Z80)",
121 "Assemblers (other)",
123 "BASIC interpreters",
126 "Source-to-source compilers",
130 "Common Lisp compilers",
132 "DIBOL/DBL compilers",
133 "ECMAScript interpreters",
144 "Scheme compilers and interpreters",
145 "Smalltalk compilers",
152 int compiler_selected = 0;
155 std::array<std::string, 8> options_label = {
161 "-Wno-class-conversion",
163 "-Wno-conversion-null",
165 std::array<bool, 8> options_state = {
166 false,
false,
false,
false,
false,
false,
false,
false,
169 std::vector<std::string> input_entries;
170 int input_selected = 0;
174 std::string input_add_content;
175 input_option.on_enter = [&] {
176 input_entries.push_back(input_add_content);
177 input_add_content =
"";
179 Component input_add =
Input(&input_add_content,
"input files", input_option);
181 std::string executable_content_ =
"";
182 Component executable_ =
Input(&executable_content_,
"executable");
185 Checkbox(&options_label[0], &options_state[0]),
186 Checkbox(&options_label[1], &options_state[1]),
187 Checkbox(&options_label[2], &options_state[2]),
188 Checkbox(&options_label[3], &options_state[3]),
189 Checkbox(&options_label[4], &options_state[4]),
190 Checkbox(&options_label[5], &options_state[5]),
191 Checkbox(&options_label[6], &options_state[6]),
192 Checkbox(&options_label[7], &options_state[7]),
207 auto render_command = [&] {
210 line.push_back(
text(compiler_entries[compiler_selected]) | bold);
212 for (
int i = 0; i < 8; ++i) {
213 if (options_state[i]) {
214 line.push_back(
text(
" "));
215 line.push_back(
text(options_label[i]) | dim);
219 if (!executable_content_.empty()) {
220 line.push_back(
text(
" -o ") | bold);
225 for (
auto& it : input_entries) {
231 auto compiler_renderer =
Renderer(compiler_component, [&] {
233 compiler->
Render() | vscroll_indicator | frame);
248 input->
Render() | vscroll_indicator | frame |
269 auto spinner_tab_renderer =
Renderer([&] {
271 for (
int i = 0; i < 22; ++i) {
272 entries.push_back(
spinner(i, shift / 2) | bold |
275 return hflow(std::move(entries));
281 auto color_tab_renderer =
Renderer([] {
282 auto basic_color_display =
284 text(
"16 color palette:"),
329 auto palette_256_color_display =
text(
"256 colors palette:");
333 for (
auto& column : info_columns) {
335 for (
auto& it : column) {
336 column_elements.push_back(
339 columns.push_back(
hbox(std::move(column_elements)));
341 palette_256_color_display =
vbox({
342 palette_256_color_display,
350 auto true_color_display =
text(
"TrueColors: 24bits:");
352 int saturation = 255;
354 for (
int value = 0; value < 255; value += 16) {
356 for (
int hue = 0; hue < 255; hue += 6) {
357 line.push_back(
text(
"â–€")
361 array.push_back(
hbox(std::move(line)));
363 true_color_display =
vbox({
366 vbox(std::move(array)),
374 palette_256_color_display,
383 auto render_gauge = [&shift](
int delta) {
384 float progress = (shift + delta) % 500 / 500.f;
386 text(std::to_string(
int(progress * 100)) +
"% ") |
392 auto gauge_component =
Renderer([render_gauge] {
417 auto make_box = [](
size_t dimx,
size_t dimy) {
418 std::string title = std::to_string(dimx) +
"x" + std::to_string(dimy);
420 text(
"content") | hcenter | dim) |
424 auto paragraph_renderer_left =
Renderer([&] {
426 "Lorem Ipsum is simply dummy text of the printing and typesetting "
427 "industry.\nLorem Ipsum has been the industry's standard dummy text "
428 "ever since the 1500s, when an unknown printer took a galley of type "
429 "and scrambled it to make a type specimen book.";
456 vscroll_indicator | yframe | flex;
459 auto paragraph_renderer_right =
Renderer([] {
460 return paragraph(
"<--- This vertical bar is resizable using the mouse") |
465 auto paragraph_renderer_group =
467 ¶graph_renderer_split_position);
468 auto paragraph_renderer_group_renderer =
470 [&] {
return paragraph_renderer_group->Render(); });
477 std::vector<std::string> tab_entries = {
478 "htop",
"color",
"spinner",
"gauge",
"compiler",
"paragraph",
486 spinner_tab_renderer,
489 paragraph_renderer_group_renderer,
504 auto main_renderer =
Renderer(main_container, [&] {
508 tab_selection->Render() |
flex,
509 exit_button->Render(),
515 std::atomic<bool> refresh_ui_continue =
true;
516 std::thread refresh_ui([&] {
517 while (refresh_ui_continue) {
518 using namespace std::chrono_literals;
519 std::this_thread::sleep_for(0.05s);
523 screen.Post([&] { shift++; });
530 screen.Loop(main_renderer);
531 refresh_ui_continue =
false;
std::vector< std::vector< ftxui::ColorInfo > > ColorInfoSorted2D()
Element make_box(int x, int y)
static ButtonOption Animated()
Create a ButtonOption, using animated colors.
Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxui::Screen representing this ftxui::...
static ScreenInteractive Fullscreen()
static const Event Custom
static MenuOption HorizontalAnimated()
Standard options for an animated horizontal menu. This can be useful to implement a tab bar.
Component Horizontal(Components children)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Component Menu(MenuOption options)
A list of text. The focused element is selected.
Component Radiobox(RadioboxOption options)
A list of element, where only one can be selected.
Component Button(ButtonOption options)
Draw a button. Execute a function when clicked.
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Component Input(InputOption options={})
An input box for editing text.
Component Checkbox(CheckboxOption options)
Draw checkable element.
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Component Tab(Components children, int *selector)
A list of components, where only one is drawn and interacted with at a time. The |selector| gives the...
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
FlexboxConfig & SetGap(int gap_x, int gap_y)
Set the flexbox flex direction.
Decorator bgcolor(Color)
Decorate using a background color.
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Element flex(Element)
Make a child element to expand proportionally to the space left in a container.
Element paragraphAlignRight(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
Element spinner(int charset_index, size_t image_index)
Useful to represent the effect of time and/or events. This displays an ASCII art "video".
Element center(Element)
Center an element horizontally and vertically.
Element paragraphAlignCenter(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Element text(std::wstring text)
Display a piece of unicode text.
Element flex_grow(Element)
Expand if possible.
Element paragraphAlignLeft(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Element filler()
An element that will take expand proportionally to the space left in a container.
Element gauge(float progress)
Draw a high definition progress bar.
Element paragraphAlignJustify(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Decorator color(Color)
Decorate using a foreground color.
Element hcenter(Element)
Center an element horizontally.
Element vbox(Elements)
A container displaying elements vertically one by one.
FlexboxConfig is a configuration structure that defines the layout properties for a flexbox container...
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.
Color is a class that represents a color in the terminal user interface.
Dimensions Size()
Get the terminal size.
The FTXUI ftxui:: namespace.
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
A container displaying elements on row/columns and capable of wrapping on the next column/row when fu...
Element hflow(Elements)
A container displaying elements in rows from left to right. When filled, it starts on a new row below...
Element hbox(Elements)
A container displaying elements horizontally one by one.
std::vector< Element > Elements
Elements paragraph(std::wstring text)
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
std::shared_ptr< ComponentBase > Component