more efficient eraseLines

This commit is contained in:
Mitchell Hashimoto
2022-05-21 18:58:53 -07:00
parent 9a48d0498d
commit acd45efe64
3 changed files with 6 additions and 15 deletions

View File

@ -648,7 +648,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(self.alloc, mode); try self.terminal.eraseLine(mode);
} }
pub fn deleteChars(self: *Window, count: usize) !void { pub fn deleteChars(self: *Window, count: usize) !void {

View File

@ -259,26 +259,17 @@ 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 => {
var x: usize = self.cursor.x; const row = self.screen.getRow(self.cursor.y);
while (x < self.cols) : (x += 1) { std.mem.set(Screen.Cell, row[self.cursor.x..], self.cursor.pen);
const cell = try self.getOrPutCell(alloc, x, self.cursor.y);
cell.* = self.cursor.pen;
cell.char = 0;
}
}, },
.left => { .left => {
var x: usize = self.cursor.x; const row = self.screen.getRow(self.cursor.y);
while (x >= 0) : (x -= 1) { std.mem.set(Screen.Cell, row[0..self.cursor.x], self.cursor.pen);
const cell = try self.getOrPutCell(alloc, x, self.cursor.y);
cell.* = self.cursor.pen;
cell.char = 0;
}
}, },
else => { else => {

View File

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