feat: several terminal tabs per project, with a dropdown

A directory now has a TerminalWorkspace holding a list of tabs instead of a
single session. The status bar's left side became a dropdown: it shows the
active tab and its state ("终端 2 · 运行中") and lists the other tabs (the
active one checked) plus "新建终端". New tabs take the smallest free number,
so closing one frees its name.

Only the active tab keeps a socket: switching detaches the old tab and
attaches the new one, whose screen is replayed from the server snapshot; the
shell itself keeps running. The tab's model stays in memory, so switching
back is immediate.

The tab list (ids, labels, active one) is saved per connection and directory.
On the first open the server's sessions for the directory are reconciled with
it: saved labels and order are kept for sessions that still exist, sessions
opened elsewhere (web UI) are appended in creation order, and tabs whose
session is gone are dropped. Project-action command runners are not shown as
tabs. The 0.4.2 single-session value is read as one tab.

0.4.3 (403).
This commit is contained in:
blumia committed 2026-11-22 15:23:21 +08:00
1 parent 675d19d563
commit a7bc380ac0
9 files changed
+717 -298

No files matched your search

+11 -11
View File
@@ -120,12 +120,12 @@ class AppState extends ChangeNotifier {
String? _sessionsNext;
bool loadingMoreSessions = false;
/// Terminals by workspace directory: switching sessions or tabs keeps the
/// shell alive, and each directory gets its own.
final Map<String, TerminalSessionState> terminals = {};
/// Terminal workspaces by directory: each holds that directory's tabs and
/// keeps their shells alive while sessions/tabs are switched.
final Map<String, TerminalWorkspace> terminals = {};
TerminalSessionState terminalFor(String directory) => terminals.putIfAbsent(
directory, () => TerminalSessionState(this, directory));
TerminalWorkspace terminalFor(String directory) => terminals.putIfAbsent(
directory, () => TerminalWorkspace(this, directory));
/// Public way to signal UI changes (notifyListeners is protected).
void touch() => notifyListeners();
@@ -297,11 +297,11 @@ class AppState extends ChangeNotifier {
}
Future<void> disconnect() async {
for (final terminal in terminals.values) {
// Closing the shell on the server is right when the connection itself
for (final workspace in terminals.values) {
// Closing the shells on the server is right when the connection itself
// goes away; a panel close only detaches.
await terminal.closeSession();
terminal.dispose();
await workspace.closeAll();
workspace.dispose();
}
terminals.clear();
client?.close();
@@ -759,8 +759,8 @@ class AppState extends ChangeNotifier {
await chat!.reloadTail();
await chat!.reloadInbox();
}
for (final terminal in terminals.values) {
await terminal.reconnectIfNeeded();
for (final workspace in terminals.values) {
await workspace.reconnectIfNeeded();
}
}