eraseChars respects pen

This commit is contained in:
Mitchell Hashimoto
2022-05-12 21:32:57 -07:00
parent fc3fac971a
commit 998a36a1c5
3 changed files with 9 additions and 13 deletions

View File

@ -558,7 +558,7 @@ pub fn deleteChars(self: *Window, count: usize) !void {
}
pub fn eraseChars(self: *Window, count: usize) !void {
try self.terminal.eraseChars(count);
try self.terminal.eraseChars(self.alloc, count);
}
pub fn deleteLines(self: *Window, count: usize) !void {

View File

@ -312,21 +312,17 @@ pub fn deleteChars(self: *Terminal, count: usize) !void {
}
// TODO: test, docs
pub fn eraseChars(self: *Terminal, count: usize) !void {
var line = &self.screen.items[self.cursor.y];
pub fn eraseChars(self: *Terminal, alloc: Allocator, count: usize) !void {
// Our last index is at most the end of the number of chars we have
// in the current line.
const end = @minimum(line.items.len, self.cursor.x + count);
// Do nothing if we have no values.
if (self.cursor.x >= line.items.len) return;
const end = @minimum(self.cols, self.cursor.x + count);
// Shift
var i: usize = self.cursor.x;
while (i < end) : (i += 1) {
line.items[i].char = 0;
// TODO: retain graphical attributes
var x: usize = self.cursor.x;
while (x < end) : (x += 1) {
const cell = try self.getOrPutCell(alloc, x, self.cursor.y);
cell.* = self.cursor.pen;
cell.char = 0;
}
}

View File

@ -48,7 +48,7 @@ pub fn Stream(comptime Handler: type) type {
//log.debug("char: {}", .{c});
const actions = self.parser.next(c);
for (actions) |action_opt| {
if (action_opt) |action| log.info("action: {}", .{action});
// if (action_opt) |action| log.info("action: {}", .{action});
switch (action_opt orelse continue) {
.print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),
.execute => |code| try self.execute(code),