inputsyntax

package
v0.222.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Highlighter

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

Highlighter applies an ordered set of rules to an already-rendered string.

func New

func New(rules []Rule, colorOf func(key string) string, render func(text, hexColor string) string) *Highlighter

New builds a Highlighter. colorOf resolves a theme color key to a hex color and render styles text with that color (e.g. styleProvider.GetThemeColor and styleProvider.RenderWithColor). rules may be empty, making Highlight a no-op.

func (*Highlighter) Highlight

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

Highlight runs every rule over s and returns the styled string. Rules are applied in order; since each rule already styles only genuine plain-text tokens (an earlier rule's ANSI moves a token's sigil off the boundary), the ordering matters only for tokens sharing a sigil (skills before shortcuts).

type Kind

type Kind int

Kind identifies a class of reserved input token.

const (
	// KindSkill is a "/<name>" token that routes to an installed agent skill.
	KindSkill Kind = iota
	// KindCatalogSkill is a "/<name>" token naming a catalog skill that is not
	// installed locally yet - invoking it downloads the skill first.
	KindCatalogSkill
	// KindShortcut is a "/<name>" token that maps to a chat shortcut command.
	KindShortcut
	// KindFileRef is an "@<path>" token expanded into file content.
	KindFileRef
	// KindIssueRef is a "#<number>" token (reserved for future use).
	KindIssueRef
)

type Rule

type Rule struct {
	Kind     Kind
	Re       *regexp.Regexp
	Sigil    byte
	ColorKey string
	Validate func(name string) bool
}

Rule describes one token class: how to find it, whether a given body is a real reference, and which theme color key to paint it with.

Regex contract: exactly two capture groups.

group 1 = the leading boundary (start-of-string or a single whitespace rune),
          re-emitted UNSTYLED (Go's regexp has no lookbehind).
group 2 = the full token INCLUDING its sigil (e.g. "/plan", "@a/b", "#365").

Sigil must be the first byte of group 2.

func CatalogSkillRule

func CatalogSkillRule(validate func(name string) bool) Rule

CatalogSkillRule highlights "/<skill>" tokens naming a catalog skill that is not installed yet, in a distinct color from an installed skill. validate must be disjoint from SkillRule's (installed vs not), so rule order is irrelevant; both still come before ShortcutRule.

func FileRefRule

func FileRefRule(validate func(name string) bool) Rule

FileRefRule highlights "@<path>" tokens. validate reports whether the path is a real, accessible file (typically fileService.ValidateFile == nil).

func IssueRefRule

func IssueRefRule(validate func(name string) bool) Rule

IssueRefRule highlights "#<number>" tokens. validate may be nil to style any "#<digits>" token. Reserved for future use.

func ShortcutRule

func ShortcutRule(validate func(name string) bool) Rule

ShortcutRule highlights "/<shortcut>" tokens. validate resolves a shortcut name to a registered shortcut (typically registry.Get). Apply AFTER SkillRule.

func SkillRule

func SkillRule(validate func(name string) bool) Rule

SkillRule highlights "/<skill>" tokens. validate resolves a lowercased skill name to a loaded skill (typically skillsService.Get).

Jump to

Keyboard shortcuts

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