Documentation
¶
Overview ¶
Package console provides a standard interface for user- and machine-interface with the console
Index ¶
- Variables
- func Bold(s string) string
- func Debug(msg string)
- func Debugf(msg string, v ...any)
- func Error(msg string)
- func Errorf(msg string, v ...any)
- func Fatal(msg string)
- func Fatalf(msg string, v ...any)
- func FormatTime(t time.Time) string
- func GetWidth() (uint16, error)
- func Info(msg string)
- func InfoUnformatted(msg string)
- func InfoUnformattedf(msg string, v ...any)
- func Infof(msg string, v ...any)
- func IsTTY(f *os.File) bool
- func IsTerminal() bool
- func Output(s string)
- func SetColor(color bool)
- func SetLevel(level Level)
- func ShouldUseColor() bool
- func Success(msg string)
- func Successf(msg string, v ...any)
- func Warn(msg string)
- func Warnf(msg string, v ...any)
- type Console
- func (c *Console) Bold(s string) string
- func (c *Console) Debug(msg string)
- func (c *Console) Debugf(msg string, v ...any)
- func (c *Console) Error(msg string)
- func (c *Console) Errorf(msg string, v ...any)
- func (c *Console) Fatal(msg string)
- func (c *Console) Fatalf(msg string, v ...any)
- func (c *Console) Info(msg string)
- func (c *Console) InfoUnformatted(msg string)
- func (c *Console) InfoUnformattedf(msg string, v ...any)
- func (c *Console) Infof(msg string, v ...any)
- func (c *Console) Output(s string)
- func (c *Console) Success(msg string)
- func (c *Console) Successf(msg string, v ...any)
- func (c *Console) Warn(msg string)
- func (c *Console) Warnf(msg string, v ...any)
- type Interactive
- type InteractiveBool
- type Level
- type Style
Constants ¶
This section is empty.
Variables ¶
var ConsoleInstance = &Console{ Color: ShouldUseColor(), 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 InfoUnformatted ¶ added in v0.17.0
func InfoUnformatted(msg string)
InfoUnformatted writes to stderr without prefix. Useful for interactive/conversational output.
func InfoUnformattedf ¶ added in v0.17.0
InfoUnformattedf writes to stderr without prefix, with formatting.
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(s string)
Output a line to stdout. Useful for printing primary output of a command, or the output of a subcommand.
func ShouldUseColor ¶ added in v0.17.0
func ShouldUseColor() bool
ShouldUseColor returns true if color output should be enabled, based on environment detection. It checks (in order):
- NO_COLOR env var is set and non-empty → no color
- COG_NO_COLOR env var is set and non-empty → no color
- TERM=dumb → no color
- stderr is not a TTY → no color
This follows the NO_COLOR standard (https://no-color.org/) and common CLI conventions. The --no-color flag is handled separately at the CLI layer.
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) Bold ¶ added in v0.17.0
Bold applies bold formatting to a string when color is enabled. Use this to highlight dynamic values (image names, paths, URLs) in log messages.
func (*Console) Debug ¶
Debug prints a verbose debugging message, that is not displayed by default to the user.
func (*Console) InfoUnformatted ¶ added in v0.17.0
InfoUnformatted writes a message to stderr without any prefix. Useful for conversational or interactive output (e.g. login prompts) where the icon prefix would be noise. Displayed at info level. Long lines are wrapped to terminal width when stderr is a TTY.
func (*Console) InfoUnformattedf ¶ added in v0.17.0
InfoUnformattedf writes a formatted message to stderr without any prefix.
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.
func (*Console) Success ¶ added in v0.17.0
Success tells the user something completed successfully. Displays at info level with a green ✓ prefix.
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.