Documentation
¶
Index ¶
- Variables
- type ColorFunc
- type ColorPair
- type ColorScheme
- func (cs *ColorScheme) Black(s string) string
- func (cs *ColorScheme) Blue(s string) string
- func (cs *ColorScheme) Bold(s string) string
- func (cs *ColorScheme) Code(s string) string
- func (cs *ColorScheme) Cyan(s string) string
- func (cs *ColorScheme) ErrorIcon() string
- func (cs *ColorScheme) Gray(s string) string
- func (cs *ColorScheme) Green(s string) string
- func (cs *ColorScheme) IsDark() bool
- func (cs *ColorScheme) Magenta(s string) string
- func (cs *ColorScheme) Red(s string) string
- func (cs *ColorScheme) SuccessIcon() string
- func (cs *ColorScheme) TemplateFuncs() template.FuncMap
- func (cs *ColorScheme) Title(s string) string
- func (cs *ColorScheme) WarningIcon() string
- func (cs *ColorScheme) White(s string) string
- func (cs *ColorScheme) Yellow(s string) string
- type ErrClosedPagerPipe
- type IO
- func (io *IO) ColorEnabled() bool
- func (io *IO) ColorScheme() *ColorScheme
- func (io *IO) Doc(s string) string
- func (io *IO) EnableActivityIndicator(enable bool)
- func (io *IO) ErrOut() io.Writer
- func (io *IO) In() io.ReadCloser
- func (io *IO) IsStderrTTY() bool
- func (io *IO) IsStdinTTY() bool
- func (io *IO) IsStdoutTTY() bool
- func (io *IO) Out() io.Writer
- func (io *IO) SetPagerCommand(command string)
- func (io *IO) StartActivityIndicator() func()
- func (io *IO) StartPager(ctx context.Context) (func(), error)
- func (io *IO) SurveyIO() survey.AskOpt
- func (io *IO) TerminalWidth() int
- type TablePrinter
Constants ¶
This section is empty.
Variables ¶
var ( Black = ColorPair{"0", "8"} Red = ColorPair{"1", "9"} Green = ColorPair{"2", "10"} Yellow = ColorPair{"3", "11"} Blue = ColorPair{"4", "12"} Magenta = ColorPair{"5", "13"} Cyan = ColorPair{"6", "14"} White = ColorPair{"7", "15"} Gray = ColorPair{"242", "248"} )
Available colors
Functions ¶
This section is empty.
Types ¶
type ColorPair ¶
type ColorPair struct {
// contains filtered or unexported fields
}
ColorPair specifies a color with different accents for light and dark background.
type ColorScheme ¶
type ColorScheme struct {
// contains filtered or unexported fields
}
ColorScheme - when enabled - returns colored string sequences. If not, they are returned unchanged.
func NewColorScheme ¶
func NewColorScheme(enabled bool) *ColorScheme
NewColorScheme creates a new color scheme. If not enabled, it will return the string sequences unchanged.
func (*ColorScheme) Black ¶
func (cs *ColorScheme) Black(s string) string
Black styles the text in black color, if the color scheme is enabled.
func (*ColorScheme) Blue ¶
func (cs *ColorScheme) Blue(s string) string
Blue styles the text in blue color, if the color scheme is enabled.
func (*ColorScheme) Bold ¶
func (cs *ColorScheme) Bold(s string) string
Bold styles the text bold, if the color scheme is enabled.
func (*ColorScheme) Code ¶
func (cs *ColorScheme) Code(s string) string
Code returns the escape sequence for the given foreground color.
func (*ColorScheme) Cyan ¶
func (cs *ColorScheme) Cyan(s string) string
Cyan styles the text in cyan color, if the color scheme is enabled.
func (*ColorScheme) ErrorIcon ¶
func (cs *ColorScheme) ErrorIcon() string
ErrorIcon returns the error icon.
func (*ColorScheme) Gray ¶
func (cs *ColorScheme) Gray(s string) string
Gray styles the text in gray color, if the color scheme is enabled.
func (*ColorScheme) Green ¶
func (cs *ColorScheme) Green(s string) string
Green styles the text in green color, if the color scheme is enabled.
func (*ColorScheme) IsDark ¶
func (cs *ColorScheme) IsDark() bool
IsDark returns true if the terminals background is dark.
func (*ColorScheme) Magenta ¶
func (cs *ColorScheme) Magenta(s string) string
Magenta styles the text in magenta color, if the color scheme is enabled.
func (*ColorScheme) Red ¶
func (cs *ColorScheme) Red(s string) string
Red styles the text in red color, if the color scheme is enabled.
func (*ColorScheme) SuccessIcon ¶
func (cs *ColorScheme) SuccessIcon() string
SuccessIcon returns the success icon.
func (*ColorScheme) TemplateFuncs ¶
func (cs *ColorScheme) TemplateFuncs() template.FuncMap
TemplateFuncs maps the color schemes functions to a map of template functions.
func (*ColorScheme) Title ¶
func (cs *ColorScheme) Title(s string) string
Title returns styles the string as a title, if the color scheme is enabled.
func (*ColorScheme) WarningIcon ¶
func (cs *ColorScheme) WarningIcon() string
WarningIcon returns the warning icon.
func (*ColorScheme) White ¶
func (cs *ColorScheme) White(s string) string
White styles the text in white color, if the color scheme is enabled.
func (*ColorScheme) Yellow ¶
func (cs *ColorScheme) Yellow(s string) string
Yellow styles the text in yellow color, if the color scheme is enabled.
type ErrClosedPagerPipe ¶ added in v0.5.0
type ErrClosedPagerPipe struct {
// contains filtered or unexported fields
}
ErrClosedPagerPipe is the error returned when writing to a pager that has been closed.
type IO ¶
type IO struct {
// contains filtered or unexported fields
}
IO is used to interact with the terminal, files and any other I/O sources.
func NewIO ¶
func NewIO() *IO
NewIO returns a new IO. It detects if a TTY is attached and detects if colored output should be enabled and auto senses the color scheme.
func TestIO ¶
func TestIO() *IO
TestIO returns an IO which does not read or write to any real outputs.
func (*IO) ColorEnabled ¶
ColorEnabled returns true if colored output is enabled.
func (*IO) ColorScheme ¶
func (io *IO) ColorScheme() *ColorScheme
ColorScheme returns the IO's color scheme used to colorize text output if enabled.
func (*IO) Doc ¶
Doc wraps a block of heredoc formatted text at terminal approximately terminal width.
func (*IO) EnableActivityIndicator ¶ added in v0.3.0
EnableActivityIndicator enables or disables the activity indicator. It does not force-enable it, if no TTY is attached.
func (*IO) IsStderrTTY ¶
IsStderrTTY returns true if a TTY is attached to stderr.
func (*IO) IsStdinTTY ¶
IsStdinTTY returns true if a TTY is attached to stdin.
func (*IO) IsStdoutTTY ¶
IsStdoutTTY returns true if a TTY is attached to stdout.
func (*IO) SetPagerCommand ¶
SetPagerCommand sets the pager command to use.
func (*IO) StartActivityIndicator ¶
func (io *IO) StartActivityIndicator() func()
StartActivityIndicator starts a spinner that indicates activity. The return function, when called, stops the spinner. When no TTY is attached, this is a nop.
func (*IO) StartPager ¶
StartPager starts the configured pager command and stream IO to it. In case the pager command is not set, set to "cat" or no TTY is attached, this is a nop.
func (*IO) SurveyIO ¶
func (io *IO) SurveyIO() survey.AskOpt
SurveyIO returns an options that makes itself the IO for survey questions. Returns a nop option if no TTY is attached.
func (*IO) TerminalWidth ¶
TerminalWidth reports the terminals width, if one is attached. If not, reports the default of 80 for common 80x24 sized terminals.
type TablePrinter ¶
type TablePrinter interface { // AddField adds a field with the given string to the row. If given, the // ColorFunc will be used to colorize the resulting field text. AddField(string, ColorFunc) // EndRow ends a row and starts with a new one on the next AddField call. EndRow() // Render the table to the underlying output. It also clears internal state // and makes the TablePrinter ready to use again. Render() error }
TablePrinter prints table formatted output.
func NewTablePrinter ¶
func NewTablePrinter(io *IO) TablePrinter
NewTablePrinter creates a new TablePrinter writing its output to the underlying IO. It auto detects if a TTY is attached and uses a different output format that is easy to parse when piped.