highlight

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package highlight implements syntax highlighting.

Uses the chroma lexer to automatically select the appropriate lexer based on file extension, tokenizing text and mapping tokens to terminal colors.

Design: The chroma library provides lexing and styling. We create our own style (easyedit style), mapped to tcell colors. Tokenized results are cached and only re-parsed when the document changes.

Supported file types: - .py Python - .js / .jsx / .mjs JavaScript - .ts / .tsx TypeScript - .json JSON - .sh / .bash Shell - .html / .htm HTML - .css CSS - .md / .markdown Markdown - .go Go - .rs Rust - .yaml / .yml YAML - .java Java - .c / .h C - .cpp / .hpp / .cc C++ - .rb Ruby - .vix / .vixl Vix-lang

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBracket

func IsBracket(ch rune) bool

IsBracket checks if a rune is a bracket character.

func MatchingBracket

func MatchingBracket(ch rune) rune

MatchingBracket returns the matching bracket for a given bracket rune.

Types

type Highlighter

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

Highlighter manages syntax highlighting.

func NewHighlighter

func NewHighlighter(filePath string) *Highlighter

NewHighlighter creates a highlighter based on file path.

func (*Highlighter) GetTokenStyle

func (h *Highlighter) GetTokenStyle(t chroma.TokenType) TokenStyle

GetTokenStyle maps a chroma token type to terminal colors. Uses the monokai theme style mapping.

func (*Highlighter) SetFile

func (h *Highlighter) SetFile(filePath string)

SetFile updates the lexer when switching files.

func (*Highlighter) Tokenize

func (h *Highlighter) Tokenize(text string) []chroma.Token

Tokenize tokenizes the text and caches the result. Returns cached tokens if the text hasn't changed.

type TokenStyle

type TokenStyle struct {
	Fg tcell.Color
	Bg tcell.Color
}

TokenStyle stores the foreground and background colors for a token.

Jump to

Keyboard shortcuts

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