terminal: horizontal tab

pull/9342/head
Mitchell Hashimoto 2025-10-23 16:27:02 -07:00
parent ccd821a0ff
commit b5da54d925
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
2 changed files with 21 additions and 28 deletions

View File

@ -33,7 +33,8 @@ pub const Action = union(Key) {
print: Print,
bell,
backspace,
horizontal_tab: HorizontalTab,
horizontal_tab: u16,
horizontal_tab_back: u16,
linefeed,
carriage_return,
enquiry,
@ -55,6 +56,7 @@ pub const Action = union(Key) {
"bell",
"backspace",
"horizontal_tab",
"horizontal_tab_back",
"linefeed",
"carriage_return",
"enquiry",
@ -98,10 +100,6 @@ pub const Action = union(Key) {
}
};
pub const HorizontalTab = lib.Struct(lib_target, struct {
count: u16,
});
pub const InvokeCharset = lib.Struct(lib_target, struct {
bank: charsets.ActiveSlot,
charset: charsets.Slots,
@ -446,7 +444,7 @@ pub fn Stream(comptime Handler: type) type {
.ENQ => try self.handler.vt(.enquiry, {}),
.BEL => try self.handler.vt(.bell, {}),
.BS => try self.handler.vt(.backspace, {}),
.HT => try self.handler.vt(.horizontal_tab, .{ .count = 1 }),
.HT => try self.handler.vt(.horizontal_tab, 1),
.LF, .VT, .FF => try self.handler.vt(.linefeed, {}),
.CR => try self.handler.vt(.carriage_return, {}),
.SO => try self.handler.vt(.invoke_charset, .{ .bank = .GL, .charset = .G1, .locking = false }),
@ -622,16 +620,14 @@ pub fn Stream(comptime Handler: type) type {
// CHT - Cursor Horizontal Tabulation
'I' => switch (input.intermediates.len) {
0 => if (@hasDecl(T, "horizontalTab")) try self.handler.horizontalTab(
switch (input.params.len) {
0 => try self.handler.vt(.horizontal_tab, switch (input.params.len) {
0 => 1,
1 => input.params[0],
else => {
log.warn("invalid horizontal tab command: {f}", .{input});
return;
},
},
) else log.warn("unimplemented CSI callback: {f}", .{input}),
}),
else => log.warn(
"ignoring unimplemented CSI I with intermediates: {s}",
@ -855,16 +851,14 @@ pub fn Stream(comptime Handler: type) type {
// CHT - Cursor Horizontal Tabulation Back
'Z' => switch (input.intermediates.len) {
0 => if (@hasDecl(T, "horizontalTabBack")) try self.handler.horizontalTabBack(
switch (input.params.len) {
0 => try self.handler.vt(.horizontal_tab_back, switch (input.params.len) {
0 => 1,
1 => input.params[0],
else => {
log.warn("invalid horizontal tab back command: {f}", .{input});
return;
},
},
) else log.warn("unimplemented CSI callback: {f}", .{input}),
}),
else => log.warn(
"ignoring unimplemented CSI Z with intermediates: {s}",

View File

@ -197,7 +197,8 @@ pub const StreamHandler = struct {
.print => try self.terminal.print(value.cp),
.bell => self.bell(),
.backspace => self.terminal.backspace(),
.horizontal_tab => try self.horizontalTab(value.count),
.horizontal_tab => try self.horizontalTab(value),
.horizontal_tab_back => try self.horizontalTabBack(value),
.linefeed => try self.linefeed(),
.carriage_return => self.terminal.carriageReturn(),
.enquiry => try self.enquiry(),
@ -372,7 +373,7 @@ pub const StreamHandler = struct {
}
}
pub inline fn horizontalTabBack(self: *StreamHandler, count: u16) !void {
inline fn horizontalTabBack(self: *StreamHandler, count: u16) !void {
for (0..count) |_| {
const x = self.terminal.screen.cursor.x;
try self.terminal.horizontalTabBack();
@ -386,8 +387,6 @@ pub const StreamHandler = struct {
try self.terminal.index();
}
pub inline fn eraseDisplay(self: *StreamHandler, mode: terminal.EraseDisplay, protected: bool) !void {
if (mode == .complete) {
// Whenever we erase the full display, scroll to bottom.