From acd45efe6425e4ff52e427e089c3c6f4b8a038a3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 21 May 2022 18:58:53 -0700 Subject: [PATCH] more efficient eraseLines --- src/Window.zig | 2 +- src/terminal/Terminal.zig | 17 ++++------------- src/terminal/stream.zig | 2 +- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Window.zig b/src/Window.zig index 3eb2f9889..8d85a358c 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -648,7 +648,7 @@ pub fn eraseDisplay(self: *Window, mode: terminal.EraseDisplay) !void { } pub fn eraseLine(self: *Window, mode: terminal.EraseLine) !void { - try self.terminal.eraseLine(self.alloc, mode); + try self.terminal.eraseLine(mode); } pub fn deleteChars(self: *Window, count: usize) !void { diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 00dda19d7..2c0440ff0 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -259,26 +259,17 @@ pub fn eraseDisplay( /// TODO: test pub fn eraseLine( self: *Terminal, - alloc: Allocator, mode: csi.EraseLine, ) !void { switch (mode) { .right => { - var x: usize = self.cursor.x; - while (x < self.cols) : (x += 1) { - const cell = try self.getOrPutCell(alloc, x, self.cursor.y); - cell.* = self.cursor.pen; - cell.char = 0; - } + const row = self.screen.getRow(self.cursor.y); + std.mem.set(Screen.Cell, row[self.cursor.x..], self.cursor.pen); }, .left => { - var x: usize = self.cursor.x; - while (x >= 0) : (x -= 1) { - const cell = try self.getOrPutCell(alloc, x, self.cursor.y); - cell.* = self.cursor.pen; - cell.char = 0; - } + const row = self.screen.getRow(self.cursor.y); + std.mem.set(Screen.Cell, row[0..self.cursor.x], self.cursor.pen); }, else => { diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 7dcc7e92d..3e6dafcfe 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: {x}", .{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),