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,
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: Style().foreground(success),
removedLine: Style().foreground(error),
contextLine: Style().foreground(onBackground),
fileHeader: Style().bold().foreground(onSurface),
hunkHeader: Style().foreground(muted),
addedGutter: Style().foreground(success).bold(),
removedGutter: Style().foreground(error).bold(),
contextGutter: Style().foreground(muted),
lineNumber: Style().foreground(muted),
// Pretty mode
prettyAddedLine: Style().foreground(success).background(addedBg),
prettyRemovedLine: Style().foreground(error).background(removedBg),
prettyContextLine: Style().foreground(onBackground),
prettyFileHeader: Style().foreground(muted),
prettyAddedLineNumber: Style().foreground(success).background(addedBg),
prettyRemovedLineNumber: Style().foreground(error).background(removedBg),
prettyContextLineNumber: Style().foreground(muted),
// Side-by-side mode
sideBySideSeparator: Style().foreground(border),
sideBySideAddedLine: Style().foreground(success).background(addedBg),
sideBySideRemovedLine: Style().foreground(error).background(removedBg),
sideBySideContextLine: Style().foreground(onBackground),
sideBySideLineNumber: Style().foreground(muted),
sideBySideEmptyCell: Style().foreground(surface),
sideBySideAddedMarker: Style().foreground(success),
sideBySideRemovedMarker: Style().foreground(error),
sideBySideContextMarker: Style().foreground(muted),
// Inline diff highlighting
inlineAddedHighlight: Style().background(
inlineAddedBg ?? const BasicColor('#2a4a2a'),
),
inlineRemovedHighlight: Style().background(
inlineRemovedBg ?? const BasicColor('#4a2a2a'),
),
);
}