diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2025-04-13 22:22:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-13 22:22:46 +0200 |
commit | 091672f57ba57b745a51202b38af61bd240d1084 (patch) | |
tree | dcdd0b4e65516682b17390f049fd8b1599274232 /spec | |
parent | 06691764e87c2979f4a00ed386e237150f055d5a (diff) | |
download | luasystem-091672f57ba57b745a51202b38af61bd240d1084.tar.gz luasystem-091672f57ba57b745a51202b38af61bd240d1084.tar.bz2 luasystem-091672f57ba57b745a51202b38af61bd240d1084.zip |
fix(terminal): readansi now properly handles <alt>+key key-presses (#62)
Also; documents the internal buffer and retry behaviour of readansi
Diffstat (limited to 'spec')
-rw-r--r-- | spec/04-term_spec.lua | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua index b3de461..0ce0033 100644 --- a/spec/04-term_spec.lua +++ b/spec/04-term_spec.lua | |||
@@ -928,10 +928,31 @@ describe("Terminal:", function() | |||
928 | end) | 928 | end) |
929 | 929 | ||
930 | 930 | ||
931 | it("reads ANSI escape sequences, just an '<esc>O' (<alt><O> key press)", function() | ||
932 | setbuffer("\27O") | ||
933 | assert.are.same({"\27O", "ansi"}, {system.readansi(0)}) | ||
934 | end) | ||
935 | |||
936 | |||
937 | it("reads <alt>+key key presses; <esc>+<key>", function() | ||
938 | setbuffer("\27a\27b\27c\27d") | ||
939 | assert.are.same({"\27a", "ansi"}, {system.readansi(0)}) | ||
940 | assert.are.same({"\27b", "ansi"}, {system.readansi(0)}) | ||
941 | assert.are.same({"\27c", "ansi"}, {system.readansi(0)}) | ||
942 | assert.are.same({"\27d", "ansi"}, {system.readansi(0)}) | ||
943 | end) | ||
944 | |||
945 | |||
946 | it("reads <ctrl><alt>[ key press; <esc>+<esc>", function() | ||
947 | setbuffer("\27\27\27\27") | ||
948 | assert.are.same({"\27\27", "ansi"}, {system.readansi(0)}) | ||
949 | assert.are.same({"\27\27", "ansi"}, {system.readansi(0)}) | ||
950 | end) | ||
951 | |||
952 | |||
931 | it("returns a single <esc> character if no sequence is found", function() | 953 | it("returns a single <esc> character if no sequence is found", function() |
932 | setbuffer("\27\27[A") | 954 | setbuffer("\27") |
933 | assert.are.same({"\27", "char"}, {system.readansi(0)}) | 955 | assert.are.same({"\27", "char"}, {system.readansi(0)}) |
934 | assert.are.same({"\27[A", "ansi"}, {system.readansi(0)}) | ||
935 | end) | 956 | end) |
936 | 957 | ||
937 | 958 | ||
@@ -945,6 +966,22 @@ describe("Terminal:", function() | |||
945 | assert.is.near(1, timing, 0.5) -- this also works for MacOS in CI | 966 | assert.is.near(1, timing, 0.5) -- this also works for MacOS in CI |
946 | end) | 967 | end) |
947 | 968 | ||
969 | |||
970 | it("incomplete ANSI sequences will be completed on next call", function() | ||
971 | setbuffer("\27[") | ||
972 | assert.are.same({nil, "timeout", "\27["}, {system.readansi(0)}) | ||
973 | setbuffer("A") | ||
974 | assert.are.same({"\27[A", "ansi"}, {system.readansi(0)}) | ||
975 | end) | ||
976 | |||
977 | |||
978 | it("incomplete UTF8 sequences will be completed on next call", function() | ||
979 | setbuffer(string.char(240, 159)) | ||
980 | assert.are.same({nil, "timeout", string.char(240, 159)}, {system.readansi(0)}) | ||
981 | setbuffer(string.char(154, 128)) | ||
982 | assert.are.same({"🚀", "char"}, {system.readansi(0)}) | ||
983 | end) | ||
984 | |||
948 | end) | 985 | end) |
949 | 986 | ||
950 | end) | 987 | end) |