Compare commits

..

1 Commits

Author SHA1 Message Date
Alex
7a8cf3e41a
Merge baa5973128 into fcd050c017 2024-08-13 18:40:36 +02:00
36 changed files with 122 additions and 291 deletions

View File

@ -27,7 +27,6 @@ Checks: "*,
-readability-simplify-boolean-expr,
-readability-static-accessed-through-instance,
-readability-use-anyofallof,
-readability-avoid-nested-conditional-operator,
-zircon-*,
"
WarningsAsErrors: ''

View File

@ -2,6 +2,8 @@ name: Build
on:
create:
tags:
-v*
push:
branches:
- main
@ -26,11 +28,10 @@ jobs:
compiler: llvm
gcov_executable: "llvm-cov gcov"
# https://github.com/aminya/setup-cpp/issues/246
#- name: MacOS clang
#os: macos-latest
#compiler: llvm
#gcov_executable: "llvm-cov gcov"
- name: MacOS clang
os: macos-latest
compiler: llvm
gcov_executable: "llvm-cov gcov"
- name: Windows MSVC
os: windows-latest
@ -43,7 +44,7 @@ jobs:
id: cpu-cores
- name: "Checkout repository"
uses: actions/checkout@v3
uses: actions/checkout@v2
- name: "Setup Cpp"
uses: aminya/setup-cpp@v1
@ -78,16 +79,11 @@ jobs:
cmake
--build ./build
- name: Unix - Test
- name: Unix - Test and coverage
if: runner.os != 'Windows'
working-directory: ./build
run: >
ctest -C Debug --rerun-failed --output-on-failure;
- name: Unix - coverage
if: runner.os != 'Windows'
working-directory: ./build
run: >
gcovr
-j ${{env.nproc}}
--delete
@ -159,7 +155,7 @@ jobs:
id: cpu-cores
- name: "Checkout repository"
uses: actions/checkout@v3
uses: actions/checkout@v2
- name: "Install cmake"
uses: lukka/get-cmake@latest
@ -190,7 +186,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
uses: actions/checkout@v2
- name: "Install cmake"
uses: lukka/get-cmake@latest

View File

