pencil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	// DefaultVerbosity is the default pencil verbosity level.
	DefaultVerbosity = nib.InfoVerbosity
	// DefaultWriter is the default pencil writer.
	DefaultWriter = os.Stdout
)
View Source
var (
	DefaultDebugIcon   = '⦿'
	DefaultErrorIcon   = '✕'
	DefaultFatalIcon   = '⭍'
	DefaultInfoIcon    = '➜'
	DefaultSuccessIcon = '✓'
	DefaultWarnIcon    = '!'
)

Default pencil verbosity level icons.

Functions

func GetDefaultIcons

func GetDefaultIcons() map[nib.Verbosity]rune

GetDefaultIcons returns a map with default verbosity level icons.

Types

type Option

type Option func(*Options)

Option is a pencil option.

func UseIcons

func UseIcons(useIcons bool) Option

UseIcons sets whether the configured icons should be printed.

func WithIcons

func WithIcons(icons map[nib.Verbosity]rune) Option

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

func WithPrefixes(prefixes ...string) Option

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

func WithVerbosity(verbosity nib.Verbosity) Option

WithVerbosity sets the verbosity level.

func WithWriter

func WithWriter(writer io.Writer) Option

WithWriter sets the output writer.

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

func NewOptions(opts ...Option) *Options

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

func New(opts ...Option) *Pencil

New creates new pencil with default Options and merges them with the given list of Option.

func (*Pencil) Compile

func (p *Pencil) Compile(v nib.Verbosity, format string, args ...interface{}) string

Compile compiles the format and arguments, ensuring a trailing newline, when the given verbosity level is enabled.

func (*Pencil) Debugf

func (p *Pencil) Debugf(format string, args ...interface{})

Debugf writes a debug message and ensures a trailing newline for the given format.

func (*Pencil) Enabled

func (p *Pencil) Enabled(v nib.Verbosity) bool

Enabled checks if the verbosity is greater than the given verbosity.

func (*Pencil) Errorf

func (p *Pencil) Errorf(format string, args ...interface{})

Errorf writes a error message and ensures a trailing newline for the given format.

func (*Pencil) Fatalf

func (p *Pencil) Fatalf(format string, args ...interface{})

Fatalf writes a fatal message and ensures a trailing newline for the given format.

func (*Pencil) GetVerbosity

func (p *Pencil) GetVerbosity() nib.Verbosity

GetVerbosity returns the nib.Verbosity level.

func (*Pencil) IconsEnabled

func (p *Pencil) IconsEnabled() bool

IconsEnabled indicates whether verbosity level icons are enabled.

func (*Pencil) Infof

func (p *Pencil) Infof(format string, args ...interface{})

Infof writes a information message and ensures a trailing newline for the given format.

func (*Pencil) Successf

func (p *Pencil) Successf(format string, args ...interface{})

Successf writes a success message and ensures a trailing newline for the given format.

func (*Pencil) Warnf

func (p *Pencil) Warnf(format string, args ...interface{})

Warnf writes a warning message and ensures a trailing newline for the given format.

func (*Pencil) Writer added in v0.2.0

func (p *Pencil) Writer() io.Writer

Writer returns the underlying io.Writer.

Jump to

Keyboard shortcuts

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