Present background tasks as adaptive status cards
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../domain/chat_task_metadata.dart';
|
||||
import '../../../ui/text/monospace.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
|
||||
bool taskCupertino(BuildContext context) =>
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
|
||||
Color taskSecondary(BuildContext context) => taskCupertino(context)
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
TextStyle taskHeading(BuildContext context) => taskCupertino(context)
|
||||
? CupertinoTheme.of(
|
||||
context,
|
||||
).textTheme.textStyle.copyWith(fontWeight: FontWeight.w600)
|
||||
: Theme.of(context).textTheme.titleMedium ?? const TextStyle();
|
||||
|
||||
String taskDisplayTitle(Map<String, dynamic> shell) =>
|
||||
taskText(shell, 'description') ??
|
||||
taskText(shell, 'command') ??
|
||||
'Background process';
|
||||
|
||||
String? taskKindLabel(Map<String, dynamic> shell) {
|
||||
final value = taskText(shell, 'task_type');
|
||||
return value == null
|
||||
? null
|
||||
: '${value[0].toUpperCase()}${value.substring(1).replaceAll('_', ' ')}';
|
||||
}
|
||||
|
||||
String _comparable(String value) => value
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replaceFirst(RegExp(r'^(agent|shell):\s*'), '')
|
||||
.replaceAll(RegExp(r'\s+'), ' ');
|
||||
|
||||
bool sameTaskText(String a, String b) => _comparable(a) == _comparable(b);
|
||||
|
||||
/// Progress is useful only when it contributes a fact beyond the title/command.
|
||||
String? distinctTaskProgress(Map<String, dynamic> shell) {
|
||||
final progress = taskText(shell, 'progress');
|
||||
if (progress == null) return null;
|
||||
return [
|
||||
taskDisplayTitle(shell),
|
||||
taskText(shell, 'description'),
|
||||
taskText(shell, 'command'),
|
||||
].whereType<String>().any((value) => sameTaskText(progress, value))
|
||||
? null
|
||||
: progress;
|
||||
}
|
||||
|
||||
String formatTaskCount(int count) {
|
||||
final digits = '$count';
|
||||
return [
|
||||
for (var end = digits.length; end > 0; end -= 3)
|
||||
digits.substring((end - 3).clamp(0, digits.length), end),
|
||||
].reversed.join(',');
|
||||
}
|
||||
|
||||
String formatTaskDate(BuildContext context, DateTime time) {
|
||||
final material = Localizations.of<MaterialLocalizations>(
|
||||
context,
|
||||
MaterialLocalizations,
|
||||
);
|
||||
final monthYear =
|
||||
material?.formatMonthYear(time) ??
|
||||
'${CupertinoLocalizations.of(context).datePickerMonth(time.month)} ${time.year}';
|
||||
return '${time.day} $monthYear · ${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
/// Native grouped surface; callers supply content that grows with text scaling.
|
||||
class ChatTaskSurface extends StatelessWidget {
|
||||
const ChatTaskSurface({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.padding = const EdgeInsets.all(16),
|
||||
});
|
||||
final Widget child;
|
||||
final EdgeInsetsGeometry padding;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => taskCupertino(context)
|
||||
? CupertinoListSection.insetGrouped(
|
||||
margin: EdgeInsets.zero,
|
||||
backgroundColor: CupertinoColors.transparent,
|
||||
children: [Padding(padding: padding, child: child)],
|
||||
)
|
||||
: Card.filled(
|
||||
margin: EdgeInsets.zero,
|
||||
child: Padding(padding: padding, child: child),
|
||||
);
|
||||
}
|
||||
|
||||
class ChatTaskFact extends StatelessWidget {
|
||||
const ChatTaskFact({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.value,
|
||||
this.monospace = false,
|
||||
});
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final String value;
|
||||
final bool monospace;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: Icon(icon, size: 18, color: taskSecondary(context)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(color: taskSecondary(context), fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
value,
|
||||
style: taskHeading(
|
||||
context,
|
||||
).copyWith(fontFamily: monospace ? appMonospaceFamily : null),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user