Documentation
¶
Index ¶
- func Highlight(path, content string, style *chroma.Style, lineNumbers bool) string
- type DiffView
- func (dv *DiffView) After(path, content string) *DiffView
- func (dv *DiffView) Before(path, content string) *DiffView
- func (dv *DiffView) ContextLines(n int) *DiffView
- func (dv *DiffView) FileName(name string) *DiffView
- func (dv *DiffView) Layout(l Layout) *DiffView
- func (dv *DiffView) LineNumberOffset(n int) *DiffView
- func (dv *DiffView) String() string
- func (dv *DiffView) Style(s Style) *DiffView
- func (dv *DiffView) Width(w int) *DiffView
- func (dv *DiffView) WithChromaStyle(s *chroma.Style) *DiffView
- type Layout
- type LineStyle
- type Style
- type ThemePalette
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Highlight ¶
Highlight renders a whole file's contents as ANSI-styled, optionally line-numbered text for a preview pane (NOT a diff). It reuses the same chroma formatter as the in-line diff highlighter, so colors stay consistent. A nil style disables colorization. Any tokenise/format error falls back to the plain (uncolored) content, so it never returns an error string.
Types ¶
type DiffView ¶
type DiffView struct {
// contains filtered or unexported fields
}
DiffView is the fluent builder and renderer. The fields after style are computed lazily on String().
func New ¶
func New() *DiffView
New returns a DiffView with sensible defaults (unified layout, 3 context lines, 4-space tab expansion, line numbers on, dark style).
func (*DiffView) ContextLines ¶
ContextLines sets the number of unchanged context lines around each hunk.
func (*DiffView) FileName ¶
FileName sets the file header rendered above the first hunk. Empty disables it.
func (*DiffView) LineNumberOffset ¶
LineNumberOffset shifts every displayed line number by n. Use it when the before/after content is a snippet lifted out of a larger file so the gutter reflects the snippet's real position (pass the snippet's first line minus 1).
type Layout ¶
type Layout int
Layout controls whether the diff is rendered as a single column (Unified) or side-by-side (Split). Auto picks Split when the available width is >= SplitThreshold, else Unified.
type LineStyle ¶
LineStyle holds the lipgloss styles for a single line type's three regions: the gutter line-number cell, the +/- symbol cell, and the code body.
type Style ¶
type Style struct {
DividerLine LineStyle
MissingLine LineStyle
EqualLine LineStyle
InsertLine LineStyle
DeleteLine LineStyle
Filename LineStyle
}
Style aggregates LineStyles for every diff line kind: the @@ hunk divider, the empty side of a split pair, context, additions, deletions and the file header.
func DefaultDarkStyle ¶
func DefaultDarkStyle() Style
DefaultDarkStyle returns a diff Style tuned for dark terminal themes.
func DefaultLightStyle ¶
func DefaultLightStyle() Style
DefaultLightStyle returns a diff Style tuned for light terminal themes.
func NewThemeAwareStyle ¶
func NewThemeAwareStyle(p ThemePalette) Style
NewThemeAwareStyle builds a diff Style whose semantic foreground colours come from the active theme, while the carefully-tuned background tints are inherited from the dark or light base style. This lets every theme show its own add/remove/accent colours without re-tuning the row backgrounds (which are what keep additions and deletions legible and colour-blind distinct).
type ThemePalette ¶
ThemePalette carries the semantic colours a diff Style derives from the app theme, so diffview stays decoupled from the theme types: additions, deletions, the hunk header accent and dim line numbers. Dark picks the background base, and an empty colour keeps the tuned base value.