console

package
v0.0.72 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 13 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)

Debug level message.

func Debugf

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

Debug level message.

func Error

func Error(msg string)

Error level message.

func Errorf

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

Error level message.

func Fatal

func Fatal(msg string)

Fatal level message.

func Fatalf

func Fatalf(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)

Info level message.

func Infof

func Infof(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(s string)

Output a line to stdout. 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)

Warn level message.

func Warnf

func Warnf(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 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)

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)

Debug prints a verbose debugging message, that is not displayed by default to the user.

func (*Console) Debugf

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

Debug level message

func (*Console) Error

func (c *Console) Error(msg string)

Error tells the user that something is broken.

func (*Console) Errorf

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

Error level message

func (*Console) Fatal

func (c *Console) Fatal(msg string)

Fatal level message, followed by exit

func (*Console) Fatalf

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

Fatal level message, followed by exit

func (*Console) Info

func (c *Console) Info(msg string)

Info tells the user what's going on.

func (*Console) Infof

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

Info level message

func (*Console) Output

func (c *Console) Output(s string)

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) Warn

func (c *Console) Warn(msg string)

Warn tells the user that something might break.

func (*Console) Warnf

func (c *Console) Warnf(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