Documentation ¶
Overview ¶
Package progress provides methods and structs for creating terminal progress bar
Index ¶
- Constants
- Variables
- type Bar
- func (b *Bar) Add(v int)
- func (b *Bar) Add64(v int64)
- func (b *Bar) Current() int64
- func (b *Bar) Finish() error
- func (b *Bar) IsFinished() bool
- func (b *Bar) IsStarted() bool
- func (b *Bar) Name() string
- func (b *Bar) Reader(r io.Reader) io.Reader
- func (b *Bar) SetCurrent(v int64)
- func (b *Bar) SetName(name string)
- func (b *Bar) SetTotal(v int64)
- func (b *Bar) Start() error
- func (b *Bar) Total() int64
- func (b *Bar) UpdateSettings(s Settings) error
- func (b *Bar) Writer(w io.Writer) io.Writer
- type Settings
Examples ¶
Constants ¶
View Source
const MIN_REFRESH_RATE = time.Duration(time.Millisecond)
MIN_REFRESH_RATE is minimal refresh rate (1 ms)
View Source
const MIN_WIDTH = 80
MIN_WIDTH is minimal progress bar width
View Source
const PROGRESS_BAR_SYMBOL = "—"
PROGRESS_BAR_SYMBOL is symbol for creating progress bar
Variables ¶
View Source
var DefaultSettings = Settings{ RefreshRate: 100 * time.Millisecond, NameColorTag: "{b}", BarFgColorTag: "{r}", BarBgColorTag: "{s-}", PercentColorTag: "{m}", SpeedColorTag: "{r}", ProgressColorTag: "{g}", RemainingColorTag: "{c}", ShowName: true, ShowPercentage: true, ShowProgress: true, ShowSpeed: true, ShowRemaining: true, IsSize: true, Width: 88, WindowSizeSec: 15.0, }
DefaultSettings is default progress bar settings
View Source
var (
ErrBarIsNil = fmt.Errorf("Progress bar struct is nil")
)
Functions ¶
This section is empty.
Types ¶
type Bar ¶
type Bar struct {
// contains filtered or unexported fields
}
Bar is progress bar struct
func New ¶
New creates new progress bar struct
Example (Download) ¶
package main import ( "io" "os" "github.com/essentialkaos/ek/v13/progress" "github.com/essentialkaos/ek/v13/req" ) func main() { pb := progress.New(0, "file.zip") resp, err := req.Request{URL: "https://domain.com/file.zip"}.Get() if err != nil { panic(err.Error()) } if resp.StatusCode != 200 { panic("Looks like something is wrong") } defer resp.Body.Close() fd, err := os.OpenFile("file.zip", os.O_CREATE|os.O_WRONLY, 0644) if err != nil { panic(err.Error()) } defer fd.Close() // Set total size to content length pb.SetTotal(resp.ContentLength) pb.Start() io.Copy(fd, pb.Reader(resp.Body)) pb.Finish() }
Output:
Example (Simple) ¶
package main import ( "time" "github.com/essentialkaos/ek/v13/progress" ) func main() { pb := progress.New(1000, "Counting…") // You can use default settings as a starting point pbs := progress.DefaultSettings pbs.RefreshRate = 50 * time.Millisecond pbs.IsSize = false // You can update all settings except RefreshRate before and after // calling Start method. RefreshRate must be set before calling // Start method. pb.UpdateSettings(pbs) pb.Start() // Start async progress handling for i := 0; i < 1000; i++ { time.Sleep(time.Second / 100) pb.Add(1) } pb.Finish() // Stop async progress handling }
Output:
func (*Bar) IsFinished ¶
IsFinished returns true if progress processing is finished
func (*Bar) SetCurrent ¶
SetCurrent sets current progress bar value
func (*Bar) UpdateSettings ¶
UpdateSettings updates progress settings
type Settings ¶
type Settings struct { RefreshRate time.Duration NameColorTag string BarFgColorTag string BarBgColorTag string PercentColorTag string ProgressColorTag string SpeedColorTag string RemainingColorTag string ShowSpeed bool ShowName bool ShowPercentage bool ShowProgress bool ShowRemaining bool Width int NameSize int WindowSizeSec int64 // Window size for passtru reader IsSize bool }
Settings contains progress bar settings
Click to show internal directories.
Click to hide internal directories.