mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 17:26:09 +03:00
terminal/new: erase => clear when the data isn't physically erased
This commit is contained in:
@ -299,13 +299,13 @@ pub fn scrollClear(self: *Screen) !void {
|
|||||||
self.kitty_images.dirty = true;
|
self.kitty_images.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erase the region specified by tl and bl, inclusive. Erased cells are
|
// Clear the region specified by tl and bl, inclusive. Cleared cells are
|
||||||
// colored with the current style background color. This will erase all
|
// colored with the current style background color. This will clear all
|
||||||
// cells in the rows.
|
// cells in the rows.
|
||||||
//
|
//
|
||||||
// If protected is true, the protected flag will be respected and only
|
// If protected is true, the protected flag will be respected and only
|
||||||
// unprotected cells will be erased. Otherwise, all cells will be erased.
|
// unprotected cells will be cleared. Otherwise, all cells will be cleared.
|
||||||
pub fn eraseRows(
|
pub fn clearRows(
|
||||||
self: *Screen,
|
self: *Screen,
|
||||||
tl: point.Point,
|
tl: point.Point,
|
||||||
bl: ?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_multi: [*]Cell = row.cells.ptr(chunk.page.data.memory);
|
||||||
const cells = cells_multi[0..self.pages.cols];
|
const cells = cells_multi[0..self.pages.cols];
|
||||||
|
|
||||||
// Erase all cells
|
// Clear all cells
|
||||||
if (protected) {
|
if (protected) {
|
||||||
self.eraseUnprotectedCells(&chunk.page.data, row, cells);
|
self.clearUnprotectedCells(&chunk.page.data, row, cells);
|
||||||
} else {
|
} 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
|
// 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.
|
/// cleaning up graphemes and styles.
|
||||||
pub fn eraseCells(
|
pub fn clearCells(
|
||||||
self: *Screen,
|
self: *Screen,
|
||||||
page: *Page,
|
page: *Page,
|
||||||
row: *Row,
|
row: *Row,
|
||||||
@ -380,8 +380,8 @@ pub fn eraseCells(
|
|||||||
@memset(cells, self.blankCell());
|
@memset(cells, self.blankCell());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Erase cells but only if they are not protected.
|
/// Clear cells but only if they are not protected.
|
||||||
pub fn eraseUnprotectedCells(
|
pub fn clearUnprotectedCells(
|
||||||
self: *Screen,
|
self: *Screen,
|
||||||
page: *Page,
|
page: *Page,
|
||||||
row: *Row,
|
row: *Row,
|
||||||
@ -390,7 +390,7 @@ pub fn eraseUnprotectedCells(
|
|||||||
for (cells) |*cell| {
|
for (cells) |*cell| {
|
||||||
if (cell.protected) continue;
|
if (cell.protected) continue;
|
||||||
const cell_multi: [*]Cell = @ptrCast(cell);
|
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));
|
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 testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
@ -800,13 +800,13 @@ test "Screen eraseRows active one line" {
|
|||||||
defer s.deinit();
|
defer s.deinit();
|
||||||
|
|
||||||
try s.testWriteString("hello, world");
|
try s.testWriteString("hello, world");
|
||||||
s.eraseRows(.{ .active = .{} }, null, false);
|
s.clearRows(.{ .active = .{} }, null, false);
|
||||||
const str = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
|
const str = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
|
||||||
defer alloc.free(str);
|
defer alloc.free(str);
|
||||||
try testing.expectEqualStrings("", str);
|
try testing.expectEqualStrings("", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "Screen eraseRows active multi line" {
|
test "Screen clearRows active multi line" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
@ -814,13 +814,13 @@ test "Screen eraseRows active multi line" {
|
|||||||
defer s.deinit();
|
defer s.deinit();
|
||||||
|
|
||||||
try s.testWriteString("hello\nworld");
|
try s.testWriteString("hello\nworld");
|
||||||
s.eraseRows(.{ .active = .{} }, null, false);
|
s.clearRows(.{ .active = .{} }, null, false);
|
||||||
const str = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
|
const str = try s.dumpStringAlloc(alloc, .{ .screen = .{} });
|
||||||
defer alloc.free(str);
|
defer alloc.free(str);
|
||||||
try testing.expectEqualStrings("", str);
|
try testing.expectEqualStrings("", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "Screen eraseRows active styled line" {
|
test "Screen clearRows active styled line" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
@ -835,7 +835,7 @@ test "Screen eraseRows active styled line" {
|
|||||||
const page = s.cursor.page_offset.page.data;
|
const page = s.cursor.page_offset.page.data;
|
||||||
try testing.expectEqual(@as(usize, 1), page.styles.count(page.memory));
|
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
|
// We should have none because active cleared it
|
||||||
try testing.expectEqual(@as(usize, 0), page.styles.count(page.memory));
|
try testing.expectEqual(@as(usize, 0), page.styles.count(page.memory));
|
||||||
|
@ -1192,7 +1192,7 @@ pub fn insertLines(self: *Terminal, count: usize) void {
|
|||||||
var page = &self.screen.cursor.page_offset.page.data;
|
var page = &self.screen.cursor.page_offset.page.data;
|
||||||
const cells = page.getCells(row);
|
const cells = page.getCells(row);
|
||||||
const cells_write = cells[self.scrolling_region.left .. self.scrolling_region.right + 1];
|
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
|
// 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;
|
var page = &self.screen.cursor.page_offset.page.data;
|
||||||
const cells = page.getCells(row);
|
const cells = page.getCells(row);
|
||||||
const cells_write = cells[self.scrolling_region.left .. self.scrolling_region.right + 1];
|
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
|
// 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.
|
// it to be empty so we don't split the multi-cell char.
|
||||||
const end: *Cell = @ptrCast(x);
|
const end: *Cell = @ptrCast(x);
|
||||||
if (end.wide == .wide) {
|
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.
|
// 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.
|
// 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.
|
/// 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.
|
// previous cell too so we don't split a multi-cell character.
|
||||||
if (self.screen.cursor.page_cell.wide == .spacer_tail) {
|
if (self.screen.cursor.page_cell.wide == .spacer_tail) {
|
||||||
assert(self.screen.cursor.x > 0);
|
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.
|
// 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) {
|
if (end.wide == .spacer_tail) {
|
||||||
const wide: [*]Cell = right + count - 1;
|
const wide: [*]Cell = right + count - 1;
|
||||||
assert(wide[0].wide == .wide);
|
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) {
|
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.
|
// 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 {
|
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
|
// are protected and go with the fast path. If the last protection
|
||||||
// mode was not ISO we also always ignore protection attributes.
|
// mode was not ISO we also always ignore protection attributes.
|
||||||
if (self.screen.protected_mode != .iso) {
|
if (self.screen.protected_mode != .iso) {
|
||||||
self.screen.eraseCells(
|
self.screen.clearCells(
|
||||||
&self.screen.cursor.page_offset.page.data,
|
&self.screen.cursor.page_offset.page.data,
|
||||||
self.screen.cursor.page_row,
|
self.screen.cursor.page_row,
|
||||||
cells[0..end],
|
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_multi: [*]Cell = @ptrCast(cells + x);
|
||||||
const cell: *Cell = @ptrCast(&cell_multi[0]);
|
const cell: *Cell = @ptrCast(&cell_multi[0]);
|
||||||
if (cell.protected) continue;
|
if (cell.protected) continue;
|
||||||
self.screen.eraseCells(
|
self.screen.clearCells(
|
||||||
&self.screen.cursor.page_offset.page.data,
|
&self.screen.cursor.page_offset.page.data,
|
||||||
self.screen.cursor.page_row,
|
self.screen.cursor.page_row,
|
||||||
cell_multi[0..1],
|
cell_multi[0..1],
|
||||||
@ -1582,7 +1582,7 @@ pub fn eraseLine(
|
|||||||
// If we're not respecting protected attributes, we can use a fast-path
|
// If we're not respecting protected attributes, we can use a fast-path
|
||||||
// to fill the entire line.
|
// to fill the entire line.
|
||||||
if (!protected) {
|
if (!protected) {
|
||||||
self.screen.eraseCells(
|
self.screen.clearCells(
|
||||||
&self.screen.cursor.page_offset.page.data,
|
&self.screen.cursor.page_offset.page.data,
|
||||||
self.screen.cursor.page_row,
|
self.screen.cursor.page_row,
|
||||||
cells[start..end],
|
cells[start..end],
|
||||||
@ -1594,7 +1594,7 @@ pub fn eraseLine(
|
|||||||
const cell_multi: [*]Cell = @ptrCast(cells + x);
|
const cell_multi: [*]Cell = @ptrCast(cells + x);
|
||||||
const cell: *Cell = @ptrCast(&cell_multi[0]);
|
const cell: *Cell = @ptrCast(&cell_multi[0]);
|
||||||
if (cell.protected) continue;
|
if (cell.protected) continue;
|
||||||
self.screen.eraseCells(
|
self.screen.clearCells(
|
||||||
&self.screen.cursor.page_offset.page.data,
|
&self.screen.cursor.page_offset.page.data,
|
||||||
self.screen.cursor.page_row,
|
self.screen.cursor.page_row,
|
||||||
cell_multi[0..1],
|
cell_multi[0..1],
|
||||||
@ -1667,7 +1667,7 @@ pub fn eraseDisplay(
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// All active area
|
// All active area
|
||||||
self.screen.eraseRows(
|
self.screen.clearRows(
|
||||||
.{ .active = .{} },
|
.{ .active = .{} },
|
||||||
null,
|
null,
|
||||||
protected,
|
protected,
|
||||||
@ -1687,7 +1687,7 @@ pub fn eraseDisplay(
|
|||||||
|
|
||||||
// All lines below
|
// All lines below
|
||||||
if (self.screen.cursor.y + 1 < self.rows) {
|
if (self.screen.cursor.y + 1 < self.rows) {
|
||||||
self.screen.eraseRows(
|
self.screen.clearRows(
|
||||||
.{ .active = .{ .y = self.screen.cursor.y + 1 } },
|
.{ .active = .{ .y = self.screen.cursor.y + 1 } },
|
||||||
null,
|
null,
|
||||||
protected,
|
protected,
|
||||||
@ -1704,7 +1704,7 @@ pub fn eraseDisplay(
|
|||||||
|
|
||||||
// All lines above
|
// All lines above
|
||||||
if (self.screen.cursor.y > 0) {
|
if (self.screen.cursor.y > 0) {
|
||||||
self.screen.eraseRows(
|
self.screen.clearRows(
|
||||||
.{ .active = .{ .y = 0 } },
|
.{ .active = .{ .y = 0 } },
|
||||||
.{ .active = .{ .y = self.screen.cursor.y - 1 } },
|
.{ .active = .{ .y = self.screen.cursor.y - 1 } },
|
||||||
protected,
|
protected,
|
||||||
|
Reference in New Issue
Block a user