DiffColors.of constructor
DiffColors.of(
- SyntaxTheme theme
Reads the colors from theme. A theme without them gets GitHub's
green and red, with line backgrounds at half the strength of
changed-word backgrounds.
Implementation
factory DiffColors.of(SyntaxTheme theme) {
final dark = theme.isDark;
final inserted =
theme.editorColor('editorGutter.addedBackground') ??
(dark ? 0xFF3FB950 : 0xFF1A7F37);
final removed =
theme.editorColor('editorGutter.deletedBackground') ??
(dark ? 0xFFF85149 : 0xFFCF222E);
final insertedText =
theme.editorColor('diffEditor.insertedTextBackground') ??
_withAlpha(inserted, 0x4D);
final removedText =
theme.editorColor('diffEditor.removedTextBackground') ??
_withAlpha(removed, 0x4D);
// Chrome is the foreground mixed into the background.
int tint(double share) => alphaBlend(
(share * 0xFF).round() << 24 | theme.foreground & 0xFFFFFF,
theme.background,
);
return DiffColors(
fileHeader: tint(0.06),
hunkHeader: tint(0.035),
emptySide: tint(0.02),
divider: tint(0.12),
muted: tint(0.62),
insertedLine:
theme.editorColor('diffEditor.insertedLineBackground') ??
_withAlpha(insertedText, _alpha(insertedText) ~/ 2),
removedLine:
theme.editorColor('diffEditor.removedLineBackground') ??
_withAlpha(removedText, _alpha(removedText) ~/ 2),
insertedText: insertedText,
removedText: removedText,
inserted: inserted,
removed: removed,
);
}