Documentation ¶
Overview ¶
Package ansi provides tools for generating terminal output containing ANSI escape codes.
Index ¶
- Constants
- Variables
- func CursorBack(columns int) string
- func CursorColumn(column int) string
- func CursorDown(lines int) string
- func CursorForward(columns int) string
- func CursorUp(lines int) string
- func Len(str string) int
- func PadRight(str string, length int) string
- func PadRightRune(str string, length int, padding rune) string
- func Strip(str string) string
- func Truncate(str string, maxLength int) string
- type EscapeSequence
- func (s EscapeSequence) Bold() EscapeSequence
- func (s EscapeSequence) Bright() EscapeSequence
- func (s EscapeSequence) BrightBG() EscapeSequence
- func (s EscapeSequence) Bytes() (bytes []byte)
- func (s EscapeSequence) IsBold() bool
- func (s EscapeSequence) IsBright() bool
- func (s EscapeSequence) IsBrightBG() bool
- func (s EscapeSequence) IsUnderline() bool
- func (s EscapeSequence) NotBold() EscapeSequence
- func (s EscapeSequence) NotBright() EscapeSequence
- func (s EscapeSequence) NotBrightBG() EscapeSequence
- func (s EscapeSequence) NotUnderline() EscapeSequence
- func (s EscapeSequence) String() (str string)
- func (s EscapeSequence) Underline() EscapeSequence
- func (s EscapeSequence) Wrap(stringToWrap string) string
Constants ¶
const ( // Reset is the ANSI reset sequence. Reset = "\033[0m" // EraseToEOL erases from the cursor to the end of the current line. EraseToEOL = "\033[K" )
Variables ¶
var EscapeSequencePattern = regexp.MustCompile(`(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]`)
EscapeSequencePattern is the pattern used for matching (and removing) ANSI escape sequences. From https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python
Functions ¶
func CursorBack ¶
func CursorColumn ¶
CursorColumn moves the cursor to an absolute position, with the leftmost column being 1.
func CursorDown ¶
func CursorForward ¶
func PadRight ¶
PadRight pads the right side of the given string using space characters, up to length, as measured by Len.
func PadRightRune ¶
PadRightRune pads the right side of the given string using rune, up to length, as measured by Len.
Types ¶
type EscapeSequence ¶
type EscapeSequence uint
EscapeSequence represents a basic ANSI escape sequence, in a way that allows bitwise combination. For example:
fmt.Print((Yellow | BlueBG | Bold).String()) # => \033[1;33;44m
const ( // Black foreground Black EscapeSequence = iota // Red foreground Red // Green foreground Green // Yellow foreground Yellow // Blue foreground Blue // Magenta foreground Magenta // Cyan foreground Cyan // White foreground White )
const ( // BlackBG background text BlackBG EscapeSequence = iota << 3 // RedBG background text RedBG // GreenBG background text GreenBG // YellowBG background text YellowBG // BlueBG background text BlueBG // MagentaBG background text MagentaBG // CyanBG background text CyanBG // WhiteBG background text WhiteBG )
const ( // Bright text Bright EscapeSequence = 1 << (iota + 6) // BrightBG background BrightBG // Bold text Bold // Underline text Underline )
func (EscapeSequence) Bold ¶
func (s EscapeSequence) Bold() EscapeSequence
func (EscapeSequence) Bright ¶
func (s EscapeSequence) Bright() EscapeSequence
func (EscapeSequence) BrightBG ¶
func (s EscapeSequence) BrightBG() EscapeSequence
func (EscapeSequence) Bytes ¶
func (s EscapeSequence) Bytes() (bytes []byte)
Bytes converts the EscapeSequence to a byte array, for writing to a terminal.
func (EscapeSequence) IsBold ¶
func (s EscapeSequence) IsBold() bool
func (EscapeSequence) IsBright ¶
func (s EscapeSequence) IsBright() bool
func (EscapeSequence) IsBrightBG ¶
func (s EscapeSequence) IsBrightBG() bool
func (EscapeSequence) IsUnderline ¶
func (s EscapeSequence) IsUnderline() bool
func (EscapeSequence) NotBold ¶
func (s EscapeSequence) NotBold() EscapeSequence
func (EscapeSequence) NotBright ¶
func (s EscapeSequence) NotBright() EscapeSequence
func (EscapeSequence) NotBrightBG ¶
func (s EscapeSequence) NotBrightBG() EscapeSequence
func (EscapeSequence) NotUnderline ¶
func (s EscapeSequence) NotUnderline() EscapeSequence
func (EscapeSequence) String ¶
func (s EscapeSequence) String() (str string)
String converts the EscapeSequence to a string, for writing to a terminal.
func (EscapeSequence) Underline ¶
func (s EscapeSequence) Underline() EscapeSequence
func (EscapeSequence) Wrap ¶
func (s EscapeSequence) Wrap(stringToWrap string) string
Wrap the given string with the escape sequence as a prefix, and Reset as a suffix.