Documentation
¶
Overview ¶
Package bullets provides a colorful terminal logger with bullet-style output. Inspired by goreleaser's logging output.
Index ¶
- Constants
- Variables
- func BatchUpdate(_ []*BulletHandle, updates map[*BulletHandle]struct{ ... })
- func Colorize(color, text string) string
- type BulletHandle
- func (h *BulletHandle) Error(msg string) *BulletHandle
- func (h *BulletHandle) GetState() HandleState
- func (h *BulletHandle) Progress(current, total int) *BulletHandle
- func (h *BulletHandle) Pulse(duration time.Duration, alternateMsg string)
- func (h *BulletHandle) SetState(state HandleState) *BulletHandle
- func (h *BulletHandle) Success(msg string) *BulletHandle
- func (h *BulletHandle) Update(level Level, msg string) *BulletHandle
- func (h *BulletHandle) UpdateBullet(bullet string) *BulletHandle
- func (h *BulletHandle) UpdateColor(color string) *BulletHandle
- func (h *BulletHandle) UpdateLevel(level Level) *BulletHandle
- func (h *BulletHandle) UpdateMessage(msg string) *BulletHandle
- func (h *BulletHandle) Warning(msg string) *BulletHandle
- func (h *BulletHandle) WithField(key string, value interface{}) *BulletHandle
- func (h *BulletHandle) WithFields(fields map[string]interface{}) *BulletHandle
- type HandleChain
- type HandleGroup
- func (hg *HandleGroup) Add(handle *BulletHandle)
- func (hg *HandleGroup) Clear()
- func (hg *HandleGroup) ErrorAll(msg string)
- func (hg *HandleGroup) Get(index int) *BulletHandle
- func (hg *HandleGroup) Size() int
- func (hg *HandleGroup) SuccessAll(msg string)
- func (hg *HandleGroup) UpdateAll(level Level, msg string)
- func (hg *HandleGroup) UpdateEach(updates map[int]struct{ ... })
- type HandleState
- type Level
- type Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) DecreasePadding()
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(msg string)
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) GetLevel() Level
- func (l *Logger) IncreasePadding()
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) ResetPadding()
- func (l *Logger) SetBullet(level Level, bullet string)
- func (l *Logger) SetBullets(bullets map[Level]string)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetUseSpecialBullets(use bool)
- func (l *Logger) Spinner(msg string) *Spinner
- func (l *Logger) SpinnerBounce(msg string) *Spinner
- func (l *Logger) SpinnerCircle(msg string) *Spinner
- func (l *Logger) SpinnerDots(msg string) *Spinner
- func (l *Logger) SpinnerWithFrames(msg string, frames []string) *Spinner
- func (l *Logger) Step(msg string) func()
- func (l *Logger) Success(msg string)
- func (l *Logger) Successf(format string, args ...interface{})
- func (l *Logger) Warn(msg string)
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) WithError(err error) *Logger
- func (l *Logger) WithField(key string, value interface{}) *Logger
- func (l *Logger) WithFields(fields map[string]interface{}) *Logger
- type Spinner
- type UpdatableLogger
- func (ul *UpdatableLogger) Debug(msg string)
- func (ul *UpdatableLogger) DebugHandle(msg string) *BulletHandle
- func (ul *UpdatableLogger) Error(msg string)
- func (ul *UpdatableLogger) ErrorHandle(msg string) *BulletHandle
- func (ul *UpdatableLogger) IncrementLineCount()
- func (ul *UpdatableLogger) Info(msg string)
- func (ul *UpdatableLogger) InfoHandle(msg string) *BulletHandle
- func (ul *UpdatableLogger) Success(msg string)
- func (ul *UpdatableLogger) Warn(msg string)
- func (ul *UpdatableLogger) WarnHandle(msg string) *BulletHandle
Constants ¶
const ( Reset = reset // Exported version // Exported color constants for public use. ColorBlack = black ColorRed = red ColorGreen = green ColorYellow = yellow ColorBlue = blue ColorMagenta = magenta ColorCyan = cyan ColorWhite = white // Exported bright color constants. ColorBrightBlack = brightBlack ColorBrightRed = brightRed ColorBrightGreen = brightGreen ColorBrightYellow = brightYellow ColorBrightBlue = brightBlue ColorBrightMagenta = brightMagenta ColorBrightCyan = brightCyan ColorBrightWhite = brightWhite // Exported style constants. StyleBold = bold StyleDim = dim StyleItalic = italic StyleUnderline = underline )
ANSI color codes for terminal output.
Variables ¶
var ErrInvalidLevel = errors.New("invalid log level")
ErrInvalidLevel is returned when parsing an invalid level string.
Functions ¶
func BatchUpdate ¶
func BatchUpdate(_ []*BulletHandle, updates map[*BulletHandle]struct { Level Level Message string })
BatchUpdate allows updating multiple handles at once. Note: The handles parameter is currently unused but kept for API compatibility.
Types ¶
type BulletHandle ¶
type BulletHandle struct {
// contains filtered or unexported fields
}
BulletHandle represents a handle to an updatable bullet.
func (*BulletHandle) Error ¶
func (h *BulletHandle) Error(msg string) *BulletHandle
Error updates the bullet to show an error.
func (*BulletHandle) GetState ¶
func (h *BulletHandle) GetState() HandleState
GetState returns the current state of the handle.
func (*BulletHandle) Progress ¶
func (h *BulletHandle) Progress(current, total int) *BulletHandle
Progress updates the bullet to show progress.
func (*BulletHandle) Pulse ¶
func (h *BulletHandle) Pulse(duration time.Duration, alternateMsg string)
Pulse creates a pulsing effect by alternating between two states.
func (*BulletHandle) SetState ¶
func (h *BulletHandle) SetState(state HandleState) *BulletHandle
SetState sets the complete state of the handle.
func (*BulletHandle) Success ¶
func (h *BulletHandle) Success(msg string) *BulletHandle
Success updates the bullet to show success.
func (*BulletHandle) Update ¶
func (h *BulletHandle) Update(level Level, msg string) *BulletHandle
Update updates the bullet with a new message and level.
func (*BulletHandle) UpdateBullet ¶
func (h *BulletHandle) UpdateBullet(bullet string) *BulletHandle
UpdateBullet updates just the bullet symbol.
func (*BulletHandle) UpdateColor ¶
func (h *BulletHandle) UpdateColor(color string) *BulletHandle
UpdateColor updates just the color of the bullet.
func (*BulletHandle) UpdateLevel ¶
func (h *BulletHandle) UpdateLevel(level Level) *BulletHandle
UpdateLevel updates just the level (and thus color/bullet).
func (*BulletHandle) UpdateMessage ¶
func (h *BulletHandle) UpdateMessage(msg string) *BulletHandle
UpdateMessage updates just the message text.
func (*BulletHandle) Warning ¶
func (h *BulletHandle) Warning(msg string) *BulletHandle
Warning updates the bullet to show a warning.
func (*BulletHandle) WithField ¶
func (h *BulletHandle) WithField(key string, value interface{}) *BulletHandle
WithField adds a field to this bullet.
func (*BulletHandle) WithFields ¶
func (h *BulletHandle) WithFields(fields map[string]interface{}) *BulletHandle
WithFields adds multiple fields to this bullet.
type HandleChain ¶
type HandleChain struct {
// contains filtered or unexported fields
}
HandleChain allows chaining updates to multiple handles.
func (*HandleChain) Error ¶
func (hc *HandleChain) Error(msg string) *HandleChain
Error marks all handles in the chain as error.
func (*HandleChain) Success ¶
func (hc *HandleChain) Success(msg string) *HandleChain
Success marks all handles in the chain as success.
func (*HandleChain) Update ¶
func (hc *HandleChain) Update(level Level, msg string) *HandleChain
Update updates all handles in the chain.
func (*HandleChain) WithField ¶
func (hc *HandleChain) WithField(key string, value interface{}) *HandleChain
WithField adds a field to all handles in the chain.
type HandleGroup ¶
type HandleGroup struct {
// contains filtered or unexported fields
}
HandleGroup manages a group of related handles.
func NewHandleGroup ¶
func NewHandleGroup(handles ...*BulletHandle) *HandleGroup
NewHandleGroup creates a new handle group.
func (*HandleGroup) Add ¶
func (hg *HandleGroup) Add(handle *BulletHandle)
Add adds a handle to the group.
func (*HandleGroup) Clear ¶
func (hg *HandleGroup) Clear()
Clear removes all handles from the group.
func (*HandleGroup) ErrorAll ¶
func (hg *HandleGroup) ErrorAll(msg string)
ErrorAll marks all handles as error.
func (*HandleGroup) Get ¶
func (hg *HandleGroup) Get(index int) *BulletHandle
Get returns the handle at the specified index.
func (*HandleGroup) Size ¶
func (hg *HandleGroup) Size() int
Size returns the number of handles in the group.
func (*HandleGroup) SuccessAll ¶
func (hg *HandleGroup) SuccessAll(msg string)
SuccessAll marks all handles as success.
func (*HandleGroup) UpdateAll ¶
func (hg *HandleGroup) UpdateAll(level Level, msg string)
UpdateAll updates all handles in the group.
func (*HandleGroup) UpdateEach ¶
func (hg *HandleGroup) UpdateEach(updates map[int]struct { Level Level Message string })
UpdateEach updates each handle with a different message.
type HandleState ¶
type HandleState struct {
Level Level
Message string
Color string
Bullet string
Fields map[string]interface{}
}
HandleState represents the state of a bullet handle.
type Level ¶
type Level uint32
Level represents a log level.
func MustParseLevel ¶
MustParseLevel parses a level string or panics.
func ParseLevel ¶
ParseLevel parses a level string into a Level.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents a logger with configurable level and output.
func (*Logger) DecreasePadding ¶
func (l *Logger) DecreasePadding()
DecreasePadding decreases the indentation level.
func (*Logger) IncreasePadding ¶
func (l *Logger) IncreasePadding()
IncreasePadding increases the indentation level.
func (*Logger) ResetPadding ¶
func (l *Logger) ResetPadding()
ResetPadding resets the indentation to zero.
func (*Logger) SetBullet ¶
SetBullet sets a custom bullet symbol for a specific log level. Custom bullets take priority over special bullets.
func (*Logger) SetBullets ¶
SetBullets sets custom bullet symbols for multiple log levels. Custom bullets take priority over special bullets.
func (*Logger) SetUseSpecialBullets ¶
SetUseSpecialBullets enables or disables special bullet symbols (✓, ✗, ⚠). When disabled (default), all levels use the circle bullet (●) with level-specific colors.
func (*Logger) Spinner ¶
Spinner creates and starts a spinner with default Braille animation. The spinner uses a smooth Braille dot pattern. Call Stop(), Success(), Error(), or Replace() on the returned spinner to stop it.
func (*Logger) SpinnerBounce ¶
SpinnerBounce creates a spinner with bouncing dot pattern. Creates a smooth bouncing animation effect.
func (*Logger) SpinnerCircle ¶
SpinnerCircle creates a spinner with growing/shrinking circle pattern. Creates a glassy circular rotation effect.
func (*Logger) SpinnerDots ¶
SpinnerDots creates a spinner with rotating Braille dots pattern. This is the default spinner style with smooth dot transitions.
func (*Logger) SpinnerWithFrames ¶
SpinnerWithFrames creates and starts a spinner with custom animation frames. Frames will cycle through the provided slice of strings. Call Stop(), Success(), Error(), or Replace() on the returned spinner to stop it.
func (*Logger) Step ¶
Step logs a step message with timing information. It returns a function that should be called when the step is complete.
func (*Logger) WithFields ¶
WithFields returns a new logger with the given fields added.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner represents an animated spinner that can be stopped and replaced.
type UpdatableLogger ¶
type UpdatableLogger struct {
*Logger
// contains filtered or unexported fields
}
UpdatableLogger wraps a regular Logger and provides updatable bullet functionality.
func NewUpdatable ¶
func NewUpdatable(w io.Writer) *UpdatableLogger
NewUpdatable creates a new updatable logger.
func (*UpdatableLogger) Debug ¶
func (ul *UpdatableLogger) Debug(msg string)
Debug logs a debug message and increments line count.
func (*UpdatableLogger) DebugHandle ¶
func (ul *UpdatableLogger) DebugHandle(msg string) *BulletHandle
DebugHandle logs a debug message and returns a handle for updates.
func (*UpdatableLogger) Error ¶
func (ul *UpdatableLogger) Error(msg string)
Error logs an error message and increments line count.
func (*UpdatableLogger) ErrorHandle ¶
func (ul *UpdatableLogger) ErrorHandle(msg string) *BulletHandle
ErrorHandle logs an error message and returns a handle for updates.
func (*UpdatableLogger) IncrementLineCount ¶
func (ul *UpdatableLogger) IncrementLineCount()
IncrementLineCount increments the line count (called by regular log methods).
func (*UpdatableLogger) Info ¶
func (ul *UpdatableLogger) Info(msg string)
Info logs an info message and increments line count.
func (*UpdatableLogger) InfoHandle ¶
func (ul *UpdatableLogger) InfoHandle(msg string) *BulletHandle
InfoHandle logs an info message and returns a handle for updates.
func (*UpdatableLogger) Success ¶
func (ul *UpdatableLogger) Success(msg string)
Success logs a success message and increments line count.
func (*UpdatableLogger) Warn ¶
func (ul *UpdatableLogger) Warn(msg string)
Warn logs a warning message and increments line count.
func (*UpdatableLogger) WarnHandle ¶
func (ul *UpdatableLogger) WarnHandle(msg string) *BulletHandle
WarnHandle logs a warning message and returns a handle for updates.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Package main demonstrates the basic usage of the bullets logger.
|
Package main demonstrates the basic usage of the bullets logger. |
|
updatable
command
Package main demonstrates updatable bullet functionality with real-time updates.
|
Package main demonstrates updatable bullet functionality with real-time updates. |