terminal

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: AGPL-3.0 Imports: 16 Imported by: 13

Documentation

Index

Constants

View Source
const (
	ErrNotATTY = termErr(0)
)

Variables

View Source
var (
	FormattingRegexp = regexp.MustCompile("(?i)<((" + tagRegex + ")?|/(" + tagRegex + ")?)>")
	StyleRegexp      = regexp.MustCompile("(?i)([^=]+)=([^;]+)(;|$)")
	EscapingRegexp   = regexp.MustCompile("([^\\\\]?)<")
)
View Source
var (
	DefaultStdout   *ConsoleOutput
	Stdout          *ConsoleOutput
	Stderr          *Output
	DiscardedOutput *Output
)
View Source
var (
	IsTTY   = isattypkg.IsTerminal
	MakeRaw = term.MakeRaw
	Restore = term.Restore
)
View Source
var (
	Stdin = &Input{
		reader:      os.Stdin,
		interactive: IsTerminal(os.Stdin) && IsTerminal(os.Stdout),
	}
)

Functions

func AskConfirmation

func AskConfirmation(message string, def bool) bool

func AskString

func AskString(message string, validator func(string) (string, bool)) string

func AskStringDefault

func AskStringDefault(message, def string, validator func(string) (string, bool)) string

func Eprint

func Eprint(a ...interface{}) (n int, err error)

Eprint formats using the default formats for its operands and writes to standard error output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func Eprintf

func Eprintf(format string, a ...interface{}) (n int, err error)

Eprintf formats according to a format specifier and writes to standard error output. It returns the number of bytes written and any write error encountered.

func Eprintfln

func Eprintfln(format string, a ...interface{}) (n int, err error)

Eprintfln formats according to a format specifier and writes to standard error output. A newline is appended. It returns the number of bytes written and any write error encountered.

func Eprintln

func Eprintln(a ...interface{}) (n int, err error)

Eprintln formats using the default formats for its operands and writes to standard error output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func Escape

func Escape(msg []byte) []byte

func EscapeTrailingBackslash

func EscapeTrailingBackslash(msg []byte) []byte

func Format

func Format(msg string) string

func FormatBlockMessage

func FormatBlockMessage(format string, msg string) string

func Formatf

func Formatf(msg string, a ...interface{}) string

func GetLogLevel

func GetLogLevel() int

func GetSize

func GetSize() (width, height int)

func HasNativeColorSupport

func HasNativeColorSupport(stream interface{}) bool

func HasPosixColorSupport

func HasPosixColorSupport() bool

func IsCI

func IsCI() bool

func IsCygwinTTY

func IsCygwinTTY(fd uintptr) bool

func IsDebug

func IsDebug() bool

func IsInteractive

func IsInteractive(stream interface{}) bool

func IsTerminal

func IsTerminal(stream interface{}) bool

func IsVerbose

func IsVerbose() bool

func Print

func Print(a ...interface{}) (n int, err error)

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func Printf

func Printf(format string, a ...interface{}) (n int, err error)

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func Printfln

func Printfln(format string, a ...interface{}) (n int, err error)

Printfln formats according to a format specifier and writes to standard error output. A newline is appended. It returns the number of bytes written and any write error encountered.

func Println

func Println(a ...interface{}) (n int, err error)

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func Scan

func Scan(a ...interface{}) (n int, err error)

Scan scans text read from standard input, storing successive space-separated values into successive arguments. Newlines count as space. It returns the number of items successfully scanned. If that is less than the number of arguments, err will report why.

func Scanf

func Scanf(format string, a ...interface{}) (n int, err error)

Scanf scans text read from standard input, storing successive space-separated values into successive arguments as determined by the format. It returns the number of items successfully scanned. If that is less than the number of arguments, err will report why. Newlines in the input must match newlines in the format. The one exception: the verb %c always scans the next rune in the input, even if it is a space (or tab etc.) or newline.

func Scanln

func Scanln(a ...interface{}) (n int, err error)

Scanln is similar to Scan, but stops scanning at a newline and after the final item there must be a newline or EOF.

func SetLogLevel

func SetLogLevel(level int) error

func SymfonyStyle

func SymfonyStyle(stdout *ConsoleOutput, stdin *Input) style

Types

type Color

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

func NewColor

func NewColor(foreground, background string, options []string) (*Color, error)

func (*Color) Apply

func (c *Color) Apply(text []byte) []byte

func (*Color) Set

func (c *Color) Set() []byte

func (*Color) Unset

func (c *Color) Unset() []byte

type ConsoleOutput

type ConsoleOutput struct {
	Stdout *Output
	Stderr *Output
}

func NewBufferedConsoleOutput

func NewBufferedConsoleOutput(stdout, stderr io.Writer) *ConsoleOutput

func RemapOutput

func RemapOutput(out, err io.Writer) *ConsoleOutput

