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 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()?.actions; /// The actions without depending on them, for a key handler. static TerminalActions? peek(BuildContext context) => context.getInheritedWidgetOfExactType()?.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);