summaryrefslogtreecommitdiff
path: root/src/tty/tty.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/tty/tty.zig')
-rw-r--r--src/tty/tty.zig38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/tty/tty.zig b/src/tty/tty.zig
index 67807cd5..0a9d65c4 100644
--- a/src/tty/tty.zig
+++ b/src/tty/tty.zig
@@ -2211,6 +2211,44 @@ test "a terminal pane gets function keys as their sequences and lone modifiers n
try std.testing.expectEqualStrings("\x1bOR\x1b[15~\x1b[2~\x1bOR\x1b[Ah", written.written());
}
+test "the terminal's keys reach a program as its cursor keys' mode and keyboard flags say" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .tty_only = true });
+ defer core.deinit();
+ core.panes[0].?.body.mode = .tty;
+ while (core.nextEffect()) |_| {}
+ var written: std.Io.Writer.Allocating = .init(gpa);
+ defer written.deinit();
+ // What the outer terminal sends, what the program asked for, and what
+ // it should read.
+ const Case = struct { modes: []const u8, in: []const u8, sent: []const u8 };
+ const cases = [_]Case{
+ .{ .modes = "", .in = "\x1b[A\x1b[H\x1bOP\x1b[15~", .sent = "\x1b[A\x1b[H\x1bOP\x1b[15~" },
+ .{ .modes = "\x1b[?1h", .in = "\x1b[A\x1b[F\x1b[1;5D", .sent = "\x1bOA\x1bOF\x1b[1;5D" },
+ .{ .modes = "\x1b[?1l\x1b[>7u", .in = "\x1b[99;5u\x1b[97;3u\x1b[A", .sent = "\x1b[99;5u\x1b[97;3u\x1b[1;1:1A" },
+ };
+ for (cases) |case| {
+ core.update(.{ .output = .{ .pane = 0, .bytes = case.modes } });
+ while (core.nextEffect()) |_| {}
+ var parser: vaxis.Parser = .{};
+ var bytes = case.in;
+ while (bytes.len > 0) {
+ const result = try parser.parse(bytes, gpa);
+ if (result.n == 0) break;
+ bytes = bytes[result.n..];
+ if (result.event) |event| switch (event) {
+ .key_press => |key| core.update(vaxis_input.keyEvent(key)),
+ else => {},
+ };
+ }
+ written.clearRetainingCapacity();
+ while (core.nextEffect()) |effect| {
+ if (effect == .write) try written.writer.writeAll(effect.write.bytes.slice());
+ }
+ try std.testing.expectEqualStrings(case.sent, written.written());
+ }
+}
+
test "keypad Enter matches Return for editor input terminal writes and paste" {
for ([_]u21{ vaxis.Key.enter, vaxis.Key.kp_enter }) |codepoint| {
const key: vaxis.Key = .{ .codepoint = codepoint };