console

package
v0.0.0-...-e8b1e36 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package console provides a standard interface for user- and machine-interface with the console

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLevel = errors.New("invalid level")

ErrInvalidLevel is returned if the severity level is invalid.

Functions

func Debug

func Debug(msg string, v ...interface{})

Debug level message.

func DebugOutput

func DebugOutput(line string)

DebugOutput a line to stdout. Like Output, but only when level is DebugLevel.

func Error

func Error(msg string, v ...interface{})

Error level message.

func Fatal

func Fatal(msg string, v ...interface{})

Fatal level message.

func FormatTime

func FormatTime(t time.Time) string

func GetWidth

func GetWidth() (uint16, error)

GetWidth returns the width of the terminal (from stderr -- stdout might be piped)

Returns 0 if we're not in a terminal

func Info

func Info(msg string, v ...interface{})

Info level message.

func IsTTY

func IsTTY(f *os.File) bool

IsTTY checks if a file is a TTY or not. E.g. IsTTY(os.Stdin)

func IsTerminal

func IsTerminal() bool

IsTerminal returns true if we're in a terminal and a user is interacting with us

func Output

func Output(line string)

Output a line to stdout. Useful for printing primary output of a command, or the output of a subcommand.

func OutputErr

func OutputErr(line string)

OutputErr a line to stderr. Useful for printing primary output of a command, or the output of a subcommand.

func SetColor

func SetColor(color bool)

SetColor sets whether to print colors

func SetLevel

func SetLevel(level Level)

SetLevel sets log level

func Warn

func Warn(msg string, v ...interface{})

Warn level message.

Types

type Console

type Console struct {
	Color     bool
	IsMachine bool
	Level     Level
	// contains filtered or unexported fields
}

Console represents a standardized interface for console UI. It is designed to abstract: - Writing messages to logs or displaying on console - Console user interface elements (progress, interactive prompts, etc) - Switching between human and machine modes for these things (e.g. don't display progress bars or colors in logs, don't prompt for input when in a script)

var ConsoleInstance *Console = &Console{
	Color:     true,
	Level:     InfoLevel,
	IsMachine: false,
}

ConsoleInstance is the global instance of console, so we don't have to pass it around everywhere

func (*Console) Debug

func (c *Console) Debug(msg string, v ...interface{})

Debug level message

func (*Console) DebugOutput

func (c *Console) DebugOutput(line string)

DebugOutput a line to stdout. Like Output, but only when level is DebugLevel.

func (*Console) Error

func (c *Console) Error(msg string, v ...interface{})

Error level message

func (*Console) Fatal

func (c *Console) Fatal(msg string, v ...interface{})

Fatal level message, followed by exit

func (*Console) Info

func (c *Console) Info(msg string, v ...interface{})

Info level message

func (*Console) Output

func (c *Console) Output(line string)

Output a line to stdout. Useful for printing primary output of a command, or the output of a subcommand.

func (*Console) OutputErr

func (c *Console) OutputErr(line string)

OutputErr a line to stderr. Useful for printing primary output of a command, or the output of a subcommand.

func (*Console) Warn

func (c *Console) Warn(msg string, v ...interface{})

Warn level message

type Interactive

type Interactive struct {
	Prompt   string
	Default  string
	Options  []string
	Required bool
}

func (Interactive) Read

func (i Interactive) Read() (string, error)

type InteractiveBool

type InteractiveBool struct {
	Prompt  string
	Default bool
	// NonDefaultFlag is the flag to suggest passing to do the thing which isn't default when running inside a script
	NonDefaultFlag string
}

func (InteractiveBool) Read

func (i InteractiveBool) Read() (bool, error)

type Level

type Level int

Level of severity.

const (
	InvalidLevel Level = iota - 1
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

Log levels.

func MustParseLevel

func MustParseLevel(s string) Level

MustParseLevel parses level string or panics.

func ParseLevel

func ParseLevel(s string) (Level, error)

ParseLevel parses level string.

func (Level) String

func (l Level) String() string

String implementation.

Jump to

Keyboard shortcuts

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