feat(app): diffs colour added lines and +N green, removed lines and -N red
This commit is contained in:
@@ -118,7 +118,7 @@ class ChangeFileRow extends StatelessWidget {
|
||||
final cupertino = usesCupertino(context);
|
||||
final leading = Icon(_kindIcon(context, file.kind));
|
||||
final title = Text(file.path, style: mono);
|
||||
final subtitle = Text(changeFileMeta(file));
|
||||
final subtitle = ChangeStatText(changeFileMeta(file));
|
||||
final trailing = cupertino
|
||||
? const CupertinoListTileChevron()
|
||||
: const Icon(Icons.chevron_right);
|
||||
|
||||
@@ -22,20 +22,64 @@ ThemeData hostTextTheme(BuildContext context) => ThemeData(
|
||||
ChangeLineKind kind,
|
||||
) => switch (kind) {
|
||||
ChangeLineKind.add => (
|
||||
text: usesCupertino(context)
|
||||
? CupertinoColors.systemGreen.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.primary,
|
||||
background: null,
|
||||
text: addedColor(context),
|
||||
background: addedColor(context).withValues(alpha: 0.12),
|
||||
),
|
||||
ChangeLineKind.remove => (
|
||||
text: usesCupertino(context)
|
||||
? CupertinoColors.destructiveRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error,
|
||||
background: null,
|
||||
text: removedColor(context),
|
||||
background: removedColor(context).withValues(alpha: 0.12),
|
||||
),
|
||||
ChangeLineKind.context => (text: labelColor(context), background: null),
|
||||
};
|
||||
|
||||
/// Added lines and counts: the platform's green, readable in both themes.
|
||||
Color addedColor(BuildContext context) => usesCupertino(context)
|
||||
? CupertinoColors.systemGreen.resolveFrom(context)
|
||||
: (Theme.of(context).brightness == Brightness.dark
|
||||
? const Color(0xFF81C995)
|
||||
: const Color(0xFF1E8E3E));
|
||||
|
||||
/// Removed lines and counts: the platform's red.
|
||||
Color removedColor(BuildContext context) => usesCupertino(context)
|
||||
? CupertinoColors.systemRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error;
|
||||
|
||||
final _statToken = RegExp(r'(?<![\w-])([+-]\d+)(?![\w])');
|
||||
|
||||
/// [text] with every `+N` in green and `-N` in red; the rest unchanged.
|
||||
class ChangeStatText extends StatelessWidget {
|
||||
const ChangeStatText(this.text, {super.key, this.style});
|
||||
|
||||
final String text;
|
||||
final TextStyle? style;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final spans = <TextSpan>[];
|
||||
var at = 0;
|
||||
for (final match in _statToken.allMatches(text)) {
|
||||
if (match.start > at) {
|
||||
spans.add(TextSpan(text: text.substring(at, match.start)));
|
||||
}
|
||||
final token = match.group(1)!;
|
||||
spans.add(
|
||||
TextSpan(
|
||||
text: token,
|
||||
style: TextStyle(
|
||||
color: token.startsWith('+')
|
||||
? addedColor(context)
|
||||
: removedColor(context),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
at = match.end;
|
||||
}
|
||||
if (at < text.length) spans.add(TextSpan(text: text.substring(at)));
|
||||
return Text.rich(TextSpan(children: spans), style: style);
|
||||
}
|
||||
}
|
||||
|
||||
Color labelColor(BuildContext context) => usesCupertino(context)
|
||||
? CupertinoColors.label.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurface;
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../domain/change_wording.dart';
|
||||
import '../domain/file_change.dart';
|
||||
import '../domain/run_changes.dart';
|
||||
import 'capture_section.dart';
|
||||
import 'change_style.dart';
|
||||
import 'file_diff_viewer.dart';
|
||||
import 'visit_pager.dart';
|
||||
|
||||
@@ -112,7 +113,7 @@ class _ChangesViewerState extends State<ChangesViewer> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
ChangeStatText(
|
||||
runChangesHeader(run),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
|
||||
@@ -114,7 +114,8 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
changeKindTitle(file.kind),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
if (stat.isNotEmpty) Text(stat, style: mono),
|
||||
if (stat.isNotEmpty)
|
||||
ChangeStatText(stat, style: mono),
|
||||
if (tags.isNotEmpty)
|
||||
Text(
|
||||
tags.join(' · '),
|
||||
|
||||
Reference in New Issue
Block a user