func (ConsoleOutput) Fd

func (cs ConsoleOutput) Fd() uintptr

func (ConsoleOutput) GetFormatter

func (cs ConsoleOutput) GetFormatter() *Formatter

func (ConsoleOutput) SetDecorated

func (cs ConsoleOutput) SetDecorated(decorated bool)

func (ConsoleOutput) SetFormatter

func (cs ConsoleOutput) SetFormatter(formatter *Formatter)

func (ConsoleOutput) Write

func (cs ConsoleOutput) Write(p []byte) (int, error)

type Cursor

type Cursor struct {
	Writer io.Writer
}

func NewCursor

func NewCursor(w io.Writer) Cursor

func (Cursor) ClearLine

func (c Cursor) ClearLine() Cursor

ClearLine clears all the output from the current line.

func (Cursor) ClearLineAfter

func (c Cursor) ClearLineAfter() Cursor

ClearLine clears all the output from the current line after the current position.

func (Cursor) ClearOutput

func (c Cursor) ClearOutput() Cursor

ClearOutput clears all the output from the cursors' current position to the end of the screen.

func (Cursor) ClearScreen

func (c Cursor) ClearScreen() Cursor

ClearOutput clears the entire screen.

func (Cursor) Hide

func (c Cursor) Hide() Cursor

func (Cursor) MoveDown

func (c Cursor) MoveDown(lines int) Cursor

func (Cursor) MoveLeft

func (c Cursor) MoveLeft(columns int) Cursor

func (Cursor) MoveRight

func (c Cursor) MoveRight(columns int) Cursor

func (Cursor) MoveToColumn

func (c Cursor) MoveToColumn(column int) Cursor

func (Cursor) MoveToPosition

func (c Cursor) MoveToPosition(column, row int) Cursor

func (Cursor) MoveUp

func (c Cursor) MoveUp(lines int) Cursor

func (Cursor) RestorePosition

func (c Cursor) RestorePosition() Cursor

func (Cursor) SavePosition

func (c Cursor) SavePosition() Cursor

func (Cursor) Show

func (c Cursor) Show() Cursor

type FdHolder

type FdHolder interface {
	Fd() uintptr
}

type FdReader

type FdReader interface {
	io.Reader
	FdHolder
}

type Formatter

type Formatter struct {
	Decorated                  bool
	SupportsAdvancedDecoration bool
	// contains filtered or unexported fields
}

func NewFormatter

func NewFormatter() *Formatter

func (*Formatter) AddAlias

func (formatter *Formatter) AddAlias(from, to string)

func (*Formatter) Format

func (formatter *Formatter) Format(msg []byte, w io.Writer) (written int, err error)

func (*Formatter) FormatBytes

func (formatter *Formatter) FormatBytes(msg []byte) ([]byte, error)

func (*Formatter) HasStyle

func (formatter *Formatter) HasStyle(name string) bool

func (*Formatter) SetStyle

func (formatter *Formatter) SetStyle(name string, style *FormatterStyle)

type FormatterStyle

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

func NewFormatterStyle

func NewFormatterStyle(foreground, background string, options []string) *FormatterStyle

func (*FormatterStyle) GetHref

func (style *FormatterStyle) GetHref() string

func (*FormatterStyle) SetHref

func (style *FormatterStyle) SetHref(href string)

type Input

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

func NewInput

func NewInput(reader io.Reader) *Input

func (*Input) Fd

func (input *Input) Fd() uintptr

func (*Input) IsInteractive

func (input *Input) IsInteractive() bool

func (*Input) Read

func (input *Input) Read(p []byte) (int, error)

func (*Input) SetInteractive

func (input *Input) SetInteractive(interactive bool)

func (*Input) SetReader

func (input *Input) SetReader(r io.Reader)

type Output

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

func NewOutput

func NewOutput(w io.Writer, formatter *Formatter) *Output

func (Output) Close

func (o Output) Close() error

func (Output) Fd

func (o Output) Fd() uintptr

func (Output) Format

func (o Output) Format(message string) string

func (Output) Formatf

func (o Output) Formatf(message string, a ...interface{}) string

func (Output) IsQuiet

func (o Output) IsQuiet() bool

func (Output) Write

func (o Output) Write(message []byte) (int, error)

type Spinner

type Spinner struct {
	Writer          io.Writer
	PrefixIndicator string
	PrefixText      string
	SuffixIndicator string
	SuffixText      string
	// contains filtered or unexported fields
}

Spinner struct

func NewSpinner

func NewSpinner(w io.Writer) *Spinner

NewSpinner creates a spinner

func (*Spinner) Active

func (s *Spinner) Active() bool

Active returns whether the spinner is currently spinning

func (*Spinner) Start

func (s *Spinner) Start()

Start starts the spinner

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner

Jump to

Keyboard shortcuts

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