msg

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 5 Imported by: 0

README

msg

License Go Report Card GitHub CI

🚀 A lightweight console printing toolkit for Go CLIs.

  • Free software: MIT License

Project Description

When writing pytoil I discovered ines/wasabi and absolutely loved it immediately! Then when I started learning go and writing some CLI's I kept wishing I had it there too.

So here it is 🎉

Full credit goes to fatih/color for handling all the difficult colouring stuff for me and to ines/wasabi for the API design.

Installation

Quickstart

Credits

This package was created with cookiecutter and the FollowTheProcess/go_cookie project template.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fail

func Fail(text string)

Fail prints an error message using the default symbols and colors

func Failf

func Failf(format string, a ...interface{})

Failf prints a formatted error message using the default symbols and colors

func Good

func Good(text string)

Good prints a success message using the default symbols and colors

func Goodf

func Goodf(format string, a ...interface{})

Goodf prints a formatted success message using the default symbols and colors

func Info

func Info(text string)

Info prints an information message using the default symbols and colors

func Infof

func Infof(format string, a ...interface{})

Infof prints a formatted information message using the default symbols and colors

func Sfail

func Sfail(text string) string

Sfail returns an error message using the default symbols and colors

func Sfailf

func Sfailf(format string, a ...interface{}) string

Sfailf returns a formatted error message using the default symbols and colors

func Sgood

func Sgood(text string) string

Sgood returns a success message using the default symbols and colors

func Sgoodf

func Sgoodf(format string, a ...interface{}) string

Sgoodf returns a formatted success message using the default symbols and colors

func Sinfo

func Sinfo(text string) string

Sinfo returns an information message using the default symbols and colors

func Sinfof

func Sinfof(format string, a ...interface{}) string

Sinfof returns a formatted information message using the default symbols and colors

func Stext

func Stext(text string) string

Stext returns a normal, uncoloured message

func Stextf

func Stextf(format string, a ...interface{}) string

Stextf returns a formatted normal, uncoloured message

func Stitle

func Stitle(text string) string

Stitle returns a Title string using the default symbols and colors

func Stitlef

func Stitlef(format string, a ...interface{}) string

Stitlef returns a formatted Title string using the default symbols and colors

func Swarn

func Swarn(text string) string

Swarn returns a warning string using the default symbols and colors

func Swarnf

func Swarnf(format string, a ...interface{}) string

Swarnf returns a formatted warning string using the default symbols and colors

func Text

func Text(text string)

Text prints a normal, uncoloured message

func Textf

func Textf(format string, a ...interface{})

Textf prints a formatted normal, uncoloured message

func Title

func Title(text string)

Title prints a Title message using the default symbols and colors

A Title is distinguishable from all other constructs in msg as it will has 1 newline before and 2 newlines after it

func Titlef

func Titlef(format string, a ...interface{})

Titlef prints a formatted Title message using the default symbols and colors

func Warn

func Warn(text string)

Warn prints a warning message using the default symbols and colors

func Warnf

func Warnf(format string, a ...interface{})

Warnf prints a formatted warning message using the default symbols and colors

Types

type Printer

type Printer struct {

	// The symbol used to prefix Info and Sinfo
	SymbolInfo string
	// The symbol used to prefix Title and Stitle
	SymbolTitle string
	// The symbol used ot prefix Warn and Swarn
	SymbolWarn string
	// The symbol used to prefix Fail and Sfail
	SymbolFail string
	// The symbol used to prefix Good and Sgood
	SymbolGood string

	// The color used for Info and Sinfo
	ColorInfo color.Attribute
	// The color used for Title and Stitle
	ColorTitle color.Attribute
	// The color used for Warn and Swarn
	ColorWarn color.Attribute
	// The color used for Fail and Sfail
	ColorFail color.Attribute
	// The color used for Good and Sgood
	ColorGood color.Attribute

	// Where to do the printing, useful for testing
	Out io.Writer
}

Printer is the primary construct in msg, it allows you to configure the colors and symbols used for each of the printing methods attached to it.

func (*Printer) Fail

func (p *Printer) Fail(text string)

Fail prints an error message

func (*Printer) Failf

func (p *Printer) Failf(format string, a ...interface{})

Failf prints a formatted error message

func (*Printer) Good

func (p *Printer) Good(text string)

Good prints a success message

func (*Printer) Goodf

func (p *Printer) Goodf(format string, a ...interface{})

Goodf prints a formatted success message

func (*Printer) Info

func (p *Printer) Info(text string)

Info prints an information message

func (*Printer) Infof

func (p *Printer) Infof(format string, a ...interface{})

Infof prints a formatted information message

func (*Printer) Sfail

func (p *Printer) Sfail(text string) string

Sfail is like Fail but returns a string rather than printing it

func (*Printer) Sfailf

func (p *Printer) Sfailf(format string, a ...interface{}) string

Sfailf returns a formatted error string

func (*Printer) Sgood

func (p *Printer) Sgood(text string) string

Sgood is like Good but returns a string rather than printing it

func (*Printer) Sgoodf

func (p *Printer) Sgoodf(format string, a ...interface{}) string

Sgoodf returns a formatted success string

func (*Printer) Sinfo

func (p *Printer) Sinfo(text string) string

Sinfo is like Info but returns a string rather than printing it

func (*Printer) Sinfof

func (p *Printer) Sinfof(format string, a ...interface{}) string

Sinfof returns a formatted info string

func (*Printer) Stext

func (p *Printer) Stext(text string) string

Stext is like Text but returns a string rather than printing it

func (*Printer) Stextf

func (p *Printer) Stextf(format string, a ...interface{}) string

Stextf returns a normal, non coloured formatted string

func (*Printer) Stitle

func (p *Printer) Stitle(text string) string

Stitle is like Title but it returns a string rather than printing it

The returned string will have all it's leading and trailing whitespace/newlines trimmed so you have access to the raw string

func (*Printer) Stitlef

func (p *Printer) Stitlef(format string, a ...interface{}) string

Stitlef returns a formatted title string, stripped of all leading/trailing whitespace

func (*Printer) Swarn

func (p *Printer) Swarn(text string) string

Swarn is like Warn but returns a string rather than printing it

func (*Printer) Swarnf

func (p *Printer) Swarnf(format string, a ...interface{}) string

Swarnf returns a formatted warning string

func (*Printer) Text

func (p *Printer) Text(text string)

Text prints a normal, uncoloured message you could argue we don't need this as all is does is call fmt.Fprintln but we're here now

func (*Printer) Textf

func (p *Printer) Textf(format string, a ...interface{})

Textf prints a formatted normal message a newline is automatically appended to the end of 'format' so you don't have to

func (*Printer) Title

func (p *Printer) Title(text string)

Title prints a Title message

A Title is distinguishable from all other constructs in msg as it will has 1 newline before and 2 newlines after it to create separation

If the Printer has a SymbolTitle, it will be prefixed onto 'text' with 2 spaces separating them

func (*Printer) Titlef

func (p *Printer) Titlef(format string, a ...interface{})

Titlef prints a formatted warning message

func (*Printer) Warn

func (p *Printer) Warn(text string)

Warn prints a Warning message

func (*Printer) Warnf

func (p *Printer) Warnf(format string, a ...interface{})

Warnf prints a formatted warning message

Jump to

Keyboard shortcuts

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