livediff

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSourceBytes = 64 << 20
View Source
const MaxSyntaxBytes = 256 << 10

Syntax is best-effort decoration. Bound lexer input independently of the display limit; huge hunks and unknown languages still display exact safe text.

View Source
const Subtle = "\x1b[2m"

Subtle marks secondary text; unsupported terminals receive a fixed-color fallback.

View Source
const SubtleReset = "\x1b[22m"

SubtleReset clears faint (SGR 22 also clears bold).

View Source
const UnknownCaller = "?"

UnknownCaller is the filter key for captures recorded without a caller, so filtering to them stays distinct from showing all.

Variables

This section is empty.

Functions

func AlignHunkColors

func AlignHunkColors(rows []mekugi.ReviewRow, before, after []string)

AlignHunkColors replaces caller-owned row text with its before/after color, preserving hunk geometry without allocating another row slice.

func CallerKey

func CallerKey(caller string) string

CallerKey is the caller filter value that selects a caller's captures.

func DiffRows

func DiffRows(source string) []mekugi.ReviewRow

DiffRows parses display-only unified output, including clipped and partial hunks. Metadata has no source-row kind; source rows omit their diff marker.

func Fade

func Fade(line string, progress float64, canvas Canvas) string

Fade renders SGR-colored text partway through appearing. Truecolor foregrounds blend from the fill beneath them, and default text takes the canvas foreground so it fades too. Fills, other attributes, and palette colors pass through. Progress 1 returns the text unchanged.

func Gutter

func Gutter(highlighted bool, theme Theme) string
func Header(text string, width int, counts Counts, theme Theme) string

Give each file a clear section boundary without painting over source colors.

func Safe

func Safe(text string, colors bool) string

Only text and SGR colors may reach the viewport. In particular, captured source must not emit cursor controls, OSC clipboard writes, or terminal titles.

func SourceLine

func SourceLine(theme Theme, width int, numbers, fragment string, kind byte) string

func WrapSource added in v0.2.0

func WrapSource(text string, width int) []string

WrapSource keeps both syntax foregrounds and word backgrounds on independently painted continuation rows. SourceLine keeps gutters and padding at the row fill.

Types

type Canvas

type Canvas struct{ Background, Foreground RGB }

Canvas is what a fading row emerges from. A terminal-reported background replaces the theme's assumed one; the foreground stands in for default text.

type Chunk

type Chunk struct {
	Key, Status   string
	Stream        string
	Workspace     string // The capturing workspace; empty when unknown.
	CaptureOrder  uint64
	SnapshotOrder int
	Review        mekugi.ReviewFile
	Highlighted   bool
	Origin
}

type Counts

type Counts struct {
	Added, Removed int
}

type File

type File struct {
	Path        string
	Chunks      []Chunk
	Highlighted bool
	// Origins are the shown changes a visible file composes, in capture
	// order. Baseline counts changes a caller filter folded into its base.
	Origins  []Origin
	Baseline int
	// contains filtered or unexported fields
}

Live views read immutable review projections, never workspace files or carriers.

func GroupCaptures

func GroupCaptures(captures []Chunk) []File

func (File) Key

func (file File) Key() string

func (File) NetCounts

func (file File) NetCounts() Counts

NetCounts reports the line counts of an already composed visible file. Unknown or inconsistent evidence never becomes a cumulative-edit total.

type LineSource

type LineSource struct {
	// Change names the capture a row shows, or for a composed file the
	// comma-separated changes it combines.
	Change, Path string
	Line         int  // Gutter coordinate: old for deletions, new otherwise.
	Deleted      bool // Line is an old-file coordinate.
	Content      int  // Display column where the row's text starts, after gutters.
}

LineSource attributes a display row. Chrome rows have no Line.

type OSC

type OSC struct {
	Active  bool
	Escaped bool
	Reply   string
}

Consume OSC replies separately from navigation. The payload is bounded even for malformed/unterminated replies, and an ST terminator may span input reads.

func (*OSC) Consume

func (osc *OSC) Consume(key byte) (reply string, complete bool)

type Origin

type Origin struct {
	Change, Caller, Source string
}

Origin attributes a capture: its change ID, the canonical agent path that made it, and the tool or program that wrote it.

type Output

type Output struct{ strings.Builder }

func (*Output) WriteString

func (b *Output) WriteString(s string) (int, error)

WriteString bounds rendered output without per-token byte-slice allocation.

type RGB

type RGB struct{ R, G, B uint8 }

RGB is a truecolor terminal color.

func BackgroundColor

func BackgroundColor(reply string) (RGB, bool)

BackgroundColor is the reported background, for blending toward it.

func ForegroundColor

func ForegroundColor(reply string) (RGB, bool)

ForegroundColor is the reported default text color (an OSC 10 reply).

type Render

type Render struct {
	Lines     []string
	Starts    []int
	Hunks     []int        // Display offsets for hunk navigation.
	RowStarts []int        // First display row of each logical row, including chrome.
	Sources   []LineSource // Aligned with Lines.
	Counts    []Counts
	// contains filtered or unexported fields
}

func (*Render) PaintViewport

func (render *Render) PaintViewport(ctx context.Context, start, end int) error

PaintViewport decorates intersecting complete hunks. Coordinates and source attribution were fixed during layout; off-screen hunks never invoke a lexer.

type Renderer

