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 ExtractDeclarationSignature(node *serialize.NodeRef, lines []string, sStartLine, sEndLine int) string
- func FormatHunkHeader(srcStart, srcCount, dstStart, dstCount int, extra string) string
- func FormatRange(start, count int) string
- func IsPunctuationOrWhitespace(s string) bool
- 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 ExtractDeclarationSignature ¶
func ExtractDeclarationSignature(node *serialize.NodeRef, lines []string, sStartLine, sEndLine int) string
ExtractDeclarationSignature extracts the declaration signature line from lines, trimming leading decorators, comments, and trailing braces.
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 IsPunctuationOrWhitespace ¶
IsPunctuationOrWhitespace reports whether s has no letters, digits, or identifier characters.
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)
HunkHeaders map[int]string // Hunk index -> " func Foo() (moved to L{dst})"
}
MoveBadges contains line-level arrow annotations and hunk header descriptions for moves.
func BuildMoveBadges ¶
func BuildMoveBadges( actions []serialize.Action, hunks []Interval, pairs []serialize.LineAlignmentPair, srcOffsets, dstOffsets []int, srcLines, dstLines []string, r *rules.Rules, promoteDeclarations bool, ) MoveBadges
BuildMoveBadges computes directional line badges and hunk header move annotations.
type SliceConfig ¶
type SliceConfig struct {
TargetWidth int
TabWidth int
ColorMode bool
PadToTargetWidth bool
// RawTabs preserves literal tab characters instead of expanding them to column tab stops (e.g. in git patch mode).
RawTabs 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.