Merge pull request #238 from mitchellh/ignore-restore-mode

CSI r for top/bot margin must have no intermediates
This commit is contained in:
Mitchell Hashimoto
2023-08-07 09:54:46 -07:00
committed by GitHub

View File

@ -452,6 +452,10 @@ pub fn Stream(comptime Handler: type) type {
// that means. And there is also `CSI > m` which is used // that means. And there is also `CSI > m` which is used
// to control modifier key reporting formats that we don't // to control modifier key reporting formats that we don't
// support yet. // support yet.
log.debug(
"ignoring unimplemented CSI m with intermediates: {s}",
.{action.intermediates},
);
}, },
// CPR - Request Cursor Postion Report // CPR - Request Cursor Postion Report
@ -481,12 +485,19 @@ pub fn Stream(comptime Handler: type) type {
// DECSTBM - Set Top and Bottom Margins // DECSTBM - Set Top and Bottom Margins
// TODO: test // TODO: test
'r' => if (@hasDecl(T, "setTopAndBottomMargin")) switch (action.params.len) { 'r' => if (action.intermediates.len == 0) {
0 => try self.handler.setTopAndBottomMargin(0, 0), if (@hasDecl(T, "setTopAndBottomMargin")) switch (action.params.len) {
1 => try self.handler.setTopAndBottomMargin(action.params[0], 0), 0 => try self.handler.setTopAndBottomMargin(0, 0),
2 => try self.handler.setTopAndBottomMargin(action.params[0], action.params[1]), 1 => try self.handler.setTopAndBottomMargin(action.params[0], 0),
else => log.warn("invalid DECSTBM command: {}", .{action}), 2 => try self.handler.setTopAndBottomMargin(action.params[0], action.params[1]),
} else log.warn("unimplemented CSI callback: {}", .{action}), else => log.warn("invalid DECSTBM command: {}", .{action}),
} else log.warn("unimplemented CSI callback: {}", .{action});
} else {
log.debug(
"ignoring unimplemented CSI r with intermediates: {s}",
.{action.intermediates},
);
},
// ICH - Insert Blanks // ICH - Insert Blanks
// TODO: test // TODO: test
@ -815,3 +826,20 @@ test "stream: set mode (SM) and reset mode (RM)" {
try s.nextSlice("\x1B[?6l"); try s.nextSlice("\x1B[?6l");
try testing.expectEqual(@as(ansi.Mode, @enumFromInt(0)), s.handler.mode); try testing.expectEqual(@as(ansi.Mode, @enumFromInt(0)), s.handler.mode);
} }
test "stream: restore mode" {
const H = struct {
const Self = @This();
called: bool = false,
pub fn setTopAndBottomMargin(self: *Self, t: u16, b: u16) !void {
_ = t;
_ = b;
self.called = true;
}
};
var s: Stream(H) = .{ .handler = .{} };
for ("\x1B[?42r") |c| try s.next(c);
try testing.expect(!s.handler.called);
}