Documentation ¶
Overview ¶
Package pencil implements nib.Nib to provide a writer for human-facing CLI messages with support for custom prefixes and verbosity level icons.
Index ¶
- Variables
- func GetDefaultIcons() map[nib.Verbosity]rune
- type Option
- type Options
- type Pencil
- func (p *Pencil) Compile(v nib.Verbosity, format string, args ...interface{}) string
- func (p *Pencil) Debugf(format string, args ...interface{})
- func (p *Pencil) Enabled(v nib.Verbosity) bool
- func (p *Pencil) Errorf(format string, args ...interface{})
- func (p *Pencil) Fatalf(format string, args ...interface{})
- func (p *Pencil) GetVerbosity() nib.Verbosity
- func (p *Pencil) IconsEnabled() bool
- func (p *Pencil) Infof(format string, args ...interface{})
- func (p *Pencil) Successf(format string, args ...interface{})
- func (p *Pencil) Warnf(format string, args ...interface{})
- func (p *Pencil) Writer() io.Writer
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultVerbosity is the default pencil verbosity level. DefaultVerbosity = nib.InfoVerbosity // DefaultWriter is the default pencil writer. DefaultWriter = os.Stdout )
var ( DefaultDebugIcon = '⦿' DefaultErrorIcon = '✕' DefaultFatalIcon = '⭍' DefaultInfoIcon = '➜' DefaultSuccessIcon = '✓' DefaultWarnIcon = '!' )
Default pencil verbosity level icons.
Functions ¶
func GetDefaultIcons ¶
GetDefaultIcons returns a map with default verbosity level icons.
Types ¶
type Option ¶
type Option func(*Options)
Option is a pencil option.
func WithIcons ¶
WithIcons sets the pencil verbosity level icons. Note that the provided map gets merged with the default map in order to ensure there are no missing icons. The default icon map uses Unicode characters which are supported by almost all terminals nowadays, but there might be cases where simple ASCII characters work better instead.
func WithPrefixes ¶
WithPrefixes sets the pencil message prefixes. By default only the verbosity level icons are printed as prefix before the given message format and arguments.
func WithVerbosity ¶
WithVerbosity sets the verbosity level.
type Options ¶
type Options struct { Icons map[nib.Verbosity]rune Prefixes []string UseIcons bool Verbosity nib.Verbosity Writer io.Writer }
Options are all pencil options.
func NewOptions ¶
NewOptions creates new default Options and merges them with the given options. By default the verbosity level is DefaultVerbosity and icons are enabled with output to DefaultWriter.
type Pencil ¶
type Pencil struct {
// contains filtered or unexported fields
}
Pencil is a writer for human-facing CLI messages with support for custom prefixes and verbosity level icons.
func New ¶
New creates new pencil with default Options and merges them with the given list of Option.
func (*Pencil) Compile ¶
Compile compiles the format and arguments, ensuring a trailing newline, when the given verbosity level is enabled.
func (*Pencil) Debugf ¶
Debugf writes a debug message and ensures a trailing newline for the given format.
func (*Pencil) Errorf ¶
Errorf writes a error message and ensures a trailing newline for the given format.
func (*Pencil) Fatalf ¶
Fatalf writes a fatal message and ensures a trailing newline for the given format.
func (*Pencil) GetVerbosity ¶
GetVerbosity returns the nib.Verbosity level.
func (*Pencil) IconsEnabled ¶
IconsEnabled indicates whether verbosity level icons are enabled.
func (*Pencil) Infof ¶
Infof writes a information message and ensures a trailing newline for the given format.
func (*Pencil) Successf ¶
Successf writes a success message and ensures a trailing newline for the given format.