Skip to content

Commit

Permalink
Merge pull request #649 from mitchellh/ris-tabs
Browse files Browse the repository at this point in the history
terminal: RIS should reset tabstops, ESC ? W should reset every 8
  • Loading branch information
mitchellh authored Oct 10, 2023
2 parents 04756e1 + f216609 commit 21ec39e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/terminal/Terminal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/terminal/modes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
6 changes: 3 additions & 3 deletions src/terminal/stream.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
4 changes: 4 additions & 0 deletions src/termio/Exec.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
30 changes: 30 additions & 0 deletions website/app/vt/ris/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import VTSequence from "@/components/VTSequence";

# Full Reset (RIS)

<VTSequence sequence={["ESC", "c"]} />

Reset the terminal.

The full reset operation does the following:

- Set the cursor shape to the default
- Reset the scroll region to the full screen
- Disable [left and right margin mode (mode 69)](#TODO)
- Disable [origin mode (mode 6)](#TODO)
- Unset cursor foreground and background colors
- Reset charsets to the default
- Reset [cursor key mode (DECCKM)](#TODO)
- Reset [disable keyboard input (KAM)](#TODO)
- Reset [application keypad mode](/vt/deckpnm)
- Reset xterm keyboard modifier state to the default
- Disable cursor [protected attribute](#TODO)
- Disable any [protected area](#TODO)
- Reset all [mouse tracking modes](#TODO)
- Reset tabstops to default
- Enable [send-receive mode (mode 12)](#TODO)
- Reset [backspace sends delete (mode 67)](#TODO)
- Return to the primary screen and clear it
- Move the cursor to the top-left corner
- Reset the pending wrap state
- Reset saved cursor state

0 comments on commit 21ec39e

Please sign in to comment.