Terminal round 3: readable palettes, panel and card sizing, rail, tabs
- 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>
This commit is contained in:
@@ -16,10 +16,14 @@ enum TerminalMode {
|
||||
final String label;
|
||||
}
|
||||
|
||||
/// The default and smallest heights of the bottom panel, and the smallest
|
||||
/// floating window; layouts clamp to what the window allows.
|
||||
const double terminalPanelDefaultHeight = 300;
|
||||
/// The smallest height of the bottom panel, and the smallest floating
|
||||
/// window; layouts clamp to what the window allows. The panel's default
|
||||
/// height depends on the window (see `terminalPanelDefaultHeight`).
|
||||
const double terminalPanelMinHeight = 120;
|
||||
|
||||
/// The fixed default panel height layouts saved before the default followed
|
||||
/// the window: a saved height of exactly this is read as never resized.
|
||||
const double terminalPanelLegacyDefaultHeight = 300;
|
||||
const Size terminalFloatMinSize = Size(320, 200);
|
||||
const Rect terminalFloatDefaultRect = Rect.fromLTWH(80, 80, 720, 420);
|
||||
|
||||
@@ -34,6 +38,19 @@ const List<int> terminalScrollbackChoices = [
|
||||
];
|
||||
const int terminalScrollbackDefault = 10000;
|
||||
|
||||
/// The terminal's ANSI colour palette. Every palette is adjusted to the
|
||||
/// light or dark theme's terminal background so text stays readable (see
|
||||
/// `chatShellTerminalPalette`); the names describe them, not products.
|
||||
enum TerminalPalette {
|
||||
theme('Theme colours'),
|
||||
classic('Classic'),
|
||||
calm('Calm'),
|
||||
vivid('Vivid');
|
||||
|
||||
const TerminalPalette(this.label);
|
||||
final String label;
|
||||
}
|
||||
|
||||
/// The terminal's text size limits (logical pixels) and one zoom step.
|
||||
const double terminalFontSizeMin = 8;
|
||||
const double terminalFontSizeMax = 32;
|
||||
@@ -83,7 +100,10 @@ class TerminalLayout extends ChangeNotifier {
|
||||
|
||||
TerminalMode mode = TerminalMode.panel;
|
||||
bool visible = false;
|
||||
double panelHeight = terminalPanelDefaultHeight;
|
||||
|
||||
/// The bottom panel's height as the operator last dragged it, or null for
|
||||
/// the default, which follows the window.
|
||||
double? panelHeight;
|
||||
|
||||
/// The floating window's frame and maximised state as saved before the
|
||||
/// window moved to the app's window system (`TerminalWindows`), which takes
|
||||
@@ -103,6 +123,9 @@ class TerminalLayout extends ChangeNotifier {
|
||||
/// Lines each terminal keeps, scrollback included.
|
||||
int scrollback = terminalScrollbackDefault;
|
||||
|
||||
/// The sixteen ANSI colours' palette.
|
||||
TerminalPalette palette = TerminalPalette.theme;
|
||||
|
||||
/// Whether a bell (BEL) flashes the terminal and dots a hidden tab.
|
||||
bool bell = true;
|
||||
|
||||
@@ -117,7 +140,10 @@ class TerminalLayout extends ChangeNotifier {
|
||||
final json = jsonDecode(raw) as Map;
|
||||
mode = TerminalMode.values.asNameMap()[json['mode']] ?? mode;
|
||||
visible = json['visible'] == true;
|
||||
panelHeight = _finite(json['panel_height']) ?? panelHeight;
|
||||
final height = _finite(json['panel_height']);
|
||||
panelHeight = height == terminalPanelLegacyDefaultHeight
|
||||
? null
|
||||
: height ?? panelHeight;
|
||||
final rect = json['float'];
|
||||
if (rect is List && rect.length == 4) {
|
||||
final values = rect.map(_finite).toList();
|
||||
@@ -139,6 +165,7 @@ class TerminalLayout extends ChangeNotifier {
|
||||
scrollback = lines;
|
||||
}
|
||||
bell = json['bell'] != false;
|
||||
palette = TerminalPalette.values.asNameMap()[json['palette']] ?? palette;
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
@@ -149,6 +176,7 @@ class TerminalLayout extends ChangeNotifier {
|
||||
void setOptionAsMeta(bool value) => _change(() => optionAsMeta = value);
|
||||
void setScrollback(int value) => _change(() => scrollback = value);
|
||||
void setBell(bool value) => _change(() => bell = value);
|
||||
void setPalette(TerminalPalette value) => _change(() => palette = value);
|
||||
|
||||
/// Sets the text size (null: the default), within the limits.
|
||||
void setFontSize(double? value) => _change(
|
||||
@@ -163,7 +191,7 @@ class TerminalLayout extends ChangeNotifier {
|
||||
void toggle() => _change(() => visible = !visible);
|
||||
void show() => _change(() => visible = true);
|
||||
void hide() => _change(() => visible = false);
|
||||
void setPanelHeight(double value, {bool save = true}) =>
|
||||
void setPanelHeight(double? value, {bool save = true}) =>
|
||||
_change(() => panelHeight = value, save: save);
|
||||
|
||||
/// Saves the current layout (a drag saves once, when it ends).
|
||||
@@ -173,7 +201,7 @@ class TerminalLayout extends ChangeNotifier {
|
||||
jsonEncode({
|
||||
'mode': mode.name,
|
||||
'visible': visible,
|
||||
'panel_height': panelHeight,
|
||||
'panel_height': ?panelHeight,
|
||||
'float': [
|
||||
floatRect.left,
|
||||
floatRect.top,
|
||||
@@ -185,6 +213,7 @@ class TerminalLayout extends ChangeNotifier {
|
||||
'font_size': ?fontSize,
|
||||
'scrollback': scrollback,
|
||||
'bell': bell,
|
||||
'palette': palette.name,
|
||||
}),
|
||||
);
|
||||
if (revision != _revision || saved != saveFailed) return;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
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';
|
||||
@@ -16,15 +18,50 @@ const double terminalPanelKeyStep = 24;
|
||||
/// Space the docked panel always leaves the app above it.
|
||||
const double terminalPanelAppMin = 160;
|
||||
|
||||
/// [height] within what a window [available] tall allows the panel.
|
||||
double terminalPanelHeight(double height, double available) {
|
||||
/// 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.clamp(terminalPanelMinHeight, max);
|
||||
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
|
||||
@@ -35,6 +72,7 @@ class TerminalPanel extends StatefulWidget {
|
||||
required this.hub,
|
||||
required this.layout,
|
||||
required this.available,
|
||||
required this.rowHeight,
|
||||
this.focus,
|
||||
});
|
||||
|
||||
@@ -44,6 +82,9 @@ class TerminalPanel extends StatefulWidget {
|
||||
/// 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;
|
||||
|
||||
@@ -54,17 +95,18 @@ class TerminalPanel extends StatefulWidget {
|
||||
class _TerminalPanelState extends State<TerminalPanel> {
|
||||
bool _active = false;
|
||||
|
||||
double get _height =>
|
||||
terminalPanelHeight(widget.layout.panelHeight, widget.available);
|
||||
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(
|
||||
terminalPanelHeight(height, widget.available),
|
||||
save: save,
|
||||
);
|
||||
widget.layout.setPanelHeight(_clamp(height), save: save);
|
||||
|
||||
String _describe(double height) =>
|
||||
'${terminalPanelHeight(height, widget.available).round()} pixels';
|
||||
String _describe(double height) => '${_clamp(height).round()} pixels';
|
||||
|
||||
KeyEventResult _key(FocusNode _, KeyEvent event) {
|
||||
if (event is! KeyDownEvent && event is! KeyRepeatEvent) {
|
||||
|
||||
@@ -39,9 +39,13 @@ class TerminalStage extends StatelessWidget {
|
||||
builder: (context, constraints) {
|
||||
final hiding = !layout.visible;
|
||||
final panel = present && layout.mode == TerminalMode.panel;
|
||||
// Measured only while the panel is there (the default height is in
|
||||
// rows).
|
||||
final rowHeight = panel ? terminalRowHeight(context, layout) : 0.0;
|
||||
final height = terminalPanelHeight(
|
||||
layout.panelHeight,
|
||||
constraints.maxHeight,
|
||||
rowHeight: rowHeight,
|
||||
);
|
||||
final inset = panel ? height * reveal.value : 0.0;
|
||||
Widget inert(Widget child) => IgnorePointer(
|
||||
@@ -75,6 +79,7 @@ class TerminalStage extends StatelessWidget {
|
||||
hub: hub,
|
||||
layout: layout,
|
||||
available: constraints.maxHeight,
|
||||
rowHeight: rowHeight,
|
||||
focus: focus,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The widest a tab's title is drawn before it ends in an ellipsis (the
|
||||
/// tooltip has it whole).
|
||||
const double terminalTabTitleMaxWidth = 220;
|
||||
|
||||
/// One terminal's tab: its [title] (ellipsised, italic once the terminal
|
||||
/// ended), a bell dot, and a close button, with the whole title and
|
||||
/// [tooltip] (machine and folder) on hover or long press.
|
||||
///
|
||||
/// The selected tab is filled with the secondary container and outlined in
|
||||
/// the accent, its title bold, so it reads as selected in either theme
|
||||
/// without relying on colour alone. The close button is a standard
|
||||
/// [IconButton]: at least 48 px square on touch platforms and 40 px on
|
||||
/// desktops (the platform's visual density).
|
||||
class TerminalTabChip extends StatelessWidget {
|
||||
const TerminalTabChip({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.tooltip,
|
||||
required this.selected,
|
||||
required this.running,
|
||||
required this.bell,
|
||||
required this.onSelect,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String tooltip;
|
||||
final bool selected;
|
||||
final bool running;
|
||||
final bool bell;
|
||||
final VoidCallback onSelect;
|
||||
final VoidCallback onClose;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final foreground = selected
|
||||
? scheme.onSecondaryContainer
|
||||
: scheme.onSurfaceVariant;
|
||||
final label = Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
softWrap: false,
|
||||
style: Theme.of(context).textTheme.labelLarge?.copyWith(
|
||||
color: foreground,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
fontStyle: running ? null : FontStyle.italic,
|
||||
),
|
||||
);
|
||||
final shape = RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(
|
||||
color: selected ? scheme.primary : scheme.outlineVariant,
|
||||
width: selected ? 2 : 1,
|
||||
),
|
||||
);
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
child: Material(
|
||||
shape: shape,
|
||||
color: selected ? scheme.secondaryContainer : Colors.transparent,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
// The title's ink fills the tab's height (the close button's).
|
||||
child: IntrinsicHeight(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Tooltip(
|
||||
message: tooltip,
|
||||
child: InkWell(
|
||||
onTap: onSelect,
|
||||
child: Semantics(
|
||||
button: true,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
start: 12,
|
||||
end: 4,
|
||||
),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: terminalTabTitleMaxWidth,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(child: label),
|
||||
if (bell)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
start: 6,
|
||||
),
|
||||
// The bell rang while the terminal was not
|
||||
// shown.
|
||||
child: Semantics(
|
||||
label: 'Bell',
|
||||
child: Badge(
|
||||
key: const ValueKey('terminal-tab-bell'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Close terminal',
|
||||
onPressed: onClose,
|
||||
color: foreground,
|
||||
iconSize: 18,
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'terminal_layout.dart';
|
||||
import 'terminal_menu.dart';
|
||||
import 'terminal_shortcuts.dart';
|
||||
import 'terminal_tab.dart';
|
||||
import 'terminal_tab_chip.dart';
|
||||
|
||||
/// The terminal's header: one tab per terminal (title, and the machine when
|
||||
/// tabs come from several), New terminal (choosing the machine when more
|
||||
@@ -84,39 +85,16 @@ class TerminalTabStrip extends StatelessWidget {
|
||||
hub.multiMachine ? '${tab.title} · ${tab.machineName}' : tab.title;
|
||||
|
||||
Widget _tab(TerminalTab tab, bool selected) {
|
||||
Widget label = Text(
|
||||
_label(tab),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: tab.info.running
|
||||
? null
|
||||
: const TextStyle(fontStyle: FontStyle.italic),
|
||||
);
|
||||
if (tab.bellUnseen) {
|
||||
// The bell rang while the terminal was not shown.
|
||||
label = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(child: label),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 6),
|
||||
child: Semantics(
|
||||
label: 'Bell',
|
||||
child: Badge(key: const ValueKey('terminal-tab-bell')),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
void close() => unawaited(hub.close(tab));
|
||||
return InputChip(
|
||||
label: label,
|
||||
final title = _label(tab);
|
||||
return TerminalTabChip(
|
||||
title: title,
|
||||
// The whole title (the tab may ellipsise it), then where it runs.
|
||||
tooltip: '$title\n${tab.machineName}: ${tab.cwd}',
|
||||
selected: selected,
|
||||
showCheckmark: false,
|
||||
tooltip: '${tab.machineName}: ${tab.cwd}',
|
||||
onSelected: (_) => hub.select(tab),
|
||||
onDeleted: close,
|
||||
deleteButtonTooltipMessage: 'Close terminal',
|
||||
running: tab.info.running,
|
||||
bell: tab.bellUnseen,
|
||||
onSelect: () => hub.select(tab),
|
||||
onClose: () => unawaited(hub.close(tab)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user