0
0
mirror of https://github.com/ArthurSonzogni/ftxui.git synced 2026-01-18 17:21:33 +01:00

Fix std::string_view compile issues.

The previous patch turning every `const std::string&` into
std::string_view had some rough edges.

Bug:https://github.com/ArthurSonzogni/FTXUI/issues/1166
This commit is contained in:
ArthurSonzogni
2025-12-17 09:55:07 +01:00
parent 170c1b94dd
commit 7bbb0ce324
5 changed files with 21 additions and 18 deletions

View File

@@ -33,6 +33,7 @@ struct Event {
static Event Character(char);
static Event Character(wchar_t);
static Event Special(std::string_view);
static Event Special(std::initializer_list<char>);
static Event Mouse(std::string_view, Mouse mouse);
static Event CursorPosition(std::string_view, int x, int y); // Internal
static Event CursorShape(std::string_view, int shape); // Internal

View File

@@ -8,8 +8,8 @@
#include <string>
namespace ftxui {
Element text(std::wstring text);
Element vtext(std::wstring text);
Element text(std::wstring_view text);
Element vtext(std::wstring_view text);
Elements paragraph(std::wstring text);
} // namespace ftxui

View File

@@ -77,6 +77,13 @@ Event Event::Special(std::string_view input) {
return event;
}
/// @brief An custom event whose meaning is defined by the user of the library.
/// @param input An arbitrary sequence of character defined by the developer.
// static
Event Event::Special(std::initializer_list<char> input) {
return Event::Special(std::string(input));
}
/// @internal
// static
Event Event::CursorPosition(std::string_view input, int x, int y) {
@@ -292,12 +299,12 @@ const Event Event::ArrowLeftCtrl = Event::Special("\x1B[1;5D");
const Event Event::ArrowRightCtrl = Event::Special("\x1B[1;5C");
const Event Event::ArrowUpCtrl = Event::Special("\x1B[1;5A");
const Event Event::ArrowDownCtrl = Event::Special("\x1B[1;5B");
const Event Event::Backspace = Event::Special(std::string({127}));
const Event Event::Backspace = Event::Special({127});
const Event Event::Delete = Event::Special("\x1B[3~");
const Event Event::Escape = Event::Special("\x1B");
const Event Event::Return = Event::Special(std::string({10}));
const Event Event::Tab = Event::Special(std::string({9}));
const Event Event::TabReverse = Event::Special(std::string({27, 91, 90}));
const Event Event::Return = Event::Special({10});
const Event Event::Tab = Event::Special({9});
const Event Event::TabReverse = Event::Special({27, 91, 90});
// See https://invisible-island.net/xterm/xterm-function-keys.html
// We follow xterm-new / vterm-xf86-v4 / mgt / screen
@@ -315,11 +322,11 @@ const Event Event::F11 = Event::Special("\x1B[23~");
const Event Event::F12 = Event::Special("\x1B[24~");
const Event Event::Insert = Event::Special("\x1B[2~");
const Event Event::Home = Event::Special(std::string({27, 91, 72}));
const Event Event::End = Event::Special(std::string({27, 91, 70}));
const Event Event::PageUp = Event::Special(std::string({27, 91, 53, 126}));
const Event Event::PageDown = Event::Special(std::string({27, 91, 54, 126}));
const Event Event::Custom = Event::Special(std::string({0}));
const Event Event::Home = Event::Special({27, 91, 72});
const Event Event::End = Event::Special({27, 91, 70});
const Event Event::PageUp = Event::Special({27, 91, 53, 126});
const Event Event::PageDown = Event::Special({27, 91, 54, 126});
const Event Event::Custom = Event::Special({0});
const Event Event::a = Event::Character("a");
const Event Event::b = Event::Character("b");

View File

@@ -52,11 +52,6 @@
#include <cerrno>
#endif
// Quick exit is missing in standard CLang headers
#if defined(__clang__) && defined(__APPLE__)
#define quick_exit(a) exit(a)
#endif
namespace ftxui {
struct ScreenInteractive::Internal {
@@ -1054,7 +1049,7 @@ void ScreenInteractive::Signal(int signal) {
}
if (signal == SIGWINCH) {
Post(Event::Special(std::string({0})));
Post(Event::Special({0}));
return;
}
#endif

View File

@@ -338,7 +338,7 @@ TEST(Event, Control) {
EXPECT_TRUE(received_events.empty());
} else {
EXPECT_EQ(1, received_events.size());
EXPECT_EQ(received_events[0], Event::Special(std::string({test.input})));
EXPECT_EQ(received_events[0], Event::Special({test.input}));
}
}
}