Documentation ¶
Index ¶
- func Actions(ctx context.Context, c ui.Creator) ([]input.Action, error)
- type Generic
- type GenericParser
- type HighlightOnChange
- func (h *HighlightOnChange) Name(context.Context) string
- func (h *HighlightOnChange) OpNames(context.Context) []string
- func (h *HighlightOnChange) SpansChanging(ctx context.Context, b input.Binder, spans ...ui.Span) []ui.Span
- func (h *HighlightOnChange) TextJustChanged(ctx context.Context, b input.Binder, hist ...)
- func (h *HighlightOnChange) Type(input.Hook)
- type Highlighter
- type Parser
- type SpanApplier
- type SyntaxTheme
- func (t *SyntaxTheme) AddBeforeAfter(_ context.Context, construct theme.LanguageConstruct, before, after string)
- func (t *SyntaxTheme) AddCustom(_ context.Context, ...)
- func (t *SyntaxTheme) AddIdents(_ context.Context, construct theme.LanguageConstruct, idents ...string)
- func (t *SyntaxTheme) AddScope(_ context.Context, open, close string)
- func (t *SyntaxTheme) AddStyle(_ context.Context, cnst theme.LanguageConstruct, st theme.Style) bool
- func (t *SyntaxTheme) AddWrappedConstruct(_ context.Context, construct theme.LanguageConstruct, canNest bool, ...)
- func (t *SyntaxTheme) CurrentHighlights(ctx context.Context, b input.Binder) (writeKey int, highlights []ui.Span)
- func (t *SyntaxTheme) Empty(context.Context) input.HookedOperation
- func (t *SyntaxTheme) HighlightSyntax(ctx context.Context, spans ...ui.Span) <-chan input.Operation
- func (t *SyntaxTheme) Name(context.Context) string
- func (t *SyntaxTheme) Run(ctx context.Context, b input.Binder) error
- func (t *SyntaxTheme) SetHook(ctx context.Context, h input.Hook) error
- func (t *SyntaxTheme) Type(input.Operation)
- func (t *SyntaxTheme) UpdateHighlights(ctx context.Context, b input.Binder, writeKey int, hl []ui.Span) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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) SpansChanging ¶
func (*HighlightOnChange) TextJustChanged ¶
func (*HighlightOnChange) Type ¶
func (h *HighlightOnChange) Type(input.Hook)
type Highlighter ¶
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 ¶
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 (t *SyntaxTheme) Empty(context.Context) input.HookedOperation
func (*SyntaxTheme) HighlightSyntax ¶
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) 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.