eraseline sets SGR on all cells

This commit is contained in:
Mitchell Hashimoto
2022-05-12 16:51:26 -07:00
parent 3a68d79d83
commit 2be8721e54
2 changed files with 12 additions and 16 deletions

View File

@ -550,7 +550,7 @@ pub fn eraseDisplay(self: *Window, mode: terminal.EraseDisplay) !void {
} }
pub fn eraseLine(self: *Window, mode: terminal.EraseLine) !void { pub fn eraseLine(self: *Window, mode: terminal.EraseLine) !void {
try self.terminal.eraseLine(mode); try self.terminal.eraseLine(self.alloc, mode);
} }
pub fn deleteChars(self: *Window, count: usize) !void { pub fn deleteChars(self: *Window, count: usize) !void {

View File

@ -243,30 +243,26 @@ pub fn eraseDisplay(
/// TODO: test /// TODO: test
pub fn eraseLine( pub fn eraseLine(
self: *Terminal, self: *Terminal,
alloc: Allocator,
mode: csi.EraseLine, mode: csi.EraseLine,
) !void { ) !void {
switch (mode) { switch (mode) {
.right => { .right => {
// If our cursor is outside our screen, we can't erase anything. var x: usize = self.cursor.x;
if (self.cursor.y >= self.screen.items.len) return; while (x < self.cols) : (x += 1) {
var line = &self.screen.items[self.cursor.y]; const cell = try self.getOrPutCell(alloc, x, self.cursor.y);
cell.* = self.cursor.pen;
// If our cursor is outside our screen, we can't erase anything.
if (self.cursor.x >= line.items.len) return;
for (line.items[self.cursor.x..line.items.len]) |*cell|
cell.char = 0; cell.char = 0;
}
}, },
.left => { .left => {
// If our cursor is outside our screen, we can't erase anything. var x: usize = self.cursor.x;
if (self.cursor.y >= self.screen.items.len) return; while (x >= 0) : (x -= 1) {
var line = &self.screen.items[self.cursor.y]; const cell = try self.getOrPutCell(alloc, x, self.cursor.y);
cell.* = self.cursor.pen;
// Clear up to our cursor
const end = @minimum(line.items.len, self.cursor.x);
for (line.items[0..end]) |*cell|
cell.char = 0; cell.char = 0;
}
}, },
else => { else => {