b59ab5fad7
- Colours: terminal background is the theme's lowest surface; the 16 ANSI colours come from a chosen palette (Theme colours, Classic, Calm, Vivid; Settings > Terminal > Colours, saved as `palette`) adjusted in lightness to the background: colours 4.5:1, bright ones lighter than normal, white light and black dark in both themes so white-on-red/blue/magenta and black-on-green/yellow/cyan (ls setuid, setgid, sticky) keep 3:1. Selection, find matches and the current match keep text at 4.5:1. - Bottom panel opens at 40% of the window, at least 16 rows, until dragged; the dragged height is remembered (old saved 300 px default reads as never resized). - Navigation rail scrolls its tabs (and below 240 px Settings too), so items never overlap under a tall panel. - Chat command cards: Expand / Collapse grows a live terminal to 60% of the window (finished output only to its rows); collapsed stays 12 rows. - Terminal tabs: ellipsised titles (220 px) with the whole title in the tooltip, selected tab filled, outlined and bold, close buttons are IconButtons (48 px touch, 40 px desktop). - Capture fixture: ?terminalColors=1 and ?terminalPalette=. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
192 lines
6.2 KiB
Dart
192 lines
6.2 KiB
Dart
import 'dart:async';
|
|
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../../ui/adaptive/resize_grip.dart';
|
|
import '../chat/shell/chat_shell_terminal_theme.dart';
|
|
import 'terminal_body.dart';
|
|
import 'terminal_hub.dart';
|
|
import 'terminal_layout.dart';
|
|
import 'terminal_tab_strip.dart';
|
|
|
|
/// Arrow-key step of the panel's resize handle.
|
|
const double terminalPanelKeyStep = 24;
|
|
|
|
/// Space the docked panel always leaves the app above it.
|
|
const double terminalPanelAppMin = 160;
|
|
|
|
/// The share of the window the panel takes until the operator resizes it.
|
|
const double terminalPanelDefaultFraction = 0.4;
|
|
|
|
/// The terminal rows the default panel shows at least, window permitting.
|
|
const int terminalPanelDefaultMinRows = 16;
|
|
|
|
/// The panel's height besides its rows: the resize handle, the tab strip
|
|
/// and the emulator's padding (an allowance; the rows are what count).
|
|
const double terminalPanelChrome = 96;
|
|
|
|
/// The panel's height until the operator resizes it, in a window
|
|
/// [available] tall whose terminal rows are [rowHeight] high: 40 % of the
|
|
/// window, and at least 16 rows.
|
|
double terminalPanelDefaultHeight(double available, double rowHeight) =>
|
|
math.max(
|
|
available * terminalPanelDefaultFraction,
|
|
terminalPanelDefaultMinRows * rowHeight + terminalPanelChrome,
|
|
);
|
|
|
|
/// [height] (null: the default) within what a window [available] tall
|
|
/// allows the panel. [rowHeight] is one terminal row's height.
|
|
double terminalPanelHeight(
|
|
double? height,
|
|
double available, {
|
|
required double rowHeight,
|
|
}) {
|
|
final max = (available - terminalPanelAppMin).clamp(
|
|
terminalPanelMinHeight,
|
|
double.infinity,
|
|
);
|
|
return (height ?? terminalPanelDefaultHeight(available, rowHeight)).clamp(
|
|
terminalPanelMinHeight,
|
|
max,
|
|
);
|
|
}
|
|
|
|
/// One terminal row's height at the terminal's text size, as the emulator
|
|
/// lays it out.
|
|
double terminalRowHeight(BuildContext context, TerminalLayout layout) =>
|
|
chatShellTerminalCellSize(
|
|
context,
|
|
chatShellTerminalStyle(context, fontSize: layout.fontSize),
|
|
).height;
|
|
|
|
/// The terminal docked at the bottom of the window, filling the height its
|
|
/// parent gives it (the layout's, see [terminalPanelHeight]): a resize
|
|
/// handle on its top edge (drag, or the arrow keys), the tabs and the
|
|
/// selected terminal.
|
|
class TerminalPanel extends StatefulWidget {
|
|
const TerminalPanel({
|
|
super.key,
|
|
required this.hub,
|
|
required this.layout,
|
|
required this.available,
|
|
required this.rowHeight,
|
|
this.focus,
|
|
});
|
|
|
|
final TerminalHub hub;
|
|
final TerminalLayout layout;
|
|
|
|
/// The height of the window the panel shares with the app.
|
|
final double available;
|
|
|
|
/// One terminal row's height (see [terminalRowHeight]).
|
|
final double rowHeight;
|
|
|
|
/// The terminal's focus scope (see [TerminalBody.focus]).
|
|
final FocusScopeNode? focus;
|
|
|
|
@override
|
|
State<TerminalPanel> createState() => _TerminalPanelState();
|
|
}
|
|
|
|
class _TerminalPanelState extends State<TerminalPanel> {
|
|
bool _active = false;
|
|
|
|
double _clamp(double? height) => terminalPanelHeight(
|
|
height,
|
|
widget.available,
|
|
rowHeight: widget.rowHeight,
|
|
);
|
|
|
|
double get _height => _clamp(widget.layout.panelHeight);
|
|
|
|
void _resize(double height, {bool save = true}) =>
|
|
widget.layout.setPanelHeight(_clamp(height), save: save);
|
|
|
|
String _describe(double height) => '${_clamp(height).round()} pixels';
|
|
|
|
KeyEventResult _key(FocusNode _, KeyEvent event) {
|
|
if (event is! KeyDownEvent && event is! KeyRepeatEvent) {
|
|
return KeyEventResult.ignored;
|
|
}
|
|
if (event.logicalKey == LogicalKeyboardKey.arrowUp) {
|
|
_resize(_height + terminalPanelKeyStep);
|
|
} else if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
|
|
_resize(_height - terminalPanelKeyStep);
|
|
} else {
|
|
return KeyEventResult.ignored;
|
|
}
|
|
return KeyEventResult.handled;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final height = _height;
|
|
final handle = Semantics(
|
|
identifier: 'terminal-panel-resize',
|
|
label: 'Terminal height',
|
|
hint: 'Drag, or use the arrow keys, to resize the terminal',
|
|
slider: true,
|
|
value: _describe(height),
|
|
increasedValue: _describe(height + terminalPanelKeyStep),
|
|
decreasedValue: _describe(height - terminalPanelKeyStep),
|
|
onIncrease: () => _resize(height + terminalPanelKeyStep),
|
|
onDecrease: () => _resize(height - terminalPanelKeyStep),
|
|
child: Focus(
|
|
onKeyEvent: _key,
|
|
onFocusChange: (value) => setState(() => _active = value),
|
|
child: MouseRegion(
|
|
cursor: SystemMouseCursors.resizeRow,
|
|
child: GestureDetector(
|
|
key: const ValueKey('terminal-panel-resize'),
|
|
behavior: HitTestBehavior.opaque,
|
|
excludeFromSemantics: true,
|
|
dragStartBehavior: DragStartBehavior.down,
|
|
onVerticalDragStart: (_) => setState(() => _active = true),
|
|
onVerticalDragUpdate: (details) =>
|
|
_resize(_height - details.delta.dy, save: false),
|
|
onVerticalDragEnd: (_) {
|
|
setState(() => _active = false);
|
|
unawaited(widget.layout.save());
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: Center(
|
|
child: AdaptiveResizeGrip(compact: true, emphasized: _active),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final surface = Theme.of(context).colorScheme.surfaceContainerLow;
|
|
final divider = Theme.of(context).colorScheme.outlineVariant;
|
|
return Semantics(
|
|
container: true,
|
|
label: 'Terminal panel',
|
|
child: DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
color: surface,
|
|
border: Border(top: BorderSide(color: divider)),
|
|
),
|
|
child: Material(
|
|
type: MaterialType.transparency,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
handle,
|
|
TerminalTabStrip(hub: widget.hub, layout: widget.layout),
|
|
Expanded(
|
|
child: TerminalBody(hub: widget.hub, focus: widget.focus),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|