35 lines
1.2 KiB
Dart
35 lines
1.2 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();
|
|
|
|
/// 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;
|
|
|
|
@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);
|