From 998a36a1c525f8913beecce6e956b928ebce3a98 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 May 2022 21:32:57 -0700 Subject: [PATCH] eraseChars respects pen --- src/Window.zig | 2 +- src/terminal/Terminal.zig | 18 +++++++----------- src/terminal/stream.zig | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Window.zig b/src/Window.zig index 9eb81f42a..ed82d39bc 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -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 { diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 1ba745487..0ddad0456 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -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; } } diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 98acb7d10..044b95cfb 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -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),