Files
pipelines/app/lib/features/terminal/terminal_scope.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

43 lines
1.6 KiB
Dart

import 'package:flutter/widgets.dart';
import '../../core/api_gateway.dart';
import '../../core/servers/server_scope.dart';
/// What screens below the app's terminal surface may ask of it.
abstract interface class TerminalActions {
/// Shows the terminal (panel, window or page) or hides it.
void toggle();
/// Whether the terminal is shown, so Ctrl+Tab and Ctrl+Shift+Tab move
/// between its tabs instead of between chat panes.
bool get claimsTabKeys;
/// Opens a new terminal in [cwd] on the machine [gateway] belongs to and
/// shows it. Returns the refusal, or null.
Future<String?> openAt(ApiGateway gateway, String cwd);
}
/// Gives screens (a chat's header, the Files panel) the app's terminal
/// surface. Absent in standalone screens and tests, which then offer no
/// terminal actions.
class TerminalScope extends InheritedWidget {
const TerminalScope({super.key, required this.actions, required super.child});
final TerminalActions actions;
static TerminalActions? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<TerminalScope>()?.actions;
/// The actions without depending on them, for a key handler.
static TerminalActions? peek(BuildContext context) =>
context.getInheritedWidgetOfExactType<TerminalScope>()?.actions;
@override
bool updateShouldNotify(TerminalScope oldWidget) =>
oldWidget.actions != actions;
}
/// The machine id [gateway] was bound to, for a terminal opened from a
/// chat or its Files panel.
String? terminalMachineOf(ApiGateway gateway) => serverIdentity(gateway);