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
@@ -19,6 +19,21 @@ import '../../../ui/input/keyboard_owner.dart';
export 'chat_shell_terminal_shortcuts.dart'
show chatShellTerminalShortcuts, chatShellCopyKey;
/// The most rows a card's terminal shows in a window [windowHeight] tall
/// with rows [rowHeight] high (see [kChatShellOutputCollapsedLines]).
int chatShellCardRows(
double windowHeight,
double rowHeight, {
required bool expanded,
}) {
if (!expanded || rowHeight <= 0) return kChatShellOutputCollapsedLines;
final rows = (windowHeight * kChatShellOutputExpandedFraction / rowHeight)
.floor();
return rows < kChatShellOutputCollapsedLines
? kChatShellOutputCollapsedLines
: rows;
}
/// Whether the soft keyboard is the main way to type here, so the key
/// toolbar offers a text field: the terminal itself takes hardware keys only.
bool chatShellTouchFirst() =>
@@ -26,8 +41,10 @@ bool chatShellTouchFirst() =>
defaultTargetPlatform == TargetPlatform.iOS;
/// One run's terminal emulator view. In a card it is bounded to
/// [kChatShellOutputCollapsedLines] rows (a finished run shrinks to its
/// output); with [fill] it takes the space its parent gives (full screen).
/// [kChatShellOutputCollapsedLines] rows, or with [expanded] to
/// [kChatShellOutputExpandedFraction] of the window's height (a finished run
/// shrinks to its output); with [fill] it takes the space its parent gives
/// (full screen).
/// It sizes the terminal to its own layout; a running process is resized to
/// match. Tapping a printed web link opens it in the browser.
///
@@ -40,12 +57,14 @@ class ChatShellTerminalView extends StatefulWidget {
super.key,
required this.session,
this.fill = false,
this.expanded = false,
this.autofocus = false,
this.autoResize = true,
});
final ChatShellTerminalSession session;
final bool fill;
final bool expanded;
final bool autofocus;
/// False while another view of the same terminal (full screen) sizes it.
@@ -164,7 +183,7 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView>
focusNode: focus,
autofocus: widget.autofocus && live,
autoResize: widget.autoResize,
theme: chatShellTerminalTheme(context),
theme: chatShellTerminalTheme(context, palette: session.layout.palette),
textStyle: style,
padding: padding,
readOnly: !live,
@@ -229,9 +248,12 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView>
final cols = ((constraints.maxWidth - padding.horizontal) / cell.width)
.floor()
.clamp(1, 1000);
final rows = live
? kChatShellOutputCollapsedLines
: session.rowsAt(cols).clamp(1, kChatShellOutputCollapsedLines);
final most = chatShellCardRows(
MediaQuery.sizeOf(context).height,
cell.height,
expanded: widget.expanded,
);
final rows = live ? most : session.rowsAt(cols).clamp(1, most);
// A pixel of slack keeps rounding from losing the last row.
return SizedBox(
height: rows * cell.height + padding.vertical + 1,