diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-06-20 10:46:19 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-06-20 10:53:48 +0200 |
| commit | 1ae9669c30089447212b05104a239c0866890116 (patch) | |
| tree | 10dd37b83ecb7843838571e19d9d5987ca3b89a1 | |
| parent | d33ec72b70fa5e403170cf06f4619dbc7f0b306e (diff) | |
| download | ttwhy-1ae9669c30089447212b05104a239c0866890116.tar.xz ttwhy-1ae9669c30089447212b05104a239c0866890116.zip | |
| -rw-r--r-- | ttwhy/scanners/terminal_policies.cppm | 1 | ||||
| -rw-r--r-- | ttwhy/scanners/terminal_scanner.cppm | 2 | ||||
| -rw-r--r-- | ttwhy/scanners/terminal_scanner.tests.cpp | 66 |
3 files changed, 65 insertions, 4 deletions
diff --git a/ttwhy/scanners/terminal_policies.cppm b/ttwhy/scanners/terminal_policies.cppm index 87e54b3..e5863d3 100644 --- a/ttwhy/scanners/terminal_policies.cppm +++ b/ttwhy/scanners/terminal_policies.cppm @@ -36,7 +36,6 @@ namespace ttwhy::scanners } }(buffer.back()); sink(navigation_event{key}); - buffer.clear(); } constexpr auto static resolve_vt100_cursor(char terminator, ttwhy::ansi_sink auto & sink) -> void diff --git a/ttwhy/scanners/terminal_scanner.cppm b/ttwhy/scanners/terminal_scanner.cppm index 4215cc8..d877350 100644 --- a/ttwhy/scanners/terminal_scanner.cppm +++ b/ttwhy/scanners/terminal_scanner.cppm @@ -62,7 +62,7 @@ namespace ttwhy::scanners::detail }; constexpr auto is_c0_chord = [](byte_received e) { - return e.value >= '\0' && e.value <= '\x1f' && !is_backspace(e) && !is_tab(e) && !is_escape(e); + return e.value >= '\0' && e.value <= '\x1f' && !is_backspace(e) && !is_tab(e) && !is_enter(e) && !is_escape(e); }; constexpr auto is_fe = [](byte_received e) { diff --git a/ttwhy/scanners/terminal_scanner.tests.cpp b/ttwhy/scanners/terminal_scanner.tests.cpp index 6fdc8af..f4ea6ad 100644 --- a/ttwhy/scanners/terminal_scanner.tests.cpp +++ b/ttwhy/scanners/terminal_scanner.tests.cpp @@ -1,6 +1,6 @@ #include <catch2/catch_test_macros.hpp> -#include <string_view> // IWYU pragma: keep +#include <string_view> #include <variant> #include <vector> @@ -14,6 +14,13 @@ using namespace std::string_view_literals; return data != nullptr && data->value == expected; } +[[nodiscard]] constexpr auto static is_control(ttwhy::scanners::input_event & event, + ttwhy::scanners::control_key expected) -> bool +{ + auto const * data = std::get_if<ttwhy::scanners::control_event>(&event); + return data != nullptr && data->key == expected; +} + SCENARIO("The ANSI scanner processes printable ASCII and standard C0 control characters", "[scanner][ansi]") { GIVEN("An initialized scanner and event sink") @@ -26,7 +33,7 @@ SCENARIO("The ANSI scanner processes printable ASCII and standard C0 control cha WHEN("Processing a standard printable character") { - scanner.process("A"); + scanner.process("A"sv); THEN("It yields a single character event") { @@ -34,5 +41,60 @@ SCENARIO("The ANSI scanner processes printable ASCII and standard C0 control cha CHECK(is_character(queue.at(0), 'A')); } } + + WHEN("Processing a BS byte (\\x08)") + { + scanner.process("\x08"sv); + + THEN("It yields a backspace control event") + { + REQUIRE(queue.size() == 1); + CHECK(is_control(queue.at(0), ttwhy::scanners::control_key::backspace)); + } + } + + WHEN("Processing a DEL byte (\\x7f as BS)") + { + scanner.process("\x7f"sv); + + THEN("It yields a backspace control event") + { + REQUIRE(queue.size() == 1); + CHECK(is_control(queue.at(0), ttwhy::scanners::control_key::backspace)); + } + } + + WHEN("Processing a TAB byte") + { + scanner.process("\x09"sv); + + THEN("It yields a tab control event") + { + REQUIRE(queue.size() == 1); + CHECK(is_control(queue.at(0), ttwhy::scanners::control_key::tab)); + } + } + + WHEN("Processing an LF byte") + { + scanner.process("\x0a"sv); + + THEN("It yields an enter control event") + { + REQUIRE(queue.size() == 1); + CHECK(is_control(queue.at(0), ttwhy::scanners::control_key::enter)); + } + } + + WHEN("Processing an CR byte") + { + scanner.process("\x0d"sv); + + THEN("It yields an enter control event") + { + REQUIRE(queue.size() == 1); + CHECK(is_control(queue.at(0), ttwhy::scanners::control_key::enter)); + } + } } } |