type Renderer struct {
	// LayoutOnly defers complete-hunk syntax decoration until PaintViewport.
	LayoutOnly bool

	// Caller presents a canonical agent path as a display name and an SGR
	// color prefix. Without it, paths appear as recorded, uncolored.
	Caller func(path string) (name, color string)
	// contains filtered or unexported fields
}

Syntax is independent of wrapping, coordinates, and recency marks. Keep bounded caches in each viewer, never shared across sessions.

func (*Renderer) ColorDiff

func (r *Renderer) ColorDiff(ctx context.Context, theme Theme, source string) ([]string, error)

ColorDiff decorates unified output without changing its rows or metadata. Partial streaming hunks use the same source lexer as the diff pane.

func (*Renderer) ColorDiffPath

func (r *Renderer) ColorDiffPath(ctx context.Context, theme Theme, path, source string) ([]string, error)

ColorDiffPath supplies the file identity for host hunks without unified headers. Explicit headers still select the language for each file.

func (*Renderer) ColorDiffRows

func (r *Renderer) ColorDiffRows(ctx context.Context, theme Theme, path, source string) ([]mekugi.ReviewRow, error)

ColorDiffRows uses the same row geometry as DiffRows and the pane's source lexer. Callers can wrap and fill rows at their own viewport width.

func (*Renderer) ColorHunk

func (r *Renderer) ColorHunk(ctx context.Context, theme Theme, review mekugi.ReviewFile, rows []mekugi.ReviewRow) ([]string, []string, error)

Tokenise the two sides separately so deleted text cannot change the syntax state of additions. Never read the workspace to fill uncaptured source gaps.

func (*Renderer) ColorSource

func (r *Renderer) ColorSource(ctx context.Context, theme Theme, path, source string) ([]string, error)

ColorSource uses the filename when supplied, otherwise content analysis.

func (*Renderer) Render

func (r *Renderer) Render(ctx context.Context, theme Theme, files []File, workspace string, width int) (Render, error)

Rendering consumes the engine's validated rows. File and hunk offsets are recorded as rows are emitted, never recovered from a subprocess's output.

type Theme

type Theme uint8
const (
	TerminalTheme Theme = iota
	LightTheme
	DarkTheme
)

func BackgroundTheme

func BackgroundTheme(reply string) (Theme, bool)

OSC 11 uses X11 rgb: components of one to four hex digits. Do not treat malformed replies as evidence of a dark background.

func EnvironmentTheme

func EnvironmentTheme(value string) Theme

COLORFGBG is a fallback for terminals that do not answer OSC 11. Its final field is the background's palette index; the optional middle field is ignored. Only neutral indices have a useful light/dark interpretation without a reply.

func (Theme) Accent

func (theme Theme) Accent() string

func (Theme) Canvas

func (theme Theme) Canvas() Canvas

func (Theme) Foreground

func (theme Theme) Foreground(kind chroma.TokenType) string

Chroma owns token inheritance; row backgrounds are applied separately.

func (Theme) RowBackground

func (theme Theme) RowBackground(kind byte) string

Changed rows use paired foregrounds and subtle fills, including before theme detection completes. Context and chrome retain the terminal background.

func (Theme) SelectionBackground

func (theme Theme) SelectionBackground() string

SelectionBackground is a neutral fill that marks a selected row in place.

func (Theme) TextCanvas

func (theme Theme) TextCanvas(kind byte, canvas Canvas) Canvas

TextCanvas is what a changed row's text emerges from: the row's own fill, which stays put, and the default text color on that fill.

func (Theme) WordBackground added in v0.2.0

func (theme Theme) WordBackground(kind byte) string

WordBackground emphasizes changed words without replacing syntax foregrounds.

type View

type View struct {
	Files        []File
	Selected     int
	Scroll       map[string]int
	Visible      map[string]File
	Following    bool
	Latest       string
	Initialized  bool
	UnseenUpdate bool
	// Caller, when set, shows only captures whose CallerKey matches. Other
	// callers' captures compose as baseline, so the net diff stays exact.
	Caller string
}

func (*View) FilterCaller

func (v *View) FilterCaller(caller string)

FilterCaller shows only one CallerKey's captures; an empty key shows all.

func (*View) FollowLatest

func (v *View) FollowLatest()

Follow the latest newly observed capture, including edits received while paused. Capture ordering here drives navigation, not a claim about execution order.

func (*View) JumpTo

func (v *View) JumpTo(render Render, offset int)

JumpTo moves the viewport like ScrollTo, but a file it leaves keeps its position.

func (*View) LatestChunk

func (v *View) LatestChunk() Chunk

func (*View) Merge

func (v *View) Merge(files []File)

func (*View) Open

func (v *View) Open(file int)

Open selects a file at its header, as an explicit navigation target.

func (*View) Reflow

func (v *View) Reflow(before, after Render)

Reflow saved positions when wrapping changes, keeping the same logical row.

func (*View) RefreshVisible

func (v *View) RefreshVisible()

Rebuild the combined result from captures.

func (*View) ScrollTo

func (v *View) ScrollTo(render Render, offset int)

Keep the viewport anchored to a file and its local row when preceding files grow. Scrolling out of a file forgets its position: only a file the viewport left by a jump (n/p, Enter, JumpTo) reopens where it was, never where a scroll passed through.

func (*View) Shows

func (v *View) Shows(chunk Chunk) bool

Shows reports whether the caller filter admits a capture.

Jump to

Keyboard shortcuts

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