b59ab5fad7
- 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>
175 lines
5.6 KiB
Dart
175 lines
5.6 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
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';
|
|
import 'chat_shell_status.dart';
|
|
import 'chat_shell_terminal_page.dart';
|
|
|
|
/// One operator command in the transcript, as a terminal card in the reading
|
|
/// column: the command and folder, its terminal (typed into while it runs),
|
|
/// a spinner and Stop while it runs, then its exit status, Copy output and
|
|
/// Send to agent, and Dismiss (for every client of the chat; the run moves
|
|
/// into the answer's command history chip, which can restore it). A
|
|
/// running command has no Dismiss: Stop it first. Full screen opens the same
|
|
/// terminal over the whole window.
|
|
///
|
|
/// It listens to [controller] itself, so streamed output rebuilds only this
|
|
/// card, never the transcript.
|
|
class ChatShellRunCard extends StatefulWidget {
|
|
const ChatShellRunCard({
|
|
super.key,
|
|
required this.controller,
|
|
required this.runId,
|
|
});
|
|
|
|
final ChatShellRunsController controller;
|
|
final String runId;
|
|
|
|
@override
|
|
State<ChatShellRunCard> createState() => _ChatShellRunCardState();
|
|
}
|
|
|
|
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(
|
|
context,
|
|
controller: widget.controller,
|
|
runId: widget.runId,
|
|
);
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_fullScreen = false;
|
|
_viewGeneration++;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: widget.controller,
|
|
builder: (context, _) {
|
|
final run = widget.controller.run(widget.runId);
|
|
if (run == null) return const SizedBox.shrink();
|
|
final body = _body(context, run);
|
|
return Semantics(
|
|
identifier: 'chat-shell-run-card',
|
|
container: true,
|
|
child: Card(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
child: Padding(padding: const EdgeInsets.all(16), child: body),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _body(BuildContext context, ChatShellRun run) {
|
|
final controller = widget.controller;
|
|
final error = controller.errorFor(run.id);
|
|
final command = (chatCardBodyStyle(context) ?? const TextStyle()).copyWith(
|
|
fontFamily: appMonospaceFamily,
|
|
fontWeight: FontWeight.w600,
|
|
);
|
|
return Column(
|
|
key: ValueKey<String>('chat-shell-run-${run.id}'),
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.only(end: 12),
|
|
child: Icon(
|
|
Icons.terminal,
|
|
color: chatCardSecondaryColor(context),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'\$ ${run.command}',
|
|
key: const Key('chat-shell-run-command'),
|
|
style: command,
|
|
),
|
|
if (run.directory.isNotEmpty)
|
|
Text(run.directory, style: chatCardSecondaryStyle(context)),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
ChatShellStatus(run: run),
|
|
if (!run.running)
|
|
ChatShellDismissButton(
|
|
onPressed: () => unawaited(
|
|
// A refusal brings the card back with the server's reason.
|
|
dismissChatShellRuns(context, controller, [run.id]),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
ChatShellOutputView(
|
|
run: run,
|
|
controller: controller,
|
|
viewKey: ValueKey<int>(_viewGeneration),
|
|
fullScreen: _fullScreen,
|
|
expanded: _expanded,
|
|
),
|
|
if (run.error.isNotEmpty && !run.running)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Text(run.error, style: chatCardSecondaryStyle(context)),
|
|
),
|
|
const SizedBox(height: 4),
|
|
ChatShellCardActions(
|
|
run: run,
|
|
controller: controller,
|
|
onFullScreen: () => _openFullScreen(),
|
|
expanded: _expanded,
|
|
onExpand: _expanded || _expandable(run)
|
|
? () => setState(() => _expanded = !_expanded)
|
|
: null,
|
|
),
|
|
if (error != null)
|
|
Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
error,
|
|
key: const Key('chat-shell-run-error'),
|
|
style: (chatCardBodyStyle(context) ?? const TextStyle()).copyWith(
|
|
color: chatCardErrorColor(context),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|