From f2166096622dcbe553692d041c76d7f1a92463f7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 10 Oct 2023 09:00:26 -0700 Subject: [PATCH] terminal: RIS should reset tabstops, ESC ? W should reset every 8 Fixes #648 Two issues here: - RIS should've been resetting the tabstops to every 8, but was clearing all tabstops. - `ESC ? W` should've reset tabstops to every 8, but was clearing all tabstops. --- src/terminal/Terminal.zig | 7 +++- src/terminal/modes.zig | 4 +- src/terminal/stream.zig | 6 +-- src/termio/Exec.zig | 4 ++ website/app/vt/ris/page.mdx | 82 ------------------------------------- 5 files changed, 16 insertions(+), 87 deletions(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 479dea21d..ed48b3752 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1487,6 +1487,11 @@ pub fn tabSet(self: *Terminal) void { self.tabstops.set(self.screen.cursor.x); } +/// TODO: test +pub fn tabReset(self: *Terminal) void { + self.tabstops.reset(TABSTOP_INTERVAL); +} + /// Carriage return moves the cursor to the first column. pub fn carriageReturn(self: *Terminal) void { const tracy = trace(@src()); @@ -1922,7 +1927,7 @@ pub fn fullReset(self: *Terminal, alloc: Allocator) void { self.screen.charset = .{}; self.modes = .{}; self.flags = .{}; - self.tabstops.reset(0); + self.tabstops.reset(TABSTOP_INTERVAL); self.screen.cursor = .{}; self.screen.saved_cursor = .{}; self.screen.selection = null; diff --git a/src/terminal/modes.zig b/src/terminal/modes.zig index 5adebb93b..bd4cbe714 100644 --- a/src/terminal/modes.zig +++ b/src/terminal/modes.zig @@ -169,9 +169,11 @@ const ModeEntry = struct { /// they're used within Ghostty or google their values. It is not /// valuable to redocument them all here. const entries: []const ModeEntry = &.{ + // ANSI .{ .name = "insert", .value = 4, .ansi = true }, - .{ .name = "cursor_keys", .value = 1 }, + // DEC + .{ .name = "cursor_keys", .value = 1 }, // DECCKM .{ .name = "132_column", .value = 3 }, .{ .name = "reverse_colors", .value = 5 }, .{ .name = "origin", .value = 6 }, diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 71c74191d..0abe37182 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -376,10 +376,10 @@ pub fn Stream(comptime Handler: type) type { 'W' => { switch (action.params.len) { 0 => if (action.intermediates.len == 1 and action.intermediates[0] == '?') { - if (@hasDecl(T, "tabClear")) - try self.handler.tabClear(.all) + if (@hasDecl(T, "tabReset")) + try self.handler.tabReset() else - log.warn("unimplemented tab clear callback: {}", .{action}); + log.warn("unimplemented tab reset callback: {}", .{action}); }, 1 => switch (action.params[0]) { diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 4c054b739..2fb617c09 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -1653,6 +1653,10 @@ const StreamHandler = struct { self.terminal.tabSet(); } + pub fn tabReset(self: *StreamHandler) !void { + self.terminal.tabReset(); + } + pub fn saveCursor(self: *StreamHandler) !void { self.terminal.saveCursor(); } diff --git a/website/app/vt/ris/page.mdx b/website/app/vt/ris/page.mdx index 3f251ea8b..3abdb88d0 100644 --- a/website/app/vt/ris/page.mdx +++ b/website/app/vt/ris/page.mdx @@ -28,85 +28,3 @@ The full reset operation does the following: - Move the cursor to the top-left corner - Reset the pending wrap state - Reset saved cursor state - -## Validation - -### DECSLRM V-1: Full Screen - -```bash -printf "\033[1;1H" # move to top-left -printf "\033[0J" # clear screen -printf "ABC\n" -printf "DEF\n" -printf "GHI\n" -printf "\033[?69h" # enable left/right margins -printf "\033[s" # scroll region left/right -printf "\033[X" -``` - -``` -|cBC_____| -|DEF_____| -|GHI_____| -``` - -### DECSLRM V-2: Left Only - -```bash -printf "\033[1;1H" # move to top-left -printf "\033[0J" # clear screen -printf "ABC\n" -printf "DEF\n" -printf "GHI\n" -printf "\033[?69h" # enable left/right margins -printf "\033[2s" # scroll region left/right -printf "\033[2G" # move cursor to column 2 -printf "\033[L" -``` - -``` -|Ac______| -|DBC_____| -|GEF_____| -| HI_____| -``` - -### DECSLRM V-3: Left And Right - -```bash -printf "\033[1;1H" # move to top-left -printf "\033[0J" # clear screen -printf "ABC\n" -printf "DEF\n" -printf "GHI\n" -printf "\033[?69h" # enable left/right margins -printf "\033[1;2s" # scroll region left/right -printf "\033[2G" # move cursor to column 2 -printf "\033[L" -``` - -``` -|_cC_____| -|ABF_____| -|DEI_____| -|GH______| -``` - -### DECSLRM V-4: Left Equal to Right - -```bash -printf "\033[1;1H" # move to top-left -printf "\033[0J" # clear screen -printf "ABC\n" -printf "DEF\n" -printf "GHI\n" -printf "\033[?69h" # enable left/right margins -printf "\033[2;2s" # scroll region left/right -printf "\033[X" -``` - -``` -|cBC_____| -|DEF_____| -|GHI_____| -```