theme

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Actions

func Actions(ctx context.Context, c ui.Creator) ([]input.Action, error)

Types

type Generic

type Generic struct {
	Scopes       []scope
	Wrapped      []wrapped
	StaticWords  map[string]theme.LanguageConstruct
	DynamicWords []word
	Custom       []func([]rune, int) (_ theme.LanguageConstruct, end int)
}

Generic understands and parses a general map of a language syntax.

Note that fields and methods on this type intentionally use unexported types to prevent plugins from importing and using this code. This is part of the GPLed code in vidar and should not be imported directly. We leave this type exported to serve as an example of a code parser for plugins to reference, not as a type for them to import.

func (*Generic) Parse

func (g *Generic) Parse(ctx context.Context, text []rune) []syntaxPart

type GenericParser

type GenericParser interface {
	input.Hook

	// SetParsingRules requests that this GenericParser apply its parsing rules
	// to the Themer (passed in as an input.Operation). The Parser can add rules
	// like so:
	//
	//     type Themer interface {
	//         WithIdent()
	//     }
	//     func SetParsingRules(ctx context.Context, op input.Operation) error {
	//         th
	//     }
	SetParsingRules(context.Context, input.Operation) error
}

GenericParser is a type which just defines very simple language constructs and how to parse them. It will be given access to a Themer which it should add its parsing rules to.

This is less powerful than the SyntaxHighlighter hook, but should provide a good starting point.

type HighlightOnChange

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

func NewHighlightOnChange

func NewHighlightOnChange(c ui.Creator) *HighlightOnChange

func (*HighlightOnChange) Name

func (*HighlightOnChange) OpNames

func (h *HighlightOnChange) OpNames(context.Context) []string

func (*HighlightOnChange) SpansChanging

func (h *HighlightOnChange) SpansChanging(ctx context.Context, b input.Binder, spans ...ui.Span) []ui.Span

func (*HighlightOnChange) TextJustChanged

func (h *HighlightOnChange) TextJustChanged(ctx context.Context, b input.Binder, hist ...struct {
	Before text.State
	Edit   input.Edit
})

func (*HighlightOnChange) Type

func (h *HighlightOnChange) Type(input.Hook)

type Highlighter

type Highlighter interface {
	input.Operation
	CurrentHighlights(context.Context, input.Binder) (int, []ui.Span)
	UpdateHighlights(context.Context, input.Binder, int, []ui.Span) bool
	HighlightSyntax(context.Context, ...ui.Span) <-chan input.Operation
}

type Parser

type Parser interface {
	input.Hook

	// Lex is called with the text of the document and the position of the next
	// rune that needs to be lexed. It returns an enum constant representing its
	// own internal tokens, the start and end indexes of that token, and any
	// error it encountered.
	//
	// The Themer expects Lex to skip any text that it does not want to pass to
	// Parse, so for example a Parser that only cares about `!=` should skip any
	// text that is not `!=`.
	//
	// If Lex returns an error, then no syntax highlighting will be performed -
	// the last successful highlights will remain in place.
	Lex(_ context.Context, text []rune, pos int) (tok int, start, end int, _ error)

	// Parse is called with the list of tokens from Lex and the index and text
	// of the unparsed token. It returns the theme.LanguageConstruct for syntax
	// highlighting purposes, the text to display for that token (usually just
	// nextTokText, although Parsers may return unicode symbols here), and any
	// error encountered.
	//
	// If Parse returns an error, then no syntax highlighting will be performed
	// - the last successful highlights will remain in place.
	//
	// Note that it's possible for multiple Parser types to be run on the same
	// text, and later Parse calls will override earlier Parse calls unless the
	// returned theme.LanguageConstruct is theme.None.
	//
	// This means that it's possible to implement a Parser that only cares about
	// translating `!=` into `≠`, returning theme.None to avoid overriding
	// highlights.
	Parse(_ context.Context, tokens []int, nextTokIdx int, nextTokText []rune) (theme.LanguageConstruct, []rune, error)
}

Parser is a type which has its own internal lexer and parser rules.

Vidar will take care of calling the Parser whenever text changes, although during rapid input the Parser may be called infrequently. Vidar tries to prioritize showing user input as soon as possible, running any potentially expensive logic concurrently and applying it during a pause in user input.

type SpanApplier

type SpanApplier interface {
	input.Operation
	WithSpans(...ui.Span) input.Operation
}

SpanApplier is the operation that applies changes to the display text.

type SyntaxTheme

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

func NewSyntaxTheme

func NewSyntaxTheme(ctx context.Context, c ui.Creator) *SyntaxTheme

func (*SyntaxTheme) AddBeforeAfter

func (t *SyntaxTheme) AddBeforeAfter(_ context.Context, construct theme.LanguageConstruct, before, after string)

func (*SyntaxTheme) AddCustom

func (t *SyntaxTheme) AddCustom(_ context.Context, f func(text []rune, startIndex int) (construct theme.LanguageConstruct, end int))

func (*SyntaxTheme) AddIdents

func (t *SyntaxTheme) AddIdents(_ context.Context, construct theme.LanguageConstruct, idents ...string)

func (*SyntaxTheme) AddScope

func (t *SyntaxTheme) AddScope(_ context.Context, open, close string)

func (*SyntaxTheme) AddStyle

func (t *SyntaxTheme) AddStyle(_ context.Context, cnst theme.LanguageConstruct, st theme.Style) bool

AddStyle adds a style for t to apply. It returns whether or not the style was applied.

AddStyle will never override an existing style, since the theme is user-configurable.

func (*SyntaxTheme) AddWrappedConstruct

func (t *SyntaxTheme) AddWrappedConstruct(_ context.Context, construct theme.LanguageConstruct, canNest bool, start, end string, escapes ...string)

func (*SyntaxTheme) CurrentHighlights

func (t *SyntaxTheme) CurrentHighlights(ctx context.Context, b input.Binder) (writeKey int, highlights []ui.Span)

CurrentHighlights returns the current highlights and a write key to use for updating the highlights using CompareAndSwapHighlights.

func (*SyntaxTheme) Empty

func (*SyntaxTheme) HighlightSyntax

func (t *SyntaxTheme) HighlightSyntax(ctx context.Context, spans ...ui.Span) <-chan input.Operation

HighlightSyntax starts parsing the syntax in spans, returning a channel that will be sent an operation to apply syntax highlighting when the parsing is done.

The function return may be used to cancel the highlighter.

func (*SyntaxTheme) Name

func (t *SyntaxTheme) Name(context.Context) string

func (*SyntaxTheme) Run

func (t *SyntaxTheme) Run(ctx context.Context, b input.Binder) error

func (*SyntaxTheme) SetHook

func (t *SyntaxTheme) SetHook(ctx context.Context, h input.Hook) error

func (*SyntaxTheme) Type

func (t *SyntaxTheme) Type(input.Operation)

func (*SyntaxTheme) UpdateHighlights

func (t *SyntaxTheme) UpdateHighlights(ctx context.Context, b input.Binder, writeKey int, hl []ui.Span) bool

UpdateHighlights updates the highlights present in b using the key returned by CurrentHighlights. If the key has changed in the mean time, UpdateHighlights will return false.

Jump to

Keyboard shortcuts

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