terminal: CSI Ps " q for setting DEC protected mode

This commit is contained in:
Mitchell Hashimoto
2023-09-25 09:45:16 -07:00
parent 2a390785f5
commit 8137a66ef6
2 changed files with 56 additions and 0 deletions

View File

@ -651,6 +651,29 @@ pub fn Stream(comptime Handler: type) type {
},
) else log.warn("unimplemented CSI callback: {}", .{action});
},
// DECSCA
'"' => {
if (@hasDecl(T, "setProtectedMode")) {
const mode_: ?ansi.ProtectedMode = switch (action.params.len) {
else => null,
0 => .off,
1 => switch (action.params[0]) {
0, 2 => .off,
1 => .dec,
else => null,
},
};
const mode = mode_ orelse {
log.warn("invalid set protected mode command: {}", .{action});
return;
};
try self.handler.setProtectedMode(mode);
} else log.warn("unimplemented CSI callback: {}", .{action});
},
// XTVERSION
'>' => {
if (@hasDecl(T, "reportXtversion")) try self.handler.reportXtversion();
@ -1202,3 +1225,32 @@ test "stream: pop kitty keyboard with no params defaults to 1" {
for ("\x1B[<u") |c| try s.next(c);
try testing.expectEqual(@as(u16, 1), s.handler.n);
}
test "stream: DECSCA" {
const H = struct {
const Self = @This();
v: ?ansi.ProtectedMode = null,
pub fn setProtectedMode(self: *Self, v: ansi.ProtectedMode) !void {
self.v = v;
}
};
var s: Stream(H) = .{ .handler = .{} };
{
for ("\x1B[\"q") |c| try s.next(c);
try testing.expectEqual(ansi.ProtectedMode.off, s.handler.v.?);
}
{
for ("\x1B[0\"q") |c| try s.next(c);
try testing.expectEqual(ansi.ProtectedMode.off, s.handler.v.?);
}
{
for ("\x1B[2\"q") |c| try s.next(c);
try testing.expectEqual(ansi.ProtectedMode.off, s.handler.v.?);
}
{
for ("\x1B[1\"q") |c| try s.next(c);
try testing.expectEqual(ansi.ProtectedMode.dec, s.handler.v.?);
}
}

View File

@ -1583,6 +1583,10 @@ const StreamHandler = struct {
}
}
pub fn setProtectedMode(self: *StreamHandler, mode: terminal.ProtectedMode) !void {
self.terminal.setProtectedMode(mode);
}
pub fn decaln(self: *StreamHandler) !void {
try self.terminal.decaln();
}