terminal/new: erase display complete

This commit is contained in:
Mitchell Hashimoto
2024-02-27 19:03:43 -08:00
parent f7e2868533
commit 116f6264ba
2 changed files with 302 additions and 62 deletions

View File

@ -6273,6 +6273,7 @@ test "Terminal: eraseDisplay below protected attributes respected with force" {
} }
} }
// X
test "Terminal: eraseDisplay erase above preserves SGR bg" { test "Terminal: eraseDisplay erase above preserves SGR bg" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);
@ -6305,6 +6306,7 @@ test "Terminal: eraseDisplay erase above preserves SGR bg" {
} }
} }
// X
test "Terminal: eraseDisplay above split multi-cell" { test "Terminal: eraseDisplay above split multi-cell" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);
@ -6327,6 +6329,7 @@ test "Terminal: eraseDisplay above split multi-cell" {
} }
} }
// X
test "Terminal: eraseDisplay above protected attributes respected with iso" { test "Terminal: eraseDisplay above protected attributes respected with iso" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);
@ -6350,6 +6353,7 @@ test "Terminal: eraseDisplay above protected attributes respected with iso" {
} }
} }
// X
test "Terminal: eraseDisplay above protected attributes ignored with dec most recent" { test "Terminal: eraseDisplay above protected attributes ignored with dec most recent" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);
@ -6375,6 +6379,7 @@ test "Terminal: eraseDisplay above protected attributes ignored with dec most re
} }
} }
// X
test "Terminal: eraseDisplay above protected attributes ignored with dec set" { test "Terminal: eraseDisplay above protected attributes ignored with dec set" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);
@ -6398,6 +6403,7 @@ test "Terminal: eraseDisplay above protected attributes ignored with dec set" {
} }
} }
// X
test "Terminal: eraseDisplay above protected attributes respected with force" { test "Terminal: eraseDisplay above protected attributes respected with force" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);
@ -6420,6 +6426,8 @@ test "Terminal: eraseDisplay above protected attributes respected with force" {
try testing.expectEqualStrings("ABC\nDEF\nGHI", str); try testing.expectEqualStrings("ABC\nDEF\nGHI", str);
} }
} }
// X
test "Terminal: eraseDisplay above" { test "Terminal: eraseDisplay above" {
var t = try init(testing.allocator, 80, 80); var t = try init(testing.allocator, 80, 80);
defer t.deinit(testing.allocator); defer t.deinit(testing.allocator);
@ -6459,6 +6467,7 @@ test "Terminal: eraseDisplay above" {
try testing.expect(cell.bg.rgb.eql(pink)); try testing.expect(cell.bg.rgb.eql(pink));
} }
// X
test "Terminal: eraseDisplay below" { test "Terminal: eraseDisplay below" {
var t = try init(testing.allocator, 80, 80); var t = try init(testing.allocator, 80, 80);
defer t.deinit(testing.allocator); defer t.deinit(testing.allocator);
@ -6492,6 +6501,7 @@ test "Terminal: eraseDisplay below" {
try testing.expect(cell.bg.rgb.eql(pink)); try testing.expect(cell.bg.rgb.eql(pink));
} }
// X
test "Terminal: eraseDisplay complete" { test "Terminal: eraseDisplay complete" {
var t = try init(testing.allocator, 80, 80); var t = try init(testing.allocator, 80, 80);
defer t.deinit(testing.allocator); defer t.deinit(testing.allocator);
@ -6536,6 +6546,7 @@ test "Terminal: eraseDisplay complete" {
try testing.expect(!cell.attrs.bold); try testing.expect(!cell.attrs.bold);
} }
// X
test "Terminal: eraseDisplay protected complete" { test "Terminal: eraseDisplay protected complete" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 10, 5); var t = try init(alloc, 10, 5);
@ -6558,6 +6569,7 @@ test "Terminal: eraseDisplay protected complete" {
} }
} }
// X
test "Terminal: eraseDisplay protected below" { test "Terminal: eraseDisplay protected below" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 10, 5); var t = try init(alloc, 10, 5);
@ -6580,6 +6592,7 @@ test "Terminal: eraseDisplay protected below" {
} }
} }
// X
test "Terminal: eraseDisplay protected above" { test "Terminal: eraseDisplay protected above" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 10, 5); var t = try init(alloc, 10, 5);
@ -6597,6 +6610,7 @@ test "Terminal: eraseDisplay protected above" {
} }
} }
// X
test "Terminal: eraseDisplay scroll complete" { test "Terminal: eraseDisplay scroll complete" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 10, 3); var t = try init(alloc, 10, 3);

