1. Purpose
Canon provides a theme system for diff display that controls colors, backgrounds, text effects, and visual markers. Themes make diffs readable on different terminal backgrounds and allow personalizing the visual style.
2. Available themes
Canon ships with four predefined themes:
| Theme | Best For | Key Characteristics |
|---|---|---|
|
Light terminal backgrounds |
Light marker backgrounds ( |
|
Dark terminal backgrounds (default) |
Saturated foreground colors, no backgrounds, |
|
Amber CRT / low blue light / accessibility |
Monochromatic amber/yellow, inverse video for removed, |
|
Maximum visual contrast (Claude Code style) |
|
3. Theme structure
Each theme is a nested hash with these top-level sections:
| Section | Controls |
|---|---|
|
Colors for removed, added, changed, unchanged, formatting, and informative diffs |
|
Colors for XML syntax elements: tags, attribute names, attribute values, text, comments, CDATA |
|
Same as |
|
Colors for line numbers, pipe separators, context lines |
|
Unicode characters for invisible whitespace (space, tab, newline, nbsp) |
|
How changed lines display: |
3.1. Styling properties
Each styled element supports these properties:
| Property | Type | Description |
|---|---|---|
|
Symbol |
ANSI foreground color |
|
Symbol or nil |
ANSI background color (nil = no background) |
|
Boolean |
Bold text |
|
Boolean |
Underlined text |
|
Boolean |
Strikethrough text |
|
Boolean |
Italic text (terminal support varies) |
3.2. Valid color values
| Color | ANSI Code |
|---|---|
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
| Color | ANSI Code |
|---|---|
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
Default terminal color |
The Rainbow gem (Canon’s terminal color library) doesn’t support :bright_black or :bright_white directly. Themes use :white or :black as substitutes.
|
4. Diff color sections
Each theme defines colors for six diff categories:
| Category | Markers | Description |
|---|---|---|
|
|
Lines or content present in the old document but not the new |
|
|
Lines or content present in the new document but not the old |
|
|
Lines with both old and new content; has |
|
` ` (space) |
Context lines with no differences |
|
|
Pure whitespace/formatting differences (no semantic change) |
|
|
Tracked differences that don’t affect equivalence |
5. Theme specifications
5.1. Light theme (:light)
Designed for light terminal backgrounds (white/light gray).
-
Removed:
:redtext with:light_redbackground on markers,:strikethroughon content -
Added:
:greentext with:light_greenbackground on markers -
Changed:
:bright_redold /:bright_greennew, bold -
Formatting:
:bright_blue(visible on light backgrounds) -
Informative:
:bright_magenta -
Structure:
:blackline numbers and pipes -
Comments:
:magentaitalic
5.2. Dark theme (:dark, default)
Designed for dark terminal backgrounds.
-
Removed:
:redtext,:strikethroughon content -
Added:
:greentext -
Changed:
:yellowmarker,:bright_redold /:bright_greennew -
Formatting:
:bright_blue(subtle but visible on dark backgrounds) -
Informative:
:cyan(distinct from formatting) -
Structure:
:whiteline numbers and pipes -
Comments:
:cyanitalic
5.3. Retro theme (:retro)
Amber CRT phosphor look. Monochromatic amber/yellow, good for low blue light and accessibility.
-
Removed: Inverse video -
:bright_yellowon:yellowbackground, bold -
Added:
:bright_white(less emphasis than removed) -
Changed:
:bright_yellowold with strikethrough /:bright_whitenew with underline -
Formatting:
:yellow(subtle) -
Informative:
:bright_yellowbold (stands out) -
Structure:
:yellowthroughout -
Comments:
:yellowitalic
5.4. Claude theme (:claude)
Claude Code diff style. Maximum visual contrast with colored backgrounds.
-
Removed:
:whitetext on:redbackground -
Added:
:blacktext on:greenbackground -
Changed:
:whiteon:magentabackground for marker -
Formatting:
:yellow -
Informative:
:bright_cyan -
Structure:
:yellowline numbers and pipes -
Comments:
:cyanitalic
6. Configuration
6.1. Setting theme by name
Canon::Config.configure do |config|
config.xml.diff.theme = :claude
end
export CANON_DIFF_THEME=claude
Valid values: light, dark, retro, claude
6.2. Resolution priority
Theme is resolved in this order (highest to lowest):
-
CANON_DIFF_THEMEenvironment variable -
config.xml.diff.theme_inheritance(base theme + overrides) -
config.xml.diff.custom_theme(complete custom theme hash) -
config.xml.diff.theme(theme name) -
:dark(default)
6.3. Theme inheritance
Create a custom theme by inheriting from a base theme and overriding specific properties:
Canon::Config.configure do |config|
config.xml.diff.theme_inheritance = {
base: :dark,
overrides: {
diff: {
removed: { content: { bg: :light_red } }
}
}
}
end
Only the overridden properties change; everything else inherits from the base theme.
custom_theme = Canon::DiffFormatter::Theme.inherit_from(:dark)
.merge(diff: { removed: { content: { bg: :light_red } } })
.build
Canon::Config.configure do |config|
config.xml.diff.custom_theme = custom_theme
end
7. Example script
Canon includes an example script that demonstrates all themes with a sample XML diff:
bundle exec ruby examples/show_themes.rb
This shows each theme’s color output side-by-side, plus plain text output and usage examples.
8. Theme validation
All themes (built-in and custom) are validated for:
-
Completeness: All required sections and keys present
-
Valid values: Colors are valid ANSI, booleans are true/false
-
MECE: No missing or extra keys
result = Canon::DiffFormatter::Theme.validate(my_theme)
result.valid? # => true/false
result.missing_keys # => ["diff.removed.content.color", ...]
result.invalid_values # => ["diff.removed.content.color must be one of ..."]
9. Rainbow gem compatibility
Canon uses the Rainbow gem for terminal colors. Some color names that Canon’s theme system accepts are translated internally:
| Theme Color | Rainbow Method Chain |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Colors :bright_black and :bright_white are not supported by Rainbow in 16-color mode. Themes use :white, :black, or :cyan as substitutes.
10. See also
-
Colors and symbols - Diff markers and classification
-
Display filtering - Control which diff types appear
-
Environment configuration - ENV variable setup
-
Environment variables reference - Complete variable listing