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
@@ -163,4 +163,64 @@ void main() {
await tester.pumpAndSettle();
expect(find.byType(TerminalView), findsOneWidget);
});
double terminalHeight(WidgetTester tester) =>
tester.getSize(find.byType(TerminalView)).height;
testWidgets('Expand grows a running terminal to 60 % of the window and '
'Collapse brings it back to 12 rows', (tester) async {
tester.view.physicalSize = const Size(1000, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
gateway.runs = [shellRecord('run_a', output: 'line 1\n', terminal: true)];
await tester.pumpWidget(shellThread(gateway));
await tester.pump();
final collapsed = terminalHeight(tester);
final toggle = find.byKey(const Key('chat-shell-run-size'));
expect(find.text('Expand'), findsOneWidget);
await tester.ensureVisible(toggle);
await tester.tap(toggle);
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
final expanded = terminalHeight(tester);
expect(expanded, greaterThan(collapsed * 2));
// Rows of the cell height, within 60 % of the window.
expect(expanded, lessThanOrEqualTo(1000 * 0.6 + 17));
expect(expanded, greaterThan(1000 * 0.6 - 40));
expect(find.text('Collapse'), findsOneWidget);
// The tall card puts the button under the composer; press it directly.
tester.widget<ButtonStyleButton>(toggle).onPressed!();
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
expect(terminalHeight(tester), collapsed);
expect(tester.takeException(), isNull);
});
testWidgets('a finished run whose output fits collapsed offers no Expand; '
'a longer one grows only to its output', (tester) async {
tester.view.physicalSize = const Size(1000, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
gateway.runs = [
shellRecord('run_short', status: 'exited', exitCode: 0, output: 'ok\n'),
shellRecord(
'run_long',
status: 'exited',
exitCode: 0,
output: List.generate(20, (i) => 'line $i').join('\r\n'),
),
];
await tester.pumpWidget(shellThread(gateway));
await tester.pumpAndSettle();
final toggles = find.byKey(const Key('chat-shell-run-size'));
expect(toggles, findsOneWidget);
final long = find.byType(TerminalView).last;
final before = tester.getSize(long).height;
await tester.ensureVisible(toggles);
await tester.tap(toggles);
await tester.pumpAndSettle();
final after = tester.getSize(find.byType(TerminalView).last).height;
// 20 rows instead of 12, not the whole 60 %.
expect(after / before, closeTo(20 / 12, 0.15));
});
}
@@ -0,0 +1,136 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_palette.dart';
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_theme.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
import 'package:xterm/xterm.dart';
const _names = [
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', //
'bright black', 'bright red', 'bright green', 'bright yellow',
'bright blue', 'bright magenta', 'bright cyan', 'bright white',
];
/// [over] painted on [under] (the emulator paints selection and matches
/// over the cells, text included).
Color _blend(Color over, Color under) => Color.alphaBlend(over, under);
List<Color> _ansi(TerminalTheme t) => [
t.black, t.red, t.green, t.yellow, t.blue, t.magenta, t.cyan, t.white, //
t.brightBlack, t.brightRed, t.brightGreen, t.brightYellow,
t.brightBlue, t.brightMagenta, t.brightCyan, t.brightWhite,
];
Future<TerminalTheme> _theme(
WidgetTester tester,
ThemeData data,
TerminalPalette palette,
) async {
late TerminalTheme theme;
await tester.pumpWidget(
MaterialApp(
theme: data,
home: Builder(
builder: (context) {
theme = chatShellTerminalTheme(context, palette: palette);
return const SizedBox();
},
),
),
);
return theme;
}
void main() {
for (final (name, data) in [
('light', appLightTheme()),
('dark', appDarkTheme()),
]) {
final dark = data.brightness == Brightness.dark;
for (final palette in TerminalPalette.values) {
testWidgets('$name theme, ${palette.label}: colours keep their '
'contrast on the background and under customary text', (
tester,
) async {
final t = await _theme(tester, data, palette);
final ansi = _ansi(t);
final bg = t.background;
void atLeast(Color a, Color b, double ratio, String what) => expect(
terminalContrast(a, b),
greaterThanOrEqualTo(ratio),
reason: '$name ${palette.label}: $what',
);
atLeast(t.foreground, bg, 7, 'text on the background');
for (var i = 1; i <= 6; i++) {
atLeast(ansi[i], bg, 4.5, '${_names[i]} on the background');
atLeast(
ansi[i + 8],
bg,
dark ? 4.5 : 3,
'${_names[i + 8]} on the background',
);
// Bright and normal are told apart, the bright one lighter.
expect(
ansi[i + 8].computeLuminance(),
greaterThan(ansi[i].computeLuminance()),
reason: '$name ${palette.label}: ${_names[i + 8]} is lighter',
);
atLeast(ansi[i + 8], ansi[i], 1.15, '${_names[i]} vs bright');
final text = terminalWhiteTextColours.contains(i) ? 7 : 0;
atLeast(
ansi[text],
ansi[i],
3,
'${_names[text]} text on ${_names[i]} (ls colours)',
);
}
atLeast(ansi[8], bg, 3, 'bright black (dim text)');
atLeast(ansi[dark ? 7 : 0], bg, 4.5, 'white/black text');
atLeast(ansi[15], ansi[0], 7, 'bright white vs black');
// White is light and black dark in both themes.
expect(ansi[7].computeLuminance(), greaterThan(0.6));
expect(ansi[0].computeLuminance(), lessThan(0.05));
// The block cursor redraws its character in the background colour.
atLeast(t.cursor, bg, 4.5, 'cursor');
for (final (what, tint) in [
('selection', t.selection),
('find match', t.searchHitBackground),
('current find match', t.searchHitBackgroundCurrent),
]) {
atLeast(
_blend(tint, t.foreground),
_blend(tint, bg),
4.5,
'text under the $what',
);
atLeast(_blend(tint, bg), bg, 1.15, 'the $what shows');
}
atLeast(
_blend(t.searchHitBackgroundCurrent, bg),
_blend(t.searchHitBackground, bg),
1.15,
'the current match stands out from the others',
);
});
}
}
test('palettes differ from each other', () {
final colours = {
for (final palette in TerminalPalette.values)
chatShellTerminalPalette(palette, Colors.white)[1].toARGB32(),
};
expect(colours, hasLength(TerminalPalette.values.length));
});
test('a colour already readable is kept as it is', () {
// The standard palette's red on white needs no change.
expect(
chatShellTerminalPalette(TerminalPalette.theme, Colors.white)[1],
const Color(0xFFCD3131),
);
});
}
@@ -77,6 +77,30 @@ void main() {
expect(saved().containsKey('font_size'), isFalse);
});
testWidgets('the colour palette is chosen in Settings, saved and '
'restored', (tester) async {
await pump(tester);
expect(find.text('Colours'), findsOneWidget);
await tester.tap(find.byType(DropdownMenu<TerminalPalette>));
await tester.pumpAndSettle();
for (final palette in TerminalPalette.values) {
expect(find.text(palette.label), findsWidgets);
}
await tester.tap(find.text('Calm').last);
await tester.pumpAndSettle();
expect(layout.palette, TerminalPalette.calm);
expect(saved()['palette'], 'calm');
final restored = TerminalLayout(store: store);
await restored.restore();
expect(restored.palette, TerminalPalette.calm);
});
test('an unknown saved palette restores the theme colours', () async {
store.saved = jsonEncode({'palette': 'nonesuch'});
await layout.restore();
expect(layout.palette, TerminalPalette.theme);
});
testWidgets('a zoom from the keyboard shows in the menu at once', (
tester,
) async {
@@ -7,6 +7,8 @@ import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'terminal_app.dart';
import 'terminal_fixtures.dart';
const double _height = 300;
void main() {
late TerminalGateway mac;
late TerminalHub hub;
@@ -15,14 +17,15 @@ void main() {
setUp(() {
mac = TerminalGateway()..add('term_a', cwd: '/Users/op/src');
hub = TerminalHub(TestMachines([machine('mac', mac, name: 'Mac')]));
layout = TerminalLayout(store: MemoryLayoutStore());
// A set height keeps the motion's arithmetic simple.
layout = TerminalLayout(store: MemoryLayoutStore())..panelHeight = _height;
});
tearDown(() async {
hub.dispose();
await mac.close();
});
const shown = 800 - terminalPanelDefaultHeight;
const shown = 800 - _height;
double appBottom(WidgetTester tester) =>
tester.getRect(find.byType(Scaffold).first).bottom;
double panelOpacity(WidgetTester tester) => tester
@@ -55,7 +58,7 @@ void main() {
// panel (at its full height) is partly below the window's edge.
expect(appBottom(tester), inExclusiveRange(shown, 800));
expect(tester.getRect(panelFinder).top, closeTo(appBottom(tester), 1));
expect(tester.getSize(panelFinder).height, terminalPanelDefaultHeight);
expect(tester.getSize(panelFinder).height, _height);
expect(panelOpacity(tester), inExclusiveRange(0.4, 1));
await tester.pumpAndSettle();
expect(appBottom(tester), shown);
@@ -0,0 +1,133 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_panel.dart';
import 'package:pipelines_app/features/terminal/terminal_tab_chip.dart';
import 'terminal_app.dart';
import 'terminal_fixtures.dart';
/// The bottom panel's default height (40 % of the window, at least 16 rows)
/// and the tab strip's tabs: long titles ellipsised with the whole title in
/// the tooltip, the selected tab marked, close buttons of touch size.
void main() {
late TerminalGateway mac;
late TerminalHub hub;
late TerminalLayout layout;
setUp(() {
mac = TerminalGateway()
..add('term_a', cwd: '/Users/op/src', text: r'$ ')
..add(
'term_b',
cwd: '/Users/op/a/rather/deep/folder/with/a/long/name/that/goes/on',
text: r'$ ',
);
layout = TerminalLayout(store: MemoryLayoutStore())..visible = true;
hub = TerminalHub(
TestMachines([machine('mac', mac, name: 'Mac')]),
layout: layout,
);
});
tearDown(() async {
hub.dispose();
await mac.close();
});
test('the default height is 40 % of the window, at least 16 rows', () {
expect(terminalPanelDefaultHeight(1000, 17), 400);
expect(terminalPanelDefaultHeight(600, 17), 16 * 17 + terminalPanelChrome);
// A short window still leaves the app its share.
expect(
terminalPanelHeight(null, 400, rowHeight: 17),
400 - terminalPanelAppMin,
);
expect(terminalPanelHeight(500, 1000, rowHeight: 17), 500);
});
test('a layout saved with the old fixed default reads as never resized; '
'a dragged height is restored', () async {
final store = MemoryLayoutStore();
await store.save(jsonEncode({'panel_height': 300}));
final legacy = TerminalLayout(store: store);
await legacy.restore();
expect(legacy.panelHeight, isNull);
await store.save(jsonEncode({'panel_height': 412.5}));
final dragged = TerminalLayout(store: store);
await dragged.restore();
expect(dragged.panelHeight, 412.5);
});
for (final size in const [Size(1280, 900), Size(1920, 1080)]) {
testWidgets('at ${size.width.round()}x${size.height.round()} the panel '
'opens at 40 % of the window and shows at least 16 rows', (
tester,
) async {
await pumpTerminalApp(tester, hub: hub, layout: layout, size: size);
await tester.pumpAndSettle();
final panel = tester.getSize(panelFinder).height;
expect(panel, greaterThanOrEqualTo(size.height * 0.4 - 1));
// The emulator lays out its rows after the debounced resize.
await tester.pump(const Duration(milliseconds: 300));
expect(
hub.selected!.session.terminal.viewHeight,
greaterThanOrEqualTo(16),
);
});
}
testWidgets('a long tab title ends in an ellipsis and its tooltip has it '
'whole; the selected tab is marked; close buttons are at least 40 px', (
tester,
) async {
await pumpTerminalApp(tester, hub: hub, layout: layout);
await tester.pumpAndSettle();
final chips = find.byType(TerminalTabChip);
expect(chips, findsNWidgets(2));
final long = tester.widget<TerminalTabChip>(chips.last);
final title = find.descendant(of: chips.last, matching: find.byType(Text));
expect(
tester.getSize(title.first).width,
lessThanOrEqualTo(terminalTabTitleMaxWidth),
);
expect(tester.widget<Text>(title.first).overflow, TextOverflow.ellipsis);
expect(long.tooltip, contains(long.title));
expect(long.tooltip, contains('Mac: /Users/op/a/rather/deep'));
expect(tester.widget<TerminalTabChip>(chips.first).selected, isTrue);
expect(long.selected, isFalse);
final selectedText = tester.widget<Text>(
find.descendant(of: chips.first, matching: find.byType(Text)).first,
);
expect(selectedText.style?.fontWeight, FontWeight.w700);
for (final close
in tester
.elementList(find.byTooltip('Close terminal'))
.map((element) => element.renderObject! as RenderBox)) {
expect(close.size.width, greaterThanOrEqualTo(40));
expect(close.size.height, greaterThanOrEqualTo(40));
}
// Selecting by the title.
await tester.tap(title.first);
await tester.pumpAndSettle();
expect(hub.selected!.info.id, 'term_b');
});
testWidgets(
'on a touch platform the close buttons are 48 px',
(tester) async {
await pumpTerminalApp(tester, hub: hub, layout: layout);
await tester.pumpAndSettle();
final close = tester.getSize(
find.widgetWithIcon(IconButton, Icons.close).first,
);
expect(close.width, greaterThanOrEqualTo(48));
expect(close.height, greaterThanOrEqualTo(48));
},
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
}
@@ -7,6 +7,7 @@ import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_keys.dart'
import 'package:pipelines_app/features/settings/settings_terminal_section.dart';
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_panel.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import 'package:xterm/xterm.dart';
@@ -95,7 +96,9 @@ void main() {
final before = tester
.getSize(find.byKey(const ValueKey('terminal-panel')))
.height;
expect(before, terminalPanelDefaultHeight);
// Never resized: the default follows the window, and is not saved.
expect(before, greaterThanOrEqualTo(800 * terminalPanelDefaultFraction));
expect(saved().containsKey('panel_height'), isFalse);
await tester.drag(
find.byKey(const ValueKey('terminal-panel-resize')),
const Offset(0, -120),
@@ -81,7 +81,7 @@ void main() {
await drain(tester);
expect(find.text('app'), findsOneWidget);
expect(hub.tabs.first.cwd, '/Users/op/src/app');
expect(find.byTooltip('Mac: /Users/op/src/app'), findsOneWidget);
expect(find.byTooltip('app\nMac: /Users/op/src/app'), findsOneWidget);
mac.write('term_a', '\x1b]0;vim notes\x07');
await drain(tester);
expect(find.text('vim notes'), findsOneWidget);
+62
View File
@@ -266,6 +266,68 @@ void main() {
expect(find.text('count 1'), findsOneWidget, reason: '$width');
}
});
// A tall terminal panel leaves the app (and the rail beside it) as little
// as 160 px: the tabs scroll, and below the pinned height Settings scrolls
// with them, so no two items ever overlap.
for (final height in const [160.0, 200.0, 260.0, 340.0, 420.0, 800.0]) {
testWidgets('a rail ${height.round()} px tall never overlaps its items', (
tester,
) async {
await pumpShell(tester, width: 1000, height: height);
expect(tester.takeException(), isNull);
final keys = [
for (final destination in [
...shellTabDestinations,
AppDestination.settings,
])
ValueKey('shell.destination.${destination.name}'),
];
// What shows of each: the scrolling group clips what is scrolled
// away.
final viewport = tester.getRect(
find.descendant(
of: find.byType(NavigationRail),
matching: find.byType(SingleChildScrollView),
),
);
Rect shown(Key key) {
final finder = find.byKey(key).first;
final rect = tester.getRect(finder);
final scrolls = find
.ancestor(of: finder, matching: find.byType(SingleChildScrollView))
.evaluate()
.isNotEmpty;
return scrolls ? rect.intersect(viewport) : rect;
}
final rects = [for (final key in keys) shown(key)];
for (var i = 0; i < rects.length; i++) {
for (var j = i + 1; j < rects.length; j++) {
expect(
rects[i].overlaps(rects[j]) &&
!rects[i].isEmpty &&
!rects[j].isEmpty,
isFalse,
reason: '${keys[i]} and ${keys[j]} at $height',
);
}
}
// Settings stays reachable: scrolled to, it is on screen and tappable.
await tester.dragUntilVisible(
find.byKey(keys.last),
find.descendant(
of: find.byType(NavigationRail),
matching: find.byType(SingleChildScrollView),
),
const Offset(0, -40),
);
expect(
tester.getRect(find.byKey(keys.last)).bottom,
lessThanOrEqualTo(height + 0.5),
);
});
}
}
class _Counter extends StatefulWidget {