msg

package
v0.13.4 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Blue   = "0;34"
	Red    = "0;31"
	Green  = "0;32"
	Yellow = "0;33"
	Cyan   = "0;36"
	Pink   = "1;35"
)

These contanstants map to color codes for shell scripts making them human readable.

Variables

View Source
var Default = NewMessenger()

Default contains a default Messenger used by package level functions

Functions

func Color

func Color(code, msg string) string

Color returns a string in a certain color if colors are enabled and available on that platform.

func Debug

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

Debug logs debug information using the Default Messenger

func Die

func Die(msg string, args ...interface{})

Die prints an error message and immediately exits the application using the Default Messenger. If PanicOnDie is set to true a panic will occur instead of os.Exit being called.

func Err

func Err(msg string, args ...interface{})

Err logs anderror using the Default Messenger

func ExitCode

func ExitCode(e int) int

ExitCode sets the exit code used by Die using the Default Messenger.

The default is 1.

Returns the old error code.

func HasErrored

func HasErrored() bool

HasErrored returns if Error has been called on the Default Messenger.

This is useful if you want to known if Error was called to exit with a non-zero exit code.

func Info

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

Info logs information using the Default Messenger

func Msg

func Msg(msg string, args ...interface{})

Msg prints a message with optional arguments, that can be printed, of varying types using the Default Messenger.

func Print

func Print(msg string)

Print prints exactly the string given using the Default Messenger.

It prints to Stdout.

func PromptUntil

func PromptUntil(opts []string) (string, error)

PromptUntil provides a prompt until one of the passed in strings has been entered and return is hit. Note, the comparisons are case insensitive meaning Y == y. The returned value is the one from the passed in options (same case). Uses the default setup.

func PromptUntilYorN

func PromptUntilYorN() bool

PromptUntilYorN provides a prompt until the user chooses yes or no. This is not case sensitive and they can input other options such as Y or N. In the response Yes is bool true and No is bool false. Uses the default setup.

func Puts

func Puts(msg string, args ...interface{})

Puts formats a message and then prints to Stdout using the Default Messenger.

It does not prefix the message, does not color it, or otherwise decorate it.

It does add a line feed.

func Warn

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

Warn logs a warning using the Default Messenger

Types

type Messenger

type Messenger struct {
	sync.Mutex

	// Quiet, if true, suppresses chatty levels, like Info.
	Quiet bool

	// IsDebugging, if true, shows Debug.
	IsDebugging bool

	// NoColor, if true, will not use color in the output.
	NoColor bool

	// Stdout is the location where this prints output.
	Stdout io.Writer

	// Stderr is the location where this prints logs.
	Stderr io.Writer

	// Stdin is the location where input is read.
	Stdin io.Reader

	// PanicOnDie if true Die() will panic instead of exiting.
	PanicOnDie bool
	// contains filtered or unexported fields
}

Messenger provides the underlying implementation that displays output to users.

func NewMessenger

func NewMessenger() *Messenger

NewMessenger creates a default Messenger to display output.

func (*Messenger) Color

func (m *Messenger) Color(code, msg string) string

Color returns a string in a certain color. The first argument is a string containing the color code or a constant from the table above mapped to a code.

The following will print the string "Foo" in yellow:

fmt.Print(Color(Yellow, "Foo"))

func (*Messenger) Debug

func (m *Messenger) Debug(msg string, args ...interface{})

Debug logs debug information

func (*Messenger) Die

func (m *Messenger) Die(msg string, args ...interface{})

Die prints an error message and immediately exits the application. If PanicOnDie is set to true a panic will occur instead of os.Exit being called.

func (*Messenger) Err

func (m *Messenger) Err(msg string, args ...interface{})

Err logs an error.

func (*Messenger) ExitCode

func (m *Messenger) ExitCode(e int) int

ExitCode sets the exit code used by Die.

The default is 1.

Returns the old error code.

func (*Messenger) HasErrored

func (m *Messenger) HasErrored() bool

HasErrored returns if Error has been called.

This is useful if you want to known if Error was called to exit with a non-zero exit code.

func (*Messenger) Info

func (m *Messenger) Info(msg string, args ...interface{})

Info logs information

func (*Messenger) Msg

func (m *Messenger) Msg(msg string, args ...interface{})

Msg prints a message with optional arguments, that can be printed, of varying types.

func (*Messenger) Print

func (m *Messenger) Print(msg string)

Print prints exactly the string given.

It prints to Stdout.

func (*Messenger) PromptUntil

func (m *Messenger) PromptUntil(opts []string) (string, error)

PromptUntil provides a prompt until one of the passed in strings has been entered and return is hit. Note, the comparisons are case insensitive meaning Y == y. The returned value is the one from the passed in options (same case).

func (*Messenger) PromptUntilYorN

func (m *Messenger) PromptUntilYorN() bool

PromptUntilYorN provides a prompt until the user chooses yes or no. This is not case sensitive and they can input other options such as Y or N. In the response Yes is bool true and No is bool false.

func (*Messenger) Puts

func (m *Messenger) Puts(msg string, args ...interface{})

Puts formats a message and then prints to Stdout.

It does not prefix the message, does not color it, or otherwise decorate it.

It does add a line feed.

func (*Messenger) Warn

func (m *Messenger) Warn(msg string, args ...interface{})

Warn logs a warning

Jump to

Keyboard shortcuts

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