From d21d7f042672977645be45a74e907673adf1884d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Feb 2024 19:58:21 -0800 Subject: [PATCH] terminal/new: erase => clear when the data isn't physically erased --- src/terminal/new/Screen.zig | 36 +++++++++++++++++------------------ src/terminal/new/Terminal.zig | 28 +++++++++++++-------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index d07f2e3ec..d533bf579 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -299,13 +299,13 @@ pub fn scrollClear(self: *Screen) !void { self.kitty_images.dirty = true; } -// Erase the region specified by tl and bl, inclusive. Erased cells are -// colored with the current style background color. This will erase all +// Clear the region specified by tl and bl, inclusive. Cleared cells are +// colored with the current style background color. This will clear all // cells in the rows. // // If protected is true, the protected flag will be respected and only -// unprotected cells will be erased. Otherwise, all cells will be erased. -pub fn eraseRows( +// unprotected cells will be cleared. Otherwise, all cells will be cleared. +pub fn clearRows( self: *Screen, tl: point.Point, bl: ?point.Point, @@ -318,11 +318,11 @@ pub fn eraseRows( const cells_multi: [*]Cell = row.cells.ptr(chunk.page.data.memory); const cells = cells_multi[0..self.pages.cols]; - // Erase all cells + // Clear all cells if (protected) { - self.eraseUnprotectedCells(&chunk.page.data, row, cells); + self.clearUnprotectedCells(&chunk.page.data, row, cells); } else { - self.eraseCells(&chunk.page.data, row, cells); + self.clearCells(&chunk.page.data, row, cells); } // Reset our row to point to the proper memory but everything @@ -332,9 +332,9 @@ pub fn eraseRows( } } -/// Erase the cells with the blank cell. This takes care to handle +/// Clear the cells with the blank cell. This takes care to handle /// cleaning up graphemes and styles. -pub fn eraseCells( +pub fn clearCells( self: *Screen, page: *Page, row: *Row, @@ -380,8 +380,8 @@ pub fn eraseCells( @memset(cells, self.blankCell()); } -/// Erase cells but only if they are not protected. -pub fn eraseUnprotectedCells( +/// Clear cells but only if they are not protected. +pub fn clearUnprotectedCells( self: *Screen, page: *Page, row: *Row, @@ -390,7 +390,7 @@ pub fn eraseUnprotectedCells( for (cells) |*cell| { if (cell.protected) continue; const cell_multi: [*]Cell = @ptrCast(cell); - self.eraseCells(page, row, cell_multi[0..1]); + self.clearCells(page, row, cell_multi[0..1]); } } @@ -792,7 +792,7 @@ test "Screen style reset with unset" { try testing.expectEqual(@as(usize, 0), page.styles.count(page.memory)); } -test "Screen eraseRows active one line" { +test "Screen clearRows active one line" { const testing = std.testing; const alloc = testing.allocator; @@ -800,13 +800,13 @@ test "Screen eraseRows active one line" { defer s.deinit(); try s.testWriteString("hello, world"); - s.eraseRows(.{ .active = .{} }, null, false); + s.clearRows(.{ .active = .{} }, null, false); const str = try s.dumpStringAlloc(alloc, .{ .screen = .{} }); defer alloc.free(str); try testing.expectEqualStrings("", str); } -test "Screen eraseRows active multi line" { +test "Screen clearRows active multi line" { const testing = std.testing; const alloc = testing.allocator; @@ -814,13 +814,13 @@ test "Screen eraseRows active multi line" { defer s.deinit(); try s.testWriteString("hello\nworld"); - s.eraseRows(.{ .active = .{} }, null, false); + s.clearRows(.{ .active = .{} }, null, false); const str = try s.dumpStringAlloc(alloc, .{ .screen = .{} }); defer alloc.free(str); try testing.expectEqualStrings("", str); } -test "Screen eraseRows active styled line" { +test "Screen clearRows active styled line" { const testing = std.testing; const alloc = testing.allocator; @@ -835,7 +835,7 @@ test "Screen eraseRows active styled line" { const page = s.cursor.page_offset.page.data; try testing.expectEqual(@as(usize, 1), page.styles.count(page.memory)); - s.eraseRows(.{ .active = .{} }, null, false); + s.clearRows(.{ .active = .{} }, null, false); // We should have none because active cleared it try testing.expectEqual(@as(usize, 0), page.styles.count(page.memory)); diff --git a/src/terminal/new/Terminal.zig b/src/terminal/new/Terminal.zig index 627a3bcb3..2a97432bc 100644 --- a/src/terminal/new/Terminal.zig +++ b/src/terminal/new/Terminal.zig @@ -1192,7 +1192,7 @@ pub fn insertLines(self: *Terminal, count: usize) void { var page = &self.screen.cursor.page_offset.page.data; const cells = page.getCells(row); const cells_write = cells[self.scrolling_region.left .. self.scrolling_region.right + 1]; - self.screen.eraseCells(page, row, cells_write); + self.screen.clearCells(page, row, cells_write); } // Move the cursor to the left margin. But importantly this also @@ -1286,7 +1286,7 @@ pub fn deleteLines(self: *Terminal, count_req: usize) void { var page = &self.screen.cursor.page_offset.page.data; const cells = page.getCells(row); const cells_write = cells[self.scrolling_region.left .. self.scrolling_region.right + 1]; - self.screen.eraseCells(page, row, cells_write); + self.screen.clearCells(page, row, cells_write); } // Move the cursor to the left margin. But importantly this also @@ -1350,7 +1350,7 @@ pub fn insertBlanks(self: *Terminal, count: usize) void { // it to be empty so we don't split the multi-cell char. const end: *Cell = @ptrCast(x); if (end.wide == .wide) { - self.screen.eraseCells(page, self.screen.cursor.page_row, end[0..1]); + self.screen.clearCells(page, self.screen.cursor.page_row, end[0..1]); } // We work backwards so we don't overwrite data. @@ -1380,7 +1380,7 @@ pub fn insertBlanks(self: *Terminal, count: usize) void { } // Insert blanks. The blanks preserve the background color. - self.screen.eraseCells(page, self.screen.cursor.page_row, left[0..adjusted_count]); + self.screen.clearCells(page, self.screen.cursor.page_row, left[0..adjusted_count]); } /// Removes amount characters from the current cursor position to the right. @@ -1410,7 +1410,7 @@ pub fn deleteChars(self: *Terminal, count: usize) void { // previous cell too so we don't split a multi-cell character. if (self.screen.cursor.page_cell.wide == .spacer_tail) { assert(self.screen.cursor.x > 0); - self.screen.eraseCells(page, self.screen.cursor.page_row, (left - 1)[0..2]); + self.screen.clearCells(page, self.screen.cursor.page_row, (left - 1)[0..2]); } // Remaining cols from our cursor to the right margin. @@ -1433,7 +1433,7 @@ pub fn deleteChars(self: *Terminal, count: usize) void { if (end.wide == .spacer_tail) { const wide: [*]Cell = right + count - 1; assert(wide[0].wide == .wide); - self.screen.eraseCells(page, self.screen.cursor.page_row, wide[0..2]); + self.screen.clearCells(page, self.screen.cursor.page_row, wide[0..2]); } while (@intFromPtr(x) <= @intFromPtr(right)) : (x += 1) { @@ -1462,7 +1462,7 @@ pub fn deleteChars(self: *Terminal, count: usize) void { } // Insert blanks. The blanks preserve the background color. - self.screen.eraseCells(page, self.screen.cursor.page_row, x[0 .. rem - scroll_amount]); + self.screen.clearCells(page, self.screen.cursor.page_row, x[0 .. rem - scroll_amount]); } pub fn eraseChars(self: *Terminal, count_req: usize) void { @@ -1497,7 +1497,7 @@ pub fn eraseChars(self: *Terminal, count_req: usize) void { // are protected and go with the fast path. If the last protection // mode was not ISO we also always ignore protection attributes. if (self.screen.protected_mode != .iso) { - self.screen.eraseCells( + self.screen.clearCells( &self.screen.cursor.page_offset.page.data, self.screen.cursor.page_row, cells[0..end], @@ -1512,7 +1512,7 @@ pub fn eraseChars(self: *Terminal, count_req: usize) void { const cell_multi: [*]Cell = @ptrCast(cells + x); const cell: *Cell = @ptrCast(&cell_multi[0]); if (cell.protected) continue; - self.screen.eraseCells( + self.screen.clearCells( &self.screen.cursor.page_offset.page.data, self.screen.cursor.page_row, cell_multi[0..1], @@ -1582,7 +1582,7 @@ pub fn eraseLine( // If we're not respecting protected attributes, we can use a fast-path // to fill the entire line. if (!protected) { - self.screen.eraseCells( + self.screen.clearCells( &self.screen.cursor.page_offset.page.data, self.screen.cursor.page_row, cells[start..end], @@ -1594,7 +1594,7 @@ pub fn eraseLine( const cell_multi: [*]Cell = @ptrCast(cells + x); const cell: *Cell = @ptrCast(&cell_multi[0]); if (cell.protected) continue; - self.screen.eraseCells( + self.screen.clearCells( &self.screen.cursor.page_offset.page.data, self.screen.cursor.page_row, cell_multi[0..1], @@ -1667,7 +1667,7 @@ pub fn eraseDisplay( // } // All active area - self.screen.eraseRows( + self.screen.clearRows( .{ .active = .{} }, null, protected, @@ -1687,7 +1687,7 @@ pub fn eraseDisplay( // All lines below if (self.screen.cursor.y + 1 < self.rows) { - self.screen.eraseRows( + self.screen.clearRows( .{ .active = .{ .y = self.screen.cursor.y + 1 } }, null, protected, @@ -1704,7 +1704,7 @@ pub fn eraseDisplay( // All lines above if (self.screen.cursor.y > 0) { - self.screen.eraseRows( + self.screen.clearRows( .{ .active = .{ .y = 0 } }, .{ .active = .{ .y = self.screen.cursor.y - 1 } }, protected,