Documentation
¶
Overview ¶
Package renderutil provides shared terminal rendering, highlighting, and hunk calculation primitives.
Index ¶
- func ComputeHunkRange(h Interval, pairs []serialize.LineAlignmentPair, hasSrc, hasDst bool) (srcStart, srcCount, dstStart, dstCount int)
- func FormatHunkHeader(srcStart, srcCount, dstStart, dstCount int, extra string) string
- func FormatRange(start, count int) string
- func IsPairChanged(pair serialize.LineAlignmentPair, leftSpans []serialize.HighlightSpan, ...) bool
- func IsPunctuationOrWhitespace(s string) bool
- func LineDisplayWidth(text string, tabWidth int) int
- func MaxVisibleLine(hunks []Interval, pairs []serialize.LineAlignmentPair) int
- func MaxVisibleLineDisplayWidth(hunks []Interval, pairs []serialize.LineAlignmentPair, ...) int
- func ShouldStyleStandalone(isUnpaired bool, spans []serialize.HighlightSpan, text string) bool
- type Interval
- type LineContext
- type MoveBadges
- type SliceConfig
- type Slicer
- type SpanCursor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeHunkRange ¶
func ComputeHunkRange( h Interval, pairs []serialize.LineAlignmentPair, hasSrc, hasDst bool, ) (srcStart, srcCount, dstStart, dstCount int)
ComputeHunkRange calculates 1-based start line numbers and line counts for both sides of a hunk.
func FormatHunkHeader ¶
FormatHunkHeader formats a standard unified diff hunk header line.
func FormatRange ¶
FormatRange formats a line start and count for a unified diff hunk header.
func IsPairChanged ¶ added in v0.15.0
func IsPairChanged( pair serialize.LineAlignmentPair, leftSpans []serialize.HighlightSpan, rightSpans []serialize.HighlightSpan, sText, dText string, showStyleChanges bool, isEOFChange bool, significantWhitespace bool, ) bool
IsPairChanged reports whether an alignment pair contains visible changes.
func IsPunctuationOrWhitespace ¶
IsPunctuationOrWhitespace reports whether s has no letters, digits, or identifier characters.
func LineDisplayWidth ¶ added in v0.15.0
LineDisplayWidth returns the column width of text in the terminal, expanding tabs and accounting for wide characters.
func MaxVisibleLine ¶ added in v0.15.0
func MaxVisibleLine(hunks []Interval, pairs []serialize.LineAlignmentPair) int
MaxVisibleLine returns the highest 1-indexed line number visible across the hunks, or 0 if empty.
func MaxVisibleLineDisplayWidth ¶ added in v0.15.0
func MaxVisibleLineDisplayWidth( hunks []Interval, pairs []serialize.LineAlignmentPair, srcLines, dstLines []string, srcBadges, dstBadges map[int]string, tabWidth int, ) int
MaxVisibleLineDisplayWidth returns the widest display width among source and destination lines across all visible hunks, including move badges.
func ShouldStyleStandalone ¶
func ShouldStyleStandalone(isUnpaired bool, spans []serialize.HighlightSpan, text string) bool
ShouldStyleStandalone returns true if an unpaired line is edited or just punctuation. Matched code stays neutral so shifted tokens aren't painted red or green.
Types ¶
type Interval ¶
Interval represents an inclusive index range [Start, End].
func BuildChangeIntervals ¶
BuildChangeIntervals collapses consecutive changed line pairs into intervals.
func MergeHunks ¶
MergeHunks expands change intervals by contextLines and merges overlapping hunks.
type LineContext ¶
type LineContext uint8
LineContext distinguishes paired aligned lines from single-sided additions or deletions.
const ( LineContextAligned LineContext = iota LineContextStandaloneDelete LineContextStandaloneInsert )
type MoveBadges ¶
type MoveBadges struct {
SrcLineBadges map[int]string // Source line index -> " ➔ L{dst}"
DstLineBadges map[int]string // Destination line index -> " ↳ L{src}"
SrcLineBadgeColors map[int]int // Source line index -> Color index (0: Cyan, 1: Magenta)
DstLineBadgeColors map[int]int // Destination line index -> Color index (0: Cyan, 1: Magenta)
}
MoveBadges contains line-level arrow annotations for moves.
func BuildMoveBadges ¶
func BuildMoveBadges( actions []serialize.Action, hunks []Interval, pairs []serialize.LineAlignmentPair, srcOffsets, dstOffsets []int, srcLines, dstLines []string, r *rules.Rules, ) MoveBadges
BuildMoveBadges computes directional line badges for moves.
type SliceConfig ¶
type SliceConfig struct {
TargetWidth int
TabWidth int
ColorMode bool
PadToTargetWidth bool
BadgeColor int
Context LineContext
}
SliceConfig configures line slicing, wrapping, and highlight styling.
type Slicer ¶
type Slicer struct {
// contains filtered or unexported fields
}
Slicer formats and slices lines into display chunks with syntax and action highlighting.
func (*Slicer) SliceLineToChunks ¶
func (s *Slicer) SliceLineToChunks( lineText string, badgeText string, spans []serialize.HighlightSpan, cfg SliceConfig, ) [][]byte
SliceLineToChunks formats a single line of text with syntax/action spans into display rows.
type SpanCursor ¶
type SpanCursor struct {
// contains filtered or unexported fields
}
SpanCursor provides zero-allocation streaming lookup over sorted disjoint spans.
func NewSpanCursor ¶
func NewSpanCursor(spans []serialize.HighlightSpan) SpanCursor
NewSpanCursor initializes a cursor over pre-sorted, pairwise-disjoint spans.
func (*SpanCursor) ActionAt ¶
func (c *SpanCursor) ActionAt(col int) color.ActionKind
ActionAt returns the highlight action active at byte offset col. col must not decrease between calls; the cursor never rewinds.
func (*SpanCursor) HasSpans ¶
func (c *SpanCursor) HasSpans() bool
HasSpans reports whether the cursor contains any highlight spans.