Files
pipelines/app/lib/features/terminal/terminal_open_action.dart
T
alan 30934aa71c Toggle the terminal with Alt/Ctrl/Cmd+T, animate it, focus it, and cycle its tabs with Ctrl+Tab
Alt+T, Ctrl+T and Cmd+T join Ctrl+` as early focus-manager key handlers, so
they toggle the panel, window or narrow page from anywhere without reaching
the shell or a text field. Opening with no terminal starts one. The shown
terminal takes the keyboard (also on reload and tab changes) and hiding gives
it back. The panel slides from the bottom edge as the app shrinks, the window
scales and fades, both on Motion.standard and off under reduced motion.
While shown, Ctrl+Tab/Ctrl+Shift+Tab move between terminal tabs instead of
chat panes. The tooltip and menu list the shortcuts the platform delivers.
2026-11-09 23:43:56 +00:00

61 lines
1.8 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import '../../core/api_gateway.dart';
import '../../ui/adaptive/segmented_bar_overflow.dart';
import 'terminal_hub.dart';
import 'terminal_scope.dart';
/// Opening the terminal with none to show starts one, as New terminal
/// does, once every machine's list has arrived.
Future<void> openTerminalIfNone(TerminalHub hub) async {
hub.activate();
await hub.listed();
if (hub.tabs.isNotEmpty || hub.connected.isEmpty) return;
await hub.open();
}
const String terminalOpenActionLabel = 'Open in terminal';
/// Opens a terminal in [directory] on [gateway]'s machine through the app's
/// terminal surface; a refusal goes to [onRefused]. Does nothing outside a
/// [TerminalScope].
void openInTerminal(
BuildContext context,
ApiGateway gateway,
String directory, {
void Function(String refusal)? onRefused,
}) {
final actions = TerminalScope.maybeOf(context);
if (actions == null) return;
unawaited(
actions.openAt(gateway, directory).then((refusal) {
if (refusal != null) onRefused?.call(refusal);
}),
);
}
/// The chat actions menu's "Open in terminal" for the chat's folder, or
/// null when the app has no terminal surface or the chat no folder.
Widget? terminalOpenMenuAction(
BuildContext context, {
required ApiGateway gateway,
required String directory,
void Function(String refusal)? onRefused,
}) {
if (TerminalScope.maybeOf(context) == null || directory.isEmpty) {
return null;
}
return SegmentedOverflowAction(
key: const ValueKey<String>('chat-open-terminal-action'),
overflowEntry: SegmentedOverflowEntry(
label: terminalOpenActionLabel,
icon: Icons.terminal,
onPressed: () =>
openInTerminal(context, gateway, directory, onRefused: onRefused),
),
child: const SizedBox.shrink(),
);
}