Documentation
¶
Overview ¶
Package console provides a standard interface for user- and machine-interface with the console
Index ¶
- Variables
- func Debug(msg string)
- func Debugf(msg string, v ...interface{})
- func Error(msg string)
- func Errorf(msg string, v ...interface{})
- func Fatal(msg string)
- func Fatalf(msg string, v ...interface{})
- func FormatTime(t time.Time) string
- func GetWidth() (uint16, error)
- func Info(msg string)
- func Infof(msg string, v ...interface{})
- func IsTTY(f *os.File) bool
- func IsTerminal() bool
- func Output(s string)
- func SetColor(color bool)
- func SetLevel(level Level)
- func Warn(msg string)
- func Warnf(msg string, v ...interface{})
- type Console
- func (c *Console) Debug(msg string)
- func (c *Console) Debugf(msg string, v ...interface{})
- func (c *Console) Error(msg string)
- func (c *Console) Errorf(msg string, v ...interface{})
- func (c *Console) Fatal(msg string)
- func (c *Console) Fatalf(msg string, v ...interface{})
- func (c *Console) Info(msg string)
- func (c *Console) Infof(msg string, v ...interface{})
- func (c *Console) Output(s string)
- func (c *Console) Warn(msg string)
- func (c *Console) Warnf(msg string, v ...interface{})
- type Interactive
- type InteractiveBool
- type Level
Constants ¶
This section is empty.
Variables ¶
var ConsoleInstance = &Console{ Color: true, Level: InfoLevel, IsMachine: false, }
ConsoleInstance is the global instance of console, so we don't have to pass it around everywhere
var ErrInvalidLevel = errors.New("invalid level")
ErrInvalidLevel is returned if the severity level is invalid.
Functions ¶
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
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 main output - Giving information to user - 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)
func (*Console) Debug ¶
Debug prints a verbose debugging message, that is not displayed by default to the user.
func (*Console) Output ¶
Output a string to stdout. Useful for printing primary output of a command, or the output of a subcommand. A newline is added to the string.
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.