Dismiss finished shell command cards with Undo
Finished command cards get a Dismiss button and the chat's More menu a Dismiss all finished commands entry. Dismissal applies to every client of the chat; a SnackBar (Material) or transient notice (Cupertino) offers Undo for 5 s. Running commands cannot be dismissed until they end.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// `?chats=N`): every fixture chat lists four recorded terminal runs
|
||||
// (succeeded, failed, stopped and an interactive login still waiting for a
|
||||
// token), and chat_shell_run/stop/share/input answer as the server does, with
|
||||
// the frames that follow. The login prompt hides what is typed, as a real
|
||||
// the frames that follow; chat_shell_dismiss/restore hide and bring back runs. The login prompt hides what is typed, as a real
|
||||
// terminal's password prompt does, and finishes on Enter.
|
||||
import 'dart:convert';
|
||||
|
||||
@@ -12,11 +12,18 @@ bool _enabled = false;
|
||||
DateTime _base = DateTime.now();
|
||||
int _loginEnd = utf8.encode(_loginPrompt).length;
|
||||
int _tokenLength = 0;
|
||||
final Set<String> _dismissed = {};
|
||||
|
||||
List<String> _runIds(Object? body) => [
|
||||
if (body is Map && body['run_ids'] is List)
|
||||
for (final id in body['run_ids'] as List) '$id',
|
||||
];
|
||||
|
||||
void configureChatShellFixture(Map<String, String> params) {
|
||||
_enabled = params['shell'] == '1';
|
||||
_base = DateTime.now().subtract(const Duration(minutes: 3));
|
||||
_loginEnd = utf8.encode(_loginPrompt).length;
|
||||
_dismissed.clear();
|
||||
}
|
||||
|
||||
const String _loginPrompt =
|
||||
@@ -116,7 +123,30 @@ JsonMap? chatShellReply(JsonMap request) {
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_shell_runs',
|
||||
'chat_shell_runs': _runs(session),
|
||||
'chat_shell_runs': [
|
||||
for (final run in _runs(session))
|
||||
if (!_dismissed.contains(run['id'])) run,
|
||||
],
|
||||
'chat_shell_dismissed': _dismissed.toList(),
|
||||
};
|
||||
case 'chat_shell_dismiss':
|
||||
final ids = _runIds(body);
|
||||
_dismissed.addAll(ids);
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_shell_dismiss',
|
||||
'chat_shell_dismissed': ids,
|
||||
};
|
||||
case 'chat_shell_restore':
|
||||
final ids = _runIds(body).toSet();
|
||||
_dismissed.removeAll(ids);
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_shell_restore',
|
||||
'chat_shell_runs': [
|
||||
for (final run in _runs(session))
|
||||
if (ids.contains(run['id'])) run,
|
||||
],
|
||||
};
|
||||
case 'chat_shell_run':
|
||||
return {
|
||||
@@ -160,6 +190,17 @@ List<JsonMap> chatShellFollowUps(JsonMap request) {
|
||||
'chat_shell_run_event': {'session_id': session, ...body},
|
||||
};
|
||||
switch ('${request['type']}') {
|
||||
case 'chat_shell_dismiss':
|
||||
return [
|
||||
for (final runId in _runIds(request['chat_shell_run_request']))
|
||||
frame({'run_id': runId, 'dismissed': true}),
|
||||
];
|
||||
case 'chat_shell_restore':
|
||||
final ids = _runIds(request['chat_shell_run_request']).toSet();
|
||||
return [
|
||||
for (final run in _runs(session))
|
||||
if (ids.contains(run['id'])) frame({'run_id': run['id'], 'run': run}),
|
||||
];
|
||||
case 'chat_shell_run':
|
||||
const text = 'hello from the fixture shell\n';
|
||||
final body = request['chat_shell_run_request'];
|
||||
|
||||
Reference in New Issue
Block a user