a6f0f0a1cb
A draft starting with ! shows a Shell mode indicator and runs through chat_shell_run instead of being sent to the agent; the chat's actions menu gains Run command. Each run is a terminal-style card among the turns with live output, Stop, its exit status, Copy output and Send to agent.
75 lines
2.5 KiB
Dart
75 lines
2.5 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../conversation/chat_card_styles.dart';
|
|
import 'chat_shell_command.dart';
|
|
import 'chat_shell_run.dart';
|
|
|
|
/// A command's state at the card's top end: the host's activity indicator
|
|
/// while it runs, then a status chip (exit code, stopped, interrupted) with
|
|
/// how long it ran. The words carry the state; colour only repeats it.
|
|
class ChatShellStatus extends StatelessWidget {
|
|
const ChatShellStatus({
|
|
super.key,
|
|
required this.run,
|
|
required this.cupertino,
|
|
});
|
|
|
|
final ChatShellRun run;
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (run.running) {
|
|
return Semantics(
|
|
key: const Key('chat-shell-run-running'),
|
|
label: chatShellStatusLabel(run),
|
|
child: cupertino
|
|
? const CupertinoActivityIndicator()
|
|
// As tall as the line of text beside it, at any text scale.
|
|
: SizedBox.square(
|
|
dimension: MediaQuery.textScalerOf(context).scale(20),
|
|
child: const CircularProgressIndicator(strokeWidth: 2),
|
|
),
|
|
);
|
|
}
|
|
final label = run.durationMs > 0
|
|
? '${chatShellStatusLabel(run)} · ${chatShellDuration(run.durationMs)}'
|
|
: chatShellStatusLabel(run);
|
|
final color = switch (run.state) {
|
|
ChatShellRunState.succeeded =>
|
|
cupertino
|
|
? CupertinoColors.systemGreen.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.primary,
|
|
ChatShellRunState.failed => chatCardErrorColor(context, cupertino),
|
|
_ => chatCardSecondaryColor(context, cupertino),
|
|
};
|
|
final icon = switch (run.state) {
|
|
ChatShellRunState.succeeded =>
|
|
cupertino
|
|
? CupertinoIcons.checkmark_circle
|
|
: Icons.check_circle_outline,
|
|
ChatShellRunState.failed =>
|
|
cupertino ? CupertinoIcons.xmark_circle : Icons.error_outline,
|
|
_ => cupertino ? CupertinoIcons.stop_circle : Icons.stop_circle_outlined,
|
|
};
|
|
if (cupertino) {
|
|
return Row(
|
|
key: const Key('chat-shell-run-status'),
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, color: color, size: 18),
|
|
const SizedBox(width: 4),
|
|
Text(label, style: chatCardSecondaryStyle(context, true)),
|
|
],
|
|
);
|
|
}
|
|
return Chip(
|
|
key: const Key('chat-shell-run-status'),
|
|
avatar: Icon(icon, color: color),
|
|
label: Text(label),
|
|
visualDensity: VisualDensity.compact,
|
|
);
|
|
}
|
|
}
|