ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package ui renders parsed diffs into a terminal view.

Index

Constants

View Source
const (
	SidebarWidthMin = 20
	SidebarWidthMax = 48
)

SidebarWidthMin and SidebarWidthMax bound the sidebar width a user can pick with --sidebar-width or shift+← / shift+→.

Variables

This section is empty.

Functions

func GitSource

func GitSource(r *git.Repo, ignoreWS bool, context int) (string, error)

GitSource reads the working tree: unstaged changes plus untracked files, rendered as one unified diff so review mode has nothing special about it. ignoreWS drops whitespace-only changes from the tracked diffs.

func NextIndex

func NextIndex(sorted []int, cur int) int

NextIndex returns the first value in sorted that is greater than cur, or the last value when there is none. Used for next-hunk and next-file jumps.

func PrevIndex

func PrevIndex(sorted []int, cur int) int

PrevIndex is NextIndex in reverse.

func Run

func Run(files []diff.File, t *theme.Theme, opts Options) error

Run puts the model on screen and blocks until the user quits.

func RunGit

func RunGit(repo *git.Repo, files []diff.File, t *theme.Theme, opts Options) error

RunGit is Run with staging enabled.

func RunLog

func RunLog(repo *git.Repo, commits []git.Commit, files []diff.File, t *theme.Theme, opts Options) error

RunLog puts the history on screen and blocks until the user quits.

Types

type BoxPart

type BoxPart int

BoxPart is one pane's share of a change block's outline on a single row.

const (
	BoxNone   BoxPart = iota // this pane is outside the block here
	BoxTop                   // the rule above it
	BoxMid                   // enclosed: the box's sides run down this row
	BoxBottom                // the rule below it
)

The parts of an outline a row can carry.

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is the whole TUI state.

func New

func New(files []diff.File, t *theme.Theme, opts Options) *Model

New builds a model over an already-parsed diff.

func NewGit

func NewGit(repo *git.Repo, files []diff.File, t *theme.Theme, opts Options) *Model

NewGit is New for a working tree hunk can stage into. It also starts following the working tree, so edits made while hunk is open show up on their own. A watcher that fails to start just leaves live-follow off.

func NewLog

func NewLog(repo *git.Repo, commits []git.Commit, files []diff.File, t *theme.Theme, opts Options) *Model

NewLog builds a model over a repository's history. It is NewGit without the index: a commit is something to read, so marking, staging and following the working tree are all off, and nothing here can write.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init starts following the working tree when live-follow is on; otherwise hunk has nothing to do before its first render.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles resizes and key presses.

func (*Model) View

func (m *Model) View() tea.View

View renders the current screen into the alternate screen buffer.

type Options

type Options struct {
	IgnoreWS  bool   // -w: open with whitespace-only changes hidden
	Unified   bool   // -u: open unified instead of side-by-side
	NoSidebar bool   // --no-sidebar: open with the file sidebar hidden
	NoFollow  bool   // --no-follow: open with live-follow paused
	Context   int    // --context: unchanged lines around each hunk (0 falls back to the default)
	ShowWS    bool   // --show-whitespace: render tabs and trailing spaces as marks
	Filter    string // --filter: hide hunks whose every changed line matches this regex
	NoSyntax  bool   // --no-syntax: open with syntax highlighting off
	// SidebarWidth is --sidebar-width: the sidebar's columns, 0 for the default.
	SidebarWidth int
}

Options are the startup preferences the command-line flags set. Every one has an in-app key that still toggles it during a session; these just pick the state hunk opens in.

type Row

type Row struct {
	Kind        RowKind
	FileIdx     int
	HunkIdx     int // -1 outside a hunk
	Text        string
	Left, Right Side
	// BoxLeft and BoxRight say what a change block's outline does in each pane
	// on this row. Each pane closes on its own last changed line, so a one-line
	// removal that became seven lines shows a short box facing a tall one.
	BoxLeft, BoxRight BoxPart
	// Arrow marks the row that carries the direction marker between the panes.
	Arrow bool
}

Row is one visual line of the whole session: every file, flattened into a single list. Flattening keeps scrolling, windowing, and next/prev navigation to simple index arithmetic instead of nested cursors.

type RowKind

type RowKind int

RowKind says what a row in the flattened view is.

const (
	RowFile        RowKind = iota // a file's header line
	RowHunk                       // an @@ line
	RowPair                       // one line of the diff, on one or both sides
	RowNotice                     // "Binary file changed", "no changes", etc.
	RowSpacer                     // blank separator between files
	RowBlockTop                   // the rule above a changed block
	RowBlockBottom                // the rule below a changed block
)

The kinds of row the flattened view is made of.

type Side

type Side struct {
	Kind   diff.Kind
	Num    int // 1-based line number; 0 when Empty
	Text   string
	Ranges []diff.Range // byte ranges within Text that actually changed
	Empty  bool
}

Side is one half of a paired row. Empty means this side has no line here, which is what a pure addition or deletion looks like side by side.

type View

type View struct {
	Rows []Row
	// FileRows[i] is the row index of file i's header.
	FileRows []int
	// HunkRows[i] is the row index of the i-th hunk across all files, in order.
	HunkRows []int
}

View is the whole render-ready diff plus the indexes navigation needs.

func Build

func Build(files []diff.File, split bool) *View

Build flattens parsed files into rows. In split mode a changed line and its replacement share one row; in unified mode they become two rows, so a row is always exactly one line on screen either way.

Jump to

Keyboard shortcuts

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