30934aa71c
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.
109 lines
2.9 KiB
Dart
109 lines
2.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'terminal_body.dart';
|
|
import 'terminal_hub.dart';
|
|
import 'terminal_layout.dart';
|
|
import 'terminal_tab_strip.dart';
|
|
|
|
/// The terminals full screen (a narrow window has no room for a panel or a
|
|
/// window), with the touch key toolbar. The shells keep running when it is
|
|
/// closed; the route's own transition animates it and returns focus to
|
|
/// whatever had it.
|
|
PageRoute<void> terminalPageRoute({
|
|
required TerminalHub hub,
|
|
required TerminalLayout layout,
|
|
required bool cupertino,
|
|
}) {
|
|
Widget page(BuildContext _) =>
|
|
TerminalPage(hub: hub, layout: layout, cupertino: cupertino);
|
|
return cupertino
|
|
? CupertinoPageRoute<void>(builder: page)
|
|
: MaterialPageRoute<void>(builder: page);
|
|
}
|
|
|
|
/// The full-screen terminal page of a narrow window, opened and closed by
|
|
/// the terminal's toggle.
|
|
class TerminalPageToggle {
|
|
PageRoute<void>? _route;
|
|
|
|
bool get open => _route != null;
|
|
|
|
/// Pushes the page on [context]'s navigator unless it is open; resolves
|
|
/// when it closes.
|
|
Future<void> show(
|
|
BuildContext context, {
|
|
required TerminalHub hub,
|
|
required TerminalLayout layout,
|
|
required bool cupertino,
|
|
}) async {
|
|
if (_route != null) return;
|
|
final route = _route = terminalPageRoute(
|
|
hub: hub,
|
|
layout: layout,
|
|
cupertino: cupertino,
|
|
);
|
|
try {
|
|
await Navigator.of(context).push(route);
|
|
} finally {
|
|
if (identical(_route, route)) _route = null;
|
|
}
|
|
}
|
|
|
|
/// Closes the page, also from under a route above it.
|
|
void close() {
|
|
final route = _route;
|
|
_route = null;
|
|
if (route == null) return;
|
|
route.isCurrent
|
|
? route.navigator?.pop()
|
|
: route.navigator?.removeRoute(route);
|
|
}
|
|
}
|
|
|
|
class TerminalPage extends StatelessWidget {
|
|
const TerminalPage({
|
|
super.key,
|
|
required this.hub,
|
|
required this.layout,
|
|
required this.cupertino,
|
|
});
|
|
|
|
final TerminalHub hub;
|
|
final TerminalLayout layout;
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final body = ListenableBuilder(
|
|
listenable: hub,
|
|
builder: (context, _) => SafeArea(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
TerminalTabStrip(
|
|
hub: hub,
|
|
layout: layout,
|
|
cupertino: cupertino,
|
|
showModes: false,
|
|
),
|
|
Expanded(
|
|
child: TerminalBody(hub: hub, cupertino: cupertino, keys: true),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
if (cupertino) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: const CupertinoNavigationBar(middle: Text('Terminal')),
|
|
child: Material(type: MaterialType.transparency, child: body),
|
|
);
|
|
}
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Terminal')),
|
|
body: body,
|
|
);
|
|
}
|
|
}
|