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.
136 lines
4.2 KiB
Dart
136 lines
4.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../chat/shell/chat_shell_terminal_keys.dart';
|
|
import '../chat/shell/chat_shell_terminal_view.dart';
|
|
import 'terminal_hub.dart';
|
|
import 'terminal_tab.dart';
|
|
|
|
/// The selected terminal: its emulator (focused when shown), what the
|
|
/// operator should know about it (ended, machine offline, ends with the
|
|
/// server) and, with [keys], the touch key toolbar. With [focus] it is that
|
|
/// focus scope, which the surface focuses whenever the terminal shows.
|
|
class TerminalBody extends StatelessWidget {
|
|
const TerminalBody({
|
|
super.key,
|
|
required this.hub,
|
|
required this.cupertino,
|
|
this.keys = false,
|
|
this.focus,
|
|
});
|
|
|
|
final TerminalHub hub;
|
|
final bool cupertino;
|
|
final bool keys;
|
|
final FocusScopeNode? focus;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final focus = this.focus;
|
|
final body = _body(context);
|
|
return focus == null ? body : FocusScope(node: focus, child: body);
|
|
}
|
|
|
|
Widget _body(BuildContext context) {
|
|
final tab = hub.selected;
|
|
if (tab == null) return _empty(context);
|
|
final notes = <String>[
|
|
if (!tab.connected)
|
|
'${tab.machineName} is not connected; the terminal resumes when it is.'
|
|
else if (!tab.info.running)
|
|
tab.info.endedText
|
|
else if (!tab.info.persistent)
|
|
'This shell ends if the server on ${tab.machineName} restarts '
|
|
'(tmux is not installed there).',
|
|
?tab.error,
|
|
?hub.error,
|
|
];
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 8),
|
|
child: ChatShellTerminalView(
|
|
key: ValueKey('terminal-view-${tab.key}'),
|
|
session: tab.session,
|
|
cupertino: cupertino,
|
|
fill: true,
|
|
autofocus: true,
|
|
),
|
|
),
|
|
),
|
|
for (final note in notes)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 0, 12, 8),
|
|
child: Text(note, style: _noteStyle(context)),
|
|
),
|
|
if (keys && tab.session.live && tab.connected)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 8),
|
|
child: ChatShellTerminalKeys(
|
|
session: tab.session,
|
|
cupertino: cupertino,
|
|
field: chatShellTouchFirst(),
|
|
),
|
|
),
|
|
if (!tab.info.running && tab.connected) _closeEnded(tab),
|
|
],
|
|
);
|
|
}
|
|
|
|
TextStyle? _noteStyle(BuildContext context) => cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
|
|
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
|
)
|
|
: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
);
|
|
|
|
Widget _closeEnded(TerminalTab tab) {
|
|
void close() => unawaited(hub.close(tab));
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 8),
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: cupertino
|
|
? CupertinoButton(onPressed: close, child: const Text('Close tab'))
|
|
: TextButton(onPressed: close, child: const Text('Close tab')),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _empty(BuildContext context) {
|
|
final machines = hub.connected;
|
|
final text = machines.isEmpty
|
|
? 'No machine is connected.'
|
|
: 'No terminals are open.';
|
|
void open() => unawaited(hub.open());
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(text, style: _noteStyle(context)),
|
|
if (hub.error case final error?)
|
|
Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: Text(error, style: _noteStyle(context)),
|
|
),
|
|
if (machines.isNotEmpty)
|
|
cupertino
|
|
? CupertinoButton(
|
|
onPressed: open,
|
|
child: const Text('New terminal'),
|
|
)
|
|
: FilledButton.tonal(
|
|
onPressed: open,
|
|
child: const Text('New terminal'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|