Documentation
¶
Overview ¶
Package syntax turns Chroma tokens into Scry-owned terminal styling.
Index ¶
- func DetectLexer(path, oldPath, sample string) chroma.Lexer
- func HighlightLine(path, oldPath, sample, body string) string
- func Highlightable(kind model.LineKind) bool
- type Cache
- type CacheKey
- type Highlighter
- func (h *Highlighter) Highlight(body string) string
- func (h *Highlighter) HighlightBackground(body string, background lipgloss.Color) string
- func (h *Highlighter) HighlightSpan(body string, start, end int) string
- func (h *Highlighter) HighlightSpanBackground(body string, start, end int, background lipgloss.Color) string
- type LineCache
- func (lc *LineCache) HighlightLine(line int, body string) string
- func (lc *LineCache) HighlightLineBackground(line int, body string, background lipgloss.Color) string
- func (lc *LineCache) HighlightLineSpan(line int, body string, start, end int) string
- func (lc *LineCache) HighlightLineSpanBackground(line int, body string, start, end int, background lipgloss.Color) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectLexer ¶
DetectLexer selects a lexer by path, old path, content sample, then fallback.
func HighlightLine ¶
HighlightLine highlights one diff body without using a cache.
func Highlightable ¶
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.
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 ¶
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 ¶
HighlightLineSpan highlights a transient search span without caching it.