feat: implement mode 1048 for saving/restoring cursor position (#7553)

Implements mode 1048 for saving/restoring cursor position.

This is the same as mode 1049 but only saves cursor position without
touching the alternate screen.

**save/restore cursor position:**
- `ESC[?1048h` - save cursor position  
- `ESC[?1048l` - restore cursor position

**Quick test:**
```bash
printf '\e[5;10H[SAVED HERE]'
printf '\e[?1048h'                # save position
printf '\e[15;1HMoved somewhere else...'
printf '\e[?1048l'                # restore 
printf ' RESTORED!'           # should appear next to [SAVED HERE]
```

Fixes #7473
pull/7559/head
Mitchell Hashimoto 2025-06-09 07:14:59 -07:00 committed by GitHub
commit 57cd5ef085
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -223,6 +223,7 @@ const entries: []const ModeEntry = &.{
.{ .name = "alt_sends_escape", .value = 1039 }, .{ .name = "alt_sends_escape", .value = 1039 },
.{ .name = "reverse_wrap_extended", .value = 1045 }, .{ .name = "reverse_wrap_extended", .value = 1045 },
.{ .name = "alt_screen", .value = 1047 }, .{ .name = "alt_screen", .value = 1047 },
.{ .name = "save_cursor", .value = 1048 },
.{ .name = "alt_screen_save_cursor_clear_enter", .value = 1049 }, .{ .name = "alt_screen_save_cursor_clear_enter", .value = 1049 },
.{ .name = "bracketed_paste", .value = 2004 }, .{ .name = "bracketed_paste", .value = 2004 },
.{ .name = "synchronized_output", .value = 2026 }, .{ .name = "synchronized_output", .value = 2026 },

View File

@ -597,6 +597,18 @@ pub const StreamHandler = struct {
try self.queueRender(); try self.queueRender();
}, },
// Mode 1048 is xterm's conditional save cursor depending
// on if alt screen is enabled or not (at the terminal emulator
// level). Alt screen is always enabled for us so this just
// does a save/restore cursor.
.save_cursor => {
if (enabled) {
self.terminal.saveCursor();
} else {
try self.terminal.restoreCursor();
}
},
// Force resize back to the window size // Force resize back to the window size
.enable_mode_3 => { .enable_mode_3 => {
const grid_size = self.size.grid(); const grid_size = self.size.grid();