From 21779522857bb45fa4baef5f6bdcbd329781cd1b Mon Sep 17 00:00:00 2001 From: sms Date: Fri, 4 Mar 2022 20:01:04 -0800 Subject: [PATCH 1/2] Last tab close -> close the app --- lib/views/terminal_frame.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/views/terminal_frame.dart b/lib/views/terminal_frame.dart index 044a7b5..6d63ec4 100644 --- a/lib/views/terminal_frame.dart +++ b/lib/views/terminal_frame.dart @@ -103,6 +103,13 @@ class _TerminalFrameState extends State { tabs.removeAt(mIndex); index = tabs.length - 1; }); + if (index == -1) { + if (Platform.isAndroid) { + SystemNavigator.pop(); + } else { + exit(0); + } + } }, ), ), From 08d12874aa8c048b28fc3bae61d511f3814dea9c Mon Sep 17 00:00:00 2001 From: sms Date: Fri, 4 Mar 2022 20:01:38 -0800 Subject: [PATCH 2/2] The shell or smth exists -> tab closes --- lib/views/terminal_frame.dart | 44 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/lib/views/terminal_frame.dart b/lib/views/terminal_frame.dart index 6d63ec4..2d0d1bb 100644 --- a/lib/views/terminal_frame.dart +++ b/lib/views/terminal_frame.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:fluent_ui/fluent_ui.dart'; import 'package:flutter/material.dart' as m; +import 'package:flutter/services.dart'; import 'package:pty/pty.dart'; import 'package:terminal/constants/constants.dart'; import 'package:terminal/views/terminal_settings.dart'; @@ -91,27 +92,46 @@ class _TerminalFrameState extends State { }, tabs: List.generate( tabs.length, - (mIndex) => Tab( - text: Row( - children: [ - Text("Terminal ${mIndex + 1}"), - ], - ), - icon: const Icon(m.Icons.computer), - onClosed: () { + (mIndex) { + var tab = Tab( + text: Row( + children: [ + Text("Terminal ${mIndex + 1}"), + ], + ), + icon: const Icon(m.Icons.computer), + onClosed: () { + setState(() { + tabs.removeAt(mIndex); + index = tabs.length - 1; + }); + if (index == -1) { + if (Platform.isAndroid) { + SystemNavigator.pop(); + } else { + exit(0); + } + } + }, + ); + tabs[mIndex].backend!.exitCode.then((code) { setState(() { tabs.removeAt(mIndex); - index = tabs.length - 1; - }); + focusNodes.removeAt(mIndex); + index = index - 1; if (index == -1) { if (Platform.isAndroid) { SystemNavigator.pop(); } else { exit(0); } + } else { + focusNodes[index].requestFocus(); } - }, - ), + }); + }); + return tab; + }, ), bodies: tabs .map((Terminal terminal) => TerminalView(