terminal

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 ColorFunc

type ColorFunc func(string) string

A ColorFunc colors a string.

type ColorPair

type ColorPair struct {
	// contains filtered or unexported fields
}

ColorPair specifies a color with different accents for light and dark background.

func (*ColorPair) Color

func (cp *ColorPair) Color(dark bool) string

Color returns the color code for the 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

func (io *IO) ColorEnabled() bool

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

func (io *IO) Doc(s string) string

Doc wraps a block of heredoc formatted text at terminal approximately terminal width.

func (*IO) EnableActivityIndicator added in v0.3.0

func (io *IO) EnableActivityIndicator(enable bool)

EnableActivityIndicator enables or disables the activity indicator. It does not force-enable it, if no TTY is attached.

func (*IO) ErrOut

func (io *IO) ErrOut() io.Writer

ErrOut returns the error output writer.

func (*IO) In

func (io *IO) In() io.ReadCloser

In returns the input reader.

func (*IO) IsStderrTTY

func (io *IO) IsStderrTTY() bool

IsStderrTTY returns true if a TTY is attached to stderr.

func (*IO) IsStdinTTY

func (io *IO) IsStdinTTY() bool

IsStdinTTY returns true if a TTY is attached to stdin.

func (*IO) IsStdoutTTY

func (io *IO) IsStdoutTTY() bool

IsStdoutTTY returns true if a TTY is attached to stdout.

func (*IO) Out

func (io *IO) Out() io.Writer

Out returns the output writer.

func (*IO) SetPagerCommand

func (io *IO) SetPagerCommand(command string)

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

func (io *IO) StartPager(ctx context.Context) (func(), error)

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

func (io *IO) TerminalWidth() int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL