Documentation
¶
Index ¶
- Constants
- Variables
- func Clear()
- func Close()
- func CloseKeepContent()
- func ColorSplit(line, sep string, headColor, sepColor, tailColor AttributeColor, reverse bool) (string, string)
- func Colorize(line string) string
- func EchoOff()
- func Eprint(msg ...any)
- func Eprintf(format string, msg ...any)
- func Eprintln(msg ...any)
- func Fprint(w io.Writer, msg ...any)
- func Fprintf(w io.Writer, format string, msg ...any)
- func Fprintln(w io.Writer, msg ...any)
- func GetBackgroundColor(tty *TTY) (float64, float64, float64, error)
- func Home()
- func Init()
- func MustTermSize() (uint, uint)
- func Print(msg ...any)
- func Printf(format string, msg ...any)
- func Println(msg ...any)
- func Reset()
- func SetLineWrap(enable bool)
- func SetNoColor()
- func SetXY(x, y uint)
- func SetupResizeHandler(sigChan chan os.Signal)
- 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
- func (ac AttributeColor) Wrap(text string) string
- 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) HideCursorAndRedrawFull()
- 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) RedrawFull()
- 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)
- func (c *Canvas) WriteTagged(x, y uint, bgColor AttributeColor, tagged string)
- func (c *Canvas) WriteWideRuneB(x, y uint, fg, bgb AttributeColor, r rune)
- func (c *Canvas) WriteWideRuneBNoLock(x, y uint, fg, bgb AttributeColor, r rune)
- type Char
- type CharAttribute
- type ColorRune
- type TTY
- func (tty *TTY) ASCII() int
- func (tty *TTY) Close()
- func (tty *TTY) CustomString() string
- 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) ReadStringKeepTiming() (string, error)
- func (tty *TTY) Restore()
- func (tty *TTY) Rune() rune
- func (tty *TTY) SetTimeout(d time.Duration) (time.Duration, error)
- func (tty *TTY) SetTimeoutNoSave(d time.Duration) error
- func (tty *TTY) String() string
- func (tty *TTY) Timeout() time.Duration
- func (tty *TTY) WriteString(s string) error
- type TextOutput
- func (o *TextOutput) DarkTags(colors ...string) string
- func (o *TextOutput) Disable()
- func (o *TextOutput) Enable()
- func (o *TextOutput) Enabled() bool
- func (o *TextOutput) Eprint(msg ...any)
- func (o *TextOutput) Eprintf(format string, args ...any)
- func (o *TextOutput) Eprintln(msg ...any)
- func (o *TextOutput) Err(msg string)
- func (o *TextOutput) ErrExit(msg string)
- func (o *TextOutput) ExtractToSlice(s string, pcc *[]CharAttribute) uint
- func (o *TextOutput) Fprint(w io.Writer, msg ...any)
- func (o *TextOutput) Fprintf(w io.Writer, format string, args ...any)
- func (o *TextOutput) Fprintln(w io.Writer, msg ...any)
- func (o *TextOutput) InterfaceTags(colors ...any) string
- func (o *TextOutput) LightBlue(s string) string
- func (o *TextOutput) LightTags(colors ...string) string
- func (o *TextOutput) OutputTags(colors ...string)
- func (o *TextOutput) Print(msg ...any)
- func (o *TextOutput) Printf(format string, args ...any)
- func (o *TextOutput) Println(msg ...any)
- func (o *TextOutput) Tags(colors ...string) string
Examples ¶
Constants ¶
const NoColor string = "\033[0m"
NoColor is the escape sequence for resetting all terminal color attributes.
Variables ¶
var ( Pink = LightMagenta Gray = DarkGray BackgroundWhite = BackgroundLightGray BackgroundGray = BackgroundLightGray BackgroundDefault = DefaultBackground )
var DarkColorMap = map[string]AttributeColor{ "black": Black, "red": Red, "green": Green, "yellow": Yellow, "blue": Blue, "magenta": Magenta, "cyan": Cyan, "gray": DarkGray, "white": LightGray, "lightwhite": White, "darkred": Red, "darkgreen": Green, "darkyellow": Yellow, "darkblue": Blue, "darkmagenta": Magenta, "darkcyan": Cyan, "darkgray": DarkGray, "lightred": LightRed, "lightgreen": LightGreen, "lightyellow": LightYellow, "lightblue": LightBlue, "lightmagenta": LightMagenta, "lightcyan": LightCyan, "lightgray": LightGray, }
DarkColorMap maps lowercase color names to AttributeColor values for dark terminals. The tag replacer generates both <name> and <Name> patterns from these keys at initialization time, so title-case duplicates are not stored here.
var EnvNoColor = env.Bool("NO_COLOR")
EnvNoColor respects the NO_COLOR environment variable
var LightColorMap = map[string]AttributeColor{ "black": Black, "red": LightRed, "green": LightGreen, "yellow": LightYellow, "blue": LightBlue, "magenta": LightMagenta, "cyan": LightCyan, "gray": LightGray, "white": White, "lightwhite": White, "lightred": LightRed, "lightgreen": LightGreen, "lightyellow": LightYellow, "lightblue": LightBlue, "lightmagenta": LightMagenta, "lightcyan": LightCyan, "lightgray": LightGray, "darkred": Red, "darkgreen": Green, "darkyellow": Yellow, "darkblue": Blue, "darkmagenta": Magenta, "darkcyan": Cyan, "darkgray": DarkGray, }
LightColorMap maps lowercase color names to AttributeColor values for light terminals. The tag replacer generates both <name> and <Name> patterns from these keys at initialization time, so title-case duplicates are not stored here.
var Multiplexed = UnderTMUX || UnderScreen || UnderZellij
Multiplexed is true when running inside any known terminal multiplexer.
var UnderScreen = env.Has("STY")
UnderScreen reports whether the process is running inside a GNU Screen session.
var UnderTMUX = env.Has("TMUX")
UnderTMUX reports whether the process is running inside a TMUX session.
var UnderZellij = env.Has("ZELLIJ")
UnderZellij reports whether the process is running inside a Zellij session.
Functions ¶
func Close ¶
func Close()
Close restores the terminal to a usable interactive state and clears the screen, so that canvas content does not bleed into the shell session after exit. Use CloseKeepContent to restore the terminal without clearing.
func CloseKeepContent ¶ added in v1.6.1
func CloseKeepContent()
CloseKeepContent restores the terminal to a usable interactive state, but leaves the canvas content visible on screen.
func ColorSplit ¶ added in v1.2.1
func ColorSplit(line, sep string, headColor, sepColor, tailColor AttributeColor, reverse bool) (string, string)
ColorSplit splits on the first sep in line. It returns two parts: left and right. The right part includes the sep itself (so subsequent splits see it). nil color funcs are skipped. reverse=true swaps which side gets the fallback when sep is absent.
func Colorize ¶
Colorize comments in gray. Colorize (){}[] in an alternating way. This provides simple/rudimentary syntax highlighting.
func GetBackgroundColor ¶
GetBackgroundColor queries the terminal emulator for its background color. Returns normalized RGB values in [0.0, 1.0], or an error.
func Init ¶
func Init()
Init initializes the terminal for full-screen canvas use. Under TMUX and GNU Screen, the hard reset (\033c) and echo-off (\033[12h) are skipped: multiplexers intercept \033c and reset their own pane state, and mishandle \033[12h in ways that suppress visible output.
func MustTermSize ¶
MustTermSize returns the terminal size using golang.org/x/term for cross-platform compatibility
func Println ¶ added in v1.2.10
func Println(msg ...any)
Example ¶
o := NewTextOutput(true, true)
o.Println("hello")
Output: hello
func SetLineWrap ¶
func SetLineWrap(enable bool)
SetLineWrap enables or disables terminal line-wrapping.
func SetupResizeHandler ¶ added in v1.3.7
SetupResizeHandler sets up terminal resize signal handling on Unix systems
func Stop ¶
func Stop() string
Stop returns the escape sequence string for resetting all color attributes.
func WaitForKey ¶
func WaitForKey()
WaitForKey waits for ctrl-c, Return, Esc, Space, or 'q' to be pressed
Types ¶
type AttributeColor ¶
type AttributeColor uint32
AttributeColor is a terminal color/attribute value stored as a uint32. The lower 16 bits hold the primary attribute; the upper 16 bits hold an optional secondary attribute packed in by Combine (for fg+bg pairs, etc.).
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
Background converts a foreground color attribute to the corresponding background attribute.
func (AttributeColor) Bright ¶
func (ac AttributeColor) Bright() AttributeColor
Bright returns a new AttributeColor with the Bright attribute combined in.
func (AttributeColor) Combine ¶
func (ac AttributeColor) Combine(other AttributeColor) AttributeColor
Combine packs two AttributeColor values into one, storing the secondary in the upper 16 bits so that String() can emit a combined escape sequence.
func (*AttributeColor) Equal ¶
func (ac *AttributeColor) Equal(other AttributeColor) bool
func (AttributeColor) Error ¶
func (ac AttributeColor) Error(text string)
Error prints text with this color to stderr, followed by a newline.
func (AttributeColor) Get ¶
func (ac AttributeColor) Get(text string) string
Get is an alias for Wrap.
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)
Output prints text with this color to stdout, followed by a newline.
func (AttributeColor) Start ¶
func (ac AttributeColor) Start(text string) string
Start returns the escape sequence followed by text, without resetting attributes.
func (AttributeColor) StartStop ¶
func (ac AttributeColor) StartStop(text string) string
StartStop is an alias for Wrap.
func (AttributeColor) Stop ¶
func (ac AttributeColor) Stop(text string) string
Stop returns text followed by the reset escape sequence.
func (AttributeColor) String ¶
func (ac AttributeColor) String() string
String returns the VT100 escape sequence for setting this color/attribute.
func (AttributeColor) Tail ¶
func (ac AttributeColor) Tail() uint32
func (AttributeColor) Wrap ¶ added in v1.6.0
func (ac AttributeColor) Wrap(text string) string
Wrap returns text wrapped with this color's escape sequence and a trailing reset.
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas holds a 2-D grid of colored characters and manages terminal rendering.
func NewCanvas ¶
func NewCanvas() *Canvas
NewCanvas creates a canvas sized to the current terminal dimensions.
func (*Canvas) Clear ¶
func (c *Canvas) Clear()
Clear resets every cell's rune to zero and marks all cells as undrawn.
func (*Canvas) Draw ¶
func (c *Canvas) Draw()
Draw renders the canvas to the terminal, temporarily hiding the cursor if it is visible.
func (*Canvas) DrawAndSetCursor ¶
DrawAndSetCursor draws the entire canvas, then places the cursor at (x, y).
func (*Canvas) Fill ¶
func (c *Canvas) Fill(fg AttributeColor)
Fill sets the foreground color of every cell on the canvas.
func (*Canvas) FillBackground ¶
func (c *Canvas) FillBackground(bg AttributeColor)
FillBackground sets the background color of every cell on the canvas.
func (*Canvas) HideCursor ¶
func (c *Canvas) HideCursor()
HideCursor records that the cursor should be hidden and flushes the change to the terminal. Redundant calls (cursor already hidden) emit no escape sequence.
func (*Canvas) HideCursorAndDraw ¶
func (c *Canvas) HideCursorAndDraw()
HideCursorAndDraw hides the cursor and renders the canvas; the cursor remains hidden.
func (*Canvas) HideCursorAndRedraw ¶
func (c *Canvas) HideCursorAndRedraw()
HideCursorAndRedraw marks all cells dirty, hides the cursor, and re-renders the canvas.
func (*Canvas) HideCursorAndRedrawFull ¶ added in v1.5.11
func (c *Canvas) HideCursorAndRedrawFull()
HideCursorAndRedrawFull hides the cursor and forces a full-frame redraw.
func (*Canvas) PlotAll ¶
func (c *Canvas) PlotAll()
PlotAll renders every cell individually to the terminal. It is very inefficient and is intended as a robust fallback (e.g. for wide characters).
func (*Canvas) PlotColor ¶
func (c *Canvas) PlotColor(x, y uint, fg AttributeColor, r rune)
PlotColor sets the rune and foreground color at (x, y).
func (*Canvas) Redraw ¶
func (c *Canvas) Redraw()
Redraw marks all cells dirty and re-renders the canvas.
func (*Canvas) RedrawFull ¶ added in v1.5.11
func (c *Canvas) RedrawFull()
RedrawFull forces a full-frame redraw by discarding the previous frame's state.
func (*Canvas) Resize ¶
func (c *Canvas) Resize()
Resize adjusts the canvas to the current terminal size, discarding old content.
func (*Canvas) Resized ¶
Resized checks whether the terminal was resized and, if so, returns a new Canvas with the old content copied in. Returns nil if the size has not changed.
func (*Canvas) SetLineWrap ¶
SetLineWrap enables or disables terminal line-wrapping and records the setting.
func (*Canvas) SetRunewise ¶
SetRunewise enables or disables per-rune rendering (as opposed to full-frame writes).
func (*Canvas) SetShowCursor ¶
SetShowCursor sets the desired cursor visibility and immediately flushes it to the terminal.
func (*Canvas) ShowCursor ¶
func (c *Canvas) ShowCursor()
ShowCursor records that the cursor should be visible and flushes the change to the terminal. Redundant calls (cursor already visible) emit no escape sequence.
func (*Canvas) Write ¶
func (c *Canvas) Write(x, y uint, fg, bg AttributeColor, s string)
Write is an alias for WriteString, kept for backwards compatibility.
func (*Canvas) WriteBackground ¶
func (c *Canvas) WriteBackground(x, y uint, bg AttributeColor)
WriteBackground sets the background color of the cell at (x, y). x and y must be within bounds.
func (*Canvas) WriteBackgroundAddRuneIfEmpty ¶
func (c *Canvas) WriteBackgroundAddRuneIfEmpty(x, y uint, bg AttributeColor, r rune)
WriteBackgroundAddRuneIfEmpty sets the background color at (x, y) and writes r if the cell is empty. x and y must be within bounds.
func (*Canvas) WriteBackgroundNoLock ¶
func (c *Canvas) WriteBackgroundNoLock(x, y uint, bg AttributeColor)
WriteBackgroundNoLock sets the background color at (x, y) without acquiring the mutex. The caller must hold the write lock.
func (*Canvas) WriteRune ¶
func (c *Canvas) WriteRune(x, y uint, fg, bg AttributeColor, r rune)
WriteRune writes a single colored rune to the canvas at (x, y).
func (*Canvas) WriteRuneB ¶
func (c *Canvas) WriteRuneB(x, y uint, fg, bgb AttributeColor, r rune)
WriteRuneB writes a colored rune to the canvas at (x, y). The "B" suffix signals that bgb is already a background color attribute (i.e. bg.Background() has already been called by the caller), avoiding a redundant conversion on hot paths. x and y must be within bounds (x < c.w and y < c.h).
func (*Canvas) WriteRuneBNoLock ¶
func (c *Canvas) WriteRuneBNoLock(x, y uint, fg, bgb AttributeColor, r rune)
WriteRuneBNoLock is the same as WriteRuneB but does not acquire the canvas mutex. The caller must hold the write lock.
func (*Canvas) WriteRunesB ¶
func (c *Canvas) WriteRunesB(x, y uint, fg, bgb AttributeColor, r rune, count uint)
WriteRunesB fills count cells starting at (x, y) with the given colored rune. The "B" suffix signals that bgb is already a background color attribute. x and y must be within bounds; x+count must also be within bounds.
func (*Canvas) WriteString ¶
func (c *Canvas) WriteString(x, y uint, fg, bg AttributeColor, s string)
WriteString writes a string to the canvas starting at (x, y) with the given colors.
func (*Canvas) WriteTagged ¶ added in v1.2.11
func (c *Canvas) WriteTagged(x, y uint, bgColor AttributeColor, tagged string)
WriteTagged writes a tagged string ("<green>hello</green>") to the Canvas
func (*Canvas) WriteWideRuneB ¶ added in v1.5.8
func (c *Canvas) WriteWideRuneB(x, y uint, fg, bgb AttributeColor, r rune)
WriteWideRuneB writes a double-width (CJK) rune to the canvas. The cell at (x+1, y) is marked as a continuation cell and skipped during drawing. x+1 must be within bounds.
func (*Canvas) WriteWideRuneBNoLock ¶ added in v1.5.8
func (c *Canvas) WriteWideRuneBNoLock(x, y uint, fg, bgb AttributeColor, r rune)
WriteWideRuneBNoLock is the same as WriteWideRuneB but does not acquire the canvas mutex. The caller must hold the write lock.
type CharAttribute ¶
type CharAttribute struct {
A AttributeColor
R rune
}
CharAttribute is a rune and a color attribute
type ColorRune ¶
type ColorRune struct {
// contains filtered or unexported fields
}
ColorRune holds a single terminal cell: its rune, foreground/background colors, whether it has been drawn, and its column width (for wide/CJK characters).
type TTY ¶
type TTY struct {
// contains filtered or unexported fields
}
func (*TTY) Close ¶
func (tty *TTY) Close()
Close restores the terminal and closes the file descriptor
func (*TTY) CustomString ¶ added in v1.5.2
CustomString reads a key string like String(), but preserves any pending input in the kernel's tty buffer. This is critical for operations like shift-insert paste, where the key escape sequence is immediately followed by paste data — flushing the buffer after reading the key would lose it.
Differences from String():
- Saves and restores timeout via SetTimeout instead of Restore()+Flush(), so the terminal stays in raw mode and pending input is preserved.
- When the first byte is ESC, reads the escape sequence byte-by-byte to avoid consuming any trailing paste data.
func (*TTY) PrintRawBytes ¶
func (tty *TTY) PrintRawBytes()
PrintRawBytes for debugging raw byte sequences
func (*TTY) ReadString ¶
ReadString reads all available data from the TTY
func (*TTY) ReadStringKeepTiming ¶ added in v1.5.9
ReadStringKeepTiming reads all available data from the TTY while preserving the caller's timeout value.
func (*TTY) SetTimeout ¶
SetTimeout sets the read timeout by updating VMIN/VTIME. It returns the previous timeout duration.
func (*TTY) SetTimeoutNoSave ¶ added in v1.5.9
SetTimeout sets the read timeout by updating VMIN/VTIME.
func (*TTY) WriteString ¶
WriteString writes a string to the terminal
type TextOutput ¶
type TextOutput struct {
// contains filtered or unexported fields
}
TextOutput keeps state about verbosity and if colors are enabled
func New ¶ added in v1.2.5
func New() *TextOutput
New can initialize a new TextOutput struct, which can have colors turned on or off and where the output can be enabled (verbose) or disabled (silent). If NO_COLOR is set, colors are disabled.
func NewTextOutput ¶
func NewTextOutput(color, enabled bool) *TextOutput
NewTextOutput can initialize a new TextOutput struct, which can have colors turned on or off and where the output can be enabled (verbose) or disabled (silent). If NO_COLOR is set, colors are disabled, regardless.
func (*TextOutput) DarkTags ¶
func (o *TextOutput) DarkTags(colors ...string) string
Replace <blue> with starting a light blue color attribute and <off> with using the default attributes. </blue> can also be used for using the default attributes.
func (*TextOutput) Enabled ¶ added in v1.3.0
func (o *TextOutput) Enabled() bool
Enabled checks if the text output is enabled
func (*TextOutput) Eprint ¶ added in v1.3.0
func (o *TextOutput) Eprint(msg ...any)
Eprint writes a message to stderr if output is enabled
func (*TextOutput) Eprintf ¶ added in v1.3.0
func (o *TextOutput) Eprintf(format string, args ...any)
Eprintf writes a formatted message to stderr if output is enabled
func (*TextOutput) Eprintln ¶ added in v1.3.0
func (o *TextOutput) Eprintln(msg ...any)
Eprintln writes a message to stderr if output is enabled
func (*TextOutput) Err ¶
func (o *TextOutput) Err(msg string)
Err writes an error message in red to stderr if output is enabled
func (*TextOutput) ErrExit ¶ added in v1.2.3
func (o *TextOutput) ErrExit(msg string)
ErrExit writes an error message to stderr and quit with exit code 1
func (*TextOutput) ExtractToSlice ¶
func (o *TextOutput) ExtractToSlice(s string, pcc *[]CharAttribute) uint
ExtractToSlice iterates over an ANSI encoded string, parsing out color codes and places it in a slice of CharAttribute. Each CharAttribute in the slice represents a character in the input string and its corresponding color attributes. This function handles escaping sequences and converts ANSI color codes to AttributeColor structs. The returned uint is the number of stored elements.
func (*TextOutput) Fprint ¶ added in v1.3.0
func (o *TextOutput) Fprint(w io.Writer, msg ...any)
Fprint writes a message to the given io.Writer, if output is enabled
func (*TextOutput) Fprintf ¶ added in v1.3.0
func (o *TextOutput) Fprintf(w io.Writer, format string, args ...any)
Fprintf writes a formatted message to the given io.Writer, if output is enabled
func (*TextOutput) Fprintln ¶ added in v1.3.0
func (o *TextOutput) Fprintln(w io.Writer, msg ...any)
Fprintln writes a message to the given io.Writer, if output is enabled
func (*TextOutput) InterfaceTags ¶
func (o *TextOutput) InterfaceTags(colors ...any) string
InterfaceTags is the same as LightTags, but with interfaces
func (*TextOutput) LightBlue ¶
func (o *TextOutput) LightBlue(s string) string
func (*TextOutput) LightTags ¶
func (o *TextOutput) LightTags(colors ...string) string
Replace <blue> with starting a light blue color attribute and <off> with using the default attributes. </blue> can also be used for using the default attributes.
func (*TextOutput) OutputTags ¶
func (o *TextOutput) OutputTags(colors ...string)
OutputTags will output text that may have tags like "<blue>", "</blue>" or "<off>" for enabling or disabling color attributes. Respects the color/enabled settings of this TextOutput.
func (*TextOutput) Print ¶
func (o *TextOutput) Print(msg ...any)
Print writes a message to stdout if output is enabled
func (*TextOutput) Printf ¶ added in v1.2.7
func (o *TextOutput) Printf(format string, args ...any)
Printf writes a formatted message to stdout if output is enabled
func (*TextOutput) Println ¶
func (o *TextOutput) Println(msg ...any)
Println writes a message to stdout if output is enabled