Files
pipelines/app/lib/features/chat/shell/chat_shell_card_actions.dart
alan 214bbbc54f Remove Cupertino branches from terminal chat shell
Keep the existing Material terminal and chat-shell behavior while removing live Cupertino widgets, icon metadata, and alternate-host branches. Retain only the documented optional compatibility parameters until remaining callers migrate.
2026-11-11 20:05:55 +00:00

135 lines
4.1 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';
/// The card's host buttons: Stop while running; Copy output, Send to agent
/// once finished; Full screen for the terminal.
class ChatShellCardActions extends StatefulWidget {
const ChatShellCardActions({
super.key,
required this.run,
required this.controller,
required this.onFullScreen,
});
final ChatShellRun run;
final ChatShellRunsController controller;
final VoidCallback onFullScreen;
@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 (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),
);
}
}