214bbbc54f
Keep the existing Material terminal and chat-shell behavior while removing live Cupertino widgets, icon metadata, and alternate-host branches. Retain only the documented optional compatibility parameters until remaining callers migrate.
80 lines
2.2 KiB
Dart
80 lines
2.2 KiB
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,
|
|
}) {
|
|
Widget page(BuildContext _) => TerminalPage(hub: hub, layout: layout);
|
|
return 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,
|
|
}) async {
|
|
if (_route != null) return;
|
|
final route = _route = terminalPageRoute(hub: hub, layout: layout);
|
|
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});
|
|
|
|
final TerminalHub hub;
|
|
final TerminalLayout layout;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final body = ListenableBuilder(
|
|
listenable: hub,
|
|
builder: (context, _) => SafeArea(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
TerminalTabStrip(hub: hub, layout: layout, showModes: false),
|
|
Expanded(child: TerminalBody(hub: hub, keys: true)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Terminal')),
|
|
body: body,
|
|
);
|
|
}
|
|
}
|