diff --git a/CMakeLists.txt b/CMakeLists.txt index d5eec13..b7768bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,7 @@ foreach(lib screen dom component) PRIVATE src ) target_compile_features(${lib} PUBLIC cxx_std_17) - target_compile_options(${lib} PRIVATE -Wall -Werror -Wextra) + target_compile_options(${lib} PRIVATE -Wall -Werror -pedantic -Wextra) endforeach() if(FTXUI_ENABLE_INSTALL) diff --git a/examples/component/gallery.cpp b/examples/component/gallery.cpp index 9458442..276cfa9 100644 --- a/examples/component/gallery.cpp +++ b/examples/component/gallery.cpp @@ -65,14 +65,10 @@ class MyComponent : public Component { Element Render() override { return vbox( - Render(L"menu", menu), - separator(), - Render(L"toggle", toggle), - separator(), - Render(L"checkbox", checkbox_container), - separator(), - Render(L"radiobox", radiobox), - separator(), + Render(L"menu", menu), separator(), + Render(L"toggle", toggle), separator(), + Render(L"checkbox", checkbox_container), separator(), + Render(L"radiobox", radiobox), separator(), Render(L"input", input) | size(WIDTH, LESS_THAN, 30) ) | border; } diff --git a/include/ftxui/dom/elements.hpp b/include/ftxui/dom/elements.hpp index 815f861..6a6828d 100644 --- a/include/ftxui/dom/elements.hpp +++ b/include/ftxui/dom/elements.hpp @@ -11,7 +11,7 @@ namespace ftxui { using Element = std::unique_ptr; using Elements = std::vector; using Decorator = std::function; -using GraphFunction = std::function(int,int)>; +using GraphFunction = std::function(int, int)>; // --- Widget --- Element text(std::wstring text); @@ -22,7 +22,7 @@ Element border(Element); Decorator borderWith(Pixel); Element window(Element title, Element content); Element spinner(int charset_index, size_t image_index); -Elements paragraph(std::wstring text); // Use inside hflow(). Split by space. +Elements paragraph(std::wstring text); // Use inside hflow(). Split by space. Element graph(GraphFunction); // -- Decorator --- @@ -83,6 +83,6 @@ TAKE_ANY_ARGS(hbox) TAKE_ANY_ARGS(dbox) TAKE_ANY_ARGS(hflow) -}; // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */ diff --git a/include/ftxui/dom/node.hpp b/include/ftxui/dom/node.hpp index f055326..18b8405 100644 --- a/include/ftxui/dom/node.hpp +++ b/include/ftxui/dom/node.hpp @@ -37,6 +37,6 @@ class Node { void Render(Screen& screen, Node* node); -}; // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_DOM_NODE_HPP */ diff --git a/include/ftxui/dom/requirement.hpp b/include/ftxui/dom/requirement.hpp index b8cf19b..d3bda6a 100644 --- a/include/ftxui/dom/requirement.hpp +++ b/include/ftxui/dom/requirement.hpp @@ -21,6 +21,6 @@ struct Requirement { Box selected_box; }; -}; // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_REQUIREMENT_HPP */ diff --git a/include/ftxui/screen/box.hpp b/include/ftxui/screen/box.hpp index e1906be..e020b64 100644 --- a/include/ftxui/screen/box.hpp +++ b/include/ftxui/screen/box.hpp @@ -12,6 +12,6 @@ struct Box { static Box Intersection(Box a, Box b); }; -}; // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_SCREEN_BOX_HPP */ diff --git a/include/ftxui/screen/color.hpp b/include/ftxui/screen/color.hpp index faeb35d..63eda3c 100644 --- a/include/ftxui/screen/color.hpp +++ b/include/ftxui/screen/color.hpp @@ -35,6 +35,6 @@ enum class Color : uint8_t { YellowLight = 93, }; -}; // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_COLOR_H_ */ diff --git a/include/ftxui/screen/screen.hpp b/include/ftxui/screen/screen.hpp index 3d1eae8..06c764a 100644 --- a/include/ftxui/screen/screen.hpp +++ b/include/ftxui/screen/screen.hpp @@ -75,6 +75,6 @@ class Screen { Cursor cursor_; }; -}; // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_SCREEN_SCREEN */ diff --git a/src/ftxui/component/event.cpp b/src/ftxui/component/event.cpp index 0c0ff4f..f47470b 100644 --- a/src/ftxui/component/event.cpp +++ b/src/ftxui/component/event.cpp @@ -59,7 +59,7 @@ Event ParseCSI(std::function getchar, std::string& input) { return Event::Special(input); // Invalid ESC in CSI. - if (c == '\e') + if (c == '\x1B') return Event::Special(input); } } @@ -68,7 +68,7 @@ Event ParseDCS(std::function getchar, std::string& input) { // Parse until the string terminator ST. while (1) { input += getchar(); - if (input.back() != '\e') + if (input.back() != '\x1B') continue; input += getchar(); if (input.back() != '\\') @@ -81,7 +81,7 @@ Event ParseOSC(std::function getchar, std::string& input) { // Parse until the string terminator ST. while (1) { input += getchar(); - if (input.back() != '\e') + if (input.back() != '\x1B') continue; input += getchar(); if (input.back() != '\\') @@ -115,7 +115,7 @@ Event Event::GetEvent(std::function getchar) { case 'P': return ParseDCS(getchar, input); - case '\e': + case '\x1B': return ParseESC(getchar, input); } @@ -129,28 +129,28 @@ Event Event::GetEvent(std::function getchar) { } // --- Arrow --- -Event Event::ArrowLeft = Event::Special("\e[D"); -Event Event::ArrowRight = Event::Special("\e[C"); -Event Event::ArrowUp = Event::Special("\e[A"); -Event Event::ArrowDown = Event::Special("\e[B"); +Event Event::ArrowLeft = Event::Special("\x1B[D"); +Event Event::ArrowRight = Event::Special("\x1B[C"); +Event Event::ArrowUp = Event::Special("\x1B[A"); +Event Event::ArrowDown = Event::Special("\x1B[B"); Event Event::Backspace = Event::Special({127}); -Event Event::Delete = Event::Special("\e[3~"); -Event Event::Escape = Event::Special("\e"); +Event Event::Delete = Event::Special("\x1B[3~"); +Event Event::Escape = Event::Special("\x1B"); Event Event::Return = Event::Special({10}); Event Event::Tab = Event::Special({9}); Event Event::TabReverse = Event::Special({27, 91, 90}); -Event Event::F1 = Event::Special("\e[OP"); -Event Event::F2 = Event::Special("\e[OQ"); -Event Event::F3 = Event::Special("\e[OR"); -Event Event::F4 = Event::Special("\e[OS"); -Event Event::F5 = Event::Special("\e[15~"); -Event Event::F6 = Event::Special("\e[17~"); -Event Event::F7 = Event::Special("\e[18~"); -Event Event::F8 = Event::Special("\e[19~"); -Event Event::F9 = Event::Special("\e[20~"); -Event Event::F10 = Event::Special("\e[21~"); -Event Event::F11 = Event::Special("\e[21~"); // Doesn't exist -Event Event::F12 = Event::Special("\e[24~"); +Event Event::F1 = Event::Special("\x1B[OP"); +Event Event::F2 = Event::Special("\x1B[OQ"); +Event Event::F3 = Event::Special("\x1B[OR"); +Event Event::F4 = Event::Special("\x1B[OS"); +Event Event::F5 = Event::Special("\x1B[15~"); +Event Event::F6 = Event::Special("\x1B[17~"); +Event Event::F7 = Event::Special("\x1B[18~"); +Event Event::F8 = Event::Special("\x1B[19~"); +Event Event::F9 = Event::Special("\x1B[20~"); +Event Event::F10 = Event::Special("\x1B[21~"); +Event Event::F11 = Event::Special("\x1B[21~"); // Doesn't exist +Event Event::F12 = Event::Special("\x1B[24~"); Event Event::Custom = Event::Special({0}); } // namespace ftxui diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index d8c9231..c9f915a 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -18,11 +18,11 @@ namespace ftxui { -static const char* HIDE_CURSOR = "\e[?25l"; -static const char* SHOW_CURSOR = "\e[?25h"; +static const char* HIDE_CURSOR = "\x1B[?25l"; +static const char* SHOW_CURSOR = "\x1B[?25h"; -static const char* DISABLE_LINE_WRAP = "\e[7l"; -static const char* ENABLE_LINE_WRAP = "\e[7h"; +static const char* DISABLE_LINE_WRAP = "\x1B[7l"; +static const char* ENABLE_LINE_WRAP = "\x1B[7h"; std::stack> on_exit_functions; void OnExit(int signal) { @@ -188,12 +188,12 @@ void ScreenInteractive::Draw(Component* component) { int dy = dimy_ - 1 - cursor_.y; if (dx != 0) { - set_cursor_position += "\e[" + std::to_string(dx) + "D"; - reset_cursor_position += "\e[" + std::to_string(dx) + "C"; + set_cursor_position += "\x1B[" + std::to_string(dx) + "D"; + reset_cursor_position += "\x1B[" + std::to_string(dx) + "C"; } if (dy != 0) { - set_cursor_position += "\e[" + std::to_string(dy) + "A"; - reset_cursor_position += "\e[" + std::to_string(dy) + "B"; + set_cursor_position += "\x1B[" + std::to_string(dy) + "A"; + reset_cursor_position += "\x1B[" + std::to_string(dy) + "B"; } } diff --git a/src/ftxui/dom/blink.cpp b/src/ftxui/dom/blink.cpp index 80debd6..936eed3 100644 --- a/src/ftxui/dom/blink.cpp +++ b/src/ftxui/dom/blink.cpp @@ -22,4 +22,4 @@ std::unique_ptr blink(Element child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/bold.cpp b/src/ftxui/dom/bold.cpp index dbce334..cbd9a70 100644 --- a/src/ftxui/dom/bold.cpp +++ b/src/ftxui/dom/bold.cpp @@ -22,4 +22,4 @@ std::unique_ptr bold(Element child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/border.cpp b/src/ftxui/dom/border.cpp index 90bf0c2..ee50ac0 100644 --- a/src/ftxui/dom/border.cpp +++ b/src/ftxui/dom/border.cpp @@ -115,4 +115,4 @@ Decorator borderWith(Pixel pixel) { }; } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/color.cpp b/src/ftxui/dom/color.cpp index 8d5bedf..29a5b67 100644 --- a/src/ftxui/dom/color.cpp +++ b/src/ftxui/dom/color.cpp @@ -58,4 +58,4 @@ Decorator bgcolor(Color c) { }; } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/dbox.cpp b/src/ftxui/dom/dbox.cpp index c72db4b..fd96383 100644 --- a/src/ftxui/dom/dbox.cpp +++ b/src/ftxui/dom/dbox.cpp @@ -37,4 +37,4 @@ std::unique_ptr dbox(Elements children) { return std::make_unique(std::move(children)); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/dim.cpp b/src/ftxui/dom/dim.cpp index f5b622f..8a80abe 100644 --- a/src/ftxui/dom/dim.cpp +++ b/src/ftxui/dom/dim.cpp @@ -24,4 +24,4 @@ std::unique_ptr dim(Element child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/flex.cpp b/src/ftxui/dom/flex.cpp index d25f4d3..6ff5910 100644 --- a/src/ftxui/dom/flex.cpp +++ b/src/ftxui/dom/flex.cpp @@ -55,4 +55,4 @@ std::unique_ptr notflex(Element child) { return std::make_unique(std::move(child)); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/frame.cpp b/src/ftxui/dom/frame.cpp index 958ce65..d154bf8 100644 --- a/src/ftxui/dom/frame.cpp +++ b/src/ftxui/dom/frame.cpp @@ -123,4 +123,4 @@ std::unique_ptr frame(Element child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/gauge.cpp b/src/ftxui/dom/gauge.cpp index f9a2c97..4755bae 100644 --- a/src/ftxui/dom/gauge.cpp +++ b/src/ftxui/dom/gauge.cpp @@ -36,4 +36,4 @@ std::unique_ptr gauge(float progress) { return std::make_unique(progress); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/graph.cpp b/src/ftxui/dom/graph.cpp index efe8555..520dd38 100644 --- a/src/ftxui/dom/graph.cpp +++ b/src/ftxui/dom/graph.cpp @@ -42,4 +42,4 @@ std::unique_ptr graph(GraphFunction graph_function) { return std::make_unique(graph_function); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/hbox.cpp b/src/ftxui/dom/hbox.cpp index 00a71f0..4272d3e 100644 --- a/src/ftxui/dom/hbox.cpp +++ b/src/ftxui/dom/hbox.cpp @@ -69,4 +69,4 @@ std::unique_ptr hbox(Elements children) { return std::make_unique(std::move(children)); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/hflow.cpp b/src/ftxui/dom/hflow.cpp index bf49251..1904f9f 100644 --- a/src/ftxui/dom/hflow.cpp +++ b/src/ftxui/dom/hflow.cpp @@ -56,4 +56,4 @@ std::unique_ptr hflow(Elements children) { return std::make_unique(std::move(children)); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/inverted.cpp b/src/ftxui/dom/inverted.cpp index 7b9fa5e..eb39278 100644 --- a/src/ftxui/dom/inverted.cpp +++ b/src/ftxui/dom/inverted.cpp @@ -24,4 +24,4 @@ std::unique_ptr inverted(Element child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/node.cpp b/src/ftxui/dom/node.cpp index c1798ba..f30330e 100644 --- a/src/ftxui/dom/node.cpp +++ b/src/ftxui/dom/node.cpp @@ -44,4 +44,4 @@ void Render(Screen& screen, Node* node) { screen.ApplyShader(); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/node_decorator.cpp b/src/ftxui/dom/node_decorator.cpp index 73061f9..f690e57 100644 --- a/src/ftxui/dom/node_decorator.cpp +++ b/src/ftxui/dom/node_decorator.cpp @@ -12,4 +12,4 @@ void NodeDecorator::SetBox(Box box) { children[0]->SetBox(box); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/node_decorator.hpp b/src/ftxui/dom/node_decorator.hpp index 42f4025..fc94502 100644 --- a/src/ftxui/dom/node_decorator.hpp +++ b/src/ftxui/dom/node_decorator.hpp @@ -15,6 +15,6 @@ class NodeDecorator : public Node { void SetBox(Box box) override; }; -}; // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_DOM_NODE_DECORATOR_H_ */ diff --git a/src/ftxui/dom/separator.cpp b/src/ftxui/dom/separator.cpp index a59fbea..0c86327 100644 --- a/src/ftxui/dom/separator.cpp +++ b/src/ftxui/dom/separator.cpp @@ -53,4 +53,4 @@ std::unique_ptr separator(Pixel pixel) { return std::make_unique(pixel); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/size.cpp b/src/ftxui/dom/size.cpp index 0439551..d4b5af4 100644 --- a/src/ftxui/dom/size.cpp +++ b/src/ftxui/dom/size.cpp @@ -74,4 +74,4 @@ Decorator size(Direction direction, Constraint constraint, int value) { }; } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/spinner.cpp b/src/ftxui/dom/spinner.cpp index 9bf5fad..b9b4b31 100644 --- a/src/ftxui/dom/spinner.cpp +++ b/src/ftxui/dom/spinner.cpp @@ -276,4 +276,4 @@ std::unique_ptr spinner(int c, size_t index) { return vbox(std::move(lines)); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/text.cpp b/src/ftxui/dom/text.cpp index 1206192..e58a1e1 100644 --- a/src/ftxui/dom/text.cpp +++ b/src/ftxui/dom/text.cpp @@ -36,4 +36,4 @@ std::unique_ptr text(std::wstring text) { return std::make_unique(text); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/underlined.cpp b/src/ftxui/dom/underlined.cpp index 42b11a6..7c51108 100644 --- a/src/ftxui/dom/underlined.cpp +++ b/src/ftxui/dom/underlined.cpp @@ -24,4 +24,4 @@ std::unique_ptr underlined(Element child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/dom/vbox.cpp b/src/ftxui/dom/vbox.cpp index a9d77e0..6d0a353 100644 --- a/src/ftxui/dom/vbox.cpp +++ b/src/ftxui/dom/vbox.cpp @@ -69,4 +69,4 @@ std::unique_ptr vbox(Elements children) { return std::make_unique(std::move(children)); } -}; // namespace ftxui +} // namespace ftxui diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index c6ad86f..525d204 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -8,24 +8,24 @@ namespace ftxui { namespace { -static const wchar_t* BOLD_SET = L"\e[1m"; -static const wchar_t* BOLD_RESET = L"\e[22m"; // Can't use 21 here. +static const wchar_t* BOLD_SET = L"\x1B[1m"; +static const wchar_t* BOLD_RESET = L"\x1B[22m"; // Can't use 21 here. -static const wchar_t* DIM_SET = L"\e[2m"; -static const wchar_t* DIM_RESET = L"\e[22m"; +static const wchar_t* DIM_SET = L"\x1B[2m"; +static const wchar_t* DIM_RESET = L"\x1B[22m"; -static const wchar_t* UNDERLINED_SET = L"\e[4m"; -static const wchar_t* UNDERLINED_RESET = L"\e[24m"; +static const wchar_t* UNDERLINED_SET = L"\x1B[4m"; +static const wchar_t* UNDERLINED_RESET = L"\x1B[24m"; -static const wchar_t* BLINK_SET = L"\e[5m"; -static const wchar_t* BLINK_RESET = L"\e[25m"; +static const wchar_t* BLINK_SET = L"\x1B[5m"; +static const wchar_t* BLINK_RESET = L"\x1B[25m"; -static const wchar_t* INVERTED_SET = L"\e[7m"; -static const wchar_t* INVERTED_RESET = L"\e[27m"; +static const wchar_t* INVERTED_SET = L"\x1B[7m"; +static const wchar_t* INVERTED_RESET = L"\x1B[27m"; static const char* MOVE_LEFT = "\r"; -static const char* MOVE_UP = "\e[1A"; -static const char* CLEAR_LINE = "\e[2K"; +static const char* MOVE_UP = "\x1B[1A"; +static const char* CLEAR_LINE = "\x1B[2K"; bool In(const Box& stencil, int x, int y) { return stencil.x_min <= x && x <= stencil.x_max && // @@ -86,9 +86,9 @@ void UpdatePixelStyle(std::wstringstream& ss, Pixel& previous, Pixel& next) { if (next.foreground_color != previous.foreground_color || next.background_color != previous.background_color) { - ss << L"\e[" + to_wstring(std::to_string((uint8_t)next.foreground_color)) + - L"m"; - ss << L"\e[" + + ss << L"\x1B[" + + to_wstring(std::to_string((uint8_t)next.foreground_color)) + L"m"; + ss << L"\x1B[" + to_wstring(std::to_string(10 + (uint8_t)next.background_color)) + L"m"; } @@ -168,4 +168,4 @@ void Screen::ApplyShader() { } // clang-format on -}; // namespace ftxui +} // namespace ftxui