DiffStyles.fromColors constructor
DiffStyles.fromColors({})
Creates diff styles from semantic colors.
Maps semantic color slots (success/error/muted/surface/onSurface/border) to the appropriate diff styles. This enables theme-driven styling without coupling to a specific theme class.
success— color for added lines (foreground).error— color for removed lines (foreground).muted— color for line numbers, context gutter, separators.surface— background for panels (used for empty cells in side-by-side mode).onSurface— text color on surface backgrounds (file headers).onBackground— text color on main background (context lines).border— border/separator color.successBg— subtle background for added lines (optional).errorBg— subtle background for removed lines (optional).
Implementation
factory DiffStyles.fromColors({
required Color success,
required Color error,
required Color muted,
required Color surface,
required Color onSurface,
required Color onBackground,
required Color border,
bool hasDarkBackground = true,
Color? successBg,
Color? errorBg,
Color? inlineAddedBg,
Color? inlineRemovedBg,
}) {
final addedBg = successBg ?? const BasicColor('#1a2e1a');
final removedBg = errorBg ?? const BasicColor('#2e1a1a');
return DiffStyles(
// Unified mode
addedLine: _bgAware(Style().foreground(success), hasDarkBackground),
removedLine: _bgAware(Style().foreground(error), hasDarkBackground),
contextLine: _bgAware(
Style().foreground(onBackground),
hasDarkBackground,
),
fileHeader: _bgAware(
Style().bold().foreground(onSurface),
hasDarkBackground,
),
hunkHeader: _bgAware(Style().foreground(muted), hasDarkBackground),
addedGutter: _bgAware(
Style().foreground(success).bold(),
hasDarkBackground,
),
removedGutter: _bgAware(
Style().foreground(error).bold(),
hasDarkBackground,
),
contextGutter: _bgAware(Style().foreground(muted), hasDarkBackground),
lineNumber: _bgAware(Style().foreground(muted), hasDarkBackground),
// Pretty mode
prettyAddedLine: _bgAware(
Style().foreground(success).background(addedBg),
hasDarkBackground,
),
prettyRemovedLine: _bgAware(
Style().foreground(error).background(removedBg),
hasDarkBackground,
),
prettyContextLine: _bgAware(
Style().foreground(onBackground),
hasDarkBackground,
),
prettyFileHeader: _bgAware(Style().foreground(muted), hasDarkBackground),
prettyAddedLineNumber: _bgAware(
Style().foreground(success).background(addedBg),
hasDarkBackground,
),
prettyRemovedLineNumber: _bgAware(
Style().foreground(error).background(removedBg),
hasDarkBackground,
),
prettyContextLineNumber: _bgAware(
Style().foreground(muted),
hasDarkBackground,
),
// Side-by-side mode
sideBySideSeparator: _bgAware(
Style().foreground(border),
hasDarkBackground,
),
sideBySideAddedLine: _bgAware(
Style().foreground(success).background(addedBg),
hasDarkBackground,
),
sideBySideRemovedLine: _bgAware(
Style().foreground(error).background(removedBg),
hasDarkBackground,
),
sideBySideContextLine: _bgAware(
Style().foreground(onBackground),
hasDarkBackground,
),
sideBySideLineNumber: _bgAware(
Style().foreground(muted),
hasDarkBackground,
),
sideBySideEmptyCell: _bgAware(
Style().foreground(surface),
hasDarkBackground,
),
sideBySideAddedMarker: _bgAware(
Style().foreground(success),
hasDarkBackground,
),
sideBySideRemovedMarker: _bgAware(
Style().foreground(error),
hasDarkBackground,
),
sideBySideContextMarker: _bgAware(
Style().foreground(muted),
hasDarkBackground,
),
// Inline diff highlighting
inlineAddedHighlight: _bgAware(
Style().background(inlineAddedBg ?? const BasicColor('#2a4a2a')),
hasDarkBackground,
),
inlineRemovedHighlight: _bgAware(
Style().background(inlineRemovedBg ?? const BasicColor('#4a2a2a')),
hasDarkBackground,
),
selectedCommentLine: _bgAware(
Style().background(
AdaptiveColor(
dark: const BasicColor('#2f3f5f'),
light: const BasicColor('#bfd7ff'),
),
),
hasDarkBackground,
),
selectedCommentGutter: _bgAware(
Style().background(
AdaptiveColor(
dark: const BasicColor('#50668f'),
light: const BasicColor('#9dbcf8'),
),
),
hasDarkBackground,
),
commentRangeLine: _bgAware(
Style().background(
AdaptiveColor(
dark: const BasicColor('#263847'),
light: const BasicColor('#d6e8ff'),
),
),
hasDarkBackground,
),
commentRangeGutter: _bgAware(
Style().background(
AdaptiveColor(
dark: const BasicColor('#3f6374'),
light: const BasicColor('#b8d7ff'),
),
),
hasDarkBackground,
),
commentThreadLine: _bgAware(
Style().background(
AdaptiveColor(
dark: const BasicColor('#5d4037'),
light: const BasicColor('#ffeb3b'),
),
),
hasDarkBackground,
),
commentThreadGutter: _bgAware(
Style().background(
AdaptiveColor(
dark: const BasicColor('#8d6e63'),
light: const BasicColor('#fbc02d'),
),
),
hasDarkBackground,
),
);
}