Documentation ¶
Overview ¶
Package console provides a standard interface for user- and machine-interface with the console
Index ¶
- Variables
- func Debug(msg string, v ...interface{})
- func DebugOutput(line string)
- func Error(msg string, v ...interface{})
- func Fatal(msg string, v ...interface{})
- func FormatTime(t time.Time) string
- func GetWidth() (uint16, error)
- func Info(msg string, v ...interface{})
- func IsTTY(f *os.File) bool
- func IsTerminal() bool
- func Output(line string)
- func OutputErr(line string)
- func SetColor(color bool)
- func SetLevel(level Level)
- func Warn(msg string, v ...interface{})
- type Console
- func (c *Console) Debug(msg string, v ...interface{})
- func (c *Console) DebugOutput(line string)
- func (c *Console) Error(msg string, v ...interface{})
- func (c *Console) Fatal(msg string, v ...interface{})
- func (c *Console) Info(msg string, v ...interface{})
- func (c *Console) Output(line string)
- func (c *Console) OutputErr(line string)
- func (c *Console) Warn(msg string, v ...interface{})
- type Interactive
- type InteractiveBool
- type Level
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidLevel = errors.New("invalid level")
ErrInvalidLevel is returned if the severity level is invalid.
Functions ¶
func DebugOutput ¶
func DebugOutput(line string)
DebugOutput a line to stdout. Like Output, but only when level is DebugLevel.
func FormatTime ¶
func GetWidth ¶
GetWidth returns the width of the terminal (from stderr -- stdout might be piped)
Returns 0 if we're not in a terminal
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.
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)
ConsoleInstance is the global instance of console, so we don't have to pass it around everywhere
func (*Console) DebugOutput ¶
DebugOutput a line to stdout. Like Output, but only when level is DebugLevel.
func (*Console) Output ¶
Output a line to stdout. Useful for printing primary output of a command, or the output of a subcommand.
type Interactive ¶
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.
Log levels.
func MustParseLevel ¶
MustParseLevel parses level string or panics.