renderutil

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package renderutil provides shared terminal rendering, highlighting, and hunk calculation primitives.

Index

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

func FormatHunkHeader(srcStart, srcCount, dstStart, dstCount int, extra string) string

FormatHunkHeader formats a standard unified diff hunk header line.

func FormatRange

func FormatRange(start, count int) string

FormatRange formats a line start and count for a unified diff hunk header.

func IsPunctuationOrWhitespace

func IsPunctuationOrWhitespace(s string) bool

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

type Interval struct {
	Start int
	End   int
}

Interval represents an inclusive index range [Start, End].

func BuildChangeIntervals

func BuildChangeIntervals(isPairChanged []bool) []Interval

BuildChangeIntervals collapses consecutive changed line pairs into intervals.

func MergeHunks

func MergeHunks(changeIntervals []Interval, totalPairs, contextLines int) []Interval

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: Teal, 1: Mauve, 2: Sapphire)
	DstLineBadgeColors map[int]int    // Destination line index -> Color index (0: Teal, 1: Mauve, 2: Sapphire)
	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
	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.

Jump to

Keyboard shortcuts

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