Files
pipelines/app/lib/features/chat/shell/chat_shell_card_actions.dart
T
alan b59ab5fad7 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>
2026-11-26 02:25:16 +00:00

154 lines
4.8 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'chat_shell_run.dart';
import 'chat_shell_runs_controller.dart';
const String chatShellStopLabel = 'Stop';
const String chatShellStoppingLabel = 'Stopping…';
const String chatShellCopyLabel = 'Copy output';
const String chatShellCopiedLabel = 'Copied';
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; 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();
}
class _ChatShellCardActionsState extends State<ChatShellCardActions> {
bool _copied = false;
Timer? _reset;
@override
void dispose() {
_reset?.cancel();
super.dispose();
}
/// Copies the plain text of everything the server kept (no terminal
/// escape sequences), read from the server.
Future<void> _copy() async {
final text = await widget.controller.plainText(widget.run.id);
if (text == null) return;
await Clipboard.setData(ClipboardData(text: text));
if (!mounted) return;
setState(() => _copied = true);
_reset?.cancel();
_reset = Timer(const Duration(seconds: 2), () {
if (mounted) setState(() => _copied = false);
});
}
@override
Widget build(BuildContext context) {
final run = widget.run;
final controller = widget.controller;
final share = controller.shareState(run.id);
final stopping = controller.stopping(run.id);
return Wrap(
spacing: 8,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
if (run.running)
_button(
key: const Key('chat-shell-run-stop'),
label: stopping ? chatShellStoppingLabel : chatShellStopLabel,
material: Icons.stop,
destructive: true,
onPressed: stopping
? null
: () => unawaited(controller.stop(run.id)),
),
if (!run.running && run.outputBytes > 0)
_button(
key: const Key('chat-shell-run-copy'),
label: _copied ? chatShellCopiedLabel : chatShellCopyLabel,
material: _copied ? Icons.check : Icons.copy_outlined,
onPressed: () => unawaited(_copy()),
),
if (!run.running)
_button(
key: const Key('chat-shell-run-share'),
label: switch (share) {
ChatShellShareState.idle => chatShellShareLabel,
ChatShellShareState.sending => chatShellSharingLabel,
ChatShellShareState.sent => chatShellSharedLabel,
},
material: share == ChatShellShareState.sent
? Icons.check
: Icons.send_outlined,
onPressed: share == ChatShellShareState.idle
? () => 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'),
label: chatShellFullScreenLabel,
material: Icons.fullscreen,
onPressed: widget.onFullScreen,
),
],
);
}
Widget _button({
required Key key,
required String label,
required IconData material,
required VoidCallback? onPressed,
bool destructive = false,
}) {
final style = destructive
? TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
)
: null;
return TextButton.icon(
key: key,
style: style,
onPressed: onPressed,
icon: Icon(material),
label: Text(label),
);
}
}