diff --git a/app/lib/features/chat/ui/transcript/chat_turn_chip.dart b/app/lib/features/chat/ui/transcript/chat_turn_chip.dart index dbd0f788..77add75d 100644 --- a/app/lib/features/chat/ui/transcript/chat_turn_chip.dart +++ b/app/lib/features/chat/ui/transcript/chat_turn_chip.dart @@ -16,6 +16,7 @@ class ChatTurnChip extends StatelessWidget { this.sheet, this.open, this.ellipsizeLabel = false, + this.labelSpans, }) : assert(sheet != null || open != null); final Key chipKey; @@ -34,6 +35,10 @@ class ChatTurnChip extends StatelessWidget { /// bounds its width (a turn footer's Wrap, an aligned row). final bool ellipsizeLabel; + /// Styled pieces of [label] (e.g. coloured counts); [label] stays the + /// plain text. Pieces without their own style inherit the chip's style. + final List Function(BuildContext context)? labelSpans; + @override Widget build(BuildContext context) { final cupertino = @@ -87,12 +92,21 @@ class ChatTurnChip extends StatelessWidget { ); } - Text _label({int? maxLines, TextOverflow? overflow}) => Text( - label, - maxLines: maxLines, - overflow: overflow, - style: TextStyle(color: color, fontSize: 13), - ); + Widget _label({int? maxLines, TextOverflow? overflow}) { + final style = TextStyle(color: color, fontSize: 13); + final spans = labelSpans; + if (spans == null) { + return Text(label, maxLines: maxLines, overflow: overflow, style: style); + } + return Builder( + builder: (context) => Text.rich( + TextSpan(children: spans(context)), + maxLines: maxLines, + overflow: overflow, + style: style, + ), + ); + } Future _open(BuildContext context, bool cupertino) { if (open case final open?) return open(context, cupertino); diff --git a/app/lib/features/chat/ui/transcript/chat_turn_diff_chip.dart b/app/lib/features/chat/ui/transcript/chat_turn_diff_chip.dart index e6e9a58a..522c04c7 100644 --- a/app/lib/features/chat/ui/transcript/chat_turn_diff_chip.dart +++ b/app/lib/features/chat/ui/transcript/chat_turn_diff_chip.dart @@ -3,6 +3,8 @@ import 'package:flutter/material.dart'; import '../../../../core/api_gateway.dart'; import '../../../../shell/list_detail_policy.dart'; +import '../../../changes/widgets/change_style.dart' + show addedColor, removedColor; import '../../domain/chat_turn_diffs.dart'; import '../sessions/chat_adaptive.dart'; import 'chat_turn_chip.dart'; @@ -38,6 +40,23 @@ class ChatTurnDiffChip extends StatelessWidget { color: color, ), label: chatTurnDiffLabel(summary), + // The counts take the run Changes colours: additions green, removals red. + labelSpans: (context) { + final files = chatTurnDiffFiles(summary); + const bold = FontWeight.w600; + return [ + TextSpan(text: '${files == 1 ? '1 file' : '$files files'} changed '), + TextSpan( + text: '+${chatTurnDiffAdditions(summary)}', + style: TextStyle(color: addedColor(context), fontWeight: bold), + ), + const TextSpan(text: ' '), + TextSpan( + text: '−${chatTurnDiffDeletions(summary)}', + style: TextStyle(color: removedColor(context), fontWeight: bold), + ), + ]; + }, color: color, semanticsLabel: chatTurnDiffSemantics(summary), ellipsizeLabel: true, diff --git a/app/test/features/chat/ui/transcript/chat_turn_diff_chip_test.dart b/app/test/features/chat/ui/transcript/chat_turn_diff_chip_test.dart index 4342b6db..dbbce091 100644 --- a/app/test/features/chat/ui/transcript/chat_turn_diff_chip_test.dart +++ b/app/test/features/chat/ui/transcript/chat_turn_diff_chip_test.dart @@ -1,3 +1,4 @@ +import 'package:pipelines_app/features/changes/widgets/change_style.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -210,4 +211,39 @@ void main() { expect(find.text('lib/a.dart'), findsOneWidget); }); } + + testWidgets('additions are green and removals red in the chip', ( + tester, + ) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ChatTurnDiffChip( + summary: const {'files': 3, 'additions': 9, 'deletions': 2}, + load: () async => const {}, + ), + ), + ), + ); + final context = tester.element(find.byType(ChatTurnDiffChip)); + final rich = tester.widget( + find.descendant( + of: find.byType(ChatTurnDiffChip), + matching: find.byWidgetPredicate( + (w) => w is RichText && w.text.toPlainText().contains('changed'), + ), + ), + ); + expect(rich.text.toPlainText(), '3 files changed +9 −2'); + final colours = {}; + rich.text.visitChildren((span) { + if (span is TextSpan && span.text != null) { + colours[span.text!] = span.style?.color; + } + return true; + }); + expect(colours['+9'], addedColor(context)); + expect(colours['−2'], removedColor(context)); + expect(addedColor(context), isNot(removedColor(context))); + }); }