@ -334,7 +334,6 @@ Feel free to add your projects here:
- [Caravan](https://github.com/r3w0p/caravan)
- [Step-Writer](https://github.com/BrianAnakPintar/step-writer)
- [XJ music](https://github.com/xjmusic/xjmusic)
- [UDP chat](https://github.com/Sergeydigl3/udp-chat-tui)
### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam)

View File

@ -38,7 +38,6 @@ example(radiobox)
example(radiobox_in_frame)
example(renderer)
example(resizable_split)
example(scrollbar)
example(slider)
example(slider_direction)
example(slider_rgb)

View File

@ -490,8 +490,8 @@ int main() {
},
&tab_index);
auto exit_button =
Button("Exit", [&] { screen.Exit(); }, ButtonOption::Animated());
auto exit_button = Button(
"Exit", [&] { screen.Exit(); }, ButtonOption::Animated());
auto main_container = Container::Vertical({
Container::Horizontal({

View File

@ -1,112 +0,0 @@
// Copyright 2023 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/component/component.hpp>
#include <ftxui/component/screen_interactive.hpp>
using namespace ftxui;
Component DummyWindowContent() {
class Impl : public ComponentBase {
private:
float scroll_x = 0.1;
float scroll_y = 0.1;
public:
Impl() {
auto content = Renderer([=] {
const std::string lorem =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
"do eiusmod tempor incididunt ut labore et dolore magna "
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
"ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis "
"aute irure dolor in reprehenderit in voluptate velit esse "
"cillum dolore eu fugiat nulla pariatur. Excepteur sint "
"occaecat cupidatat non proident, sunt in culpa qui officia "
"deserunt mollit anim id est laborum.";
return vbox({
text(lorem.substr(0, -1)), text(lorem.substr(5, -1)), text(""),
text(lorem.substr(10, -1)), text(lorem.substr(15, -1)), text(""),
text(lorem.substr(20, -1)), text(lorem.substr(25, -1)), text(""),
text(lorem.substr(30, -1)), text(lorem.substr(35, -1)), text(""),
text(lorem.substr(40, -1)), text(lorem.substr(45, -1)), text(""),
text(lorem.substr(50, -1)), text(lorem.substr(55, -1)), text(""),
text(lorem.substr(60, -1)), text(lorem.substr(65, -1)), text(""),
text(lorem.substr(70, -1)), text(lorem.substr(75, -1)), text(""),
text(lorem.substr(80, -1)), text(lorem.substr(85, -1)), text(""),
text(lorem.substr(90, -1)), text(lorem.substr(95, -1)), text(""),
text(lorem.substr(100, -1)), text(lorem.substr(105, -1)), text(""),
text(lorem.substr(110, -1)), text(lorem.substr(115, -1)), text(""),
text(lorem.substr(120, -1)), text(lorem.substr(125, -1)), text(""),
text(lorem.substr(130, -1)), text(lorem.substr(135, -1)), text(""),
text(lorem.substr(140, -1)),
});
});
auto scrollable_content = Renderer(content, [&, content] {
return content->Render() | focusPositionRelative(scroll_x, scroll_y) |
frame | flex;
});
SliderOption<float> option_x;
option_x.value = &scroll_x;
option_x.min = 0.f;
option_x.max = 1.f;
option_x.increment = 0.1f;
option_x.direction = Direction::Right;
option_x.color_active = Color::Blue;
option_x.color_inactive = Color::BlueLight;
auto scrollbar_x = Slider(option_x);
SliderOption<float> option_y;
option_y.value = &scroll_y;
option_y.min = 0.f;
option_y.max = 1.f;
option_y.increment = 0.1f;
option_y.direction = Direction::Down;
option_y.color_active = Color::Yellow;
option_y.color_inactive = Color::YellowLight;
auto scrollbar_y = Slider(option_y);
Add(Container::Vertical({
Container::Horizontal({
scrollable_content,
scrollbar_y,
}) | flex,
Container::Horizontal({
scrollbar_x,
Renderer([] { return text(L"x"); }),
}),
}));
}
};
return Make<Impl>();
}
int main() {
auto window_1 = Window({
.inner = DummyWindowContent(),
.title = "First window",
.width = 80,
.height = 30,
});
auto window_2 = Window({
.inner = DummyWindowContent(),
.title = "My window",
.left = 40,
.top = 20,
.width = 80,
.height = 30,
});
auto window_container = Container::Stacked({
window_1,
window_2,
});
auto screen = ScreenInteractive::Fullscreen();
screen.Loop(window_container);
return EXIT_SUCCESS;
}

View File

@ -49,4 +49,4 @@ struct Pixel {
} // namespace ftxui
#endif // FTXUI_SCREEN_PIXEL_HPP
#endif // FTXUI_SCREEN_PIXEL_HPP

View File

@ -205,7 +205,7 @@ Component Button(ButtonOption option) {
Component Button(ConstStringRef label,
std::function<void()> on_click,
ButtonOption option) {
option.label = std::move(label);
option.label = label;
option.on_click = std::move(on_click);
return Make<ButtonBase>(std::move(option));
}

View File

@ -47,7 +47,7 @@ Component Collapsible(ConstStringRef label, Component child, Ref<bool> show) {
return hbox({prefix, t});
};
Add(Container::Vertical({
Checkbox(std::move(label), show_.operator->(), opt),
Checkbox(label, show_.operator->(), opt),
Maybe(std::move(child), show_.operator->()),
}));
}

View File

@ -5,7 +5,6 @@
#include <cassert> // for assert
#include <cstddef> // for size_t
#include <iterator> // for begin, end
#include <memory> // for unique_ptr, make_unique
#include <utility> // for move
#include <vector> // for vector, __alloc_traits<>::value_type

View File

@ -3,11 +3,12 @@
// the LICENSE file.
#include "ftxui/component/component_options.hpp"
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
#include <ftxui/screen/color.hpp> // for Color, Color::White, Color::Black, Color::GrayDark, Color::Blue, Color::GrayLight, Color::Red
#include <memory> // for shared_ptr
#include <utility> // for move
#include "ftxui/component/animation.hpp" // for Function, Duration
#include "ftxui/dom/direction.hpp"
#include "ftxui/dom/elements.hpp" // for operator|=, Element, text, bgcolor, inverted, bold, dim, operator|, color, borderEmpty, hbox, automerge, border, borderLight
namespace ftxui {

View File

@ -1,11 +1,11 @@
// Copyright 2021 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 <cstddef> // for size_t
#include <ftxui/component/event.hpp>
#include <functional> // for function
#include <string> // for string
#include <utility>
#include "ftxui/component/component.hpp" // for Maybe, Checkbox, Make, Radiobox, Vertical, Dropdown
#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
#include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState
@ -21,7 +21,7 @@ namespace ftxui {
/// @param selected The index of the selected entry.
Component Dropdown(ConstStringListRef entries, int* selected) {
DropdownOption option;
option.radiobox.entries = std::move(entries);
option.radiobox.entries = entries;
option.radiobox.selected = selected;
return Dropdown(option);
}
@ -29,7 +29,6 @@ Component Dropdown(ConstStringListRef entries, int* selected) {
/// @brief A dropdown menu.
/// @ingroup component
/// @param option The options for the dropdown.
// NOLINTNEXTLINE
Component Dropdown(DropdownOption option) {
class Impl : public ComponentBase, public DropdownOption {
public:

View File

@ -1,8 +1,7 @@
// 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 <map> // for map
#include <string>
#include <map> // for map
#include <utility> // for move
#include "ftxui/component/event.hpp"

View File

@ -1,8 +1,9 @@
// Copyright 2022 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 <functional> // for function
#include <utility> // for move
#include <ftxui/component/captured_mouse.hpp> // for CapturedMouse
#include <functional> // for function
#include <utility> // for move
#include "ftxui/component/component.hpp" // for ComponentDecorator, Hoverable, Make
#include "ftxui/component/component_base.hpp" // for ComponentBase

View File

@ -69,10 +69,10 @@ TEST(HoverableTest, BasicCallback) {
int on_enter_2 = 0;
int on_leave_1 = 0;
int on_leave_2 = 0;
auto c1 =
Hoverable(BasicComponent(), [&] { on_enter_1++; }, [&] { on_leave_1++; });
auto c2 =
Hoverable(BasicComponent(), [&] { on_enter_2++; }, [&] { on_leave_2++; });
auto c1 = Hoverable(
BasicComponent(), [&] { on_enter_1++; }, [&] { on_leave_1++; });
auto c2 = Hoverable(
BasicComponent(), [&] { on_enter_2++; }, [&] { on_leave_2++; });
auto layout = Container::Horizontal({c1, c2});
auto screen = Screen(8, 2);
Render(screen, layout->Render());

View File

@ -5,11 +5,13 @@
#include <cstddef> // for size_t
#include <cstdint> // for uint32_t
#include <functional> // for function
#include <sstream> // for basic_istream, stringstream
#include <string> // for string, basic_string, operator==, getline
#include <utility> // for move
#include <vector> // for vector
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
#include <sstream> // for basic_istream, stringstream
#include <string> // for string, basic_string, operator==, getline
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
#include "ftxui/component/component.hpp" // for Make, Input
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
@ -132,7 +134,7 @@ class InputBase : public ComponentBase, public InputOption {
break;
}
cursor_char_index -= static_cast<int>(line.size() + 1);
cursor_char_index -= line.size() + 1;
cursor_line++;
}
@ -162,7 +164,7 @@ class InputBase : public ComponentBase, public InputOption {
// The cursor is on this line.
const int glyph_start = cursor_char_index;
const int glyph_end = static_cast<int>(GlyphNext(line, glyph_start));
const int glyph_end = GlyphNext(line, glyph_start);
const std::string part_before_cursor = line.substr(0, glyph_start);
const std::string part_at_cursor =
line.substr(glyph_start, glyph_end - glyph_start);
@ -204,7 +206,7 @@ class InputBase : public ComponentBase, public InputOption {
const size_t start = GlyphPrevious(content(), cursor_position());
const size_t end = cursor_position();
content->erase(start, end - start);
cursor_position() = static_cast<int>(start);
cursor_position() = start;
on_change();
return true;
}
@ -232,8 +234,7 @@ class InputBase : public ComponentBase, public InputOption {
return false;
}
cursor_position() =
static_cast<int>(GlyphPrevious(content(), cursor_position()));
cursor_position() = GlyphPrevious(content(), cursor_position());
return true;
}
@ -242,8 +243,7 @@ class InputBase : public ComponentBase, public InputOption {
return false;
}
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
cursor_position() = GlyphNext(content(), cursor_position());
return true;
}
@ -258,7 +258,7 @@ class InputBase : public ComponentBase, public InputOption {
if (content()[iter] == '\n') {
break;
}
width += static_cast<int>(GlyphWidth(content(), iter));
width += GlyphWidth(content(), iter);
}
return width;
}
@ -271,9 +271,8 @@ class InputBase : public ComponentBase, public InputOption {
return;
}
columns -= static_cast<int>(GlyphWidth(content(), cursor_position()));
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
columns -= GlyphWidth(content(), cursor_position());
cursor_position() = GlyphNext(content(), cursor_position());
}
}
@ -293,10 +292,9 @@ class InputBase : public ComponentBase, public InputOption {
if (content()[previous] == '\n') {
break;
}
cursor_position() = static_cast<int>(previous);
cursor_position() = previous;
}
cursor_position() =
static_cast<int>(GlyphPrevious(content(), cursor_position()));
cursor_position() = GlyphPrevious(content(), cursor_position());
while (true) {
if (cursor_position() == 0) {
break;
@ -305,10 +303,10 @@ class InputBase : public ComponentBase, public InputOption {
if (content()[previous] == '\n') {
break;
}
cursor_position() = static_cast<int>(previous);
cursor_position() = previous;
}
MoveCursorColumn(static_cast<int>(columns));
MoveCursorColumn(columns);
return true;
}
@ -324,16 +322,14 @@ class InputBase : public ComponentBase, public InputOption {
if (content()[cursor_position()] == '\n') {
break;
}
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
cursor_position() = GlyphNext(content(), cursor_position());
if (cursor_position() == (int)content().size()) {
return true;
}
}
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
cursor_position() = GlyphNext(content(), cursor_position());
MoveCursorColumn(static_cast<int>(columns));
MoveCursorColumn(columns);
return true;
}
@ -343,7 +339,7 @@ class InputBase : public ComponentBase, public InputOption {
}
bool HandleEnd() {
cursor_position() = static_cast<int>(content->size());
cursor_position() = content->size();
return true;
}
@ -361,7 +357,7 @@ class InputBase : public ComponentBase, public InputOption {
DeleteImpl();
}
content->insert(cursor_position(), character);
cursor_position() += static_cast<int>(character.size());
cursor_position() += character.size();
on_change();
return true;
}
@ -425,7 +421,7 @@ class InputBase : public ComponentBase, public InputOption {
if (IsWordCharacter(content(), previous)) {
break;
}
cursor_position() = static_cast<int>(previous);
cursor_position() = previous;
}
// Move left, as long as left is a word character:
while (cursor_position()) {
@ -433,7 +429,7 @@ class InputBase : public ComponentBase, public InputOption {
if (!IsWordCharacter(content(), previous)) {
break;
}
cursor_position() = static_cast<int>(previous);
cursor_position() = previous;
}
return true;
}
@ -445,8 +441,7 @@ class InputBase : public ComponentBase, public InputOption {
// Move right, until entering a word.
while (cursor_position() < (int)content().size()) {
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
cursor_position() = GlyphNext(content(), cursor_position());
if (IsWordCharacter(content(), cursor_position())) {
break;
}
@ -457,7 +452,7 @@ class InputBase : public ComponentBase, public InputOption {
if (!IsWordCharacter(content(), cursor_position())) {
break;
}
cursor_position() = static_cast<int>(next);
cursor_position() = next;
}
return true;
@ -494,7 +489,7 @@ class InputBase : public ComponentBase, public InputOption {
break;
}
cursor_char_index -= static_cast<int>(line.size() + 1);
cursor_char_index -= line.size() + 1;
cursor_line++;
}
const int cursor_column =
@ -520,13 +515,11 @@ class InputBase : public ComponentBase, public InputOption {
// Convert back the new_cursor_{line,column} toward cursor_position:
cursor_position() = 0;
for (int i = 0; i < new_cursor_line; ++i) {
cursor_position() += static_cast<int>(lines[i].size() + 1);
cursor_position() += lines[i].size() + 1;
}
while (new_cursor_column > 0) {
new_cursor_column -=
static_cast<int>(GlyphWidth(content(), cursor_position()));
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
new_cursor_column -= GlyphWidth(content(), cursor_position());
cursor_position() = GlyphNext(content(), cursor_position());
}
on_change();

View File

@ -511,7 +511,6 @@ class MenuBase : public ComponentBase, public MenuOption {
/// entry 2
/// entry 3
/// ```
// NOLINTNEXTLINE
Component Menu(MenuOption option) {
return Make<MenuBase>(std::move(option));
}
@ -544,7 +543,7 @@ Component Menu(MenuOption option) {
/// entry 3
/// ```
Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
option.entries = std::move(entries);
option.entries = entries;
option.selected = selected;
return Menu(option);
}
@ -555,7 +554,7 @@ Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
/// See also |Menu|.
/// @ingroup component
Component Toggle(ConstStringListRef entries, int* selected) {
return Menu(std::move(entries), selected, MenuOption::Toggle());
return Menu(entries, selected, MenuOption::Toggle());
}
/// @brief A specific menu entry. They can be put into a Container::Vertical to

View File

@ -204,7 +204,6 @@ class RadioboxBase : public ComponentBase, public RadioboxOption {
/// ○ entry 2
/// ○ entry 3
/// ```
/// NOLINTNEXTLINE
Component Radiobox(RadioboxOption option) {
return Make<RadioboxBase>(std::move(option));
}
@ -240,7 +239,7 @@ Component Radiobox(RadioboxOption option) {
Component Radiobox(ConstStringListRef entries,
int* selected,
RadioboxOption option) {
option.entries = std::move(entries);
option.entries = entries;
option.selected = selected;
return Make<RadioboxBase>(std::move(option));
}

View File

@ -1,38 +1,34 @@
// 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/component/screen_interactive.hpp"
#include <algorithm> // for copy, max, min
#include <array> // for array
#include <atomic>
#include <chrono> // for operator-, milliseconds, operator>=, duration, common_type<>::type, time_point
#include <csignal> // for signal, SIGTSTP, SIGABRT, SIGWINCH, raise, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, __sighandler_t, size_t
#include <cstdint>
#include <cstdio> // for fileno, stdin
#include <cstdio> // for fileno, stdin
#include <ftxui/component/task.hpp> // for Task, Closure, AnimationTask
#include <ftxui/screen/screen.hpp> // for Pixel, Screen::Cursor, Screen, Screen::Cursor::Hidden
#include <functional> // for function
#include <initializer_list> // for initializer_list
#include <iostream> // for cout, ostream, operator<<, basic_ostream, endl, flush
#include <memory>
#include <stack> // for stack
#include <string>
#include <thread> // for thread, sleep_for
#include <tuple> // for _Swallow_assign, ignore
#include <stack> // for stack
#include <thread> // for thread, sleep_for
#include <tuple> // for _Swallow_assign, ignore
#include <type_traits> // for decay_t
#include <utility> // for move, swap
#include <variant> // for visit, variant
#include <vector> // for vector
#include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse, CapturedMouseInterface
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/event.hpp" // for Event
#include "ftxui/component/loop.hpp" // for Loop
#include "ftxui/component/receiver.hpp" // for ReceiverImpl, Sender, MakeReceiver, SenderImpl, Receiver
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputParser
#include "ftxui/dom/node.hpp" // for Node, Render
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/screen/pixel.hpp" // for Pixel
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
#if defined(_WIN32)
@ -162,7 +158,7 @@ void ftxui_on_resize(int columns, int rows) {
#else // POSIX (Linux & Mac)
int CheckStdinReady(int usec_timeout) {
timeval tv = {0, usec_timeout}; // NOLINT
timeval tv = {0, usec_timeout};
fd_set fds;
FD_ZERO(&fds); // NOLINT
FD_SET(STDIN_FILENO, &fds); // NOLINT
@ -217,11 +213,11 @@ void RecordSignal(int signal) {
break;
#if !defined(_WIN32)
case SIGTSTP: // NOLINT
case SIGTSTP:
g_signal_stop_count++;
break;
case SIGWINCH: // NOLINT
case SIGWINCH:
g_signal_resize_count++;
break;
#endif
@ -269,7 +265,7 @@ const std::string ST = "\x1b\\"; // NOLINT
const std::string DECRQSS_DECSCUSR = DCS + "$q q" + ST; // NOLINT
// DEC: Digital Equipment Corporation
enum class DECMode : std::uint16_t {
enum class DECMode {
kLineWrap = 7,
kCursor = 25,
@ -288,7 +284,7 @@ enum class DECMode : std::uint16_t {
};
// Device Status Report (DSR) {
enum class DSRMode : std::uint8_t {
enum class DSRMode {
kCursor = 6,
};
@ -547,8 +543,7 @@ void ScreenInteractive::PostMain() {
// On final exit, keep the current drawing and reset cursor position one
// line after it.
if (!use_alternative_screen_) {
std::cout << '\n';
std::cout << std::flush;
std::cout << std::endl;
}
}
}
@ -602,7 +597,7 @@ void ScreenInteractive::Install() {
// Request the terminal to report the current cursor shape. We will restore it
// on exit.
std::cout << DECRQSS_DECSCUSR;
on_exit_functions.emplace([this] {
on_exit_functions.emplace([=] {
std::cout << "\033[?25h"; // Enable cursor.
std::cout << "\033[" + std::to_string(cursor_reset_shape_) + " q";
});

View File

@ -9,7 +9,7 @@
#include <map>
#include <memory> // for unique_ptr, allocator
#include <utility> // for move
#include <vector>
#include "ftxui/component/event.hpp" // for Event
#include "ftxui/component/task.hpp" // for Task

View File

@ -5,14 +5,8 @@
#include <algorithm>
#include <ftxui/component/component.hpp>
#include <ftxui/component/component_base.hpp>
#include <ftxui/component/component_options.hpp>
#include <ftxui/component/screen_interactive.hpp> // for ScreenInteractive
#include <memory>
#include <utility>
#include "ftxui/dom/elements.hpp" // for text, window, hbox, vbox, size, clear_under, reflect, emptyElement
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
#include "ftxui/screen/color.hpp" // for Color
#include "ftxui/screen/screen.hpp" // for Screen
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
namespace ftxui {
@ -93,7 +87,7 @@ class ResizeDecorator : public NodeDecorator {
Element DefaultRenderState(const WindowRenderState& state) {
Element element = state.inner;
if (!state.active) {
if (state.active) {
element |= dim;
}
@ -212,7 +206,7 @@ class WindowImpl : public ComponentBase, public WindowOptions {
}
// Clamp the window size.
width() = std::max<int>(width(), static_cast<int>(title().size() + 2));
width() = std::max<int>(width(), title().size() + 2);
height() = std::max<int>(height(), 2);
return true;

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <benchmark/benchmark.h>
#include <iostream>
#include "ftxui/dom/elements.hpp" // for gauge, separator, operator|, text, Element, hbox, vbox, blink, border, inverted
#include "ftxui/dom/node.hpp" // for Render

View File

@ -8,12 +8,12 @@
#include <optional> // for optional, nullopt
#include <string> // for basic_string, string
#include <utility> // for move
#include <vector> // for __alloc_traits<>::value_type
#include "ftxui/dom/elements.hpp" // for unpack, Element, Decorator, BorderStyle, ROUNDED, borderStyled, Elements, DASHED, DOUBLE, EMPTY, HEAVY, LIGHT, border, borderDashed, borderDouble, borderEmpty, borderHeavy, borderLight, borderRounded, borderWith, window
#include "ftxui/dom/node.hpp" // for Node, Elements
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/pixel.hpp" // for Pixel
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
namespace ftxui {
@ -38,8 +38,7 @@ class Border : public Node {
BorderStyle style,
std::optional<Color> foreground_color = std::nullopt)
: Node(std::move(children)),
charset_(simple_border_charset[style]) // NOLINT
,
charset_(simple_border_charset[style]),
foreground_color_(foreground_color) {} // NOLINT
const Charset& charset_; // NOLINT

View File

@ -4,7 +4,6 @@
#include "ftxui/dom/box_helper.hpp"
#include <algorithm> // for max
#include <vector> // for vector
namespace ftxui::box_helper {

View File

@ -8,7 +8,6 @@
#include <cstdint> // for uint8_t
#include <cstdlib> // for abs
#include <ftxui/screen/color.hpp> // for Color
#include <functional> // for function
#include <map> // for map
#include <memory> // for make_shared
#include <utility> // for move, pair
@ -18,8 +17,6 @@
#include "ftxui/dom/node.hpp" // for Node
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/image.hpp" // for Image
#include "ftxui/screen/pixel.hpp" // for Pixel
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
#include "ftxui/screen/string.hpp" // for Utf8ToGlyphs
#include "ftxui/util/ref.hpp" // for ConstRef
@ -31,7 +28,7 @@ namespace {
// Base UTF8 pattern:
// 11100010 10100000 10000000 // empty
// Pattern for the individual dots:
// Pattern for the individuel dots:
// ┌──────┬───────┐
// │dot1 │ dot4 │
// ├──────┼───────┤

View File

@ -2,16 +2,13 @@
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <algorithm> // for max
#include <cstddef> // for size_t
#include <memory> // for __shared_ptr_access, shared_ptr, make_shared
#include <utility> // for move
#include <vector>
#include "ftxui/dom/elements.hpp" // for Element, Elements, dbox
#include "ftxui/dom/node.hpp" // for Node, Elements
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/pixel.hpp" // for Pixel
namespace ftxui {
@ -52,13 +49,12 @@ class DBox : public Node {
void Render(Screen& screen) override {
if (children_.size() <= 1) {
Node::Render(screen);
return;
return Node::Render(screen);
}
const int width = box_.x_max - box_.x_min + 1;
const int height = box_.y_max - box_.y_min + 1;
std::vector<Pixel> pixels(std::size_t(width * height));
std::vector<Pixel> pixels(size_t(width * height));
for (auto& child : children_) {
child->Render(screen);
@ -71,7 +67,7 @@ class DBox : public Node {
acc->background_color =
Color::Blend(acc->background_color, pixel.background_color);
acc->automerge = pixel.automerge || acc->automerge;
if (pixel.character.empty()) {
if (pixel.character == "") {
acc->foreground_color =
Color::Blend(acc->foreground_color, pixel.background_color);
} else {
@ -86,7 +82,7 @@ class DBox : public Node {
acc->character = pixel.character;
acc->foreground_color = pixel.foreground_color;
}
++acc; // NOLINT
++acc;
pixel = Pixel();
}
@ -97,7 +93,7 @@ class DBox : public Node {
Pixel* acc = pixels.data();
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
screen.PixelAt(x + box_.x_min, y + box_.y_min) = *acc++; // NOLINT
screen.PixelAt(x + box_.x_min, y + box_.y_min) = *acc++;
}
}
}

View File

@ -3,6 +3,7 @@
// the LICENSE file.
#include <memory> // for make_shared, __shared_ptr_access
#include <utility> // for move
#include <vector> // for __alloc_traits<>::value_type
#include "ftxui/dom/elements.hpp" // for Element, unpack, filler, flex, flex_grow, flex_shrink, notflex, xflex, xflex_grow, xflex_shrink, yflex, yflex_grow, yflex_shrink
#include "ftxui/dom/node.hpp" // for Elements, Node

View File

@ -7,7 +7,6 @@
#include <cstddef> // for size_t
#include <ftxui/dom/flexbox_config.hpp> // for FlexboxConfig, FlexboxConfig::Direction, FlexboxConfig::AlignContent, FlexboxConfig::JustifyContent, FlexboxConfig::Wrap, FlexboxConfig::Direction::RowInversed, FlexboxConfig::AlignItems, FlexboxConfig::Direction::Row, FlexboxConfig::Direction::Column, FlexboxConfig::Direction::ColumnInversed, FlexboxConfig::Wrap::WrapInversed, FlexboxConfig::AlignContent::Stretch, FlexboxConfig::JustifyContent::Stretch, FlexboxConfig::Wrap::Wrap, FlexboxConfig::AlignContent::Center, FlexboxConfig::AlignContent::FlexEnd, FlexboxConfig::AlignContent::FlexStart, FlexboxConfig::AlignContent::SpaceAround, FlexboxConfig::AlignContent::SpaceBetween, FlexboxConfig::AlignContent::SpaceEvenly, FlexboxConfig::AlignItems::Center, FlexboxConfig::AlignItems::FlexEnd, FlexboxConfig::AlignItems::FlexStart, FlexboxConfig::AlignItems::Stretch, FlexboxConfig::JustifyContent::Center, FlexboxConfig::JustifyContent::FlexEnd, FlexboxConfig::JustifyContent::FlexStart, FlexboxConfig::JustifyContent::SpaceAround, FlexboxConfig::JustifyContent::SpaceBetween, FlexboxConfig::JustifyContent::SpaceEvenly, FlexboxConfig::Wrap::NoWrap
#include <utility> // for swap, move
#include <vector>
#include "ftxui/dom/box_helper.hpp" // for Element, Compute
@ -331,8 +330,8 @@ void Compute3(Global& global) {
line = Line();
}
block.line = static_cast<int>(lines.size());
block.line_position = static_cast<int>(line.blocks.size());
block.line = lines.size();
block.line_position = line.blocks.size();
line.blocks.push_back(&block);
x += block.min_size_x + global.config.gap_x;
}

View File

@ -32,7 +32,7 @@ class Reflect : public Node {
void Render(Screen& screen) final {
reflected_box_ = Box::Intersection(screen.stencil, reflected_box_);
Node::Render(screen);
return Node::Render(screen);
}
private:

View File

@ -11,7 +11,6 @@
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/color.hpp" // for Color
#include "ftxui/screen/pixel.hpp" // for Pixel
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
namespace ftxui {
@ -64,8 +63,7 @@ class SeparatorAuto : public Node {
const bool is_column = (box_.x_max == box_.x_min);
const bool is_line = (box_.y_min == box_.y_max);
const std::string c =
charsets[style_][int(is_line && !is_column)]; // NOLINT
const std::string c = charsets[style_][int(is_line && !is_column)];
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {

View File

@ -6,7 +6,6 @@
#include <algorithm> // for max
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
#include <utility> // for move, swap
#include <vector> // for vector
#include "ftxui/dom/elements.hpp" // for Element, operator|, text, separatorCharacter, Elements, BorderStyle, Decorator, emptyElement, size, gridbox, EQUAL, flex, flex_shrink, HEIGHT, WIDTH

View File

@ -6,12 +6,14 @@
#include <array> // for array
#include <cmath>
#include <cstdint>
#include <string>
#include "ftxui/screen/color_info.hpp" // for GetColorInfo, ColorInfo
#include "ftxui/screen/terminal.hpp" // for ColorSupport, Color, Palette256, TrueColor
namespace ftxui {
using namespace std::literals;
namespace {
const std::array<const char*, 33> palette16code = {
"30", "40", //
@ -44,33 +46,23 @@ bool Color::operator!=(const Color& rhs) const {
}
std::string Color::Print(bool is_background_color) const {
if (is_background_color) {
switch (type_) {
case ColorType::Palette1:
return "49";
case ColorType::Palette16:
return palette16code[2 * red_ + 1]; // NOLINT
case ColorType::Palette256:
return "48;5;" + std::to_string(red_);
case ColorType::TrueColor:
return "48;2;" + std::to_string(red_) + ";" + std::to_string(green_) +
";" + std::to_string(blue_);
}
} else {
switch (type_) {
case ColorType::Palette1:
return "39";
case ColorType::Palette16:
return palette16code[2 * red_]; // NOLINT
case ColorType::Palette256:
return "38;5;" + std::to_string(red_);
case ColorType::TrueColor:
return "38;2;" + std::to_string(red_) + ";" + std::to_string(green_) +
";" + std::to_string(blue_);
}
switch (type_) {
case ColorType::Palette1:
return is_background_color ? "49"s : "39"s;
case ColorType::Palette16:
return palette16code[2 * red_ + is_background_color]; // NOLINT;
case ColorType::Palette256:
return (is_background_color ? "48;5;"s : "38;5;"s) + std::to_string(red_);
case ColorType::TrueColor:
default:
return (is_background_color ? "48;2;"s : "38;2;"s) //
+ std::to_string(red_) + ";" //
+ std::to_string(green_) + ";" //
+ std::to_string(blue_); //
}
// NOTREACHED();
return "";
}
/// @brief Build a transparent color.

View File

@ -2,11 +2,8 @@
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <sstream> // IWYU pragma: keep
#include <string>
#include <vector>
#include "ftxui/screen/image.hpp"
#include "ftxui/screen/pixel.hpp"
namespace ftxui {

View File

@ -1,16 +1,13 @@
// 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 <cstddef> // for size_t
#include <cstdint>
#include <cstdint> // for size_t
#include <iostream> // for operator<<, stringstream, basic_ostream, flush, cout, ostream
#include <limits>
#include <map> // for _Rb_tree_const_iterator, map, operator!=, operator==
#include <sstream> // IWYU pragma: keep
#include <utility> // for pair
#include "ftxui/screen/image.hpp" // for Image
#include "ftxui/screen/pixel.hpp" // for Pixel
#include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp" // for string_width
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
@ -120,11 +117,11 @@ void UpdatePixelStyle(const Screen* screen,
}
struct TileEncoding {
std::uint8_t left : 2;
std::uint8_t top : 2;
std::uint8_t right : 2;
std::uint8_t down : 2;
std::uint8_t round : 1;
uint8_t left : 2;
uint8_t top : 2;
uint8_t right : 2;
uint8_t down : 2;
uint8_t round : 1;
// clang-format off
bool operator<(const TileEncoding& other) const {
@ -524,20 +521,20 @@ void Screen::ApplyShader() {
}
// clang-format on
std::uint8_t Screen::RegisterHyperlink(const std::string& link) {
for (std::size_t i = 0; i < hyperlinks_.size(); ++i) {
uint8_t Screen::RegisterHyperlink(const std::string& link) {
for (size_t i = 0; i < hyperlinks_.size(); ++i) {
if (hyperlinks_[i] == link) {
return i;
}
}
if (hyperlinks_.size() == std::numeric_limits<std::uint8_t>::max()) {
if (hyperlinks_.size() == std::numeric_limits<uint8_t>::max()) {
return 0;
}
hyperlinks_.push_back(link);
return hyperlinks_.size() - 1;
}
const std::string& Screen::Hyperlink(std::uint8_t id) const {
const std::string& Screen::Hyperlink(uint8_t id) const {
if (id >= hyperlinks_.size()) {
return hyperlinks_[0];
}

View File

@ -16,7 +16,6 @@
#include <cstdint> // for uint32_t, uint8_t, uint16_t, int32_t
#include <string> // for string, basic_string, wstring
#include <tuple> // for _Swallow_assign, ignore
#include <vector>
#include "ftxui/screen/deprecated.hpp" // for wchar_width, wstring_width
#include "ftxui/screen/string_internal.hpp" // for WordBreakProperty, EatCodePoint, CodepointToWordBreakProperty, GlyphCount, GlyphIterate, GlyphNext, GlyphPrevious, IsCombining, IsControl, IsFullWidth, Utf8ToWordBreakProperty
@ -1356,6 +1355,7 @@ int string_width(const std::string& input) {
std::vector<std::string> Utf8ToGlyphs(const std::string& input) {
std::vector<std::string> out;
const std::string current;
out.reserve(input.size());
size_t start = 0;
size_t end = 0;

View File

@ -1,7 +1,3 @@
// Copyright 2023 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/util/ref.hpp"
#include <gtest/gtest.h>