Documentation ¶
Overview ¶
Package prettyprogress contains some handy objects for printing out nice-looking progress information to a terminal
Example ¶
multiStep := prettyprogress.NewMultistep( writer(func(s string) { fmt.Println("---") fmt.Println(s) }), prettyprogress.WithBarWidth(5), prettyprogress.WithBarLabel(ui.PercentageLabel), ) step1 := multiStep.AddStep("Prepare..", 0) step2 := multiStep.AddStep("Download XYZ..", 100) step1.Complete("Prepared") bar := step2.Bar(ui.Downloading, "Downloading..") bar.Update(80) step2.Fail("Download Failed")
Output: --- Prepare.. --- Prepare.. Download XYZ.. --- ✓ Prepared Download XYZ.. --- ✓ Prepared ↡ Downloading.. [████ ] 80% --- ✓ Prepared ✗ Download Failed
Index ¶
- Variables
- func WithAnimationFrameTicker(c <-chan time.Time) func(*Steps)
- func WithBarLabel(fn ui.LabelFunc) func(*Steps)
- func WithBarWidth(width int) func(s *Steps)
- func WithBullets(b ui.BulletSet) func(*Steps)
- func WithLabelColors(colors Colors) func(*Steps)
- func Write(w io.Writer) func(s string)
- func Writeln(w io.Writer) func(s string)
- type Bar
- type Colors
- type PrintFunc
- type Step
- func (b *Step) Bar(bullet ui.Bullet, status string) *Bar
- func (b *Step) Complete(msg string)
- func (b *Step) Fail(msg string)
- func (b *Step) Start(msg string)
- func (b *Step) Update(bullet ui.Bullet, status string)
- func (b *Step) UpdateState(state ui.BulletState, status string)
- func (b *Step) UpdateWithProgress(bullet ui.Bullet, status string, progress int)
- type Steps
- type StepsOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func WithBarLabel ¶
func WithBarWidth ¶
func WithBullets ¶
func WithLabelColors ¶
func Write ¶
Write creates a Watcher function that writes to a given io.Writer, useful for passing to one of the constructors in this package, e.g.
NewBar(100,100,Write(os.Stdout))
Write will panic if it is unable to write to the underlying writer
Types ¶
type Bar ¶
type Bar struct {
// contains filtered or unexported fields
}
Bar is an updater that calls its watcher with the String() version of a ui.Bar whenever its UpdateProgress method is called.
Example ¶
package main import ( "os" "github.com/julz/prettyprogress" ) func main() { bar := prettyprogress.NewBar(100, 5, prettyprogress.Writeln(os.Stdout)) bar.Update(20) bar.Update(40) bar.Update(80) }
Output: [█ ] [██ ] [████ ]
type PrintFunc ¶
type PrintFunc func(s string)
PrintFunc is a function that is called when new versions of a Bar, Step or Multistep are created as a result of calling UpdateX methods.
type Step ¶
type Step struct {
// contains filtered or unexported fields
}
Step is an updater whose watcher recieves the output of ui.Step's String() method whenever its UpdateStatus method is called
Example ¶
package main import ( "os" "github.com/julz/prettyprogress" "github.com/julz/prettyprogress/ui" ) func main() { step := prettyprogress.NewStep(100, 5, prettyprogress.Writeln(os.Stdout)) step.Start("Starting..") step.UpdateWithProgress(ui.Downloading, "Downloading", 20) step.UpdateWithProgress(ui.Downloading, "Downloading", 80) step.Complete("Done!") }
Output: ► Starting.. ↡ Downloading [█ ] ↡ Downloading [████ ] ✓ Done!
func (*Step) Bar ¶
Bar returns just the Bar component of the Step which can be updated to show numeric progress of the current task
For example, this could be used with a function that expects an interface with an Update method as follows:
download(step.Bar(ui.Downloading, "Downloading layer.."))
The corresponding `download` method could look as follows:
bar(p type interface{ Update(int) }) { p.Update(10) p.Update(30) p.Update(100) })
Example ¶
package main import ( "os" "github.com/julz/prettyprogress" "github.com/julz/prettyprogress/ui" ) func main() { step := prettyprogress.NewStep(100, 5, prettyprogress.Writeln(os.Stdout)) step.Update(ui.Running, "Preparing") bar := step.Bar(ui.Downloading, "Downloading") bar.Update(20) bar.Update(80) bar.Update(100) }
Output: ► Preparing ↡ Downloading [█ ] ↡ Downloading [████ ] ↡ Downloading [█████]
func (*Step) Complete ¶
Complete sets the steps name to the given string and changes the bullet to a symbol indicating the task has been completed
func (*Step) Fail ¶
Fail sets the steps name to the given string and changes the bullet to a symbol indicating failure
func (*Step) Start ¶
Start sets the steps name to the given string and changes the bullet to a symbol indicating the task is running
func (*Step) Update ¶
Update sets the steps name to the givem status and updated the bullet to the given Bullet
func (*Step) UpdateState ¶
func (b *Step) UpdateState(state ui.BulletState, status string)
UpdateState updates the step with the given status and the bullet from the current BulletSet corresponding to the given state
func (*Step) UpdateWithProgress ¶
UpdateWithProgress updates the Bullet, Status and Progress Bar of the current step. Often either one of the convenience methods like Start, Fail, Complete, or Bar will be a better option.
type Steps ¶
type Steps struct {
// contains filtered or unexported fields
}
func NewFancyMultistep ¶
func NewFancyMultistep(writer io.Writer, extraOptions ...StepsOption) *Steps
NewFancyMultistep creates a new updater that prints step progress with fancy colours, bullets and animations using the given Watcher
func NewMultistep ¶
func NewMultistep(writer io.Writer, options ...StepsOption) *Steps
NewMultistep creates a new updater that can have multiple sub-steps. When any of the steps are updated, the Writer is called with the new string to display.
type StepsOption ¶
type StepsOption func(s *Steps)
Directories ¶
Path | Synopsis |
---|---|
example
|
|
pexec provides a wrapper for exec.Command that prints progress
|
pexec provides a wrapper for exec.Command that prints progress |
Package ui contains some simple structs that have nice-looking String() methods for printing console output with unicode characters.
|
Package ui contains some simple structs that have nice-looking String() methods for printing console output with unicode characters. |