iostreams

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsTerminal = func(f *os.File) bool {
	return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
}

IsTerminal reports whether the file descriptor is connected to a terminal

View Source
var TerminalSize = func(w interface{}) (int, int, error) {
	if f, isFile := w.(*os.File); isFile {
		return term.GetSize(int(f.Fd()))
	}

	return 0, 0, fmt.Errorf("%v is not a file", w)
}

Functions

func Is256ColorSupported added in v1.16.0

func Is256ColorSupported() bool

func IsCygwinTerminal

func IsCygwinTerminal(f *os.File) bool

func NewColorable

func NewColorable(out io.Writer) io.Writer

NewColorable returns an output stream that handles ANSI color sequences on Windows

func TerminalWidth

func TerminalWidth(out io.Writer) int

Types

type ColorPalette

type ColorPalette struct {
	// Magenta outputs ANSI color if stdout is a tty
	Magenta func(string) string
	// Cyan outputs ANSI color if stdout is a tty
	Cyan func(string) string
	// Red outputs ANSI color if stdout is a tty
	Red func(string) string
	// Yellow outputs ANSI color if stdout is a tty
	Yellow func(string) string
	// Blue outputs ANSI color if stdout is a tty
	Blue func(string) string
	// Green outputs ANSI color if stdout is a tty
	Green func(string) string
	// Gray outputs ANSI color if stdout is a tty
	Gray func(string) string
	// Bold outputs ANSI color if stdout is a tty
	Bold func(string) string
}

func (*ColorPalette) DotWarnIcon added in v1.18.0

func (c *ColorPalette) DotWarnIcon() string

func (*ColorPalette) FailedIcon

func (c *ColorPalette) FailedIcon() string

func (*ColorPalette) GreenCheck

func (c *ColorPalette) GreenCheck() string

func (*ColorPalette) ProgressIcon added in v1.18.0

func (c *ColorPalette) ProgressIcon() string

func (*ColorPalette) RedCheck

func (c *ColorPalette) RedCheck() string

func (*ColorPalette) WarnIcon

func (c *ColorPalette) WarnIcon() string

type IOStreams

type IOStreams struct {
	In     io.ReadCloser
	StdOut io.Writer
	StdErr io.Writer

	IsaTTY   bool //stdout is a tty
	IsErrTTY bool //stderr is a tty
	IsInTTY  bool //stdin is a tty
	// contains filtered or unexported fields
}

func Init

func Init() *IOStreams

func Test

func Test() (streams *IOStreams, in *bytes.Buffer, out *bytes.Buffer, errOut *bytes.Buffer)

func (*IOStreams) BackgroundColor added in v1.16.0

func (s *IOStreams) BackgroundColor() string

func (*IOStreams) Color

func (s *IOStreams) Color() *ColorPalette

func (*IOStreams) ColorEnabled

func (s *IOStreams) ColorEnabled() bool

func (*IOStreams) Is256ColorSupported added in v1.16.0

func (s *IOStreams) Is256ColorSupported() bool

func (*IOStreams) IsOutputTTY

func (s *IOStreams) IsOutputTTY() bool

IsOutputTTY returns true if both stdout and stderr is TTY

func (*IOStreams) Log added in v1.18.0

func (s *IOStreams) Log(msg ...interface{})

Log prints output to StdErr

func (*IOStreams) LogInfo added in v1.18.0

func (s *IOStreams) LogInfo(a ...interface{})

LogInfo is just like Log but prints output to StdOut

func (*IOStreams) LogInfof added in v1.18.0

func (s *IOStreams) LogInfof(format string, a ...interface{})

LogInfof formats according to a format specifier and writes to StdOut

func (*IOStreams) Logf added in v1.18.0

func (s *IOStreams) Logf(format string, a ...interface{})

Logf formats according to a format specifier and writes to StdErr

func (*IOStreams) PromptEnabled

func (s *IOStreams) PromptEnabled() bool

func (*IOStreams) ResolveBackgroundColor added in v1.16.0

func (s *IOStreams) ResolveBackgroundColor(style string) string

func (*IOStreams) SetPager

func (s *IOStreams) SetPager(cmd string)

func (*IOStreams) SetPrompt

func (s *IOStreams) SetPrompt(promptDisabled string)

func (*IOStreams) StartPager

func (s *IOStreams) StartPager() error

func (*IOStreams) StartSpinner

func (s *IOStreams) StartSpinner(format string, a ...interface{})

func (*IOStreams) StopPager

func (s *IOStreams) StopPager()

func (*IOStreams) StopSpinner

func (s *IOStreams) StopSpinner(format string, a ...interface{})

func (*IOStreams) TerminalWidth

func (s *IOStreams) TerminalWidth() int

Jump to

Keyboard shortcuts

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