Documentation
¶
Overview ¶
Package cli provides terminal output helpers for CLI applications.
It includes a banner printer with ASCII art, a colored header with system information, plain colored text output, and a Progress display for tracking concurrent workers in the terminal.
Banner and header ¶
if err := cli.PrintBanner("myapp"); err != nil {
log.Fatal(err)
}
cli.PrintHeader("v1.0.0")
Progress display ¶
Progress manages a fixed pool of terminal lines for tracking concurrent operations. Acquire blocks until a slot is free, acting as both a display allocator and a concurrency gate.
p := cli.New(4)
p.Start()
defer p.Stop()
var wg sync.WaitGroup
for _, item := range items {
wg.Add(1)
go func(item string) {
defer wg.Done()
idx := p.Acquire(item)
defer p.Release(idx)
p.Update(idx, "processing...")
if err := process(item); err != nil {
p.Fail(idx, err.Error())
return
}
p.Done(idx, "ok")
}(item)
}
wg.Wait()
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyFontsList = errors.New("fonts list is empty") ErrOSReleaseNotFound = errors.New("/etc/os-release not found") ErrReadOSReleaseFailed = errors.New("failed to read /etc/os-release") ErrDistributionNotFound = errors.New("distribution name not found in /etc/os-release") ErrHostnameFailed = errors.New("failed to get hostname") ErrKernelVersionFailed = errors.New("failed to get kernel version") )
Functions ¶
func PrintBanner ¶
func PrintHeader ¶
func PrintHeader(content string)
Types ¶
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress manages a fixed pool of terminal lines, one per concurrent worker.
Acquire blocks the caller until a display slot is free, acting as the concurrency gate (replaces a semaphore). Release returns the slot to the pool when the worker finishes. The terminal always shows exactly numSlots lines regardless of how many total subscribers exist.
All exported methods are goroutine-safe.
func (*Progress) Acquire ¶
Acquire blocks until a display slot is free, initialises it with desc, and returns its index. Call this before launching a worker.
func (*Progress) Release ¶
Release marks the slot as idle and returns it to the pool. Call this at the end of the worker goroutine (typically via defer).
func (*Progress) Start ¶
func (p *Progress) Start()
Start begins the 100 ms background render loop. Safe to call multiple times only the first call has effect.