Skip to content

Commit 908eb6d

Browse files
authored
On wait-after-command (or abnormal exit), only close on encoded key (ghostty-org#7800)
Fixes ghostty-org#7794 This commit also resets some terminal state to give us a better chance of getting an encoded key, such as ensuring keyboard input is enabled and disabling any Kitty protocols. This shouldn't ever be set but just in case!
2 parents d474337 + eea073c commit 908eb6d

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/Surface.zig

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,12 @@ fn childExited(self: *Surface, info: apprt.surface.Message.ChildExited) void {
10341034
t.printString("Process exited. Press any key to close the terminal.") catch
10351035
break :terminal;
10361036
t.modes.set(.cursor_visible, false);
1037+
1038+
// We also want to ensure that normal keyboard encoding is on
1039+
// so that we can close the terminal. We close the terminal on
1040+
// any key press that encodes a character.
1041+
t.modes.set(.disable_keyboard, false);
1042+
t.screen.kitty_keyboard.set(.set, .{});
10371043
}
10381044

10391045
// Waiting after command we stop here. The terminal is updated, our
@@ -2129,14 +2135,6 @@ pub fn keyCallback(
21292135
if (self.io.terminal.modes.get(.disable_keyboard)) return .consumed;
21302136
}
21312137

2132-
// If our process is exited and we press a key then we close the
2133-
// surface. We may want to eventually move this to the apprt rather
2134-
// than in core.
2135-
if (self.child_exited and event.action == .press) {
2136-
self.close();
2137-
return .closed;
2138-
}
2139-
21402138
// If this input event has text, then we hide the mouse if configured.
21412139
// We only do this on pressed events to avoid hiding the mouse when we
21422140
// change focus due to a keybinding (i.e. switching tabs).
@@ -2231,6 +2229,14 @@ pub fn keyCallback(
22312229
event,
22322230
if (insp_ev) |*ev| ev else null,
22332231
)) |write_req| {
2232+
// If our process is exited and we press a key that results in
2233+
// an encoded value, we close the surface. We want to eventually
2234+
// move this behavior to the apprt probably.
2235+
if (self.child_exited) {
2236+
self.close();
2237+
return .closed;
2238+
}
2239+
22342240
errdefer write_req.deinit();
22352241
self.io.queueMessage(switch (write_req) {
22362242
.small => |v| .{ .write_small = v },

0 commit comments

Comments
 (0)