textdiff

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package textdiff renders a bounded, hand-rolled unified line diff (stdlib only, no diff library). It backs `mesh conflicts diff` and `mesh curator show`, which show a parked loser against the current note. Bounded by design: it refuses to run the O(n*m) LCS on very large inputs, degrading to a line-count summary so a hostile or huge note cannot hang the CLI. Reusable by a future TUI view.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(s string) string

Sanitize replaces C0/C1 control bytes (except tab) with the Unicode replacement char so untrusted note content cannot inject ANSI escapes, cursor moves, or a fake prompt when the diff is printed to a real terminal. Exported so callers can scrub hub-supplied labels (e.g. a note path) the same way.

func Unified

func Unified(a, b []byte, opts Options) string

Unified returns a unified diff of a (the base) vs b (mine), or "" if identical.

Types

type Options

type Options struct {
	Context  int  // equal lines of context around a change (default 3)
	Full     bool // emit the whole file as one hunk, not just changed regions
	MaxLines int  // cap on emitted +/- lines before truncating (default 400)
	Color    bool // ANSI-color the +/- lines (the caller gates this on a TTY)
}

Options tunes Unified. Zero values are sensible (3 lines of context, a 400 changed-line cap, no color, hunks only).

Jump to

Keyboard shortcuts

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