Skip to main content

Overview

The DiffRenderable component displays git-style diffs with syntax highlighting, line numbers, and support for both unified and split view modes. It parses standard unified diff format and provides rich styling options.

Basic Usage

Props

string
default:"''"
Unified diff content in standard git diff format.
'unified' | 'split'
default:"'unified'"
Diff view mode:
  • 'unified': Single pane with +/- indicators
  • 'split': Side-by-side comparison
string
Language/filetype for syntax highlighting (e.g., "typescript", "python").
SyntaxStyle
Syntax styling configuration for code highlighting.
boolean
default:"true"
Show line numbers in the gutter.
'none' | 'char' | 'word'
Text wrapping behavior.
boolean
default:"false"
Enable concealment of hidden syntax elements.
TreeSitterClient
Tree-sitter client for syntax parsing.

Color Customization

string | RGBA
Default foreground color.
string | RGBA
default:"'#1a4d1a'"
Background color for added lines (gutter).
string | RGBA
default:"'#4d1a1a'"
Background color for removed lines (gutter).
string | RGBA
default:"'transparent'"
Background color for unchanged context lines (gutter).
string | RGBA
Background color for added line content. Falls back to addedBg if not specified.
string | RGBA
Background color for removed line content. Falls back to removedBg if not specified.
string | RGBA
Background color for context line content. Falls back to contextBg if not specified.
string | RGBA
default:"'#22c55e'"
Color for the ”+” sign on added lines.
string | RGBA
default:"'#ef4444'"
Color for the ”-” sign on removed lines.
string | RGBA
default:"'#888888'"
Foreground color for line numbers.
string | RGBA
default:"'transparent'"
Background color for the line number gutter.
string | RGBA
default:"'transparent'"
Background color for line numbers on added lines.
string | RGBA
default:"'transparent'"
Background color for line numbers on removed lines.
string | RGBA
Background color for selected text.
string | RGBA
Foreground color for selected text.

View Modes

Unified View

Displays changes in a single column with + for additions and - for removals:

Split View

Displays before and after side-by-side:

Examples

GitHub Dark Theme

Split View

Toggle View Mode

Custom Color Scheme (Monokai)

Without Line Numbers

With Word Wrapping

Real Git Diff

Methods

setLineColor()

Set custom color for a specific line.

clearLineColor()

Clear custom color for a line.

setLineColors()

Set multiple line colors at once.

highlightLines()

Highlight a range of lines.

clearHighlightLines()

Clear highlighting for a range.

clearAllLineColors()

Clear all custom line colors.

Properties

diff

Get or set the diff content.

view

Get or set the view mode.

filetype

Get or set the language for syntax highlighting.

syntaxStyle

Get or set the syntax style.

wrapMode

Get or set the wrap mode.

showLineNumbers

Get or set line number visibility.

Color Properties

All color properties can be read and written:

Diff Format

DiffRenderable expects standard unified diff format:
You can generate this format using:
  • git diff
  • diff -u file1 file2
  • JavaScript diff libraries like diff package

Error Handling

If the diff cannot be parsed, DiffRenderable displays an error message and falls back to showing the raw diff as syntax-highlighted code:

Performance

  • Efficient diff parsing with the diff package
  • Smart content alignment in split view for wrapped lines
  • Minimal re-rendering when toggling styles
  • Handles large diffs with good performance
  • Code - Syntax-highlighted code display (used internally)
  • LineNumberRenderable - Line number gutter (used internally)
  • Text - Plain text display