fix: auto-close terminal tab/window when shell exits (#15448)

This commit is contained in:
alonginwind
2026-07-02 16:43:27 +08:00
committed by GitHub
parent dce221be5a
commit a2b79462ab
4 changed files with 48 additions and 3 deletions

View File

@@ -38,6 +38,10 @@ class TerminalModel with ChangeNotifier {
void Function(int w, int h, int pw, int ph)? onResizeExternal;
/// Called when the terminal session ends (shell exits).
/// The listener (typically TerminalPage) can use this to auto-close the tab/page.
VoidCallback? onClosed;
Future<void> _handleInput(String data) async {
// Soft keyboards (notably iOS) emit '\n' when Enter is pressed, while a
// real keyboard's Enter sends '\r'. Some Android keyboards also emit '\n'.
@@ -473,6 +477,8 @@ class TerminalModel with ChangeNotifier {
_writeToTerminal('\r\nTerminal closed with exit code: $exitCode\r\n');
_terminalOpened = false;
notifyListeners();
// Auto-close the tab/page
onClosed?.call();
}
void _handleTerminalError(Map<String, dynamic> evt) {