implement ECH

This commit is contained in:
Mitchell Hashimoto
2022-05-09 21:17:21 -07:00
parent eaffc8a0d1
commit adac8a3f60

View File

@ -131,7 +131,7 @@ pub fn appendChar(self: *Terminal, alloc: Allocator, c: u8) !void {
//log.debug("char: {}", .{c}); //log.debug("char: {}", .{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| try self.print(alloc, p), .print => |p| try self.print(alloc, p),
.execute => |code| try self.execute(alloc, code), .execute => |code| try self.execute(alloc, code),
@ -226,6 +226,16 @@ fn csiDispatch(
}, },
}), }),
// Erase Characters (ECH)
'X' => try self.eraseChars(switch (action.params.len) {
0 => 1,
1 => action.params[0],
else => {
log.warn("invalid erase characters command: {}", .{action});
return;
},
}),
// HPA - Cursor Horizontal Position Absolute // HPA - Cursor Horizontal Position Absolute
'`' => if (action.params.len == 0) { '`' => if (action.params.len == 0) {
try self.setCursorPosition(self.cursor.y + 1, 1); try self.setCursorPosition(self.cursor.y + 1, 1);
@ -460,6 +470,25 @@ 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];
// 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;
// Shift
var i: usize = self.cursor.x;
while (i < end) : (i += 1) {
line.items[i].char = 0;
// TODO: retain graphical attributes
}
}
/// Move the cursor right amount columns. If amount is greater than the /// Move the cursor right amount columns. If amount is greater than the
/// maximum move distance then it is internally adjusted to the maximum. /// maximum move distance then it is internally adjusted to the maximum.
/// This sequence will not scroll the screen or scroll region. If amount is /// This sequence will not scroll the screen or scroll region. If amount is