style

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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

View Source
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 ForExtension

func ForExtension(extension string) string

ForExtension returns the style for a given file extension (e.g. "json", "go"). The leading dot is optional and matching is case-insensitive. An LS_COLORS entry ("*.<ext>") takes precedence and is returned verbatim; otherwise the documented built-in extension map applies; otherwise candidates reset to standard terminal styling.

func ForPathExt

func ForPathExt(path string) string

ForPathExt returns the style for a given path based on its extension. Compound archive extensions (.tar.gz, .tar.bz2, .tar.xz) are matched before the final path element extension.

func IndexedHex

func IndexedHex(index int) (string, bool)

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

func NearestIndexed(red int, green int, blue int) int

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 Of

func Of(styles ...string) string

Of combines multiple style tokens into a single space-delimited style string.

func RGBHex

func RGBHex(red, green, blue int) string

RGBHex renders an RGB triple as a "#rrggbb" hex code.

func SGR

func SGR(s string) string

SGR returns the ECMA-48 SGR parameter numbers for a given style string.

func TruecolorRGB

func TruecolorRGB(token string) (int, int, int, bool)

TruecolorRGB parses a truecolor token ("#rrggbb" or "rgb(r,g,b)") into its RGB components, and reports whether the token is a truecolor form.

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.

func (Palette) Highlight

func (p Palette) Highlight(level int) string

Highlight returns the configured style for a given highlight depth level (0–11). Out-of-range levels reset to standard terminal styling.

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

func Parse(s string) Style

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

func (s Style) SGR() string

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.

Jump to

Keyboard shortcuts

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