terminal: CHT/CBT

This commit is contained in:
Mitchell Hashimoto
2023-06-25 09:53:58 -07:00
parent cbded6a95a
commit 03fd649b5e
2 changed files with 39 additions and 3 deletions

View File

@ -92,7 +92,7 @@ pub fn Stream(comptime Handler: type) type {
log.warn("unimplemented execute: {x}", .{c}), log.warn("unimplemented execute: {x}", .{c}),
.HT => if (@hasDecl(T, "horizontalTab")) .HT => if (@hasDecl(T, "horizontalTab"))
try self.handler.horizontalTab() try self.handler.horizontalTab(1)
else else
log.warn("unimplemented execute: {x}", .{c}), log.warn("unimplemented execute: {x}", .{c}),
@ -205,6 +205,18 @@ pub fn Stream(comptime Handler: type) type {
else => log.warn("invalid CUP command: {}", .{action}), else => log.warn("invalid CUP command: {}", .{action}),
} else log.warn("unimplemented CSI callback: {}", .{action}), } else log.warn("unimplemented CSI callback: {}", .{action}),
// CHT - Cursor Horizontal Tabulation
'I' => if (@hasDecl(T, "horizontalTab")) try self.handler.horizontalTab(
switch (action.params.len) {
0 => 1,
1 => action.params[0],
else => {
log.warn("invalid horizontal tab command: {}", .{action});
return;
},
},
) else log.warn("unimplemented CSI callback: {}", .{action}),
// Erase Display // Erase Display
// TODO: test // TODO: test
'J' => if (@hasDecl(T, "eraseDisplay")) try self.handler.eraseDisplay( 'J' => if (@hasDecl(T, "eraseDisplay")) try self.handler.eraseDisplay(
@ -316,6 +328,18 @@ pub fn Stream(comptime Handler: type) type {
}, },
) else log.warn("unimplemented CSI callback: {}", .{action}), ) else log.warn("unimplemented CSI callback: {}", .{action}),
// CHT - Cursor Horizontal Tabulation Back
'Z' => if (@hasDecl(T, "horizontalTabBack")) try self.handler.horizontalTabBack(
switch (action.params.len) {
0 => 1,
1 => action.params[0],
else => {
log.warn("invalid horizontal tab back command: {}", .{action});
return;
},
},
) else log.warn("unimplemented CSI callback: {}", .{action}),
// Repeat Previous Char (REP) // Repeat Previous Char (REP)
'b' => if (@hasDecl(T, "printRepeat")) try self.handler.printRepeat( 'b' => if (@hasDecl(T, "printRepeat")) try self.handler.printRepeat(
switch (action.params.len) { switch (action.params.len) {

View File

@ -959,8 +959,20 @@ const StreamHandler = struct {
self.terminal.backspace(); self.terminal.backspace();
} }
pub fn horizontalTab(self: *StreamHandler) !void { pub fn horizontalTab(self: *StreamHandler, count: u16) !void {
for (0..count) |_| {
const x = self.terminal.screen.cursor.x;
try self.terminal.horizontalTab(); try self.terminal.horizontalTab();
if (x == self.terminal.screen.cursor.x) break;
}
}
pub fn horizontalTabBack(self: *StreamHandler, count: u16) !void {
for (0..count) |_| {
const x = self.terminal.screen.cursor.x;
try self.terminal.horizontalTabBack();
if (x == self.terminal.screen.cursor.x) break;
}
} }
pub fn linefeed(self: *StreamHandler) !void { pub fn linefeed(self: *StreamHandler) !void {