From 104001d25c9c8cb5ec45ced1678f7c7b70888808 Mon Sep 17 00:00:00 2001 From: t Date: Mon, 8 Jun 2026 14:48:33 -0600 Subject: keybinding fixes --- src/tui_terminal.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/tui_terminal.zig') diff --git a/src/tui_terminal.zig b/src/tui_terminal.zig index 0f8b3d9..0b00bb4 100644 --- a/src/tui_terminal.zig +++ b/src/tui_terminal.zig @@ -252,6 +252,31 @@ pub const Terminal = struct { if (active_restore == &self.restore) active_restore = null; } + /// Temporarily return the tty to its ORIGINAL (cooked) termios so a child + /// process (e.g. `$EDITOR`) can drive the terminal normally, and show the + /// cursor. Pairs with `resumeRawMode`. Unlike `deinit`, this does NOT clear + /// the global restore record or mark the restore done — the signal/panic + /// restore path stays armed with the original termios (restoring to cooked + /// is exactly what we'd want on a crash mid-editor), and we re-enter raw + /// mode afterward. + /// + /// No-op if not currently in raw mode. + pub fn suspendRawMode(self: *Terminal) void { + if (!self.raw_mode) return; + posix.tcsetattr(self.fd, .FLUSH, self.restore.original) catch {}; + self.raw_mode = false; + self.writeAll(seq.show_cursor); + } + + /// Re-enter raw mode after `suspendRawMode` and hide the cursor again. The + /// global restore record and signal handlers are already installed (they + /// were never torn down), so this just reapplies the raw termios. + pub fn resumeRawMode(self: *Terminal) Error!void { + if (self.raw_mode) return; + try self.enableRawMode(); + self.writeAll(seq.hide_cursor); + } + // -- output helpers ----------------------------------------------------- /// Raw write of `bytes` to the tty. Returns the count written (short -- cgit v1.3