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:
2026-11-26 02:25:16 +00:00
parent e526150b1e
commit b59ab5fad7
27 changed files with 1141 additions and 145 deletions
@@ -6,52 +6,71 @@ import 'package:xterm/xterm.dart';
import '../../../ui/text/monospace.dart';
import '../../../ui/text/terminal_symbols_font.dart';
import '../../terminal/terminal_layout.dart';
import '../conversation/chat_card_styles.dart';
import 'chat_shell_terminal_palette.dart';
/// The terminal's colours from the host theme: the card's inset surface as
/// How strongly the selection and find matches tint the cells they cover
/// (painted over the text, so the text shows through).
const double chatShellTerminalSelectionAlpha = 0.35;
const double chatShellTerminalMatchAlpha = 0.2;
const double chatShellTerminalCurrentMatchAlpha = 0.4;
/// The terminal's background: the theme's lowest surface, the most
/// contrast its colours can have in either brightness.
Color chatShellTerminalBackground(BuildContext context) =>
Theme.of(context).colorScheme.surfaceContainerLowest;
/// The terminal's colours from the host theme: its lowest surface as
/// background, the body text colour as foreground, the accent as cursor and
/// selection. The sixteen ANSI colours are the emulator's standard palette,
/// darkened on a light surface so coloured output stays readable.
TerminalTheme chatShellTerminalTheme(BuildContext context) {
final dark = Theme.of(context).brightness == Brightness.dark;
final background = chatCardFillColor(context);
final foreground = Theme.of(context).colorScheme.onSurface;
final accent = Theme.of(context).colorScheme.primary;
final base = TerminalThemes.defaultTheme;
Color ansi(Color color) {
if (dark) return color;
final hsl = HSLColor.fromColor(color);
return hsl.lightness > 0.4 ? hsl.withLightness(0.36).toColor() : color;
}
/// selection, and [palette]'s sixteen ANSI colours adjusted to that
/// background (see [chatShellTerminalPalette]).
TerminalTheme chatShellTerminalTheme(
BuildContext context, {
TerminalPalette palette = TerminalPalette.theme,
}) {
final scheme = Theme.of(context).colorScheme;
final background = chatShellTerminalBackground(context);
final ansi = chatShellTerminalPalette(palette, background);
final matches = chatShellTerminalMatchColours(context);
return TerminalTheme(
cursor: accent,
selection: accent.withValues(alpha: 0.35),
foreground: foreground,
// Opaque: the emulator paints cells over its own background.
background: Color.alphaBlend(
background,
Theme.of(context).colorScheme.surface,
cursor: scheme.primary,
selection: scheme.primary.withValues(
alpha: chatShellTerminalSelectionAlpha,
),
black: dark ? base.black : foreground,
red: ansi(base.red),
green: ansi(base.green),
yellow: ansi(base.yellow),
blue: ansi(base.blue),
magenta: ansi(base.magenta),
cyan: ansi(base.cyan),
white: dark ? base.white : ansi(base.brightBlack),
brightBlack: ansi(base.brightBlack),
brightRed: ansi(base.brightRed),
brightGreen: ansi(base.brightGreen),
brightYellow: ansi(base.brightYellow),
brightBlue: ansi(base.brightBlue),
brightMagenta: ansi(base.brightMagenta),
brightCyan: ansi(base.brightCyan),
brightWhite: dark ? base.brightWhite : foreground,
searchHitBackground: base.searchHitBackground,
searchHitBackgroundCurrent: base.searchHitBackgroundCurrent,
searchHitForeground: base.searchHitForeground,
foreground: scheme.onSurface,
background: background,
black: ansi[0],
red: ansi[1],
green: ansi[2],
yellow: ansi[3],
blue: ansi[4],
magenta: ansi[5],
cyan: ansi[6],
white: ansi[7],
brightBlack: ansi[8],
brightRed: ansi[9],
brightGreen: ansi[10],
brightYellow: ansi[11],
brightBlue: ansi[12],
brightMagenta: ansi[13],
brightCyan: ansi[14],
brightWhite: ansi[15],
searchHitBackground: matches.hit,
searchHitBackgroundCurrent: matches.current,
searchHitForeground: scheme.onSurface,
);
}
/// The tints of find matches and of the current match: the theme's tertiary
/// colour, light enough over the text that it keeps 4.5:1 contrast.
({Color hit, Color current}) chatShellTerminalMatchColours(
BuildContext context,
) {
final tertiary = Theme.of(context).colorScheme.tertiary;
return (
hit: tertiary.withValues(alpha: chatShellTerminalMatchAlpha),
current: tertiary.withValues(alpha: chatShellTerminalCurrentMatchAlpha),
);
}