Files
pipelines/app/lib/application/detached/detached_terminal.dart
T
alan 61c7eee2b0 App: open a chat, the terminal or a diff in a new window
"Open in new window" sits beside Float: the chat pane and chat list row
menus, a floating chat window's title bar, the terminal options menu and
the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in
the shortcut help). Once the window opens the item leaves the main window
as Float takes a pane out of the tiling.

The window is its own app instance at /window/chat/<id>,
/window/terminal?tab=<key> or /window/diff/<token>: only that item, named
after it, with "Bring back to main window". It has its own connection and
writes no shared layout (no open-chat workspace, window store or terminal
layout) and posts no notifications, so they stay the main window's.

Web opens a popup window (a blocked popup offers a tab); Linux and macOS
start a second process with --detached (Flutter's multi-window API is still
experimental); Android and iOS hide the action. The capture kit gains a
follow step for windows a page opens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 12:47:42 +00:00

93 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import '../../features/terminal/terminal_body.dart';
import '../../features/terminal/terminal_hub.dart';
import '../../features/terminal/terminal_layout.dart';
import '../../features/terminal/terminal_tab_strip.dart';
import '../app_terminals.dart';
import 'detached_route.dart';
import 'detached_window_body.dart';
/// The terminal alone in a detached window: its tabs (the machines'
/// terminals, which every client of the server shares) on the tab it was
/// sent from. The device's terminal layout is read, never written (see
/// [TerminalLayout.persist]); there is no panel or window mode to choose.
class DetachedTerminal extends StatefulWidget {
const DetachedTerminal({
super.key,
required this.terminals,
required this.tabKey,
required this.window,
});
/// This window's terminals, over its own connection.
final AppTerminals terminals;
/// The tab to select once the machines' terminals are listed.
final String tabKey;
final DetachedWindowControls window;
@override
State<DetachedTerminal> createState() => _DetachedTerminalState();
}
class _DetachedTerminalState extends State<DetachedTerminal> {
TerminalHub get _hub => widget.terminals.hub;
bool _placed = false;
@override
void initState() {
super.initState();
_hub
..addListener(_changed)
..activate();
_changed();
}
@override
void dispose() {
_hub.removeListener(_changed);
super.dispose();
}
/// Selects the tab the window was opened on as soon as it is listed, once,
/// and names the window after the selected tab.
void _changed() {
if (!_placed && widget.tabKey.isNotEmpty) {
final tab = _hub.tabs.where((tab) => tab.key == widget.tabKey);
if (tab.isNotEmpty) {
_placed = true;
_hub.select(tab.first);
}
}
final title = _hub.selected?.title;
widget.window.setTitle(
title == null || title.isEmpty ? 'Terminal' : 'Terminal: $title',
);
}
void _bringBack() =>
widget.window.bringBack(DetachedKind.terminal, _hub.selected?.key ?? '');
@override
Widget build(BuildContext context) => Material(
child: SafeArea(
child: ListenableBuilder(
listenable: Listenable.merge([_hub, widget.terminals.layout]),
builder: (context, _) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TerminalTabStrip(
hub: _hub,
layout: widget.terminals.layout,
showModes: false,
trailing: [DetachedBringBackButton(onPressed: _bringBack)],
),
Expanded(child: TerminalBody(hub: _hub)),
],
),
),
),
);
}