#include <stddef.h>
#include <array>
#include <atomic>
#include <chrono>
#include <cmath>
#include <functional>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#include <vector>
#include "../dom/color_info_sorted_2d.ipp"
int main() {
auto screen = ScreenInteractive::Fullscreen();
int shift = 0;
auto my_graph = [&shift](int width, int height) {
std::vector<int> output(width);
for (int i = 0; i < width; ++i) {
float v = 0.5f;
v += 0.1f * sin((i + shift) * 0.1f);
v += 0.2f * sin((i + shift + 10) * 0.15f);
v += 0.1f * sin((i + shift) * 0.03f);
v *= height;
output[i] = (int)v;
}
return output;
};
}),
});
auto utilization =
vbox({
}),
graph(std::ref(my_graph)) |
color(Color::RedLight),
});
}),
graph(std::ref(my_graph)) |
color(Color::BlueLight),
});
}) |
});
const std::vector<std::string> compiler_entries = {
"gcc",
"clang",
"emcc",
"game_maker",
"Ada compilers",
"ALGOL 60 compilers",
"ALGOL 68 compilers",
"Assemblers (Intel *86)",
"Assemblers (Motorola 68*)",
"Assemblers (Zilog Z80)",
"Assemblers (other)",
"BASIC Compilers",
"BASIC interpreters",
"Batch compilers",
"C compilers",
"Source-to-source compilers",
"C++ compilers",
"C# compilers",
"COBOL compilers",
"Common Lisp compilers",
"D compilers",
"DIBOL/DBL compilers",
"ECMAScript interpreters",
"Eiffel compilers",
"Fortran compilers",
"Go compilers",
"Haskell compilers",
"Java compilers",
"Pascal compilers",
"Perl Interpreters",
"PHP compilers",
"PL/I compilers",
"Python compilers",
"Scheme compilers and interpreters",
"Smalltalk compilers",
"Tcl Interpreters",
"VMS Interpreters",
"Rexx Interpreters",
"CLI compilers",
};
int compiler_selected = 0;
std::array<std::string, 8> options_label = {
"-Wall",
"-Werror",
"-lpthread",
"-O3",
"-Wabi-tag",
"-Wno-class-conversion",
"-Wcomma-subscript",
"-Wno-conversion-null",
};
std::array<bool, 8> options_state = {
false, false, false, false, false, false, false, false,
};
std::vector<std::string> input_entries;
int input_selected = 0;
std::string input_add_content;
input_option.on_enter = [&] {
input_entries.push_back(input_add_content);
input_add_content = "";
};
Component input_add =
Input(&input_add_content,
"input files", input_option);
std::string executable_content_ = "";
Checkbox(&options_label[0], &options_state[0]),
Checkbox(&options_label[1], &options_state[1]),
Checkbox(&options_label[2], &options_state[2]),
Checkbox(&options_label[3], &options_state[3]),
Checkbox(&options_label[4], &options_state[4]),
Checkbox(&options_label[5], &options_state[5]),
Checkbox(&options_label[6], &options_state[6]),
Checkbox(&options_label[7], &options_state[7]),
});
compiler,
flags,
executable_,
input_add,
input,
}),
}),
});
auto render_command = [&] {
line.push_back(
text(compiler_entries[compiler_selected]) |
bold);
for (int i = 0; i < 8; ++i) {
if (options_state[i]) {
line.push_back(
text(
" "));
line.push_back(
text(options_label[i]) |
dim);
}
}
if (!executable_content_.empty()) {
line.push_back(
text(executable_content_) |
color(Color::BlueLight) |
}
for (auto& it : input_entries) {
line.push_back(
text(
" " + it) |
color(Color::RedLight));
}
return line;
};
auto compiler_renderer =
Renderer(compiler_component, [&] {
auto flags_win =
auto executable_win =
window(
text(
"Executable:"), executable_->Render());
auto input_win =
input_add->Render(),
}),
}));
compiler_win,
flags_win,
}),
}) |
});
auto spinner_tab_renderer =
Renderer([&] {
for (int i = 0; i < 22; ++i) {
}
return hflow(std::move(entries));
});
auto basic_color_display =
text(
"16 color palette:"),
color(Color::GreenLight,
text(
"GreenLight")),
color(Color::MagentaLight,
text(
"MagentaLight")),
color(Color::YellowLight,
text(
"YellowLight")),
}),
}),
}),
}) |
auto palette_256_color_display =
text(
"256 colors palette:");
{
std::vector<std::vector<ColorInfo>> info_columns = ColorInfoSorted2D();
for (auto& column : info_columns) {
for (auto& it : column) {
column_elements.push_back(
}
columns.push_back(
hbox(std::move(column_elements)));
}
palette_256_color_display =
vbox({
palette_256_color_display,
}) |
}
auto true_color_display =
text(
"TrueColors: 24bits:");
{
int saturation = 255;
for (int value = 0; value < 255; value += 16) {
for (int hue = 0; hue < 255; hue += 6) {
|
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,
}) |
}
{
basic_color_display,
palette_256_color_display,
true_color_display,
},
});
auto render_gauge = [&shift](int delta) {
float progress = (shift + delta) % 500 / 500.f;
});
};
auto gauge_component =
Renderer([render_gauge] {
render_gauge(0) |
color(Color::Black),
render_gauge(100) |
color(Color::GrayDark),
render_gauge(50) |
color(Color::GrayLight),
render_gauge(6894) |
color(Color::White),
render_gauge(6841) |
color(Color::Blue),
render_gauge(9813) |
color(Color::BlueLight),
render_gauge(98765) |
color(Color::Cyan),
render_gauge(98) |
color(Color::CyanLight),
render_gauge(9846) |
color(Color::Green),
render_gauge(1122) |
color(Color::GreenLight),
render_gauge(84) |
color(Color::Magenta),
render_gauge(645) |
color(Color::MagentaLight),
render_gauge(568) |
color(Color::Red),
render_gauge(2222) |
color(Color::RedLight),
render_gauge(220) |
color(Color::Yellow),
render_gauge(348) |
color(Color::YellowLight),
});
});
auto make_box = [](size_t dimx, size_t dimy) {
};
auto paragraph_renderer_left =
Renderer([&] {
std::string str =
"Lorem Ipsum is simply dummy text of the printing and typesetting "
"industry. Lorem Ipsum has been the industry's standard dummy text "
"ever since the 1500s, when an unknown printer took a galley of type "
"and scrambled it to make a type specimen book.";
})),
make_box(10, 5),
make_box(9, 4),
make_box(8, 4),
make_box(6, 3),
make_box(10, 5),
make_box(9, 4),
make_box(8, 4),
make_box(6, 3),
make_box(10, 5),
make_box(9, 4),
make_box(8, 4),
make_box(6, 3),
})),
}) |
});
auto paragraph_renderer_right =
Renderer([] {
return paragraph(
"<--- This vertical bar is resizable using the mouse") |
});
auto paragraph_renderer_group =
¶graph_renderer_split_position);
auto paragraph_renderer_group_renderer =
[&] { return paragraph_renderer_group->Render(); });
int tab_index = 0;
std::vector<std::string> tab_entries = {
"htop", "color", "spinner", "gauge", "compiler", "paragraph",
};
auto tab_selection =
Menu(&tab_entries, &tab_index, MenuOption::HorizontalAnimated());
{
htop,
color_tab_renderer,
spinner_tab_renderer,
gauge_component,
compiler_renderer,
paragraph_renderer_group_renderer,
},
&tab_index);
tab_selection,
tab_content,
});
auto main_renderer =
Renderer(main_container, [&] {
tab_selection->Render(),
tab_content->Render() |
flex,
});
});
std::atomic<bool> refresh_ui_continue = true;
std::thread refresh_ui([&] {
while (refresh_ui_continue) {
using namespace std::chrono_literals;
std::this_thread::sleep_for(0.05s);
screen.Post([&] { shift++; });
screen.Post(Event::Custom);
}
});
screen.Loop(main_renderer);
refresh_ui_continue = false;
refresh_ui.join();
return 0;
}
Component Horizontal(Components children)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
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...
Dimensions Size()
Get the terminal size.
Decorator bgcolor(Color)
Decorate using a background color.
Element vscroll_indicator(Element)
Display a vertical scrollbar to the right. colors.
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Component Checkbox(CheckboxOption options)
Element flex(Element)
Make a child element to expand proportionnally to the space left in a container.
Component Menu(MenuOption options)
A list of text. The focused element is selected.
Element paragraphAlignRight(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
std::shared_ptr< ComponentBase > Component
Element bold(Element)
Use a bold font, for elements with more emphasis.
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".
Component Radiobox(RadioboxOption options)
A list of element, where only one can be selected.
Element window(Element title, Element content)
Draw window with a title and a border around the element.
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Element hbox(Elements)
A container displaying elements horizontally one by one.
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.
std::string to_string(const std::wstring &s)
Convert a UTF8 std::string into a std::wstring.
Element text(std::wstring text)
Display a piece of unicode text.
std::vector< Element > Elements
Element yframe(Element)
Same as frame, but only on the y-axis.
Component Input(InputOption options={})
An input box for editing 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 proportionnally to the space left in a container.
Elements paragraph(std::wstring text)
Element dim(Element)
Use a light font, for elements with less emphasis.
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Element gauge(float progress)
Draw a high definition progress bar.
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Element paragraphAlignJustify(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
Element border(Element)
Draw a border around the element.
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 & SetGap(int gap_x, int gap_y)
Set the flexbox flex direction.