Merge branch 'worktree-agent-a34c5b595a9afef6e'
This commit is contained in:
@@ -14,21 +14,31 @@ const String chatShellShareLabel = 'Send to agent';
|
||||
const String chatShellSharingLabel = 'Sending…';
|
||||
const String chatShellSharedLabel = 'Sent to agent';
|
||||
const String chatShellFullScreenLabel = 'Full screen';
|
||||
const String chatShellExpandLabel = 'Expand';
|
||||
const String chatShellCollapseLabel = 'Collapse';
|
||||
|
||||
/// The card's host buttons: Stop while running; Copy output, Send to agent
|
||||
/// once finished; Full screen for the terminal.
|
||||
/// once finished; Expand or Collapse (when [onExpand] is given) and Full
|
||||
/// screen for the terminal.
|
||||
class ChatShellCardActions extends StatefulWidget {
|
||||
const ChatShellCardActions({
|
||||
super.key,
|
||||
required this.run,
|
||||
required this.controller,
|
||||
required this.onFullScreen,
|
||||
this.expanded = false,
|
||||
this.onExpand,
|
||||
});
|
||||
|
||||
final ChatShellRun run;
|
||||
final ChatShellRunsController controller;
|
||||
final VoidCallback onFullScreen;
|
||||
|
||||
/// Whether the terminal is expanded, and the toggle (null: nothing to
|
||||
/// expand, the output fits collapsed).
|
||||
final bool expanded;
|
||||
final VoidCallback? onExpand;
|
||||
|
||||
@override
|
||||
State<ChatShellCardActions> createState() => _ChatShellCardActionsState();
|
||||
}
|
||||
@@ -100,6 +110,15 @@ class _ChatShellCardActionsState extends State<ChatShellCardActions> {
|
||||
? () => unawaited(controller.share(run.id))
|
||||
: null,
|
||||
),
|
||||
if (widget.onExpand case final toggle?)
|
||||
_button(
|
||||
key: const Key('chat-shell-run-size'),
|
||||
label: widget.expanded
|
||||
? chatShellCollapseLabel
|
||||
: chatShellExpandLabel,
|
||||
material: widget.expanded ? Icons.unfold_less : Icons.unfold_more,
|
||||
onPressed: toggle,
|
||||
),
|
||||
if (run.running || run.output.isNotEmpty)
|
||||
_button(
|
||||
key: const Key('chat-shell-run-expand'),
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
/// The one layout bound of a shell command card: how many terminal rows its
|
||||
/// output area shows. A running command's terminal has this many rows; a
|
||||
/// finished one shrinks to the rows its output uses, up to this many, and
|
||||
/// scrolls within them. Full screen takes the whole window instead.
|
||||
/// The layout bounds of a shell command card's output area, in terminal
|
||||
/// rows. Collapsed (the default), a running command's terminal has
|
||||
/// [kChatShellOutputCollapsedLines] rows; a finished one shrinks to the rows
|
||||
/// its output uses, up to this many, and scrolls within them. Expanded, the
|
||||
/// bound is [kChatShellOutputExpandedFraction] of the window's height (never
|
||||
/// fewer rows than collapsed). Full screen takes the whole window instead.
|
||||
const int kChatShellOutputCollapsedLines = 12;
|
||||
|
||||
/// The share of the window's height an expanded card's terminal may take.
|
||||
const double kChatShellOutputExpandedFraction = 0.6;
|
||||
|
||||
@@ -16,6 +16,7 @@ class ChatShellOutputView extends StatelessWidget {
|
||||
required this.controller,
|
||||
required this.viewKey,
|
||||
required this.fullScreen,
|
||||
this.expanded = false,
|
||||
});
|
||||
|
||||
final ChatShellRun run;
|
||||
@@ -28,6 +29,10 @@ class ChatShellOutputView extends StatelessWidget {
|
||||
/// True while the full-screen view sizes the terminal.
|
||||
final bool fullScreen;
|
||||
|
||||
/// Whether the card shows its terminal expanded (see
|
||||
/// [ChatShellTerminalView.expanded]).
|
||||
final bool expanded;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!run.running && run.output.isEmpty) {
|
||||
@@ -45,6 +50,7 @@ class ChatShellOutputView extends StatelessWidget {
|
||||
ChatShellTerminalView(
|
||||
key: viewKey,
|
||||
session: session,
|
||||
expanded: expanded,
|
||||
autoResize: !fullScreen,
|
||||
),
|
||||
if (session.live && !fullScreen)
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../../../ui/text/monospace.dart';
|
||||
import '../conversation/chat_card_styles.dart';
|
||||
import 'chat_shell_card_actions.dart';
|
||||
import 'chat_shell_dismiss.dart';
|
||||
import 'chat_shell_metrics.dart';
|
||||
import 'chat_shell_output_view.dart';
|
||||
import 'chat_shell_run.dart';
|
||||
import 'chat_shell_runs_controller.dart';
|
||||
@@ -38,8 +39,20 @@ class ChatShellRunCard extends StatefulWidget {
|
||||
|
||||
class _ChatShellRunCardState extends State<ChatShellRunCard> {
|
||||
bool _fullScreen = false;
|
||||
bool _expanded = false;
|
||||
int _viewGeneration = 0;
|
||||
|
||||
/// Whether expanding would show more: a live terminal grows to the
|
||||
/// window; other output only if it has more rows than the collapsed box
|
||||
/// (at the width it was laid out at).
|
||||
bool _expandable(ChatShellRun run) {
|
||||
if (!run.running && run.output.isEmpty) return false;
|
||||
final session = widget.controller.terminals.session(run);
|
||||
return session.live ||
|
||||
session.rowsAt(session.terminal.viewWidth) >
|
||||
kChatShellOutputCollapsedLines;
|
||||
}
|
||||
|
||||
Future<void> _openFullScreen() async {
|
||||
setState(() => _fullScreen = true);
|
||||
await openChatShellTerminalPage(
|
||||
@@ -127,6 +140,7 @@ class _ChatShellRunCardState extends State<ChatShellRunCard> {
|
||||
controller: controller,
|
||||
viewKey: ValueKey<int>(_viewGeneration),
|
||||
fullScreen: _fullScreen,
|
||||
expanded: _expanded,
|
||||
),
|
||||
if (run.error.isNotEmpty && !run.running)
|
||||
Padding(
|
||||
@@ -138,6 +152,10 @@ class _ChatShellRunCardState extends State<ChatShellRunCard> {
|
||||
run: run,
|
||||
controller: controller,
|
||||
onFullScreen: () => _openFullScreen(),
|
||||
expanded: _expanded,
|
||||
onExpand: _expanded || _expandable(run)
|
||||
? () => setState(() => _expanded = !_expanded)
|
||||
: null,
|
||||
),
|
||||
if (error != null)
|
||||
Semantics(
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'chat_shell_terminal_actions.dart';
|
||||
import 'chat_shell_terminal_find.dart';
|
||||
import 'chat_shell_terminal_find_bar.dart';
|
||||
import 'chat_shell_terminal_session.dart';
|
||||
import 'chat_shell_terminal_theme.dart';
|
||||
|
||||
/// A terminal view's find in the scrollback: opening the bar (or focusing
|
||||
/// it), stepping between matches and scrolling each into view, and closing
|
||||
@@ -29,13 +30,13 @@ mixin ChatShellTerminalFindHost<T extends StatefulWidget> on State<T> {
|
||||
_findFocus.requestFocus();
|
||||
return;
|
||||
}
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final colours = chatShellTerminalMatchColours(context);
|
||||
setState(() {
|
||||
_find = ChatShellTerminalFind(
|
||||
terminal: session.terminal,
|
||||
controller: controller,
|
||||
hit: scheme.tertiary.withValues(alpha: 0.3),
|
||||
current: scheme.tertiary.withValues(alpha: 0.6),
|
||||
hit: colours.hit,
|
||||
current: colours.current,
|
||||
);
|
||||
});
|
||||
// The field's autofocus would not take the keyboard from the terminal,
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
import 'package:flutter/painting.dart';
|
||||
|
||||
import '../../terminal/terminal_layout.dart';
|
||||
|
||||
/// The contrast the sixteen ANSI colours keep, as WCAG contrast ratios.
|
||||
abstract final class TerminalContrast {
|
||||
/// Red, green, yellow, blue, magenta and cyan, and white on a dark
|
||||
/// background (black on a light one), against the background: body text.
|
||||
static const double text = 4.5;
|
||||
|
||||
/// The bright colours on a light background, and bright black (dim text,
|
||||
/// suggestions) on either: secondary text.
|
||||
static const double secondary = 3;
|
||||
|
||||
/// White text on the normal colours as backgrounds (`ls` setuid is white
|
||||
/// on red) and black text on them (setgid, sticky directories).
|
||||
static const double onColour = 3;
|
||||
|
||||
/// How far each bright colour stands from its normal one, lighter.
|
||||
static const double brightStep = 1.2;
|
||||
}
|
||||
|
||||
/// The normal colours programs customarily put white text on (red, blue,
|
||||
/// magenta: `ls` setuid, dialog boxes); black text goes on the others
|
||||
/// (green, yellow, cyan: setgid, sticky directories, status bars).
|
||||
const Set<int> terminalWhiteTextColours = {1, 4, 5};
|
||||
|
||||
/// The sixteen ANSI colours (black, red, green, yellow, blue, magenta, cyan,
|
||||
/// white, then the bright ones) of [palette] for a terminal drawn on
|
||||
/// [background], adjusted to meet [TerminalContrast]: each colour keeps its
|
||||
/// hue and saturation and moves only in lightness, and only as far as needed.
|
||||
///
|
||||
/// White stays light and black dark in both themes, so the coloured
|
||||
/// backgrounds keep their customary text readable (see
|
||||
/// [terminalWhiteTextColours]); as in other terminals, white text on a light
|
||||
/// background and black on a dark one are faint.
|
||||
List<Color> chatShellTerminalPalette(
|
||||
TerminalPalette palette,
|
||||
Color background,
|
||||
) => _computed.putIfAbsent((
|
||||
palette,
|
||||
background.toARGB32(),
|
||||
), () => List.unmodifiable(_adjust(palette, background)));
|
||||
|
||||
/// Adjusted palettes by palette and background (a handful per app run).
|
||||
final Map<(TerminalPalette, int), List<Color>> _computed = {};
|
||||
|
||||
List<Color> _adjust(TerminalPalette palette, Color background) {
|
||||
final base = [for (final value in _bases[palette]!) Color(value)];
|
||||
final bg = background.computeLuminance();
|
||||
final dark = bg < 0.5;
|
||||
final out = List.of(base);
|
||||
// Black and white first: the colours under text are bounded by them.
|
||||
out[0] = _within(base[0], 0, dark ? 0.03 : 0.015);
|
||||
final black = out[0].computeLuminance();
|
||||
out[8] = _within(
|
||||
base[8],
|
||||
_above(dark ? bg : black, TerminalContrast.secondary),
|
||||
_below(dark ? 1 : bg, TerminalContrast.secondary),
|
||||
);
|
||||
// On a light background white rises to the normal colours chosen below.
|
||||
out[7] = _within(base[7], dark ? 0.78 : 0, 1);
|
||||
final readable = dark
|
||||
? (low: _above(bg, TerminalContrast.text), high: 1.0)
|
||||
: (low: 0.0, high: _below(bg, TerminalContrast.text));
|
||||
final brightHigh = dark ? 1.0 : _below(bg, TerminalContrast.secondary);
|
||||
var whiteNeeded = 0.0;
|
||||
for (var i = 1; i <= 6; i++) {
|
||||
final white = terminalWhiteTextColours.contains(i);
|
||||
final textHigh = white && dark
|
||||
? _below(out[7].computeLuminance(), TerminalContrast.onColour)
|
||||
: 1.0;
|
||||
final textLow = white ? 0.0 : _above(black, TerminalContrast.onColour);
|
||||
out[i] = _within(
|
||||
base[i],
|
||||
_max(readable.low, textLow),
|
||||
_min(readable.high, textHigh),
|
||||
);
|
||||
final normal = out[i].computeLuminance();
|
||||
if (white) {
|
||||
whiteNeeded = _max(
|
||||
whiteNeeded,
|
||||
_above(normal, TerminalContrast.onColour),
|
||||
);
|
||||
}
|
||||
out[i + 8] = _within(
|
||||
base[i + 8],
|
||||
_max(
|
||||
_above(normal, TerminalContrast.brightStep),
|
||||
dark ? readable.low : 0,
|
||||
),
|
||||
brightHigh,
|
||||
);
|
||||
}
|
||||
out[7] = _within(out[7], whiteNeeded, 1);
|
||||
out[15] = _within(base[15], out[7].computeLuminance(), 1);
|
||||
return out;
|
||||
}
|
||||
|
||||
double _max(double a, double b) => a > b ? a : b;
|
||||
double _min(double a, double b) => a < b ? a : b;
|
||||
|
||||
/// The WCAG contrast ratio of two colours.
|
||||
double terminalContrast(Color a, Color b) {
|
||||
final la = a.computeLuminance();
|
||||
final lb = b.computeLuminance();
|
||||
return la > lb ? (la + 0.05) / (lb + 0.05) : (lb + 0.05) / (la + 0.05);
|
||||
}
|
||||
|
||||
/// The luminance [ratio] above / below [luminance].
|
||||
double _above(double luminance, double ratio) =>
|
||||
((luminance + 0.05) * ratio - 0.05).clamp(0, 1);
|
||||
double _below(double luminance, double ratio) =>
|
||||
((luminance + 0.05) / ratio - 0.05).clamp(0, 1);
|
||||
|
||||
/// [color] moved in lightness until its luminance is within [low]..[high]
|
||||
/// (at [low] when the range is empty: the lower bound wins).
|
||||
Color _within(Color color, double low, double high) {
|
||||
final luminance = color.computeLuminance();
|
||||
if (high < low || luminance < low) return _toLuminance(color, low);
|
||||
if (luminance > high) return _toLuminance(color, high);
|
||||
return color;
|
||||
}
|
||||
|
||||
/// [color] at the HSL lightness whose luminance is [target], by bisection
|
||||
/// (luminance grows with lightness at a fixed hue and saturation); rounded
|
||||
/// to the side that keeps the bound.
|
||||
Color _toLuminance(Color color, double target) {
|
||||
final hsl = HSLColor.fromColor(color);
|
||||
final up = target > color.computeLuminance();
|
||||
var lo = up ? hsl.lightness : 0.0;
|
||||
var hi = up ? 1.0 : hsl.lightness;
|
||||
for (var i = 0; i < 24; i++) {
|
||||
final mid = (lo + hi) / 2;
|
||||
if (hsl.withLightness(mid).toColor().computeLuminance() < target) {
|
||||
lo = mid;
|
||||
} else {
|
||||
hi = mid;
|
||||
}
|
||||
}
|
||||
// 8-bit channels round; step a little further so the bound holds.
|
||||
final settle = up
|
||||
? (hi + 0.004).clamp(0.0, 1.0)
|
||||
: (lo - 0.004).clamp(0.0, 1.0);
|
||||
return hsl.withLightness(settle).toColor();
|
||||
}
|
||||
|
||||
/// Each palette's colours before adjustment, ARGB, in ANSI order.
|
||||
const Map<TerminalPalette, List<int>> _bases = {
|
||||
// The emulator's standard palette (the colours this app always used).
|
||||
TerminalPalette.theme: [
|
||||
0xFF000000, 0xFFCD3131, 0xFF0DBC79, 0xFFE5E510, //
|
||||
0xFF2472C8, 0xFFBC3FBC, 0xFF11A8CD, 0xFFE5E5E5,
|
||||
0xFF666666, 0xFFF14C4C, 0xFF23D18B, 0xFFF5F543,
|
||||
0xFF3B8EEA, 0xFFD670D6, 0xFF29B8DB, 0xFFFFFFFF,
|
||||
],
|
||||
// The long-standing desktop terminal default (Tango-like).
|
||||
TerminalPalette.classic: [
|
||||
0xFF2E3436, 0xFFCC0000, 0xFF4E9A06, 0xFFC4A000, //
|
||||
0xFF3465A4, 0xFF75507B, 0xFF06989A, 0xFFD3D7CF,
|
||||
0xFF555753, 0xFFEF2929, 0xFF8AE234, 0xFFFCE94F,
|
||||
0xFF729FCF, 0xFFAD7FA8, 0xFF34E2E2, 0xFFEEEEEC,
|
||||
],
|
||||
// Muted, warm accents of even lightness (Solarized-like).
|
||||
TerminalPalette.calm: [
|
||||
0xFF073642, 0xFFDC322F, 0xFF859900, 0xFFB58900, //
|
||||
0xFF268BD2, 0xFFD33682, 0xFF2AA198, 0xFFEEE8D5,
|
||||
0xFF586E75, 0xFFF0605C, 0xFFA8BF2A, 0xFFD9A825,
|
||||
0xFF5AAEEA, 0xFFE86AA6, 0xFF4FC4B8, 0xFFFDF6E3,
|
||||
],
|
||||
// Soft pastel accents (One-like).
|
||||
TerminalPalette.vivid: [
|
||||
0xFF282C34, 0xFFE06C75, 0xFF98C379, 0xFFE5C07B, //
|
||||
0xFF61AFEF, 0xFFC678DD, 0xFF56B6C2, 0xFFABB2BF,
|
||||
0xFF5C6370, 0xFFFF8A93, 0xFFB5E890, 0xFFFFD68A,
|
||||
0xFF8CC8FF, 0xFFDE9BF0, 0xFF7FD4DE, 0xFFFFFFFF,
|
||||
],
|
||||
};
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -6,9 +6,10 @@ import 'settings_group.dart';
|
||||
/// The text sizes the setting offers (besides Default and the current one).
|
||||
const List<double> _fontSizes = [10, 11, 12, 13, 14, 15, 16, 18, 20, 24];
|
||||
|
||||
/// Appearance → Terminal's text size, scrollback and bell controls.
|
||||
/// Appearance → Terminal's text size, colours, scrollback and bell controls.
|
||||
List<Widget> settingsTerminalControls(TerminalLayout layout) => [
|
||||
SettingsGroupItem(child: _FontSize(layout: layout)),
|
||||
SettingsGroupItem(child: _Palette(layout: layout)),
|
||||
SettingsGroupItem(child: _Scrollback(layout: layout)),
|
||||
SwitchListTile(
|
||||
key: const ValueKey('settings-terminal-bell'),
|
||||
@@ -54,6 +55,29 @@ class _FontSize extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _Palette extends StatelessWidget {
|
||||
const _Palette({required this.layout});
|
||||
final TerminalLayout layout;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => DropdownMenu<TerminalPalette>(
|
||||
key: ValueKey('settings-terminal-palette-${layout.palette.name}'),
|
||||
expandedInsets: EdgeInsets.zero,
|
||||
label: const Text('Colours'),
|
||||
helperText:
|
||||
'The sixteen terminal colours, adjusted to the light or dark theme '
|
||||
'so text stays readable.',
|
||||
initialSelection: layout.palette,
|
||||
dropdownMenuEntries: [
|
||||
for (final palette in TerminalPalette.values)
|
||||
DropdownMenuEntry(value: palette, label: palette.label),
|
||||
],
|
||||
onSelected: (palette) {
|
||||
if (palette != null) layout.setPalette(palette);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _Scrollback extends StatelessWidget {
|
||||
const _Scrollback({required this.layout});
|
||||
final TerminalLayout layout;
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'settings_theme.dart';
|
||||
|
||||
/// Appearance → Terminal: whether the terminal docks at the bottom of the
|
||||
/// window or floats over it (Ctrl+` shows and hides it either way), the
|
||||
/// Option key, text size, scrollback length and visual bell.
|
||||
/// Option key, text size, colours, scrollback length and visual bell.
|
||||
class SettingsTerminalSection extends StatelessWidget {
|
||||
const SettingsTerminalSection({super.key, required this.layout});
|
||||
|
||||
|
||||
@@ -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)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ const double kNavigationRailSpace = kNavigationRailWidth + 1;
|
||||
const double kNavigationRailMinWindowWidth =
|
||||
kListDetailMinWidth + kNavigationRailSpace;
|
||||
|
||||
/// The rail's height below which Settings scrolls with the tabs instead of
|
||||
/// staying pinned to the rail's foot: room for Settings and about two tabs.
|
||||
const double kNavigationRailPinnedSettingsMinHeight = 240;
|
||||
|
||||
/// Whether the window at [context] shows the destination rail. Read from the
|
||||
/// window's own [MediaQuery], so the shell and the floating windows layer
|
||||
/// (which sits above the shell) agree.
|
||||
@@ -32,6 +36,10 @@ bool showsFloatingTabBarOnly(BuildContext context) =>
|
||||
/// an icon and a label per tab, the selected tab marked by the rail's
|
||||
/// indicator, and Settings pinned to its bottom.
|
||||
///
|
||||
/// The tabs scroll when the rail is too short for them (a tall terminal
|
||||
/// panel shrinks the app above it), and on a very short rail Settings
|
||||
/// scrolls with them, so items never overlap at any height.
|
||||
///
|
||||
/// [icon] builds each tab's icon (its running or unread badge included), so
|
||||
/// the rail shows the same counts the floating bar did. [selected] is the
|
||||
/// shell's destination: Settings (a page, not a tab) selects no tab but its
|
||||
@@ -67,38 +75,50 @@ class ShellNavigationRail extends StatelessWidget {
|
||||
padding: padding,
|
||||
child: SizedBox(
|
||||
width: kNavigationRailWidth,
|
||||
child: NavigationRail(
|
||||
key: const ValueKey('shell.navigation-rail'),
|
||||
backgroundColor: surface,
|
||||
minWidth: kNavigationRailWidth,
|
||||
labelType: NavigationRailLabelType.all,
|
||||
selectedIndex: index < 0 ? null : index,
|
||||
onDestinationSelected: (value) =>
|
||||
onSelected(shellTabDestinations[value]),
|
||||
destinations: [
|
||||
for (final destination in shellTabDestinations)
|
||||
NavigationRailDestination(
|
||||
icon: KeyedSubtree(
|
||||
key: ValueKey('shell.destination.${destination.name}'),
|
||||
// The bar it replaces named each tab in a tooltip too.
|
||||
child: Tooltip(
|
||||
message: destinationDetails(destination).label,
|
||||
child: icon(destination),
|
||||
),
|
||||
),
|
||||
label: Text(destinationDetails(destination).label),
|
||||
),
|
||||
],
|
||||
trailingAtBottom: true,
|
||||
trailing: _SettingsRailItem(
|
||||
selected: selected == AppDestination.settings,
|
||||
onTap: () => onSelected(AppDestination.settings),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => _rail(
|
||||
index,
|
||||
surface,
|
||||
pinSettings:
|
||||
constraints.maxHeight >=
|
||||
kNavigationRailPinnedSettingsMinHeight,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _rail(int index, Color surface, {required bool pinSettings}) =>
|
||||
NavigationRail(
|
||||
key: const ValueKey('shell.navigation-rail'),
|
||||
backgroundColor: surface,
|
||||
minWidth: kNavigationRailWidth,
|
||||
labelType: NavigationRailLabelType.all,
|
||||
selectedIndex: index < 0 ? null : index,
|
||||
onDestinationSelected: (value) =>
|
||||
onSelected(shellTabDestinations[value]),
|
||||
destinations: [
|
||||
for (final destination in shellTabDestinations)
|
||||
NavigationRailDestination(
|
||||
icon: KeyedSubtree(
|
||||
key: ValueKey('shell.destination.${destination.name}'),
|
||||
// The bar it replaces named each tab in a tooltip too.
|
||||
child: Tooltip(
|
||||
message: destinationDetails(destination).label,
|
||||
child: icon(destination),
|
||||
),
|
||||
),
|
||||
label: Text(destinationDetails(destination).label),
|
||||
),
|
||||
],
|
||||
scrollable: true,
|
||||
trailingAtBottom: pinSettings,
|
||||
trailing: _SettingsRailItem(
|
||||
selected: selected == AppDestination.settings,
|
||||
onTap: () => onSelected(AppDestination.settings),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Settings at the rail's foot, drawn as a [NavigationRailDestination] is: an
|
||||
|
||||
@@ -68,9 +68,15 @@ tmux inside it for work that must survive that).
|
||||
emulator is not resized during the motion); the floating window scales
|
||||
from 92 % and fades in its own place. During the hide motion the terminal
|
||||
stays mounted but takes no pointer or focus (`terminal_stage.dart`).
|
||||
- **Bottom panel:** resized by dragging its top edge (the app's
|
||||
`AdaptiveResizeGrip`; arrow keys too, slider semantics); its height is
|
||||
remembered. The panel always leaves the app at least 160 px.
|
||||
- **Bottom panel:** opens at 40 % of the window, and at least 16 terminal
|
||||
rows (`terminalPanelDefaultHeight`), until the operator resizes it by
|
||||
dragging its top edge (the app's `AdaptiveResizeGrip`; arrow keys too,
|
||||
slider semantics); the dragged height is remembered (`panel_height`; a
|
||||
layout saved with the old fixed 300 px default reads as never resized).
|
||||
The panel always leaves the app at least 160 px. The destination rail
|
||||
beside the app scrolls its tabs when the panel leaves it too little
|
||||
height, and below 240 px Settings scrolls with them instead of staying
|
||||
pinned, so rail items never overlap.
|
||||
- **Floating window:** dragged by its title bar, resized from its lower
|
||||
right corner, double-click or Maximise fills the app (8 px margin),
|
||||
Minimise collapses it to its title bar, × hides it. Frame and state are
|
||||
@@ -172,6 +178,43 @@ context menu, Ctrl+= zoom, OSC 8 link hover underline; a synthetic
|
||||
`contextmenu` event over the terminal is default-prevented, elsewhere not.
|
||||
The capture kit gained `rightclick=<target>`.
|
||||
|
||||
## Theme and layout polish (round 3, 2026-11-26)
|
||||
|
||||
- **Colours** (`chat_shell_terminal_palette.dart`, `chat_shell_terminal_theme.dart`):
|
||||
the terminal's background is the theme's lowest surface (white in light,
|
||||
near-black in dark), the foreground the body text colour. Settings →
|
||||
Terminal → Colours offers *Theme colours* (the emulator's standard
|
||||
palette, default), *Classic* (Tango-like), *Calm* (Solarized-like) and
|
||||
*Vivid* (One-like), saved as `palette`. Every palette is adjusted to the
|
||||
background by moving each colour's lightness only as far as needed:
|
||||
red to cyan at 4.5:1 on the background (bright ones 4.5:1 dark, 3:1
|
||||
light, and lighter than their normal colour), bright black 3:1, white
|
||||
light and black dark in both themes so white text on red, blue and
|
||||
magenta (`ls` setuid, dialogs) and black text on green, yellow and cyan
|
||||
(setgid, sticky, status bars) keep 3:1. As in other terminals, white
|
||||
text on a light background and black on a dark one stay faint, and
|
||||
colour-on-colour pairs such as `ls` other-writable (blue on green) are
|
||||
not guaranteed.
|
||||
- **Selection and find:** selection is the accent at 35 %, find matches the
|
||||
tertiary colour at 20 % and the current match at 40 %; all are painted
|
||||
over the text and keep it at 4.5:1. The block cursor (accent) keeps 4.5:1
|
||||
with the character it redraws in the background colour.
|
||||
- **Tabs** (`terminal_tab_chip.dart`): titles ellipsise at 220 px with the
|
||||
whole title, machine and folder in the tooltip; the selected tab is
|
||||
filled, outlined in the accent and bold; the close button is a standard
|
||||
`IconButton` (48 px on touch, 40 px on desktops).
|
||||
- **Chat command cards:** collapsed they keep 12 rows; **Expand** (shown
|
||||
for a live terminal, or output longer than 12 rows) grows the terminal
|
||||
to 60 % of the window's height (`kChatShellOutputExpandedFraction`; a
|
||||
finished run only to its output), and **Collapse** returns.
|
||||
- Evidence: tests `test/features/chat/shell/chat_shell_terminal_palette_test.dart`
|
||||
(contrast of every palette in both themes), `test/features/terminal/
|
||||
terminal_panel_layout_test.dart`, `test/shell/navigation_rail_test.dart`
|
||||
(no overlap at 160-800 px), `chat_shell_run_card_test.dart` (Expand),
|
||||
`settings_terminal_controls_test.dart` (Colours). Capture fixture
|
||||
`?terminalColors=1` prints the palette, backgrounds and `ls` pairs in the
|
||||
home terminal; `?terminalPalette=classic|calm|vivid` picks a palette.
|
||||
|
||||
## Protocol (server)
|
||||
|
||||
`internal/protocol/terminal.go`; documented in `docs/cli.md` ("Machine
|
||||
@@ -490,7 +533,7 @@ software) costs about 2 ms more raster. Runs on this machine vary by about
|
||||
`websocket.go`, `cmd/pipelines-server/main.go`; tests `terminal_ws_test.go`,
|
||||
`terminal_login_test.go`, `terminal_lifetime_test.go`, `terminal_legacy_tmux_test.go`,
|
||||
`internal/pipeline/terminals_test.go`; `docs/cli.md`.
|
||||
- App: `lib/features/terminal/` (`terminal_{info,stream,tab,hub,listing,machines,layout,scope,surface,stage,focus,shortcuts,panel,float,float_frame,page,body,tab_strip,menu,toggle_button,open_action}.dart`),
|
||||
- App: `lib/features/terminal/` (`terminal_{info,stream,tab,hub,listing,machines,layout,scope,surface,stage,focus,shortcuts,panel,float,float_frame,page,body,tab_strip,tab_chip,menu,toggle_button,open_action}.dart`),
|
||||
`lib/application/app_terminals.dart`, `pipelines_app.dart`,
|
||||
`bootstrap.dart`, `lib/shell/adaptive_shell.dart` (`barActions`),
|
||||
`lib/features/settings/settings_terminal_section.dart` (+ screen/topic
|
||||
@@ -500,7 +543,9 @@ software) costs about 2 ms more raster. Runs on this machine vary by about
|
||||
made public), `lib/features/chat/chat_screen_workspace.dart` (Ctrl+Tab
|
||||
yields to a shown terminal). Tests `test/features/terminal/`. Probe fixture
|
||||
`tool/perf/terminal_fixture.dart` (`?terminals=1`, `?terminal=panel|float`,
|
||||
showcases `?terminalAttrs=1`, `?terminalUnicode=1`).
|
||||
showcases `?terminalAttrs=1`, `?terminalUnicode=1`, `?terminalColors=1`,
|
||||
`?terminalPalette=`). Colours: `lib/features/chat/shell/chat_shell_terminal_{theme,palette}.dart`;
|
||||
rail: `lib/shell/navigation_rail.dart`.
|
||||
- Emulator Unicode and drawing: `third_party/xterm/lib/src/utils/unicode_{width,tables}.dart`,
|
||||
`core/buffer/{graphemes,grapheme_join}.dart`, `ui/{cell_glyphs,text_runs,row_pictures,painter}.dart`,
|
||||
`third_party/xterm/tool/gen_unicode_tables.py`; tests
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
// home shell) and terminal_open/input/resize/output/close answer as the
|
||||
// server does, with the output frames that follow. Typed text is echoed and
|
||||
// Enter prints a fresh prompt. `?terminal=panel` or `?terminal=float` opens
|
||||
// the terminal at launch in that mode.
|
||||
// the terminal at launch in that mode; `?terminalPalette=classic` (calm,
|
||||
// vivid) picks a colour palette.
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -61,6 +62,38 @@ const String _unicodeShowcase =
|
||||
'\uE0B1 \uE0B3 |\r\n'
|
||||
'icons: \uF418 \uF09B \uF303 \uE615 \u23FB |\r\n';
|
||||
|
||||
/// `?terminalColors=1`: the sixteen ANSI colours as text on the default
|
||||
/// background, as backgrounds under the default, black and white text, and
|
||||
/// the `ls` colour pairs that use them (setuid white on red, setgid black
|
||||
/// on yellow, sticky other-writable black on green, other-writable blue on
|
||||
/// green), printed into the home terminal after its prompt.
|
||||
String _colourShowcase() {
|
||||
final out = StringBuffer('printf colours\r\n');
|
||||
const names = ['blk', 'red', 'grn', 'yel', 'blu', 'mag', 'cyn', 'wht'];
|
||||
for (final base in [30, 90]) {
|
||||
for (var i = 0; i < 8; i++) {
|
||||
out.write('\x1b[${base + i}m${names[i]}${base + i}\x1b[0m ');
|
||||
}
|
||||
out.write('\r\n');
|
||||
}
|
||||
for (final fg in ['39', '30', '37', '97']) {
|
||||
for (final base in [40, 100]) {
|
||||
for (var i = 0; i < 8; i++) {
|
||||
out.write('\x1b[$fg;${base + i}m${fg.padLeft(2)}/${base + i}\x1b[0m');
|
||||
}
|
||||
out.write(' ');
|
||||
}
|
||||
out.write('\r\n');
|
||||
}
|
||||
out.write(
|
||||
'\x1b[37;41msudo\x1b[0m \x1b[30;43mwall\x1b[0m '
|
||||
'\x1b[30;42mtmp\x1b[0m \x1b[34;42mshared\x1b[0m '
|
||||
'\x1b[1;34mbold-dir\x1b[0m \x1b[1;32mrun.sh\x1b[0m '
|
||||
'\x1b[2mdim\x1b[0m \x1b[7minverse\x1b[0m\r\n',
|
||||
);
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
void configureTerminalFixture(Map<String, String> params) {
|
||||
_enabled = params['terminals'] == '1';
|
||||
if (!_enabled) return;
|
||||
@@ -93,6 +126,9 @@ void configureTerminalFixture(Map<String, String> params) {
|
||||
if (params['terminalAttrs'] == '1') {
|
||||
_output['term_build'] = _output['term_build']! + _attributeShowcase;
|
||||
}
|
||||
if (params['terminalColors'] == '1') {
|
||||
_output['term_home'] = _output['term_home']! + _colourShowcase();
|
||||
}
|
||||
if (params['terminalUnicode'] == '1') {
|
||||
_output['term_build'] = _output['term_build']! + _unicodeShowcase;
|
||||
}
|
||||
@@ -101,6 +137,8 @@ void configureTerminalFixture(Map<String, String> params) {
|
||||
'float' => TerminalMode.float,
|
||||
_ => null,
|
||||
};
|
||||
final palette = TerminalPalette.values.asNameMap()[params['terminalPalette']];
|
||||
if (palette != null) TerminalLayout.instance.palette = palette;
|
||||
if (mode != null) {
|
||||
TerminalLayout.instance
|
||||
..mode = mode
|
||||
|
||||
@@ -889,7 +889,8 @@ class _FixtureSink implements WebSocketSink {
|
||||
/// (tool/perf/perf_fixture.dart);
|
||||
/// `?terminals=1` lists two machine terminals, and `?terminal=panel` or
|
||||
/// `?terminal=float` opens them at launch, with `?terminalAttrs=1` and
|
||||
/// `?terminalUnicode=1` adding emulator showcases
|
||||
/// `?terminalUnicode=1` adding emulator showcases and `?terminalColors=1`
|
||||
/// the ANSI palette
|
||||
/// (tool/perf/terminal_fixture.dart);
|
||||
/// `?windows=N` opens N floating probe windows whose content opens every
|
||||
/// kind of popup and a pushed page (tool/capture/window_probe.dart);
|
||||
|
||||
Reference in New Issue
Block a user