implement erase line (EL) CSI

This commit is contained in:
Mitchell Hashimoto
2022-05-08 20:20:21 -07:00
parent 4314ea86b3
commit fd0fa1d08b
3 changed files with 49 additions and 4 deletions

View File

@ -104,7 +104,7 @@ pub fn next(self: *Parser, c: u8) [3]?Action {
break :effect table[c][@enumToInt(self.state)];
};
log.info("next: {x}", .{c});
// log.info("next: {x}", .{c});
const next_state = effect.state;
const action = effect.action;

View File

@ -160,7 +160,7 @@ fn csiDispatch(
}
break :mode @intToEnum(
csi.EraseDisplayMode,
csi.EraseDisplay,
action.params[0],
);
},
@ -170,6 +170,27 @@ fn csiDispatch(
},
}),
// Erase Line
'K' => try self.eraseLine(switch (action.params.len) {
0 => .right,
1 => mode: {
// TODO: use meta to get enum max
if (action.params[0] > 3) {
log.warn("invalid erase line command: {}", .{action});
return;
}
break :mode @intToEnum(
csi.EraseLine,
action.params[0],
);
},
else => {
log.warn("invalid erase line command: {}", .{action});
return;
},
}),
else => log.warn("unimplemented CSI: {}", .{action}),
}
}
@ -229,7 +250,7 @@ pub fn setCursorPosition(self: *Terminal, row: usize, col: usize) !void {
pub fn eraseDisplay(
self: *Terminal,
alloc: Allocator,
mode: csi.EraseDisplayMode,
mode: csi.EraseDisplay,
) !void {
switch (mode) {
.complete => {
@ -240,6 +261,22 @@ pub fn eraseDisplay(
}
}
/// Erase the line.
/// TODO: test
pub fn eraseLine(
self: *Terminal,
mode: csi.EraseLine,
) !void {
switch (mode) {
.right => {
var line = &self.screen.items[self.cursor.y];
for (line.items[self.cursor.x..line.items.len]) |*cell|
cell.char = 0;
},
else => @panic("unimplemented"),
}
}
/// Backspace moves the cursor back a column (but not less than 0).
pub fn backspace(self: *Terminal) void {
const tracy = trace(@src());

View File

@ -1,7 +1,15 @@
// Modes for the ED CSI command.
pub const EraseDisplayMode = enum(u8) {
pub const EraseDisplay = enum(u8) {
below = 0,
above = 1,
complete = 2,
scrollback = 3,
};
// Modes for the EL CSI command.
pub const EraseLine = enum(u8) {
right = 0,
left = 1,
complete = 3,
right_unless_pending_wrap = 4,
};