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:
@@ -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),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user