Run shell commands from the chat composer and show them as cards
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.
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/text/monospace.dart';
|
||||
import 'chat_shell_command.dart';
|
||||
|
||||
/// The chat actions menu's "Run command…": a small host dialog with one
|
||||
/// command field. Returns the trimmed command, or null when cancelled.
|
||||
Future<String?> showChatShellRunDialog(
|
||||
BuildContext context, {
|
||||
required bool cupertino,
|
||||
}) => cupertino
|
||||
? showCupertinoDialog<String>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (_) => const ChatShellRunDialog(cupertino: true),
|
||||
)
|
||||
: showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => const ChatShellRunDialog(cupertino: false),
|
||||
);
|
||||
|
||||
class ChatShellRunDialog extends StatefulWidget {
|
||||
const ChatShellRunDialog({super.key, required this.cupertino});
|
||||
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<ChatShellRunDialog> createState() => _ChatShellRunDialogState();
|
||||
}
|
||||
|
||||
class _ChatShellRunDialogState extends State<ChatShellRunDialog> {
|
||||
final TextEditingController _text = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_text.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
final command = _text.text.trim();
|
||||
Navigator.pop(context, command.isEmpty ? null : command);
|
||||
}
|
||||
|
||||
void _cancel() => Navigator.pop(context);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const mono = TextStyle(fontFamily: appMonospaceFamily);
|
||||
if (widget.cupertino) {
|
||||
return CupertinoAlertDialog(
|
||||
title: const Text(chatShellRunDialogTitle),
|
||||
content: Column(
|
||||
children: [
|
||||
const Text(chatShellModeHint),
|
||||
const SizedBox(height: 12),
|
||||
CupertinoTextField(
|
||||
key: const Key('chat-shell-run-field'),
|
||||
controller: _text,
|
||||
autofocus: true,
|
||||
placeholder: 'Command',
|
||||
style: mono,
|
||||
onSubmitted: (_) => _submit(),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: _cancel,
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
key: const Key('chat-shell-run-confirm'),
|
||||
isDefaultAction: true,
|
||||
onPressed: _submit,
|
||||
child: const Text(chatShellRunDialogConfirm),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return AlertDialog(
|
||||
title: const Text(chatShellRunDialogTitle),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(chatShellModeHint),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
key: const Key('chat-shell-run-field'),
|
||||
controller: _text,
|
||||
autofocus: true,
|
||||
style: mono,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Command',
|
||||
prefixText: '\$ ',
|
||||
),
|
||||
onSubmitted: (_) => _submit(),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: _cancel, child: const Text('Cancel')),
|
||||
FilledButton(
|
||||
key: const Key('chat-shell-run-confirm'),
|
||||
onPressed: _submit,
|
||||
child: const Text(chatShellRunDialogConfirm),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user