Documentation
¶
Overview ¶
Package ui renders parsed diffs into a terminal view.
Index ¶
- Constants
- func GitSource(r *git.Repo, ignoreWS bool, context int) (string, error)
- func NextIndex(sorted []int, cur int) int
- func PrevIndex(sorted []int, cur int) int
- func Run(files []diff.File, t *theme.Theme, opts Options) error
- func RunGit(repo *git.Repo, files []diff.File, t *theme.Theme, opts Options) error
- func RunLog(repo *git.Repo, commits []git.Commit, files []diff.File, t *theme.Theme, ...) error
- type BoxPart
- type Model
- type Options
- type Row
- type RowKind
- type Side
- type View
Constants ¶
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 ¶
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 ¶
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.
Types ¶
type BoxPart ¶
type BoxPart int
BoxPart is one pane's share of a change block's outline on a single row.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the whole TUI state.
func NewGit ¶
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 ¶
Init starts following the working tree when live-follow is on; otherwise hunk has nothing to do before its first render.
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.