iostreams

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 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 terminal.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) FailedIcon

func (c *ColorPalette) FailedIcon() string

func (*ColorPalette) GreenCheck

func (c *ColorPalette) GreenCheck() 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() (*IOStreams, *bytes.Buffer, *bytes.Buffer, *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) 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(loadingMSG string)

func (*IOStreams) StopPager

func (s *IOStreams) StopPager()

func (*IOStreams) StopSpinner

func (s *IOStreams) StopSpinner(finalMSG string)

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