Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package render turns unified diff text into styled terminal lines. It is the read-only half of jj-diff's diff rendering, published for other tools to draw a diff the same way this one does: the same parser, the same word-level intra-line highlighting, and the same syntax highlighting. Hunk and line selection stay inside jj-diff, since only an editor needs them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lines

func Lines(diffText string, opts Options) []string

Lines renders diffText as one styled string per terminal row, in file order. Input that parses to nothing returns nothing, because a caller has a better empty state than a blank pane.

Input must be in git format, since jj's own default format does not parse. Callers run `jj diff --git`.

Types

type Options

type Options struct {
	Palette Palette
	// Width truncates each line to that many display cells. Zero leaves lines whole.
	Width int
	// Syntax highlights the code inside each line. It costs a lexer pass per line, so a caller
	// drawing a large diff into a small pane can leave it off.
	Syntax bool
	// WordDiff marks what changed inside a modified line, pairing each deletion with the addition
	// that replaced it.
	WordDiff bool
	// LineNumbers puts the old and new line numbers in a gutter.
	LineNumbers bool
	// SideBySide draws the old and the new content in two columns, pairing each run of deletions
	// with the additions that replaced it. It needs Width, since the columns are cut from it.
	SideBySide bool
}

Options is what one call renders. The zero value is a plain, full-width, unhighlighted diff.

type Palette

type Palette struct {
	// File heads the block for one path.
	File color.Color
	// Hunk is the @@ line naming the range.
	Hunk color.Color
	// Added, Removed, and Context are the line faces, applied to the whole line.
	Added   color.Color
	Removed color.Color
	Context color.Color
	// AddedWord and RemovedWord are the backgrounds marking what changed inside a line, drawn only
	// when Options.WordDiff is set.
	AddedWord   color.Color
	RemovedWord color.Color
	// Gutter is the line-number column, drawn only when Options.LineNumbers is set.
	Gutter color.Color
	// Syntax is the token faces. A zero Syntax renders code unhighlighted.
	Syntax SyntaxPalette
}

Palette is every face a rendered diff draws in. A nil color leaves that part unstyled, so a caller with no color for one of these passes nothing rather than a guess.

type SyntaxPalette

type SyntaxPalette struct {
	Comment  color.Color
	Keyword  color.Color
	String   color.Color
	Number   color.Color
	Name     color.Color
	Type     color.Color
	Operator color.Color
}

SyntaxPalette is the face each class of code token renders in. A nil color leaves that class unstyled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL