syntax

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package syntax turns Chroma tokens into Scry-owned terminal styling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectLexer

func DetectLexer(path, oldPath, sample string) chroma.Lexer

DetectLexer selects a lexer by path, old path, content sample, then fallback.

func HighlightLine

func HighlightLine(path, oldPath, sample, body string) string

HighlightLine highlights one diff body without using a cache.

func Highlightable

func Highlightable(kind model.LineKind) bool

Highlightable reports whether syntax highlighting should apply to a diff line.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache owns memoized syntax rendering for loaded patches.

func NewCache

func NewCache(profiles ...terminal.ColorProfile) *Cache

NewCache creates an empty syntax cache.

func (*Cache) ForPatch

func (c *Cache) ForPatch(patch model.FilePatch, contentHash string) *LineCache

ForPatch returns the line cache keyed by path and PatchLoadState content hash.

type CacheKey

type CacheKey struct {
	Path        string
	ContentHash string
}

CacheKey identifies the highlighted line cache for one loaded patch.

type Highlighter

type Highlighter struct {
	// contains filtered or unexported fields
}

Highlighter wraps a coalesced Chroma lexer.

func NewHighlighter

func NewHighlighter(path, oldPath, sample string, profiles ...terminal.ColorProfile) *Highlighter

NewHighlighter creates a highlighter using Scry's lexer detection order.

func (*Highlighter) Highlight

func (h *Highlighter) Highlight(body string) string

Highlight renders body text with Scry-owned styles.

func (*Highlighter) HighlightBackground added in v0.5.1

func (h *Highlighter) HighlightBackground(body string, background lipgloss.Color) string

HighlightBackground renders body text with a background applied to every token.

func (*Highlighter) HighlightSpan

func (h *Highlighter) HighlightSpan(body string, start, end int) string

HighlightSpan renders body text and reverses the provided raw byte span.

func (*Highlighter) HighlightSpanBackground added in v0.5.1

func (h *Highlighter) HighlightSpanBackground(body string, start, end int, background lipgloss.Color) string

HighlightSpanBackground renders a reversed raw byte span over a token background.

type LineCache

type LineCache struct {
	// contains filtered or unexported fields
}

LineCache memoizes highlighted bodies by logical diff-line index.

func NewLineCache

func NewLineCache(path, oldPath, sample string, profiles ...terminal.ColorProfile) *LineCache

NewLineCache creates a per-patch line highlighter.

func (*LineCache) HighlightLine

func (lc *LineCache) HighlightLine(line int, body string) string

HighlightLine returns the cached highlighted body for a diff line.

func (*LineCache) HighlightLineBackground added in v0.5.1

func (lc *LineCache) HighlightLineBackground(line int, body string, background lipgloss.Color) string

HighlightLineBackground returns a cached highlighted line with a background applied to every token.

func (*LineCache) HighlightLineSpan

func (lc *LineCache) HighlightLineSpan(line int, body string, start, end int) string

HighlightLineSpan highlights a transient search span without caching it.

func (*LineCache) HighlightLineSpanBackground added in v0.5.1

func (lc *LineCache) HighlightLineSpanBackground(line int, body string, start, end int, background lipgloss.Color) string

HighlightLineSpanBackground highlights a transient search span over a background.

Jump to

Keyboard shortcuts

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