gobar

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2023 License: MIT Imports: 5 Imported by: 0

README

gobar

godocs

A minimal and extremely hackable progressbar for golang.

Install

go get -u github.com/talwat/gobar

Why?

Originally, I was using progressbar by schollz in my programs.

However, that library has (mostly) been unmaintained, only with PR's being merged and dependencies being updated from time to time.

And this would have been fine, except that I was having a bug which meant that it put my other program to a halt because I couldn't do anything else.

So, after waiting a while, I decided to just make my own progressbar with only ~70 sloc! (In comparison to ~800 of progressbar)

Of course this comes at the cost of customizability, but I think it's worth it in my opinion to at least have something that works for me.

Examples

Basic increment
bar := gobar.NewBar(0, 100, "basic", "done!")

for i := 0; i < 100; i++ {
    time.Sleep(10 * time.Millisecond)
    bar.Increment(1)
}
IO operations
req, _ := http.NewRequest("GET", "https://dl.google.com/go/go1.14.2.src.tar.gz", nil)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()

f, _ := os.OpenFile("go1.14.2.src.tar.gz", os.O_CREATE|os.O_WRONLY, 0644)
defer f.Close()

bar := gobar.NewBar(0, resp.ContentLength, "io", "done!")
io.Copy(io.MultiWriter(f, bar), resp.Body)

Documentation

Overview

A super minimalistic library for progressbars in golang.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar struct {
	Value       int64
	Total       int64
	Description string
	Throttle    int64
	// contains filtered or unexported fields
}

The bar class, do not initialize directly, instead, use NewBar.

func NewBar

func NewBar(value int64, total int64, description string) *Bar

Makes a new bar and initializes it. This will call bar.Display(), so be careful not to call it to early in your program.

func (*Bar) Add

func (bar *Bar) Add(num int64)

Adds an int to the value of the bar. This also adds a rate aswell with the same number. Rate defines whether to add a rate.

func (*Bar) Display

func (bar *Bar) Display(ignoreThrottle bool)

Display the bar. This does not change the bar, or increment the value.

func (*Bar) Finish

func (bar *Bar) Finish()

Makes some newlines and finishes the bar. This is usually called automatically once the bar is full.

func (*Bar) Increment

func (bar *Bar) Increment(num int64)

Increments the bar by num and displays it.

func (*Bar) Init

func (bar *Bar) Init()

Initializes a new bar and renders it in a 0% progress state.

func (*Bar) Write

func (bar *Bar) Write(data []byte) (int, error)

Implementation for io.Writer.

Jump to

Keyboard shortcuts

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