mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-28 14:16:29 +08:00
Compare commits
16 Commits
d69f4ff128
...
05915fb90b
Author | SHA1 | Date | |
---|---|---|---|
|
05915fb90b | ||
|
f5d8c7deb5 | ||
|
7cdf9a4890 | ||
|
eb21c23f60 | ||
|
e3dd95d63c | ||
|
53f179c776 | ||
|
2de925f2c6 | ||
|
10a4a04529 | ||
|
27424d5c20 | ||
|
465822523d | ||
|
719a2388f5 | ||
|
c1c6afc0ba | ||
|
70b32fe523 | ||
|
e9d13e2c2c | ||
|
9dfbdd168b | ||
|
73cd1d0190 |
@ -27,6 +27,7 @@ Checks: "*,
|
|||||||
-readability-simplify-boolean-expr,
|
-readability-simplify-boolean-expr,
|
||||||
-readability-static-accessed-through-instance,
|
-readability-static-accessed-through-instance,
|
||||||
-readability-use-anyofallof,
|
-readability-use-anyofallof,
|
||||||
|
-readability-avoid-nested-conditional-operator,
|
||||||
-zircon-*,
|
-zircon-*,
|
||||||
"
|
"
|
||||||
WarningsAsErrors: ''
|
WarningsAsErrors: ''
|
||||||
|
@ -82,6 +82,7 @@ add_library(dom
|
|||||||
src/ftxui/dom/gridbox.cpp
|
src/ftxui/dom/gridbox.cpp
|
||||||
src/ftxui/dom/hbox.cpp
|
src/ftxui/dom/hbox.cpp
|
||||||
src/ftxui/dom/inverted.cpp
|
src/ftxui/dom/inverted.cpp
|
||||||
|
src/ftxui/dom/selectable.cpp
|
||||||
src/ftxui/dom/linear_gradient.cpp
|
src/ftxui/dom/linear_gradient.cpp
|
||||||
src/ftxui/dom/node.cpp
|
src/ftxui/dom/node.cpp
|
||||||
src/ftxui/dom/node_decorator.cpp
|
src/ftxui/dom/node_decorator.cpp
|
||||||
|
@ -38,6 +38,7 @@ example(radiobox)
|
|||||||
example(radiobox_in_frame)
|
example(radiobox_in_frame)
|
||||||
example(renderer)
|
example(renderer)
|
||||||
example(resizable_split)
|
example(resizable_split)
|
||||||
|
example(selectable_input)
|
||||||
example(slider)
|
example(slider)
|
||||||
example(slider_direction)
|
example(slider_direction)
|
||||||
example(slider_rgb)
|
example(slider_rgb)
|
||||||
|
@ -490,8 +490,8 @@ int main() {
|
|||||||
},
|
},
|
||||||
&tab_index);
|
&tab_index);
|
||||||
|
|
||||||
auto exit_button = Button(
|
auto exit_button =
|
||||||
"Exit", [&] { screen.Exit(); }, ButtonOption::Animated());
|
Button("Exit", [&] { screen.Exit(); }, ButtonOption::Animated());
|
||||||
|
|
||||||
auto main_container = Container::Vertical({
|
auto main_container = Container::Vertical({
|
||||||
Container::Horizontal({
|
Container::Horizontal({
|
||||||
|
80
examples/component/selectable_input.cpp
Normal file
80
examples/component/selectable_input.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// 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 <memory> // for allocator, __shared_ptr_access
|
||||||
|
#include <string> // for char_traits, operator+, string, basic_string
|
||||||
|
|
||||||
|
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||||
|
#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
|
||||||
|
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||||
|
#include "ftxui/component/component_options.hpp" // for InputOption
|
||||||
|
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||||
|
#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
|
||||||
|
#include "ftxui/util/ref.hpp" // for Ref
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
using namespace ftxui;
|
||||||
|
|
||||||
|
// The data:
|
||||||
|
std::string first_name;
|
||||||
|
std::string last_name;
|
||||||
|
std::string password;
|
||||||
|
std::string phoneNumber;
|
||||||
|
Region selection;
|
||||||
|
std::string textToCopy;
|
||||||
|
|
||||||
|
auto screen = ScreenInteractive::TerminalOutput();
|
||||||
|
|
||||||
|
// The basic input components:
|
||||||
|
Component input_first_name = Input(&first_name, "first name");
|
||||||
|
Component input_last_name = Input(&last_name, "last name");
|
||||||
|
|
||||||
|
// The password input component:
|
||||||
|
InputOption password_option;
|
||||||
|
password_option.password = true;
|
||||||
|
Component input_password = Input(&password, "password", password_option);
|
||||||
|
|
||||||
|
// The phone number input component:
|
||||||
|
// We are using `CatchEvent` to filter out non-digit characters.
|
||||||
|
Component input_phone_number = Input(&phoneNumber, "phone number");
|
||||||
|
input_phone_number |= CatchEvent([&](Event event) {
|
||||||
|
return event.is_character() && !std::isdigit(event.character()[0]);
|
||||||
|
});
|
||||||
|
input_phone_number |= CatchEvent([&](Event event) {
|
||||||
|
return event.is_character() && phoneNumber.size() > 10;
|
||||||
|
});
|
||||||
|
|
||||||
|
// The component tree:
|
||||||
|
auto component = Container::Vertical({
|
||||||
|
input_first_name,
|
||||||
|
input_last_name,
|
||||||
|
input_password,
|
||||||
|
input_phone_number,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tweak how the component tree is rendered:
|
||||||
|
auto renderer = Renderer(component, [&] {
|
||||||
|
return vbox({
|
||||||
|
hbox(text(" First name : "), input_first_name->Render()),
|
||||||
|
hbox(text(" Last name : "), input_last_name->Render()),
|
||||||
|
hbox(text(" Password : "), input_password->Render()),
|
||||||
|
hbox(text(" Phone num : "), input_phone_number->Render()),
|
||||||
|
separator(),
|
||||||
|
text("Hello " + first_name + " " + last_name),
|
||||||
|
text("Your password is " + password),
|
||||||
|
text("Your phone number is " + phoneNumber),
|
||||||
|
text("select_start " + std::to_string(selection.startx) + ";" + std::to_string(selection.starty)),
|
||||||
|
text("select_end " + std::to_string(selection.endx) + ";" + std::to_string(selection.endy)),
|
||||||
|
text("textToCopy " + textToCopy)
|
||||||
|
}) |
|
||||||
|
border | selectable([&textToCopy](std::string txtSelected){textToCopy = txtSelected;});
|
||||||
|
});
|
||||||
|
|
||||||
|
renderer |= CatchEvent([&](Event event) {
|
||||||
|
|
||||||
|
return selectableCatchEvent(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
screen.Loop(renderer);
|
||||||
|
}
|
@ -16,6 +16,7 @@
|
|||||||
#include "ftxui/screen/color.hpp"
|
#include "ftxui/screen/color.hpp"
|
||||||
#include "ftxui/screen/terminal.hpp"
|
#include "ftxui/screen/terminal.hpp"
|
||||||
#include "ftxui/util/ref.hpp"
|
#include "ftxui/util/ref.hpp"
|
||||||
|
#include "ftxui/component/event.hpp"
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
class Node;
|
class Node;
|
||||||
@ -33,6 +34,15 @@ enum BorderStyle {
|
|||||||
EMPTY,
|
EMPTY,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
uint16_t startx = 0;
|
||||||
|
uint16_t endx = 0;
|
||||||
|
uint16_t starty = 0;
|
||||||
|
uint16_t endy = 0;
|
||||||
|
bool changed = false;
|
||||||
|
} Region;
|
||||||
|
|
||||||
// Pipe elements into decorator togethers.
|
// Pipe elements into decorator togethers.
|
||||||
// For instance the next lines are equivalents:
|
// For instance the next lines are equivalents:
|
||||||
// -> text("ftxui") | bold | underlined
|
// -> text("ftxui") | bold | underlined
|
||||||
@ -96,6 +106,9 @@ Element canvas(std::function<void(Canvas&)>);
|
|||||||
Element bold(Element);
|
Element bold(Element);
|
||||||
Element dim(Element);
|
Element dim(Element);
|
||||||
Element inverted(Element);
|
Element inverted(Element);
|
||||||
|
Element selectable(std::function<void(const std::string)> onSelectionChange, Element);
|
||||||
|
Decorator selectable(std::function<void(const std::string)> onSelectionChange);
|
||||||
|
bool selectableCatchEvent(Event event);
|
||||||
Element underlined(Element);
|
Element underlined(Element);
|
||||||
Element underlinedDouble(Element);
|
Element underlinedDouble(Element);
|
||||||
Element blink(Element);
|
Element blink(Element);
|
||||||
|
@ -205,7 +205,7 @@ Component Button(ButtonOption option) {
|
|||||||
Component Button(ConstStringRef label,
|
Component Button(ConstStringRef label,
|
||||||
std::function<void()> on_click,
|
std::function<void()> on_click,
|
||||||
ButtonOption option) {
|
ButtonOption option) {
|
||||||
option.label = label;
|
option.label = std::move(label);
|
||||||
option.on_click = std::move(on_click);
|
option.on_click = std::move(on_click);
|
||||||
return Make<ButtonBase>(std::move(option));
|
return Make<ButtonBase>(std::move(option));
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ Component Collapsible(ConstStringRef label, Component child, Ref<bool> show) {
|
|||||||
return hbox({prefix, t});
|
return hbox({prefix, t});
|
||||||
};
|
};
|
||||||
Add(Container::Vertical({
|
Add(Container::Vertical({
|
||||||
Checkbox(label, show_.operator->(), opt),
|
Checkbox(std::move(label), show_.operator->(), opt),
|
||||||
Maybe(std::move(child), show_.operator->()),
|
Maybe(std::move(child), show_.operator->()),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <cassert> // for assert
|
#include <cassert> // for assert
|
||||||
#include <cstddef> // for size_t
|
#include <cstddef> // for size_t
|
||||||
#include <iterator> // for begin, end
|
#include <iterator> // for begin, end
|
||||||
|
#include <memory> // for unique_ptr, make_unique
|
||||||
#include <utility> // for move
|
#include <utility> // for move
|
||||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||||
|
|
||||||
|
@ -3,12 +3,11 @@
|
|||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include "ftxui/component/component_options.hpp"
|
#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 <ftxui/screen/color.hpp> // for Color, Color::White, Color::Black, Color::GrayDark, Color::Blue, Color::GrayLight, Color::Red
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <utility> // for move
|
#include <utility> // for move
|
||||||
|
|
||||||
#include "ftxui/component/animation.hpp" // for Function, Duration
|
#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
|
#include "ftxui/dom/elements.hpp" // for operator|=, Element, text, bgcolor, inverted, bold, dim, operator|, color, borderEmpty, hbox, automerge, border, borderLight
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <cstddef> // for size_t
|
|
||||||
#include <ftxui/component/event.hpp>
|
#include <ftxui/component/event.hpp>
|
||||||
#include <functional> // for function
|
#include <functional> // for function
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include "ftxui/component/component.hpp" // for Maybe, Checkbox, Make, Radiobox, Vertical, Dropdown
|
#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_base.hpp" // for Component, ComponentBase
|
||||||
#include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState
|
#include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState
|
||||||
@ -21,7 +21,7 @@ namespace ftxui {
|
|||||||
/// @param selected The index of the selected entry.
|
/// @param selected The index of the selected entry.
|
||||||
Component Dropdown(ConstStringListRef entries, int* selected) {
|
Component Dropdown(ConstStringListRef entries, int* selected) {
|
||||||
DropdownOption option;
|
DropdownOption option;
|
||||||
option.radiobox.entries = entries;
|
option.radiobox.entries = std::move(entries);
|
||||||
option.radiobox.selected = selected;
|
option.radiobox.selected = selected;
|
||||||
return Dropdown(option);
|
return Dropdown(option);
|
||||||
}
|
}
|
||||||
@ -29,6 +29,7 @@ Component Dropdown(ConstStringListRef entries, int* selected) {
|
|||||||
/// @brief A dropdown menu.
|
/// @brief A dropdown menu.
|
||||||
/// @ingroup component
|
/// @ingroup component
|
||||||
/// @param option The options for the dropdown.
|
/// @param option The options for the dropdown.
|
||||||
|
// NOLINTNEXTLINE
|
||||||
Component Dropdown(DropdownOption option) {
|
Component Dropdown(DropdownOption option) {
|
||||||
class Impl : public ComponentBase, public DropdownOption {
|
class Impl : public ComponentBase, public DropdownOption {
|
||||||
public:
|
public:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <map> // for map
|
#include <map> // for map
|
||||||
|
#include <string>
|
||||||
#include <utility> // for move
|
#include <utility> // for move
|
||||||
|
|
||||||
#include "ftxui/component/event.hpp"
|
#include "ftxui/component/event.hpp"
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <ftxui/component/captured_mouse.hpp> // for CapturedMouse
|
|
||||||
#include <functional> // for function
|
#include <functional> // for function
|
||||||
#include <utility> // for move
|
#include <utility> // for move
|
||||||
|
|
||||||
|
@ -69,10 +69,10 @@ TEST(HoverableTest, BasicCallback) {
|
|||||||
int on_enter_2 = 0;
|
int on_enter_2 = 0;
|
||||||
int on_leave_1 = 0;
|
int on_leave_1 = 0;
|
||||||
int on_leave_2 = 0;
|
int on_leave_2 = 0;
|
||||||
auto c1 = Hoverable(
|
auto c1 =
|
||||||
BasicComponent(), [&] { on_enter_1++; }, [&] { on_leave_1++; });
|
Hoverable(BasicComponent(), [&] { on_enter_1++; }, [&] { on_leave_1++; });
|
||||||
auto c2 = Hoverable(
|
auto c2 =
|
||||||
BasicComponent(), [&] { on_enter_2++; }, [&] { on_leave_2++; });
|
Hoverable(BasicComponent(), [&] { on_enter_2++; }, [&] { on_leave_2++; });
|
||||||
auto layout = Container::Horizontal({c1, c2});
|
auto layout = Container::Horizontal({c1, c2});
|
||||||
auto screen = Screen(8, 2);
|
auto screen = Screen(8, 2);
|
||||||
Render(screen, layout->Render());
|
Render(screen, layout->Render());
|
||||||
|
@ -5,13 +5,11 @@
|
|||||||
#include <cstddef> // for size_t
|
#include <cstddef> // for size_t
|
||||||
#include <cstdint> // for uint32_t
|
#include <cstdint> // for uint32_t
|
||||||
#include <functional> // for function
|
#include <functional> // for function
|
||||||
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
|
|
||||||
#include <sstream> // for basic_istream, stringstream
|
#include <sstream> // for basic_istream, stringstream
|
||||||
#include <string> // for string, basic_string, operator==, getline
|
#include <string> // for string, basic_string, operator==, getline
|
||||||
#include <utility> // for move
|
#include <utility> // for move
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
|
||||||
#include "ftxui/component/component.hpp" // for Make, Input
|
#include "ftxui/component/component.hpp" // for Make, Input
|
||||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||||
#include "ftxui/component/component_options.hpp" // for InputOption
|
#include "ftxui/component/component_options.hpp" // for InputOption
|
||||||
@ -134,7 +132,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor_char_index -= line.size() + 1;
|
cursor_char_index -= static_cast<int>(line.size() + 1);
|
||||||
cursor_line++;
|
cursor_line++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +162,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
|
|
||||||
// The cursor is on this line.
|
// The cursor is on this line.
|
||||||
const int glyph_start = cursor_char_index;
|
const int glyph_start = cursor_char_index;
|
||||||
const int glyph_end = GlyphNext(line, glyph_start);
|
const int glyph_end = static_cast<int>(GlyphNext(line, glyph_start));
|
||||||
const std::string part_before_cursor = line.substr(0, glyph_start);
|
const std::string part_before_cursor = line.substr(0, glyph_start);
|
||||||
const std::string part_at_cursor =
|
const std::string part_at_cursor =
|
||||||
line.substr(glyph_start, glyph_end - glyph_start);
|
line.substr(glyph_start, glyph_end - glyph_start);
|
||||||
@ -206,7 +204,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
const size_t start = GlyphPrevious(content(), cursor_position());
|
const size_t start = GlyphPrevious(content(), cursor_position());
|
||||||
const size_t end = cursor_position();
|
const size_t end = cursor_position();
|
||||||
content->erase(start, end - start);
|
content->erase(start, end - start);
|
||||||
cursor_position() = start;
|
cursor_position() = static_cast<int>(start);
|
||||||
on_change();
|
on_change();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -234,7 +232,8 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor_position() = GlyphPrevious(content(), cursor_position());
|
cursor_position() =
|
||||||
|
static_cast<int>(GlyphPrevious(content(), cursor_position()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +242,8 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor_position() = GlyphNext(content(), cursor_position());
|
cursor_position() =
|
||||||
|
static_cast<int>(GlyphNext(content(), cursor_position()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
if (content()[iter] == '\n') {
|
if (content()[iter] == '\n') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
width += GlyphWidth(content(), iter);
|
width += static_cast<int>(GlyphWidth(content(), iter));
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
@ -271,8 +271,9 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
columns -= GlyphWidth(content(), cursor_position());
|
columns -= static_cast<int>(GlyphWidth(content(), cursor_position()));
|
||||||
cursor_position() = GlyphNext(content(), cursor_position());
|
cursor_position() =
|
||||||
|
static_cast<int>(GlyphNext(content(), cursor_position()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,9 +293,10 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
if (content()[previous] == '\n') {
|
if (content()[previous] == '\n') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cursor_position() = previous;
|
cursor_position() = static_cast<int>(previous);
|
||||||
}
|
}
|
||||||
cursor_position() = GlyphPrevious(content(), cursor_position());
|
cursor_position() =
|
||||||
|
static_cast<int>(GlyphPrevious(content(), cursor_position()));
|
||||||
while (true) {
|
while (true) {
|
||||||
if (cursor_position() == 0) {
|
if (cursor_position() == 0) {
|
||||||
break;
|
break;
|
||||||
@ -303,10 +305,10 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
if (content()[previous] == '\n') {
|
if (content()[previous] == '\n') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cursor_position() = previous;
|
cursor_position() = static_cast<int>(previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveCursorColumn(columns);
|
MoveCursorColumn(static_cast<int>(columns));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,14 +324,16 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
if (content()[cursor_position()] == '\n') {
|
if (content()[cursor_position()] == '\n') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cursor_position() = GlyphNext(content(), cursor_position());
|
cursor_position() =
|
||||||
|
static_cast<int>(GlyphNext(content(), cursor_position()));
|
||||||
if (cursor_position() == (int)content().size()) {
|
if (cursor_position() == (int)content().size()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor_position() = GlyphNext(content(), cursor_position());
|
cursor_position() =
|
||||||
|
static_cast<int>(GlyphNext(content(), cursor_position()));
|
||||||
|
|
||||||
MoveCursorColumn(columns);
|
MoveCursorColumn(static_cast<int>(columns));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +343,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool HandleEnd() {
|
bool HandleEnd() {
|
||||||
cursor_position() = content->size();
|
cursor_position() = static_cast<int>(content->size());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +361,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
DeleteImpl();
|
DeleteImpl();
|
||||||
}
|
}
|
||||||
content->insert(cursor_position(), character);
|
content->insert(cursor_position(), character);
|
||||||
cursor_position() += character.size();
|
cursor_position() += static_cast<int>(character.size());
|
||||||
on_change();
|
on_change();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -421,7 +425,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
if (IsWordCharacter(content(), previous)) {
|
if (IsWordCharacter(content(), previous)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cursor_position() = previous;
|
cursor_position() = static_cast<int>(previous);
|
||||||
}
|
}
|
||||||
// Move left, as long as left is a word character:
|
// Move left, as long as left is a word character:
|
||||||
while (cursor_position()) {
|
while (cursor_position()) {
|
||||||
@ -429,7 +433,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
if (!IsWordCharacter(content(), previous)) {
|
if (!IsWordCharacter(content(), previous)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cursor_position() = previous;
|
cursor_position() = static_cast<int>(previous);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -441,7 +445,8 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
|
|
||||||
// Move right, until entering a word.
|
// Move right, until entering a word.
|
||||||
while (cursor_position() < (int)content().size()) {
|
while (cursor_position() < (int)content().size()) {
|
||||||
cursor_position() = GlyphNext(content(), cursor_position());
|
cursor_position() =
|
||||||
|
static_cast<int>(GlyphNext(content(), cursor_position()));
|
||||||
if (IsWordCharacter(content(), cursor_position())) {
|
if (IsWordCharacter(content(), cursor_position())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -452,7 +457,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
if (!IsWordCharacter(content(), cursor_position())) {
|
if (!IsWordCharacter(content(), cursor_position())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cursor_position() = next;
|
cursor_position() = static_cast<int>(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -489,7 +494,7 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor_char_index -= line.size() + 1;
|
cursor_char_index -= static_cast<int>(line.size() + 1);
|
||||||
cursor_line++;
|
cursor_line++;
|
||||||
}
|
}
|
||||||
const int cursor_column =
|
const int cursor_column =
|
||||||
@ -515,11 +520,13 @@ class InputBase : public ComponentBase, public InputOption {
|
|||||||
// Convert back the new_cursor_{line,column} toward cursor_position:
|
// Convert back the new_cursor_{line,column} toward cursor_position:
|
||||||
cursor_position() = 0;
|
cursor_position() = 0;
|
||||||
for (int i = 0; i < new_cursor_line; ++i) {
|
for (int i = 0; i < new_cursor_line; ++i) {
|
||||||
cursor_position() += lines[i].size() + 1;
|
cursor_position() += static_cast<int>(lines[i].size() + 1);
|
||||||
}
|
}
|
||||||
while (new_cursor_column > 0) {
|
while (new_cursor_column > 0) {
|
||||||
new_cursor_column -= GlyphWidth(content(), cursor_position());
|
new_cursor_column -=
|
||||||
cursor_position() = GlyphNext(content(), cursor_position());
|
static_cast<int>(GlyphWidth(content(), cursor_position()));
|
||||||
|
cursor_position() =
|
||||||
|
static_cast<int>(GlyphNext(content(), cursor_position()));
|
||||||
}
|
}
|
||||||
|
|
||||||
on_change();
|
on_change();
|
||||||
|
@ -511,6 +511,7 @@ class MenuBase : public ComponentBase, public MenuOption {
|
|||||||
/// entry 2
|
/// entry 2
|
||||||
/// entry 3
|
/// entry 3
|
||||||
/// ```
|
/// ```
|
||||||
|
// NOLINTNEXTLINE
|
||||||
Component Menu(MenuOption option) {
|
Component Menu(MenuOption option) {
|
||||||
return Make<MenuBase>(std::move(option));
|
return Make<MenuBase>(std::move(option));
|
||||||
}
|
}
|
||||||
@ -543,7 +544,7 @@ Component Menu(MenuOption option) {
|
|||||||
/// entry 3
|
/// entry 3
|
||||||
/// ```
|
/// ```
|
||||||
Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
|
Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
|
||||||
option.entries = entries;
|
option.entries = std::move(entries);
|
||||||
option.selected = selected;
|
option.selected = selected;
|
||||||
return Menu(option);
|
return Menu(option);
|
||||||
}
|
}
|
||||||
@ -554,7 +555,7 @@ Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
|
|||||||
/// See also |Menu|.
|
/// See also |Menu|.
|
||||||
/// @ingroup component
|
/// @ingroup component
|
||||||
Component Toggle(ConstStringListRef entries, int* selected) {
|
Component Toggle(ConstStringListRef entries, int* selected) {
|
||||||
return Menu(entries, selected, MenuOption::Toggle());
|
return Menu(std::move(entries), selected, MenuOption::Toggle());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief A specific menu entry. They can be put into a Container::Vertical to
|
/// @brief A specific menu entry. They can be put into a Container::Vertical to
|
||||||
|
@ -204,6 +204,7 @@ class RadioboxBase : public ComponentBase, public RadioboxOption {
|
|||||||
/// ○ entry 2
|
/// ○ entry 2
|
||||||
/// ○ entry 3
|
/// ○ entry 3
|
||||||
/// ```
|
/// ```
|
||||||
|
/// NOLINTNEXTLINE
|
||||||
Component Radiobox(RadioboxOption option) {
|
Component Radiobox(RadioboxOption option) {
|
||||||
return Make<RadioboxBase>(std::move(option));
|
return Make<RadioboxBase>(std::move(option));
|
||||||
}
|
}
|
||||||
@ -239,7 +240,7 @@ Component Radiobox(RadioboxOption option) {
|
|||||||
Component Radiobox(ConstStringListRef entries,
|
Component Radiobox(ConstStringListRef entries,
|
||||||
int* selected,
|
int* selected,
|
||||||
RadioboxOption option) {
|
RadioboxOption option) {
|
||||||
option.entries = entries;
|
option.entries = std::move(entries);
|
||||||
option.selected = selected;
|
option.selected = selected;
|
||||||
return Make<RadioboxBase>(std::move(option));
|
return Make<RadioboxBase>(std::move(option));
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,38 @@
|
|||||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
|
#include "ftxui/component/screen_interactive.hpp"
|
||||||
#include <algorithm> // for copy, max, min
|
#include <algorithm> // for copy, max, min
|
||||||
#include <array> // for array
|
#include <array> // for array
|
||||||
|
#include <atomic>
|
||||||
#include <chrono> // for operator-, milliseconds, operator>=, duration, common_type<>::type, time_point
|
#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 <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/component/task.hpp> // for Task, Closure, AnimationTask
|
||||||
#include <ftxui/screen/screen.hpp> // for Pixel, Screen::Cursor, Screen, Screen::Cursor::Hidden
|
#include <ftxui/screen/screen.hpp> // for Pixel, Screen::Cursor, Screen, Screen::Cursor::Hidden
|
||||||
#include <functional> // for function
|
#include <functional> // for function
|
||||||
#include <initializer_list> // for initializer_list
|
#include <initializer_list> // for initializer_list
|
||||||
#include <iostream> // for cout, ostream, operator<<, basic_ostream, endl, flush
|
#include <iostream> // for cout, ostream, operator<<, basic_ostream, endl, flush
|
||||||
|
#include <memory>
|
||||||
#include <stack> // for stack
|
#include <stack> // for stack
|
||||||
|
#include <string>
|
||||||
#include <thread> // for thread, sleep_for
|
#include <thread> // for thread, sleep_for
|
||||||
#include <tuple> // for _Swallow_assign, ignore
|
#include <tuple> // for _Swallow_assign, ignore
|
||||||
#include <type_traits> // for decay_t
|
#include <type_traits> // for decay_t
|
||||||
#include <utility> // for move, swap
|
#include <utility> // for move, swap
|
||||||
#include <variant> // for visit, variant
|
#include <variant> // for visit, variant
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
#include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame
|
#include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame
|
||||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse, CapturedMouseInterface
|
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse, CapturedMouseInterface
|
||||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||||
#include "ftxui/component/event.hpp" // for Event
|
#include "ftxui/component/event.hpp" // for Event
|
||||||
#include "ftxui/component/loop.hpp" // for Loop
|
#include "ftxui/component/loop.hpp" // for Loop
|
||||||
#include "ftxui/component/receiver.hpp" // for ReceiverImpl, Sender, MakeReceiver, SenderImpl, Receiver
|
#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/component/terminal_input_parser.hpp" // for TerminalInputParser
|
||||||
#include "ftxui/dom/node.hpp" // for Node, Render
|
#include "ftxui/dom/node.hpp" // for Node, Render
|
||||||
#include "ftxui/dom/requirement.hpp" // for Requirement
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
||||||
|
#include "ftxui/screen/pixel.hpp" // for Pixel
|
||||||
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@ -42,6 +46,7 @@
|
|||||||
#error Must be compiled in UNICODE mode
|
#error Must be compiled in UNICODE mode
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#include <bits/types/struct_timeval.h>
|
||||||
#include <sys/select.h> // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set, timeval
|
#include <sys/select.h> // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set, timeval
|
||||||
#include <termios.h> // for tcsetattr, termios, tcgetattr, TCSANOW, cc_t, ECHO, ICANON, VMIN, VTIME
|
#include <termios.h> // for tcsetattr, termios, tcgetattr, TCSANOW, cc_t, ECHO, ICANON, VMIN, VTIME
|
||||||
#include <unistd.h> // for STDIN_FILENO, read
|
#include <unistd.h> // for STDIN_FILENO, read
|
||||||
@ -213,11 +218,11 @@ void RecordSignal(int signal) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
case SIGTSTP:
|
case SIGTSTP: // NOLINT
|
||||||
g_signal_stop_count++;
|
g_signal_stop_count++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SIGWINCH:
|
case SIGWINCH: // NOLINT
|
||||||
g_signal_resize_count++;
|
g_signal_resize_count++;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@ -265,7 +270,7 @@ const std::string ST = "\x1b\\"; // NOLINT
|
|||||||
const std::string DECRQSS_DECSCUSR = DCS + "$q q" + ST; // NOLINT
|
const std::string DECRQSS_DECSCUSR = DCS + "$q q" + ST; // NOLINT
|
||||||
|
|
||||||
// DEC: Digital Equipment Corporation
|
// DEC: Digital Equipment Corporation
|
||||||
enum class DECMode {
|
enum class DECMode : std::uint16_t {
|
||||||
kLineWrap = 7,
|
kLineWrap = 7,
|
||||||
kCursor = 25,
|
kCursor = 25,
|
||||||
|
|
||||||
@ -284,7 +289,7 @@ enum class DECMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Device Status Report (DSR) {
|
// Device Status Report (DSR) {
|
||||||
enum class DSRMode {
|
enum class DSRMode : std::uint8_t {
|
||||||
kCursor = 6,
|
kCursor = 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -543,7 +548,8 @@ void ScreenInteractive::PostMain() {
|
|||||||
// On final exit, keep the current drawing and reset cursor position one
|
// On final exit, keep the current drawing and reset cursor position one
|
||||||
// line after it.
|
// line after it.
|
||||||
if (!use_alternative_screen_) {
|
if (!use_alternative_screen_) {
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
|
std::cout << std::flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -597,7 +603,7 @@ void ScreenInteractive::Install() {
|
|||||||
// Request the terminal to report the current cursor shape. We will restore it
|
// Request the terminal to report the current cursor shape. We will restore it
|
||||||
// on exit.
|
// on exit.
|
||||||
std::cout << DECRQSS_DECSCUSR;
|
std::cout << DECRQSS_DECSCUSR;
|
||||||
on_exit_functions.emplace([=] {
|
on_exit_functions.emplace([cursor_reset_shape_ = cursor_reset_shape_] {
|
||||||
std::cout << "\033[?25h"; // Enable cursor.
|
std::cout << "\033[?25h"; // Enable cursor.
|
||||||
std::cout << "\033[" + std::to_string(cursor_reset_shape_) + " q";
|
std::cout << "\033[" + std::to_string(cursor_reset_shape_) + " q";
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <memory> // for unique_ptr, allocator
|
#include <memory> // for unique_ptr, allocator
|
||||||
#include <utility> // for move
|
#include <utility> // for move
|
||||||
|
#include <vector>
|
||||||
#include "ftxui/component/event.hpp" // for Event
|
#include "ftxui/component/event.hpp" // for Event
|
||||||
#include "ftxui/component/task.hpp" // for Task
|
#include "ftxui/component/task.hpp" // for Task
|
||||||
|
|
||||||
|
@ -5,8 +5,14 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ftxui/component/component.hpp>
|
#include <ftxui/component/component.hpp>
|
||||||
#include <ftxui/component/component_base.hpp>
|
#include <ftxui/component/component_base.hpp>
|
||||||
|
#include <ftxui/component/component_options.hpp>
|
||||||
#include <ftxui/component/screen_interactive.hpp> // for ScreenInteractive
|
#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/dom/node_decorator.hpp" // for NodeDecorator
|
||||||
|
#include "ftxui/screen/color.hpp" // for Color
|
||||||
|
#include "ftxui/screen/screen.hpp" // for Screen
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
@ -206,7 +212,7 @@ class WindowImpl : public ComponentBase, public WindowOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clamp the window size.
|
// Clamp the window size.
|
||||||
width() = std::max<int>(width(), title().size() + 2);
|
width() = std::max<int>(width(), static_cast<int>(title().size() + 2));
|
||||||
height() = std::max<int>(height(), 2);
|
height() = std::max<int>(height(), 2);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <benchmark/benchmark.h>
|
#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/elements.hpp" // for gauge, separator, operator|, text, Element, hbox, vbox, blink, border, inverted
|
||||||
#include "ftxui/dom/node.hpp" // for Render
|
#include "ftxui/dom/node.hpp" // for Render
|
||||||
|
@ -8,12 +8,12 @@
|
|||||||
#include <optional> // for optional, nullopt
|
#include <optional> // for optional, nullopt
|
||||||
#include <string> // for basic_string, string
|
#include <string> // for basic_string, string
|
||||||
#include <utility> // for move
|
#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/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/node.hpp" // for Node, Elements
|
||||||
#include "ftxui/dom/requirement.hpp" // for Requirement
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
||||||
#include "ftxui/screen/box.hpp" // for Box
|
#include "ftxui/screen/box.hpp" // for Box
|
||||||
|
#include "ftxui/screen/pixel.hpp" // for Pixel
|
||||||
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
@ -38,7 +38,8 @@ class Border : public Node {
|
|||||||
BorderStyle style,
|
BorderStyle style,
|
||||||
std::optional<Color> foreground_color = std::nullopt)
|
std::optional<Color> foreground_color = std::nullopt)
|
||||||
: Node(std::move(children)),
|
: Node(std::move(children)),
|
||||||
charset_(simple_border_charset[style]),
|
charset_(simple_border_charset[style]) // NOLINT
|
||||||
|
,
|
||||||
foreground_color_(foreground_color) {} // NOLINT
|
foreground_color_(foreground_color) {} // NOLINT
|
||||||
|
|
||||||
const Charset& charset_; // NOLINT
|
const Charset& charset_; // NOLINT
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "ftxui/dom/box_helper.hpp"
|
#include "ftxui/dom/box_helper.hpp"
|
||||||
|
|
||||||
#include <algorithm> // for max
|
#include <algorithm> // for max
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
namespace ftxui::box_helper {
|
namespace ftxui::box_helper {
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <cstdint> // for uint8_t
|
#include <cstdint> // for uint8_t
|
||||||
#include <cstdlib> // for abs
|
#include <cstdlib> // for abs
|
||||||
#include <ftxui/screen/color.hpp> // for Color
|
#include <ftxui/screen/color.hpp> // for Color
|
||||||
|
#include <functional> // for function
|
||||||
#include <map> // for map
|
#include <map> // for map
|
||||||
#include <memory> // for make_shared
|
#include <memory> // for make_shared
|
||||||
#include <utility> // for move, pair
|
#include <utility> // for move, pair
|
||||||
@ -17,6 +18,8 @@
|
|||||||
#include "ftxui/dom/node.hpp" // for Node
|
#include "ftxui/dom/node.hpp" // for Node
|
||||||
#include "ftxui/dom/requirement.hpp" // for Requirement
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
||||||
#include "ftxui/screen/box.hpp" // for Box
|
#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/screen.hpp" // for Pixel, Screen
|
||||||
#include "ftxui/screen/string.hpp" // for Utf8ToGlyphs
|
#include "ftxui/screen/string.hpp" // for Utf8ToGlyphs
|
||||||
#include "ftxui/util/ref.hpp" // for ConstRef
|
#include "ftxui/util/ref.hpp" // for ConstRef
|
||||||
@ -28,7 +31,7 @@ namespace {
|
|||||||
// Base UTF8 pattern:
|
// Base UTF8 pattern:
|
||||||
// 11100010 10100000 10000000 // empty
|
// 11100010 10100000 10000000 // empty
|
||||||
|
|
||||||
// Pattern for the individuel dots:
|
// Pattern for the individual dots:
|
||||||
// ┌──────┬───────┐
|
// ┌──────┬───────┐
|
||||||
// │dot1 │ dot4 │
|
// │dot1 │ dot4 │
|
||||||
// ├──────┼───────┤
|
// ├──────┼───────┤
|
||||||
|
@ -2,13 +2,16 @@
|
|||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <algorithm> // for max
|
#include <algorithm> // for max
|
||||||
|
#include <cstddef> // for size_t
|
||||||
#include <memory> // for __shared_ptr_access, shared_ptr, make_shared
|
#include <memory> // for __shared_ptr_access, shared_ptr, make_shared
|
||||||
#include <utility> // for move
|
#include <utility> // for move
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "ftxui/dom/elements.hpp" // for Element, Elements, dbox
|
#include "ftxui/dom/elements.hpp" // for Element, Elements, dbox
|
||||||
#include "ftxui/dom/node.hpp" // for Node, Elements
|
#include "ftxui/dom/node.hpp" // for Node, Elements
|
||||||
#include "ftxui/dom/requirement.hpp" // for Requirement
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
||||||
#include "ftxui/screen/box.hpp" // for Box
|
#include "ftxui/screen/box.hpp" // for Box
|
||||||
|
#include "ftxui/screen/pixel.hpp" // for Pixel
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
@ -49,12 +52,13 @@ class DBox : public Node {
|
|||||||
|
|
||||||
void Render(Screen& screen) override {
|
void Render(Screen& screen) override {
|
||||||
if (children_.size() <= 1) {
|
if (children_.size() <= 1) {
|
||||||
return Node::Render(screen);
|
Node::Render(screen);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int width = box_.x_max - box_.x_min + 1;
|
const int width = box_.x_max - box_.x_min + 1;
|
||||||
const int height = box_.y_max - box_.y_min + 1;
|
const int height = box_.y_max - box_.y_min + 1;
|
||||||
std::vector<Pixel> pixels(size_t(width * height));
|
std::vector<Pixel> pixels(std::size_t(width * height));
|
||||||
|
|
||||||
for (auto& child : children_) {
|
for (auto& child : children_) {
|
||||||
child->Render(screen);
|
child->Render(screen);
|
||||||
@ -67,7 +71,7 @@ class DBox : public Node {
|
|||||||
acc->background_color =
|
acc->background_color =
|
||||||
Color::Blend(acc->background_color, pixel.background_color);
|
Color::Blend(acc->background_color, pixel.background_color);
|
||||||
acc->automerge = pixel.automerge || acc->automerge;
|
acc->automerge = pixel.automerge || acc->automerge;
|
||||||
if (pixel.character == "") {
|
if (pixel.character.empty()) {
|
||||||
acc->foreground_color =
|
acc->foreground_color =
|
||||||
Color::Blend(acc->foreground_color, pixel.background_color);
|
Color::Blend(acc->foreground_color, pixel.background_color);
|
||||||
} else {
|
} else {
|
||||||
@ -82,7 +86,7 @@ class DBox : public Node {
|
|||||||
acc->character = pixel.character;
|
acc->character = pixel.character;
|
||||||
acc->foreground_color = pixel.foreground_color;
|
acc->foreground_color = pixel.foreground_color;
|
||||||
}
|
}
|
||||||
++acc;
|
++acc; // NOLINT
|
||||||
|
|
||||||
pixel = Pixel();
|
pixel = Pixel();
|
||||||
}
|
}
|
||||||
@ -93,7 +97,7 @@ class DBox : public Node {
|
|||||||
Pixel* acc = pixels.data();
|
Pixel* acc = pixels.data();
|
||||||
for (int x = 0; x < width; ++x) {
|
for (int x = 0; x < width; ++x) {
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
screen.PixelAt(x + box_.x_min, y + box_.y_min) = *acc++;
|
screen.PixelAt(x + box_.x_min, y + box_.y_min) = *acc++; // NOLINT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <memory> // for make_shared, __shared_ptr_access
|
#include <memory> // for make_shared, __shared_ptr_access
|
||||||
#include <utility> // for move
|
#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/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
|
#include "ftxui/dom/node.hpp" // for Elements, Node
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <cstddef> // for size_t
|
#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 <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 <utility> // for swap, move
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "ftxui/dom/box_helper.hpp" // for Element, Compute
|
#include "ftxui/dom/box_helper.hpp" // for Element, Compute
|
||||||
|
|
||||||
@ -330,8 +331,8 @@ void Compute3(Global& global) {
|
|||||||
line = Line();
|
line = Line();
|
||||||
}
|
}
|
||||||
|
|
||||||
block.line = lines.size();
|
block.line = static_cast<int>(lines.size());
|
||||||
block.line_position = line.blocks.size();
|
block.line_position = static_cast<int>(line.blocks.size());
|
||||||
line.blocks.push_back(&block);
|
line.blocks.push_back(&block);
|
||||||
x += block.min_size_x + global.config.gap_x;
|
x += block.min_size_x + global.config.gap_x;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class Reflect : public Node {
|
|||||||
|
|
||||||
void Render(Screen& screen) final {
|
void Render(Screen& screen) final {
|
||||||
reflected_box_ = Box::Intersection(screen.stencil, reflected_box_);
|
reflected_box_ = Box::Intersection(screen.stencil, reflected_box_);
|
||||||
return Node::Render(screen);
|
Node::Render(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
84
src/ftxui/dom/selectable.cpp
Normal file
84
src/ftxui/dom/selectable.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// 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 <memory> // for make_shared
|
||||||
|
#include <utility> // for move
|
||||||
|
|
||||||
|
#include "ftxui/dom/elements.hpp" // for Element, inverted
|
||||||
|
#include "ftxui/dom/node.hpp" // for Node
|
||||||
|
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||||
|
#include "ftxui/screen/box.hpp" // for Box
|
||||||
|
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
||||||
|
|
||||||
|
namespace ftxui {
|
||||||
|
|
||||||
|
Region selectedRegion;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
class Selectable : public NodeDecorator {
|
||||||
|
public:
|
||||||
|
using NodeDecorator::NodeDecorator;
|
||||||
|
Selectable(Element child, std::function<void(const std::string)> onSelectionChange)
|
||||||
|
: NodeDecorator(std::move(child)), onSelectionChange_(onSelectionChange) {}
|
||||||
|
|
||||||
|
void Render(Screen& screen) override {
|
||||||
|
Node::Render(screen);
|
||||||
|
std::string selectedText = "";
|
||||||
|
for (int y = std::min(selectedRegion.starty, selectedRegion.endy); y <= std::max(selectedRegion.starty, selectedRegion.endy); ++y) {
|
||||||
|
for (int x = std::min(selectedRegion.startx, selectedRegion.endx); x <= std::max(selectedRegion.startx, selectedRegion.endx)-1; ++x) {
|
||||||
|
screen.PixelAt(x, y).inverted ^= true;
|
||||||
|
selectedText += screen.PixelAt(x, y).character;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(selectedRegion.changed == true) {
|
||||||
|
selectedRegion.changed = false;;
|
||||||
|
onSelectionChange_(selectedText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::function<void(const std::string)> onSelectionChange_;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
/// @brief Add a filter that will invert the foreground and the background
|
||||||
|
/// colors.
|
||||||
|
/// @ingroup dom
|
||||||
|
|
||||||
|
Element selectable(std::function<void(const std::string)> onSelectionChange, Element child) {
|
||||||
|
return std::make_shared<Selectable>(std::move(child), onSelectionChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
Decorator selectable(std::function<void(const std::string)> onSelectionChange) {
|
||||||
|
return [onSelectionChange](Element child) { return selectable(onSelectionChange, std::move(child)); };
|
||||||
|
}
|
||||||
|
|
||||||
|
bool selectableCatchEvent(Event event) {
|
||||||
|
|
||||||
|
if (event.is_mouse()) {
|
||||||
|
auto& mouse = event.mouse();
|
||||||
|
if (mouse.button == Mouse::Left) {
|
||||||
|
|
||||||
|
if (mouse.motion == Mouse::Pressed) {
|
||||||
|
selectedRegion.startx = mouse.x;
|
||||||
|
selectedRegion.starty = mouse.y;
|
||||||
|
selectedRegion.endx = mouse.x;
|
||||||
|
selectedRegion.endy = mouse.y;
|
||||||
|
selectedRegion.changed = true;
|
||||||
|
} else if (mouse.motion == Mouse::Released) {
|
||||||
|
selectedRegion.endx = mouse.x;
|
||||||
|
selectedRegion.endy = mouse.y;
|
||||||
|
selectedRegion.changed = true;
|
||||||
|
} else if (mouse.motion == Mouse::Moved) {
|
||||||
|
selectedRegion.endx = mouse.x;
|
||||||
|
selectedRegion.endy = mouse.y;
|
||||||
|
selectedRegion.changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ftxui
|
@ -11,6 +11,7 @@
|
|||||||
#include "ftxui/dom/requirement.hpp" // for Requirement
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
||||||
#include "ftxui/screen/box.hpp" // for Box
|
#include "ftxui/screen/box.hpp" // for Box
|
||||||
#include "ftxui/screen/color.hpp" // for Color
|
#include "ftxui/screen/color.hpp" // for Color
|
||||||
|
#include "ftxui/screen/pixel.hpp" // for Pixel
|
||||||
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
@ -63,7 +64,8 @@ class SeparatorAuto : public Node {
|
|||||||
const bool is_column = (box_.x_max == box_.x_min);
|
const bool is_column = (box_.x_max == box_.x_min);
|
||||||
const bool is_line = (box_.y_min == box_.y_max);
|
const bool is_line = (box_.y_min == box_.y_max);
|
||||||
|
|
||||||
const std::string c = charsets[style_][int(is_line && !is_column)];
|
const std::string c =
|
||||||
|
charsets[style_][int(is_line && !is_column)]; // NOLINT
|
||||||
|
|
||||||
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
||||||
for (int x = box_.x_min; x <= box_.x_max; ++x) {
|
for (int x = box_.x_min; x <= box_.x_max; ++x) {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <algorithm> // for max
|
#include <algorithm> // for max
|
||||||
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
|
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
|
||||||
#include <utility> // for move, swap
|
#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
|
#include "ftxui/dom/elements.hpp" // for Element, operator|, text, separatorCharacter, Elements, BorderStyle, Decorator, emptyElement, size, gridbox, EQUAL, flex, flex_shrink, HEIGHT, WIDTH
|
||||||
|
|
||||||
|
@ -6,14 +6,12 @@
|
|||||||
#include <array> // for array
|
#include <array> // for array
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "ftxui/screen/color_info.hpp" // for GetColorInfo, ColorInfo
|
#include "ftxui/screen/color_info.hpp" // for GetColorInfo, ColorInfo
|
||||||
#include "ftxui/screen/terminal.hpp" // for ColorSupport, Color, Palette256, TrueColor
|
#include "ftxui/screen/terminal.hpp" // for ColorSupport, Color, Palette256, TrueColor
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
using namespace std::literals;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const std::array<const char*, 33> palette16code = {
|
const std::array<const char*, 33> palette16code = {
|
||||||
"30", "40", //
|
"30", "40", //
|
||||||
@ -46,22 +44,30 @@ bool Color::operator!=(const Color& rhs) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string Color::Print(bool is_background_color) const {
|
std::string Color::Print(bool is_background_color) const {
|
||||||
|
if (is_background_color) {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case ColorType::Palette1:
|
case ColorType::Palette1:
|
||||||
return is_background_color ? "49"s : "39"s;
|
return "49";
|
||||||
|
|
||||||
case ColorType::Palette16:
|
case ColorType::Palette16:
|
||||||
return palette16code[2 * red_ + is_background_color]; // NOLINT;
|
return palette16code[2 * red_ + 1]; // NOLINT
|
||||||
|
|
||||||
case ColorType::Palette256:
|
case ColorType::Palette256:
|
||||||
return (is_background_color ? "48;5;"s : "38;5;"s) + std::to_string(red_);
|
return "48;5;" + std::to_string(red_);
|
||||||
|
|
||||||
case ColorType::TrueColor:
|
case ColorType::TrueColor:
|
||||||
default:
|
return "48;2;" + std::to_string(red_) + ";" + std::to_string(green_) +
|
||||||
return (is_background_color ? "48;2;"s : "38;2;"s) //
|
";" + std::to_string(blue_);
|
||||||
+ std::to_string(red_) + ";" //
|
}
|
||||||
+ std::to_string(green_) + ";" //
|
} else {
|
||||||
+ std::to_string(blue_); //
|
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_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <sstream> // IWYU pragma: keep
|
#include <sstream> // IWYU pragma: keep
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "ftxui/screen/image.hpp"
|
#include "ftxui/screen/image.hpp"
|
||||||
|
#include "ftxui/screen/pixel.hpp"
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <cstdint> // for size_t
|
#include <cstddef> // for size_t
|
||||||
|
#include <cstdint>
|
||||||
#include <iostream> // for operator<<, stringstream, basic_ostream, flush, cout, ostream
|
#include <iostream> // for operator<<, stringstream, basic_ostream, flush, cout, ostream
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map> // for _Rb_tree_const_iterator, map, operator!=, operator==
|
#include <map> // for _Rb_tree_const_iterator, map, operator!=, operator==
|
||||||
#include <sstream> // IWYU pragma: keep
|
#include <sstream> // IWYU pragma: keep
|
||||||
#include <utility> // for pair
|
#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/screen.hpp"
|
||||||
#include "ftxui/screen/string.hpp" // for string_width
|
#include "ftxui/screen/string.hpp" // for string_width
|
||||||
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
||||||
@ -117,11 +120,11 @@ void UpdatePixelStyle(const Screen* screen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct TileEncoding {
|
struct TileEncoding {
|
||||||
uint8_t left : 2;
|
std::uint8_t left : 2;
|
||||||
uint8_t top : 2;
|
std::uint8_t top : 2;
|
||||||
uint8_t right : 2;
|
std::uint8_t right : 2;
|
||||||
uint8_t down : 2;
|
std::uint8_t down : 2;
|
||||||
uint8_t round : 1;
|
std::uint8_t round : 1;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
bool operator<(const TileEncoding& other) const {
|
bool operator<(const TileEncoding& other) const {
|
||||||
@ -521,20 +524,20 @@ void Screen::ApplyShader() {
|
|||||||
}
|
}
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
uint8_t Screen::RegisterHyperlink(const std::string& link) {
|
std::uint8_t Screen::RegisterHyperlink(const std::string& link) {
|
||||||
for (size_t i = 0; i < hyperlinks_.size(); ++i) {
|
for (std::size_t i = 0; i < hyperlinks_.size(); ++i) {
|
||||||
if (hyperlinks_[i] == link) {
|
if (hyperlinks_[i] == link) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hyperlinks_.size() == std::numeric_limits<uint8_t>::max()) {
|
if (hyperlinks_.size() == std::numeric_limits<std::uint8_t>::max()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
hyperlinks_.push_back(link);
|
hyperlinks_.push_back(link);
|
||||||
return hyperlinks_.size() - 1;
|
return hyperlinks_.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Screen::Hyperlink(uint8_t id) const {
|
const std::string& Screen::Hyperlink(std::uint8_t id) const {
|
||||||
if (id >= hyperlinks_.size()) {
|
if (id >= hyperlinks_.size()) {
|
||||||
return hyperlinks_[0];
|
return hyperlinks_[0];
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <cstdint> // for uint32_t, uint8_t, uint16_t, int32_t
|
#include <cstdint> // for uint32_t, uint8_t, uint16_t, int32_t
|
||||||
#include <string> // for string, basic_string, wstring
|
#include <string> // for string, basic_string, wstring
|
||||||
#include <tuple> // for _Swallow_assign, ignore
|
#include <tuple> // for _Swallow_assign, ignore
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "ftxui/screen/deprecated.hpp" // for wchar_width, wstring_width
|
#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
|
#include "ftxui/screen/string_internal.hpp" // for WordBreakProperty, EatCodePoint, CodepointToWordBreakProperty, GlyphCount, GlyphIterate, GlyphNext, GlyphPrevious, IsCombining, IsControl, IsFullWidth, Utf8ToWordBreakProperty
|
||||||
@ -1355,7 +1356,6 @@ int string_width(const std::string& input) {
|
|||||||
|
|
||||||
std::vector<std::string> Utf8ToGlyphs(const std::string& input) {
|
std::vector<std::string> Utf8ToGlyphs(const std::string& input) {
|
||||||
std::vector<std::string> out;
|
std::vector<std::string> out;
|
||||||
const std::string current;
|
|
||||||
out.reserve(input.size());
|
out.reserve(input.size());
|
||||||
size_t start = 0;
|
size_t start = 0;
|
||||||
size_t end = 0;
|
size_t end = 0;
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// 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 "ftxui/util/ref.hpp"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user