terminal: CSI < u defaults param to "1" if not set (pop kitty keyboard)

This commit is contained in:
Mitchell Hashimoto
2023-08-20 22:01:49 -07:00
parent 1921fb8e6a
commit e7ab16f0e1
2 changed files with 20 additions and 5 deletions

View File

@ -669,7 +669,7 @@ pub fn Stream(comptime Handler: type) type {
const number: u16 = if (action.params.len == 1) const number: u16 = if (action.params.len == 1)
action.params[0] action.params[0]
else else
0; 1;
try self.handler.popKittyKeyboard(number); try self.handler.popKittyKeyboard(number);
}, },
@ -1073,3 +1073,18 @@ test "stream: restore mode" {
for ("\x1B[?42r") |c| try s.next(c); for ("\x1B[?42r") |c| try s.next(c);
try testing.expect(!s.handler.called); try testing.expect(!s.handler.called);
} }
test "stream: pop kitty keyboard with no params defaults to 1" {
const H = struct {
const Self = @This();
n: u16 = 0,
pub fn popKittyKeyboard(self: *Self, n: u16) !void {
self.n = n;
}
};
var s: Stream(H) = .{ .handler = .{} };
for ("\x1B[<u") |c| try s.next(c);
try testing.expectEqual(@as(u16, 1), s.handler.n);
}

View File

@ -1415,7 +1415,7 @@ const StreamHandler = struct {
pub fn queryKittyKeyboard(self: *StreamHandler) !void { pub fn queryKittyKeyboard(self: *StreamHandler) !void {
if (comptime disable_kitty_keyboard_protocol) return; if (comptime disable_kitty_keyboard_protocol) return;
// log.debug("querying kitty keyboard mode", .{}); log.debug("querying kitty keyboard mode", .{});
var data: termio.Message.WriteReq.Small.Array = undefined; var data: termio.Message.WriteReq.Small.Array = undefined;
const resp = try std.fmt.bufPrint(&data, "\x1b[?{}u", .{ const resp = try std.fmt.bufPrint(&data, "\x1b[?{}u", .{
self.terminal.screen.kitty_keyboard.current().int(), self.terminal.screen.kitty_keyboard.current().int(),
@ -1435,14 +1435,14 @@ const StreamHandler = struct {
) !void { ) !void {
if (comptime disable_kitty_keyboard_protocol) return; if (comptime disable_kitty_keyboard_protocol) return;
// log.debug("pushing kitty keyboard mode: {}", .{flags}); log.debug("pushing kitty keyboard mode: {}", .{flags});
self.terminal.screen.kitty_keyboard.push(flags); self.terminal.screen.kitty_keyboard.push(flags);
} }
pub fn popKittyKeyboard(self: *StreamHandler, n: u16) !void { pub fn popKittyKeyboard(self: *StreamHandler, n: u16) !void {
if (comptime disable_kitty_keyboard_protocol) return; if (comptime disable_kitty_keyboard_protocol) return;
// log.debug("popping kitty keyboard mode", .{}); log.debug("popping kitty keyboard mode n={}", .{n});
self.terminal.screen.kitty_keyboard.pop(@intCast(n)); self.terminal.screen.kitty_keyboard.pop(@intCast(n));
} }
@ -1453,7 +1453,7 @@ const StreamHandler = struct {
) !void { ) !void {
if (comptime disable_kitty_keyboard_protocol) return; if (comptime disable_kitty_keyboard_protocol) return;
// log.debug("setting kitty keyboard mode: {} {}", .{mode, flags}); log.debug("setting kitty keyboard mode: {} {}", .{ mode, flags });
self.terminal.screen.kitty_keyboard.set(mode, flags); self.terminal.screen.kitty_keyboard.set(mode, flags);
} }