Documentation
¶
Overview ¶
Package style provides the terminal styling vocabulary for CONGA completion: color and attribute tokens, their ECMA-48 SGR translations, file extension styling, and the default completion palette.
Vocabulary ¶
Style strings are space-separated token strings from a closed vocabulary (see docs/completion-wire-protocol.md §6):
- Attributes: "bold", "dim", "italic", "underlined", "blink", "inverse"
- Foreground: "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "bright-" prefixed variants, "fg-default"
- Background: "bg-" prefixed foreground tokens, including "bg-bright-*" variants and "bg-default"
- Extended: "color0"–"color255", "#rrggbb", and "rgb(r,g,b)", each also usable after a "bg-" prefix
Tokens outside this vocabulary are ignored. SGR parameter numbers are emitted in a fixed order: attributes (bold 1, dim 2, italic 3, underlined 4, blink 5, inverse 7), then foreground, then background.
Index ¶
- Constants
- Variables
- func ForDirectory() string
- func ForExecutable() string
- func ForOrphanSymlink() string
- func ForPathExt(path string) string
- func ForSymlink() string
- func IndexedHex(index int) (string, bool)
- func NearestIndexed(red int, green int, blue int) int
- func Of(styles ...string) string
- func RGBHex(red, green, blue int) string
- func SGR(s string) string
- func SymlinkAsTarget() bool
- func TruecolorRGB(token string) (int, int, int, bool)
- type Palette
- type Style
Constants ¶
const ( // Default resets to standard terminal styling. Default = "" // Black standard foreground color. Black = "black" // Red standard foreground color. Red = "red" // Green standard foreground color. Green = "green" // Yellow standard foreground color. Yellow = "yellow" // Blue standard foreground color. Blue = "blue" // Magenta standard foreground color. Magenta = "magenta" // Cyan standard foreground color. Cyan = "cyan" // White standard foreground color. White = "white" // BrightBlack bright foreground color. BrightBlack = "bright-black" // BrightRed bright foreground color. BrightRed = "bright-red" // BrightGreen bright foreground color. BrightGreen = "bright-green" // BrightYellow bright foreground color. BrightYellow = "bright-yellow" // BrightBlue bright foreground color. BrightBlue = "bright-blue" // BrightMagenta bright foreground color. BrightMagenta = "bright-magenta" // BrightCyan bright foreground color. BrightCyan = "bright-cyan" // BrightWhite bright foreground color. BrightWhite = "bright-white" // BgBlack standard background color. BgBlack = "bg-black" // BgRed standard background color. BgRed = "bg-red" // BgGreen standard background color. BgGreen = "bg-green" // BgYellow standard background color. BgYellow = "bg-yellow" // BgBlue standard background color. BgBlue = "bg-blue" // BgMagenta standard background color. BgMagenta = "bg-magenta" // BgCyan standard background color. BgCyan = "bg-cyan" // BgWhite standard background color. BgWhite = "bg-white" // BgBrightBlack bright background color. BgBrightBlack = "bg-bright-black" // BgBrightRed bright background color. BgBrightRed = "bg-bright-red" // BgBrightGreen bright background color. BgBrightGreen = "bg-bright-green" // BgBrightYellow bright background color. BgBrightYellow = "bg-bright-yellow" // BgBrightBlue bright background color. BgBrightBlue = "bg-bright-blue" // BgBrightMagenta bright background color. BgBrightMagenta = "bg-bright-magenta" // BgBrightCyan bright background color. BgBrightCyan = "bg-bright-cyan" // BgBrightWhite bright background color. BgBrightWhite = "bg-bright-white" // Bold text formatting attribute. Bold = "bold" // Dim text formatting attribute. Dim = "dim" // Italic text formatting attribute. Italic = "italic" // Underlined text formatting attribute. Underlined = "underlined" // Blink text formatting attribute. Blink = "blink" // Inverse text formatting attribute. Inverse = "inverse" )
Variables ¶
var Theme = Palette{ Value: Default, Description: Dim, Error: "bold red", Usage: Dim, Highlights: [12]string{ Blue, Yellow, Magenta, Cyan, Green, "dim blue", "dim yellow", "dim magenta", "dim cyan", "dim green", Bold, "dim bold", }, FlagArg: Blue, FlagMultiArg: Magenta, FlagNoArg: Default, FlagOptArg: Yellow, }
Theme is the active completion palette. Drivers read styles from it when rendering candidates; its fields may be overridden to customize colors.
Functions ¶
func ForDirectory ¶ added in v0.9.0
func ForDirectory() string
ForDirectory returns the style for a directory: the LS_COLORS "di" entry, otherwise bold blue.
func ForExecutable ¶ added in v0.9.0
func ForExecutable() string
ForExecutable returns the style for an executable file: the LS_COLORS "ex" entry, otherwise green. As in ls, it outranks the file's suffix entry.
func ForOrphanSymlink ¶ added in v0.9.0
func ForOrphanSymlink() string
ForOrphanSymlink returns the style for a symbolic link whose target is missing: the LS_COLORS "or" entry, otherwise the link style. Under "ln=target" a missing target has no style to borrow, so the link renders plain ("fg-default"), which also overrides the theme's value style.
func ForPathExt ¶
ForPathExt returns the style for a regular file by its name. The last LS_COLORS "*<suffix>" entry the name ends with wins ("*.go", "*.tar.gz", "*README"), matched case-insensitively and translated from its SGR codes into the style vocabulary ("01;36" → "bold cyan"), as ls does. Without a matching entry the documented built-in extension map applies, compound archive extensions (.tar.gz, .tar.bz2, .tar.xz) before the final one; otherwise candidates reset to standard terminal styling.
func ForSymlink ¶ added in v0.9.0
func ForSymlink() string
ForSymlink returns the style for a symbolic link whose target exists: the LS_COLORS "ln" entry, otherwise cyan. Callers check SymlinkAsTarget first.
func IndexedHex ¶
IndexedHex returns the "#rrggbb" rendering of the xterm 256-color palette entry with the given index, and false when the index is out of range.
func NearestIndexed ¶
NearestIndexed returns the index (0-255) of the xterm 256-color palette entry nearest to the given RGB triple by squared RGB distance; ties resolve to the lowest index.
func SymlinkAsTarget ¶ added in v0.9.0
func SymlinkAsTarget() bool
SymlinkAsTarget reports whether LS_COLORS sets "ln=target": a link whose target exists is then styled as its target would be (directory, executable, or by the target's name).
Types ¶
type Palette ¶
type Palette struct {
// Value is the default style for values.
Value string
// Description is the default style for descriptions.
Description string
// Error is the default style for errors.
Error string
// Usage is the default style for usage messages.
Usage string
// Highlights styles grouped candidate categories by depth (index 0-11).
Highlights [12]string
// FlagArg styles flags with an argument.
FlagArg string
// FlagMultiArg styles flags with multiple arguments.
FlagMultiArg string
// FlagNoArg styles flags without an argument.
FlagNoArg string
// FlagOptArg styles flags with an optional argument.
FlagOptArg string
}
Palette defines the color palette for completion rendering. All fields hold style token strings from the package vocabulary.
type Style ¶
type Style struct {
Foreground string
Background string
Bold bool
Dim bool
Italic bool
Underlined bool
Blink bool
Inverse bool
}
Style represents parsed text styling attributes and colors.
func Parse ¶
Parse parses a space-separated style string into a structured Style. Tokens are matched case-insensitively against the closed vocabulary; unknown tokens are ignored.
func (Style) SGR ¶
SGR returns the semicolon-delimited ECMA-48 SGR parameter numbers for this style: attributes first (bold 1, dim 2, italic 3, underlined 4, blink 5, inverse 7), then foreground, then background. Colors that cannot be translated are omitted. The result carries no escape-sequence framing.