terminal: add ESC [ 22 J (scroll and clear)

This commit is contained in:
Mitchell Hashimoto
2023-11-19 20:45:57 -08:00
parent b220179c3a
commit 39c2549b1a
3 changed files with 63 additions and 0 deletions

View File

@ -6421,6 +6421,34 @@ test "Screen: resize less cols with reflow previously wrapped and scrollback" {
try testing.expectEqual(@as(usize, 2), s.cursor.y);
}
// test "Screen: resize less cols with scrollback keeps cursor row" {
// const testing = std.testing;
// const alloc = testing.allocator;
//
// var s = try init(alloc, 3, 5, 5);
// defer s.deinit();
// const str = "1A\n2B\n3C\n4D\n5E";
// try s.testWriteString(str);
//
// // Put our cursor on the end
// s.cursor.x = 1;
// s.cursor.y = s.rows - 1;
// try testing.expectEqual(@as(u32, 'E'), s.getCell(.active, s.cursor.y, s.cursor.x).char);
//
// try s.resize(3, 3);
//
// {
// const contents = try s.testString(alloc, .viewport);
// defer alloc.free(contents);
// const expected = "3C\n4D\n5E";
// try testing.expectEqualStrings(expected, contents);
// }
//
// // Cursor should be on the last line
// try testing.expectEqual(@as(usize, 1), s.cursor.x);
// try testing.expectEqual(@as(usize, 2), s.cursor.y);
// }
//
test "Screen: resize more rows, less cols with reflow with scrollback" {
const testing = std.testing;
const alloc = testing.allocator;

View File

@ -1144,6 +1144,20 @@ pub fn eraseDisplay(
const protected = self.screen.protected_mode == .iso or protected_req;
switch (mode) {
.scroll_complete => {
self.screen.scroll(.{ .clear = {} }) catch |err| {
log.warn("scroll clear failed, doing a normal clear err={}", .{err});
self.eraseDisplay(alloc, .complete, protected_req);
return;
};
// Unsets pending wrap state
self.screen.cursor.pending_wrap = false;
// Clear all Kitty graphics state for this screen
self.screen.kitty_images.delete(alloc, self, .{ .all = true });
},
.complete => {
var it = self.screen.rowIterator(.active);
while (it.next()) |row| {
@ -6017,6 +6031,23 @@ test "Terminal: eraseDisplay protected above" {
var t = try init(alloc, 10, 5);
defer t.deinit(alloc);
try t.print('A');
t.carriageReturn();
try t.linefeed();
t.eraseDisplay(alloc, .scroll_complete, false);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("", str);
}
}
test "Terminal: eraseDisplay scroll complete" {
const alloc = testing.allocator;
var t = try init(alloc, 10, 3);
defer t.deinit(alloc);
try t.print('A');
t.carriageReturn();
try t.linefeed();

View File

@ -4,6 +4,10 @@ pub const EraseDisplay = enum(u8) {
above = 1,
complete = 2,
scrollback = 3,
/// This is an extension added by Kitty to move the viewport into the
/// scrollback and then erase the display.
scroll_complete = 22,
};
// Modes for the EL CSI command.