line

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Base text effects.
	Reset      = "\x1b[0m"
	Bold       = "\x1b[1m"
	Dim        = "\x1b[2m"
	Underscore = "\x1b[4m"
	Blink      = "\x1b[5m"
	Reverse    = "\x1b[7m"

	// Effects reset.
	BoldReset       = "\x1b[22m" // 21 actually causes underline instead
	DimReset        = "\x1b[22m"
	UnderscoreReset = "\x1b[24m"
	BlinkReset      = "\x1b[25m"
	ReverseReset    = "\x1b[27m"

	// Colors
	GreenFG       = "\x1b[32m"
	YellowFG      = "\x1b[33m"
	ResetFG       = "\x1b[39m"
	BrightWhiteFG = "\x1b[38;05;244m"
)
View Source
var (
	SplitChars        = " \n\t"
	SingleChar        = '\''
	DoubleChar        = '"'
	EscapeChar        = '\\'
	DoubleEscapeChars = "$`\"\n\\"
)
View Source
var (
	ErrUnterminatedSingleQuote = errors.New("unterminated single-quoted string")
	ErrUnterminatedDoubleQuote = errors.New("unterminated double-quoted string")
	ErrUnterminatedEscape      = errors.New("unterminated backslash-escape")
)

Functions

func AcceptMultiline

func AcceptMultiline(line []rune, mode EscapeMode) (accept bool)

acceptMultiline determines if the line just accepted is complete (in which case we should execute it), or incomplete (in which case we must read in multiline).

The mode controls escape handling: in EscapeLiteral, a trailing backslash is an ordinary character and never requests another line (only unterminated quotes do).

func HighlightCommand

func HighlightCommand(done, args []string, root *cobra.Command, cmdColor string) ([]string, []string)

HighlightCommand applies highlighting to commands in an input line.

func HighlightCommandFlags

func HighlightCommandFlags(done, args []string, flagColor string) ([]string, []string)

HighlightCommand applies highlighting to command flags in an input line.

func IsEmpty

func IsEmpty(line string, emptyChars ...rune) bool

IsEmpty checks if a given input line is empty. It accepts a list of characters that we consider to be irrelevant, that is, if the given line only contains these characters, it will be considered empty.

func Parse

func Parse(input string, mode EscapeMode) (args []string, err error)

Parse is in charge of removing all comments from the input line before execution, and if successfully parsed, split into words.

The mode governs how backslashes are treated when the (comment-stripped) line is split into words: EscapeShell applies POSIX escape rules, while EscapeLiteral preserves backslashes verbatim.

func Split

func Split(input string, hl bool, mode EscapeMode) (words []string, remainder string, err error)

Split has been copied from go-shellquote and slightly modified so as to also return the remainder when the parsing failed because of an unterminated quote.

In EscapeLiteral mode, backslashes are treated as ordinary characters: they are neither consumed as escapes nor able to mark a line continuation.

func TrimSpaces

func TrimSpaces(remain []string) (trimmed []string)

TrimSpaces removes all leading/trailing spaces from words

func UnescapeValue

func UnescapeValue(prefixComp, prefixLine, val string) string

UnescapeValue is used When the completer has returned us some completions, we sometimes need to post-process them a little before passing them to our shell.

Types

type EscapeMode added in v0.5.0

type EscapeMode int

EscapeMode controls how the line parser treats backslashes when splitting an input line into words.

const (
	// EscapeShell is the default POSIX-shell behaviour: a backslash escapes the
	// following character, so `C:\Windows` becomes `C:Windows`, and a trailing
	// backslash marks the line as an incomplete continuation.
	EscapeShell EscapeMode = iota

	// EscapeLiteral preserves backslashes as ordinary characters. Quotes still
	// group words and are removed, but `C:\Windows\Temp` is passed through
	// verbatim and a trailing backslash does not request another line.
	EscapeLiteral
)

Jump to

Keyboard shortcuts

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