View File

@ -1627,14 +1627,14 @@ pub fn eraseDisplay(
// // Clear all Kitty graphics state for this screen // // Clear all Kitty graphics state for this screen
// self.screen.kitty_images.delete(alloc, self, .{ .all = true }); // self.screen.kitty_images.delete(alloc, self, .{ .all = true });
// }, // },
//
// .complete => { .complete => {
// // If we're on the primary screen and our last non-empty row is // If we're on the primary screen and our last non-empty row is
// // a prompt, then we do a scroll_complete instead. This is a // a prompt, then we do a scroll_complete instead. This is a
// // heuristic to get the generally desirable behavior that ^L // heuristic to get the generally desirable behavior that ^L
// // at a prompt scrolls the screen contents prior to clearing. // at a prompt scrolls the screen contents prior to clearing.
// // Most shells send `ESC [ H ESC [ 2 J` so we can't just check // Most shells send `ESC [ H ESC [ 2 J` so we can't just check
// // our current cursor position. See #905 // our current cursor position. See #905
// if (self.active_screen == .primary) at_prompt: { // if (self.active_screen == .primary) at_prompt: {
// // Go from the bottom of the viewport up and see if we're // // Go from the bottom of the viewport up and see if we're
// // at a prompt. // // at a prompt.
@ -1664,31 +1664,21 @@ pub fn eraseDisplay(
// // so we don't worry about the error. // // so we don't worry about the error.
// }; // };
// } // }
//
// var it = self.screen.rowIterator(.active); // All active area
// while (it.next()) |row| { self.screen.eraseRows(
// row.setWrapped(false); .{ .active = .{} },
// row.setDirty(true); null,
// protected,
// if (!protected) { );
// row.clear(pen);
// continue; // Unsets pending wrap state
// } self.screen.cursor.pending_wrap = false;
//
// // Protected mode erase // Clear all Kitty graphics state for this screen
// for (0..row.lenCells()) |x| { // TODO
// const cell = row.getCellPtr(x);
// if (cell.attrs.protected) continue;
// cell.* = pen;
// }
// }
//
// // 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 }); //self.screen.kitty_images.delete(alloc, self, .{ .all = true });
// }, },
.below => { .below => {
// All lines to the right (including the cursor) // All lines to the right (including the cursor)
@ -6813,3 +6803,239 @@ test "Terminal: eraseDisplay simple erase above" {
try testing.expectEqualStrings("\n F\nGHI", str); try testing.expectEqualStrings("\n F\nGHI", str);
} }
} }
test "Terminal: eraseDisplay erase above preserves SGR bg" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
for ("ABC") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("DEF") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("GHI") |c| try t.print(c);
t.setCursorPos(2, 2);
try t.setAttribute(.{ .direct_color_bg = .{
.r = 0xFF,
.g = 0,
.b = 0,
} });
t.eraseDisplay(.above, false);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n F\nGHI", str);
for (0..2) |x| {
const list_cell = t.screen.pages.getCell(.{ .active = .{ .x = x, .y = 1 } }).?;
try testing.expect(list_cell.cell.content_tag == .bg_color_rgb);
try testing.expectEqual(Cell.RGB{
.r = 0xFF,
.g = 0,
.b = 0,
}, list_cell.cell.content.color_rgb);
}
}
}
test "Terminal: eraseDisplay above split multi-cell" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printString("AB橋C");
t.carriageReturn();
try t.linefeed();
try t.printString("DE橋F");
t.carriageReturn();
try t.linefeed();
try t.printString("GH橋I");
t.setCursorPos(2, 3);
t.eraseDisplay(.above, false);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n F\nGH橋I", str);
}
}
test "Terminal: eraseDisplay above protected attributes respected with iso" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
t.setProtectedMode(.iso);
for ("ABC") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("DEF") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("GHI") |c| try t.print(c);
t.setCursorPos(2, 2);
t.eraseDisplay(.above, false);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("ABC\nDEF\nGHI", str);
}
}
test "Terminal: eraseDisplay above protected attributes ignored with dec most recent" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
t.setProtectedMode(.iso);
for ("ABC") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("DEF") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("GHI") |c| try t.print(c);
t.setProtectedMode(.dec);
t.setProtectedMode(.off);
t.setCursorPos(2, 2);
t.eraseDisplay(.above, false);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n F\nGHI", str);
}
}
test "Terminal: eraseDisplay above protected attributes ignored with dec set" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
t.setProtectedMode(.dec);
for ("ABC") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("DEF") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("GHI") |c| try t.print(c);
t.setCursorPos(2, 2);
t.eraseDisplay(.above, false);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n F\nGHI", str);
}
}
test "Terminal: eraseDisplay above protected attributes respected with force" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
t.setProtectedMode(.dec);
for ("ABC") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("DEF") |c| try t.print(c);
t.carriageReturn();
try t.linefeed();
for ("GHI") |c| try t.print(c);
t.setCursorPos(2, 2);
t.eraseDisplay(.above, true);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("ABC\nDEF\nGHI", str);
}
}
test "Terminal: eraseDisplay protected complete" {
const alloc = testing.allocator;
var t = try init(alloc, 10, 5);
defer t.deinit(alloc);
try t.print('A');
t.carriageReturn();
try t.linefeed();
for ("123456789") |c| try t.print(c);
t.setCursorPos(t.screen.cursor.y + 1, 6);
t.setProtectedMode(.dec);
try t.print('X');
t.setCursorPos(t.screen.cursor.y + 1, 4);
t.eraseDisplay(.complete, true);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n X", str);
}
}
test "Terminal: eraseDisplay protected below" {
const alloc = testing.allocator;
var t = try init(alloc, 10, 5);
defer t.deinit(alloc);
try t.print('A');
t.carriageReturn();
try t.linefeed();
for ("123456789") |c| try t.print(c);
t.setCursorPos(t.screen.cursor.y + 1, 6);
t.setProtectedMode(.dec);
try t.print('X');
t.setCursorPos(t.screen.cursor.y + 1, 4);
t.eraseDisplay(.below, true);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("A\n123 X", str);
}
}
// test "Terminal: eraseDisplay scroll complete" {
// const alloc = testing.allocator;
// var t = try init(alloc, 10, 5);
// defer t.deinit(alloc);
//
// try t.print('A');
// t.carriageReturn();
// try t.linefeed();
// t.eraseDisplay(.scroll_complete, false);
//
// {
// const str = try t.plainString(testing.allocator);
// defer testing.allocator.free(str);
// try testing.expectEqualStrings("", str);
// }
// }
test "Terminal: eraseDisplay protected above" {
const alloc = testing.allocator;
var t = try init(alloc, 10, 3);
defer t.deinit(alloc);
try t.print('A');
t.carriageReturn();
try t.linefeed();
for ("123456789") |c| try t.print(c);
t.setCursorPos(t.screen.cursor.y + 1, 6);
t.setProtectedMode(.dec);
try t.print('X');
t.setCursorPos(t.screen.cursor.y + 1, 8);
t.eraseDisplay(.above, true);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n X 9", str);
}
}