Documentation
¶
Index ¶
- Constants
- Variables
- func Clear()
- func Close()
- func Colorize(line string) string
- func EchoOff()
- func GetBackgroundColor(tty *TTY) (float64, float64, float64, error)
- func Home()
- func Init()
- func MustTermSize() (uint, uint)
- func Reset()
- func SetLineWrap(enable bool)
- func SetNoColor()
- func SetXY(x, y uint)
- func SetXYDirect(x, y uint)
- func ShowCursor(enable bool)
- func Stop() string
- func WaitForKey()
- 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() uint32
- 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() uint32
- 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) DrawAndSetCursor(x, y uint)
- 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) HideCursorAndDraw()
- func (c *Canvas) HideCursorAndRedraw()
- func (c *Canvas) Lock()
- 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) ToImage() (image.Image, error)
- func (c *Canvas) Unlock()
- 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) WriteBackground(x, y uint, bg AttributeColor)
- func (c *Canvas) WriteBackgroundAddRuneIfEmpty(x, y uint, bg AttributeColor, r rune)
- func (c *Canvas) WriteBackgroundNoLock(x, y uint, bg AttributeColor)
- 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) WriteRuneBNoLock(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) Flush()
- func (tty *TTY) Key() int
- func (tty *TTY) KeyCode() int
- func (tty *TTY) NoBlock()
- func (tty *TTY) PrintRawBytes()
- 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 ¶
const NoColor string = "\033[0m"
Variables ¶
var ( Pink = LightMagenta Gray = DarkGray BackgroundWhite = BackgroundLightGray BackgroundGray = BackgroundLightGray BackgroundDefault = DefaultBackground )
var ( 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 GetBackgroundColor ¶
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 SetLineWrap ¶
func SetLineWrap(enable bool)
func SetNoColor ¶
func SetNoColor()
func SetXYDirect ¶
func SetXYDirect(x, y uint)
func ShowCursor ¶
func ShowCursor(enable bool)
Types ¶
type AttributeColor ¶
type AttributeColor uint32
const ( // Non-color attributes ResetAll AttributeColor = 0 Bright AttributeColor = 1 Dim AttributeColor = 2 Underscore AttributeColor = 4 Blink AttributeColor = 5 Reverse AttributeColor = 7 Hidden AttributeColor = 8 None AttributeColor = 0 Black AttributeColor = 30 Red AttributeColor = 31 Green AttributeColor = 32 Yellow AttributeColor = 33 Blue AttributeColor = 34 Magenta AttributeColor = 35 Cyan AttributeColor = 36 LightGray AttributeColor = 37 DarkGray AttributeColor = 90 LightRed AttributeColor = 91 LightGreen AttributeColor = 92 LightYellow AttributeColor = 93 LightBlue AttributeColor = 94 LightMagenta AttributeColor = 95 LightCyan AttributeColor = 96 White AttributeColor = 97 BackgroundBlack AttributeColor = 40 BackgroundRed AttributeColor = 41 BackgroundGreen AttributeColor = 42 BackgroundYellow AttributeColor = 43 BackgroundBlue AttributeColor = 44 BackgroundMagenta AttributeColor = 45 BackgroundCyan AttributeColor = 46 BackgroundLightGray AttributeColor = 47 Default AttributeColor = 39 DefaultBackground AttributeColor = 49 )
func (AttributeColor) Background ¶
func (ac AttributeColor) Background() AttributeColor
Modify color attributes so that they become background color attributes instead
func (AttributeColor) Bright ¶
func (ac AttributeColor) Bright() AttributeColor
Return a new AttributeColor that has "Bright" added to the list of attributes
func (AttributeColor) Combine ¶
func (ac AttributeColor) Combine(other AttributeColor) AttributeColor
func (*AttributeColor) Equal ¶
func (ac *AttributeColor) Equal(other AttributeColor) bool
func (AttributeColor) Error ¶
func (ac AttributeColor) Error(text string)
Same as output, but outputs to stderr instead of stdout
func (AttributeColor) Head ¶
func (ac AttributeColor) Head() uint32
func (AttributeColor) Ints ¶
func (ac AttributeColor) Ints() []int
func (AttributeColor) Output ¶
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 ¶
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 ¶
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 ¶
func (ac AttributeColor) Stop(text string) string
Get the text and the terminal codes for resetting the attributes
func (AttributeColor) String ¶
func (ac AttributeColor) String() string
Return the VT100 terminal codes for setting this combination of attributes and color attributes
func (AttributeColor) Tail ¶
func (ac AttributeColor) Tail() uint32
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
func (*Canvas) Copy ¶
Copy creates a new Canvas struct that is a copy of this one. The mutex is initialized as a new mutex.
func (*Canvas) DrawAndSetCursor ¶
DrawAndSetCursor draws the entire canvas and then places the cursor at x,y
func (*Canvas) Fill ¶
func (c *Canvas) Fill(fg AttributeColor)
Change the foreground color for each character
func (*Canvas) FillBackground ¶
func (c *Canvas) FillBackground(bg AttributeColor)
Change the background color for each character
func (*Canvas) HideCursor ¶
func (c *Canvas) HideCursor()
func (*Canvas) HideCursorAndDraw ¶
func (c *Canvas) HideCursorAndDraw()
HideCursorAndDraw will hide the cursor and then draw the entire canvas
func (*Canvas) HideCursorAndRedraw ¶
func (c *Canvas) HideCursorAndRedraw()
func (*Canvas) PlotAll ¶
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) Resized ¶
Check if the canvas was resized, and adjust values accordingly. Returns a new canvas, or nil.
func (*Canvas) SetLineWrap ¶
func (*Canvas) SetRunewise ¶
func (*Canvas) SetShowCursor ¶
func (*Canvas) ShowCursor ¶
func (c *Canvas) ShowCursor()
func (*Canvas) String ¶
String returns only the characters, as a long string with a newline after each row
func (*Canvas) WriteBackground ¶
func (c *Canvas) WriteBackground(x, y uint, bg AttributeColor)
WriteBackground will write a background color to the canvas The x and y must be within range (x < c.w and y < c.h)
func (*Canvas) WriteBackgroundAddRuneIfEmpty ¶
func (c *Canvas) WriteBackgroundAddRuneIfEmpty(x, y uint, bg AttributeColor, r rune)
WriteBackgroundAddRuneIfEmpty will write a background color to the canvas The x and y must be within range (x < c.w and y < c.h)
func (*Canvas) WriteBackgroundNoLock ¶
func (c *Canvas) WriteBackgroundNoLock(x, y uint, bg AttributeColor)
WriteBackgroundNoLock will write a background color to the canvas The x and y must be within range (x < c.w and y < c.h) The canvas mutex is not locked
func (*Canvas) WriteRune ¶
func (c *Canvas) WriteRune(x, y uint, fg, bg AttributeColor, r rune)
WriteRune will write a colored rune to the canvas
func (*Canvas) WriteRuneB ¶
func (c *Canvas) WriteRuneB(x, y uint, fg, bgb AttributeColor, r rune)
WriteRuneB will write a colored rune to the canvas The x and y must be within range (x < c.w and y < c.h)
func (*Canvas) WriteRuneBNoLock ¶
func (c *Canvas) WriteRuneBNoLock(x, y uint, fg, bgb AttributeColor, r rune)
WriteRuneBNoLock will write a colored rune to the canvas The x and y must be within range (x < c.w and y < c.h) The canvas mutex is not locked
func (*Canvas) WriteRunesB ¶
func (c *Canvas) WriteRunesB(x, y uint, fg, bgb AttributeColor, r rune, count uint)
WriteRunesB will write repeated 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 ¶
func (c *Canvas) WriteString(x, y uint, fg, bg AttributeColor, s string)
WriteString will write a string to the canvas.
type TTY ¶
type TTY struct {
// contains filtered or unexported fields
}
func (*TTY) NoBlock ¶
func (tty *TTY) NoBlock()
NoBlock sets the terminal to cbreak mode (non-blocking)
func (*TTY) PrintRawBytes ¶
func (tty *TTY) PrintRawBytes()
PrintRawBytes for debugging raw byte sequences
func (*TTY) ReadString ¶
ReadString reads a string from the TTY
func (*TTY) SetTimeout ¶
SetTimeout sets a timeout for reading a key
func (*TTY) WriteString ¶
WriteString writes a string to the terminal