Documentation ¶
Index ¶
- Variables
- func ASCIIOnce() int
- func AttributeAndColor(attr, name string) string
- func AttributeNumber(name string) string
- func AttributeOrColor(name string) string
- func BrightColor(text, color string) string
- func Clear()
- func Close()
- func ColorNum(colorNum int) string
- func ColorString(line, colors string) string
- func Colors() []string
- func Commands() []string
- func DarkColor(text, color string) string
- func Do(command string)
- func Down(n uint)
- func EchoOff()
- func Get(command string, replacemap map[string]string) string
- func GetBackgroundColor(tty *TTY) (float64, float64, float64, error)
- func Home()
- func Init()
- func KeyCodeOnce() int
- func KeyOnce() int
- func Left(n uint)
- func NoColor() string
- func Reset()
- func Right(n uint)
- func ScreenHeight() int
- func ScreenWidth() int
- func Set(command string, replacemap map[string]string)
- func SetAttribute(name string)
- func SetAttributeAndColor(attr, name string)
- func SetColorNum(colorNum int)
- func SetLineWrap(enable bool)
- func SetNoColor()
- func SetXY(x, y uint)
- func ShowCursor(enable bool)
- func Stop() string
- func TermSize() (uint, uint, error)
- func TrueColor(fg color.Color, text string) string
- func Up(n uint)
- func WaitForKey()
- func Words(line string, colors ...string) string
- func Write(x, y int, text string, fg, bg AttributeColor)
- func WriteRune(x, y int, r rune, fg, bg AttributeColor)
- type AttributeColor
- func (ac AttributeColor) Background() AttributeColor
- func (ac AttributeColor) Bright() AttributeColor
- func (ac AttributeColor) Combine(other AttributeColor) AttributeColor
- func (ac *AttributeColor) Equal(other AttributeColor) bool
- func (ac AttributeColor) Error(text string)
- func (ac AttributeColor) Get(text string) string
- func (ac AttributeColor) Head() byte
- func (ac AttributeColor) Ints() []int
- func (ac AttributeColor) Output(text string)
- func (ac AttributeColor) Start(text string) string
- func (ac AttributeColor) StartStop(text string) string
- func (ac AttributeColor) Stop(text string) string
- func (ac AttributeColor) String() string
- func (ac AttributeColor) Tail() []byte
- type Canvas
- func (c *Canvas) At(x, y uint) (rune, error)
- func (c *Canvas) Clear()
- func (c *Canvas) Copy() Canvas
- func (c *Canvas) Draw()
- func (c *Canvas) Fill(fg AttributeColor)
- func (c *Canvas) FillBackground(bg AttributeColor)
- func (c *Canvas) H() uint
- func (c *Canvas) Height() uint
- func (c *Canvas) HideCursor()
- func (c *Canvas) Plot(x, y uint, r rune)
- func (c *Canvas) PlotAll()
- func (c *Canvas) PlotColor(x, y uint, fg AttributeColor, r rune)
- func (c *Canvas) Redraw()
- func (c *Canvas) Resize()
- func (c *Canvas) Resized() *Canvas
- func (c *Canvas) SetLineWrap(enable bool)
- func (c *Canvas) SetRunewise(b bool)
- func (c *Canvas) SetShowCursor(enable bool)
- func (c *Canvas) ShowCursor()
- func (c *Canvas) Size() (uint, uint)
- func (c *Canvas) String() string
- func (c *Canvas) W() uint
- func (c *Canvas) Width() uint
- func (c *Canvas) Write(x, y uint, fg, bg AttributeColor, s string)
- func (c *Canvas) WriteRune(x, y uint, fg, bg AttributeColor, r rune)
- func (c *Canvas) WriteRuneB(x, y uint, fg, bgb AttributeColor, r rune)
- func (c *Canvas) WriteRunesB(x, y uint, fg, bgb AttributeColor, r rune, count uint)
- func (c *Canvas) WriteString(x, y uint, fg, bg AttributeColor, s string)
- type Char
- type ColorRune
- type TTY
- func (tty *TTY) ASCII() int
- func (tty *TTY) Close()
- func (tty *TTY) Key() int
- func (tty *TTY) KeyCode() int
- func (tty *TTY) NoBlock()
- func (tty *TTY) RawMode()
- func (tty *TTY) ReadString() (string, error)
- func (tty *TTY) Restore()
- func (tty *TTY) Rune() rune
- func (tty *TTY) SetTimeout(d time.Duration)
- func (tty *TTY) String() string
- func (tty *TTY) Term() *term.Term
- func (tty *TTY) WriteString(s string) error
Constants ¶
This section is empty.
Variables ¶
var ( // Non-color attributes ResetAll = NewAttributeColor("Reset all attributes") Bright = NewAttributeColor("Bright") Dim = NewAttributeColor("Dim") Underscore = NewAttributeColor("Underscore") Blink = NewAttributeColor("Blink") Reverse = NewAttributeColor("Reverse") Hidden = NewAttributeColor("Hidden") None AttributeColor // Dark foreground colors (+ light gray) Black = NewAttributeColor("Black") Red = NewAttributeColor("Red") Green = NewAttributeColor("Green") Yellow = NewAttributeColor("Yellow") Blue = NewAttributeColor("Blue") Magenta = NewAttributeColor("Magenta") Cyan = NewAttributeColor("Cyan") LightGray = NewAttributeColor("White") // Light foreground colors (+ dark gray) DarkGray = NewAttributeColor("90") LightRed = NewAttributeColor("91") LightGreen = NewAttributeColor("92") LightYellow = NewAttributeColor("93") LightBlue = NewAttributeColor("94") LightMagenta = NewAttributeColor("95") LightCyan = NewAttributeColor("96") White = NewAttributeColor("97") // Aliases Pink = LightMagenta Gray = DarkGray // Dark background colors (+ light gray) BackgroundBlack = NewAttributeColor("40") BackgroundRed = NewAttributeColor("41") BackgroundGreen = NewAttributeColor("42") BackgroundYellow = NewAttributeColor("43") BackgroundBlue = NewAttributeColor("44") BackgroundMagenta = NewAttributeColor("45") BackgroundCyan = NewAttributeColor("46") BackgroundLightGray = NewAttributeColor("47") // Aliases BackgroundWhite = BackgroundLightGray BackgroundGray = BackgroundLightGray // Default colors (usually gray) Default = NewAttributeColor("39") DefaultBackground = NewAttributeColor("49") BackgroundDefault = NewAttributeColor("49") DarkColorMap = map[string]AttributeColor{ "black": Black, "Black": Black, "red": Red, "Red": Red, "green": Green, "Green": Green, "yellow": Yellow, "Yellow": Yellow, "blue": Blue, "Blue": Blue, "magenta": Magenta, "Magenta": Magenta, "cyan": Cyan, "Cyan": Cyan, "gray": DarkGray, "Gray": DarkGray, "white": LightGray, "White": LightGray, "lightwhite": White, "LightWhite": White, "darkred": Red, "DarkRed": Red, "darkgreen": Green, "DarkGreen": Green, "darkyellow": Yellow, "DarkYellow": Yellow, "darkblue": Blue, "DarkBlue": Blue, "darkmagenta": Magenta, "DarkMagenta": Magenta, "darkcyan": Cyan, "DarkCyan": Cyan, "darkgray": DarkGray, "DarkGray": DarkGray, "lightred": LightRed, "LightRed": LightRed, "lightgreen": LightGreen, "LightGreen": LightGreen, "lightyellow": LightYellow, "LightYellow": LightYellow, "lightblue": LightBlue, "LightBlue": LightBlue, "lightmagenta": LightMagenta, "LightMagenta": LightMagenta, "lightcyan": LightCyan, "LightCyan": LightCyan, "lightgray": LightGray, "LightGray": LightGray, } LightColorMap = map[string]AttributeColor{ "black": Black, "Black": Black, "red": LightRed, "Red": LightRed, "green": LightGreen, "Green": LightGreen, "yellow": LightYellow, "Yellow": LightYellow, "blue": LightBlue, "Blue": LightBlue, "magenta": LightMagenta, "Magenta": LightMagenta, "cyan": LightCyan, "Cyan": LightCyan, "gray": LightGray, "Gray": LightGray, "white": White, "White": White, "lightwhite": White, "LightWhite": White, "lightred": LightRed, "LightRed": LightRed, "lightgreen": LightGreen, "LightGreen": LightGreen, "lightyellow": LightYellow, "LightYellow": LightYellow, "lightblue": LightBlue, "LightBlue": LightBlue, "lightmagenta": LightMagenta, "LightMagenta": LightMagenta, "lightcyan": LightCyan, "LightCyan": LightCyan, "lightgray": LightGray, "LightGray": LightGray, "darkred": Red, "DarkRed": Red, "darkgreen": Green, "DarkGreen": Green, "darkyellow": Yellow, "DarkYellow": Yellow, "darkblue": Blue, "DarkBlue": Blue, "darkmagenta": Magenta, "DarkMagenta": Magenta, "darkcyan": Cyan, "DarkCyan": Cyan, "darkgray": DarkGray, "DarkGray": DarkGray, } )
Functions ¶
func AttributeAndColor ¶
Get the terminal command for setting a terminal attribute and a color
func AttributeNumber ¶ added in v0.5.0
Returns the number (as a string) for a given attribute name. Returns the given string if the attribute was not found in the spec.
func AttributeOrColor ¶
Execute the terminal command for setting a given display attribute name, like "Bright" or "Blink"
func BrightColor ¶
Return text with a bright color applied
func ColorString ¶ added in v1.2.0
ColorString takes a string with words to be colored and another string with colors with which to color the words. Example strings: "hello there" and "red blue".
func GetBackgroundColor ¶ added in v1.10.0
GetBackgroundColor prints a code to the terminal emulator, reads the results and tries to interpret it as the RGB background color. Returns three float64 values, and possibly an error value.
func KeyCodeOnce ¶ added in v0.2.1
func KeyCodeOnce() int
func NoColor ¶
func NoColor() string
Get the terminal command for setting no colors or other display attributes
func SetAttribute ¶
func SetAttribute(name string)
Execute the terminal command for setting a given display attribute name, like "Bright" or "Blink"
func SetAttributeAndColor ¶
func SetAttributeAndColor(attr, name string)
Execute the terminal command for setting a terminal attribute and a color
func SetColorNum ¶
func SetColorNum(colorNum int)
Execute the terminal command for setting a given color number
func SetLineWrap ¶
func SetLineWrap(enable bool)
func SetNoColor ¶
func SetNoColor()
Execute the terminal command for setting no colors or other display attributes
func ShowCursor ¶
func ShowCursor(enable bool)
func TrueColor ¶ added in v0.4.0
This is not part of the VT100 spec, but an easteregg for displaying 24-bit "true color" on some terminals. Example use: fmt.Println(vt100.TrueColor(color.RGBA{0xa0, 0xe0, 0xff, 0xff}, "TrueColor"))
func Words ¶ added in v0.7.0
Words takes a string with words and several color-strings, like "blue". Color the words with the corresponding colors and return the string.
func Write ¶ added in v0.6.0
func Write(x, y int, text string, fg, bg AttributeColor)
Output a string at x, y with the given colors
func WriteRune ¶ added in v0.6.0
func WriteRune(x, y int, r rune, fg, bg AttributeColor)
Output a rune at x, y with the given colors
Types ¶
type AttributeColor ¶ added in v0.3.0
type AttributeColor []byte
func NewAttributeColor ¶ added in v0.5.0
func NewAttributeColor(attributes ...string) AttributeColor
func (AttributeColor) Background ¶ added in v0.7.0
func (ac AttributeColor) Background() AttributeColor
Modify color attributes so that they become background color attributes instead
func (AttributeColor) Bright ¶ added in v0.6.0
func (ac AttributeColor) Bright() AttributeColor
Return a new AttributeColor that has "Bright" added to the list of attributes
func (AttributeColor) Combine ¶ added in v0.5.0
func (ac AttributeColor) Combine(other AttributeColor) AttributeColor
func (*AttributeColor) Equal ¶ added in v1.4.0
func (ac *AttributeColor) Equal(other AttributeColor) bool
Equal checks if two colors have the same attributes, in the same order. The values that are being compared must have at least 1 byte in them.
func (AttributeColor) Error ¶ added in v1.0.1
func (ac AttributeColor) Error(text string)
Same as output, but outputs to stderr instead of stdout
func (AttributeColor) Get ¶ added in v0.3.0
func (ac AttributeColor) Get(text string) string
An alias for StartStop
func (AttributeColor) Head ¶ added in v0.6.0
func (ac AttributeColor) Head() byte
func (AttributeColor) Ints ¶ added in v0.7.0
func (ac AttributeColor) Ints() []int
func (AttributeColor) Output ¶ added in v0.3.0
func (ac AttributeColor) Output(text string)
Use this color to output the given text. Will reset the attributes at the end of the string. Outputs a newline.
func (AttributeColor) Start ¶ added in v0.6.0
func (ac AttributeColor) Start(text string) string
Get the full string needed for outputting colored text, with the text, but don't reset the attributes at the end of the string
func (AttributeColor) StartStop ¶ added in v0.6.0
func (ac AttributeColor) StartStop(text string) string
Get the full string needed for outputting colored texti, with the text and stopping the color attribute
func (AttributeColor) Stop ¶ added in v0.6.0
func (ac AttributeColor) Stop(text string) string
Get the text and the terminal codes for resetting the attributes
func (AttributeColor) String ¶ added in v0.6.0
func (ac AttributeColor) String() string
Return the VT100 terminal codes for setting this combination of attributes and color attributes
func (AttributeColor) Tail ¶ added in v0.6.0
func (ac AttributeColor) Tail() []byte
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
func (*Canvas) At ¶ added in v0.2.1
At returns the rune at the given coordinates, or an error if out of bounds
func (*Canvas) Copy ¶ added in v1.5.1
Copy creates a new Canvas struct that is a copy of this one. The mutex is kept as a pointer to the original.
func (*Canvas) Fill ¶ added in v0.6.0
func (c *Canvas) Fill(fg AttributeColor)
Change the foreground color for each character
func (*Canvas) FillBackground ¶ added in v0.6.0
func (c *Canvas) FillBackground(bg AttributeColor)
Change the background color for each character
func (*Canvas) HideCursor ¶ added in v1.5.1
func (c *Canvas) HideCursor()
func (*Canvas) PlotAll ¶ added in v1.8.7
func (c *Canvas) PlotAll()
PlotAll tries to plot each individual rune. It's very inefficient and meant to be used as a robust fallback.
func (*Canvas) PlotColor ¶ added in v1.3.0
func (c *Canvas) PlotColor(x, y uint, fg AttributeColor, r rune)
func (*Canvas) Resized ¶
Check if the canvas was resized, and adjust values accordingly. Returns a new canvas, or nil.
func (*Canvas) SetLineWrap ¶ added in v1.9.2
func (*Canvas) SetRunewise ¶ added in v1.8.7
func (*Canvas) SetShowCursor ¶ added in v1.9.2
func (*Canvas) ShowCursor ¶ added in v1.5.1
func (c *Canvas) ShowCursor()
func (*Canvas) String ¶ added in v0.2.1
String returns only the characters, as a long string with a newline after each row
func (*Canvas) Write ¶ added in v0.8.0
func (c *Canvas) Write(x, y uint, fg, bg AttributeColor, s string)
func (*Canvas) WriteRune ¶ added in v0.9.0
func (c *Canvas) WriteRune(x, y uint, fg, bg AttributeColor, r rune)
WriteRune will write a colored rune to the canvas
func (*Canvas) WriteRuneB ¶ added in v1.8.6
func (c *Canvas) WriteRuneB(x, y uint, fg, bgb AttributeColor, r rune)
WriteRuneB will write a colored rune to the canvas This is the same as WriteRuneB, but bg.Background() has already been called on the background attribute. The x and y must be within range (x < c.w and y < c.h)
func (*Canvas) WriteRunesB ¶ added in v1.11.0
func (c *Canvas) WriteRunesB(x, y uint, fg, bgb AttributeColor, r rune, count uint)
WriteRunesB will write several colored runes to the canvas This is the same as WriteRuneB, but bg.Background() has already been called on the background attribute. The x and y must be within range (x < c.w and y < c.h). x + count must be within range too.
func (*Canvas) WriteString ¶ added in v1.5.0
func (c *Canvas) WriteString(x, y uint, fg, bg AttributeColor, s string)
WriteString will write a string to the canvas.
type ColorRune ¶ added in v1.8.6
type ColorRune struct {
// contains filtered or unexported fields
}
type TTY ¶ added in v0.2.1
type TTY struct {
// contains filtered or unexported fields
}
func (*TTY) Close ¶ added in v0.2.1
func (tty *TTY) Close()
Close will Restore and close the raw terminal
func (*TTY) NoBlock ¶ added in v0.2.1
func (tty *TTY) NoBlock()
NoBlock leaves "cooked" mode and enters "cbreak" mode
func (*TTY) RawMode ¶ added in v0.2.1
func (tty *TTY) RawMode()
RawMode will switch the terminal to raw mode
func (*TTY) ReadString ¶ added in v1.10.0
Read a string from the TTY
func (*TTY) Rune ¶ added in v1.8.0
Rune will block and then return a rune. Arrow keys are returned as ←, →, ↑ or ↓ returns a rune(0) if the pressed key could not be interpreted
func (*TTY) SetTimeout ¶ added in v0.2.1
SetTimeout sets a timeout for reading a key
func (*TTY) String ¶ added in v1.8.0
String will block and then return a string Arrow keys are returned as ←, →, ↑ or ↓ returns an empty string if the pressed key could not be interpreted
func (*TTY) WriteString ¶ added in v1.10.0
Write a string to the TTY