MCPcopy
hub / github.com/cheggaaa/pb

github.com/cheggaaa/pb @v3.1.7 sqlite

repository ↗ · DeepWiki ↗ · release v3.1.7 ↗
266 symbols 890 edges 46 files 128 documented · 48%
README

Terminal progress bar for Go

Simple progress bar for console programs.

Installation

go get github.com/cheggaaa/pb

Usage

package main

import (
    "github.com/cheggaaa/pb"
    "time"
)

func main() {
    count := 100000
    bar := pb.StartNew(count)
    for i := 0; i < count; i++ {
        bar.Increment()
        time.Sleep(time.Millisecond)
    }
    bar.FinishPrint("The End!")
}

Result will be like this:

> go run test.go
37158 / 100000 [================>_______________________________] 37.16% 1m11s

Customization

// create bar
bar := pb.New(count)

// refresh info every second (default 200ms)
bar.SetRefreshRate(time.Second)

// show percents (by default already true)
bar.ShowPercent = true

// show bar (by default already true)
bar.ShowBar = true

// no counters
bar.ShowCounters = false

// show "time left"
bar.ShowTimeLeft = true

// show average speed
bar.ShowSpeed = true

// sets the width of the progress bar
bar.SetWidth(80)

// sets the width of the progress bar, but if terminal size smaller will be ignored
bar.SetMaxWidth(80)

// convert output to readable format (like KB, MB)
bar.SetUnits(pb.U_BYTES)

// and start
bar.Start()

Progress bar for IO Operations

// create and start bar
bar := pb.New(myDataLen).SetUnits(pb.U_BYTES)
bar.Start()

// my io.Reader
r := myReader

// my io.Writer
w := myWriter

// create proxy reader
reader := bar.NewProxyReader(r)

// and copy from pb reader
io.Copy(w, reader)

// create and start bar
bar := pb.New(myDataLen).SetUnits(pb.U_BYTES)
bar.Start()

// my io.Reader
r := myReader

// my io.Writer
w := myWriter

// create multi writer
writer := io.MultiWriter(w, bar)

// and copy
io.Copy(writer, r)

bar.Finish()

Custom Progress Bar Look-and-feel

bar.Format("<.- >")

Multiple Progress Bars (experimental and unstable)

Do not print to terminal while pool is active.

package main

import (
    "math/rand"
    "sync"
    "time"

    "github.com/cheggaaa/pb"
)

func main() {
    // create bars
    first := pb.New(200).Prefix("First ")
    second := pb.New(200).Prefix("Second ")
    third := pb.New(200).Prefix("Third ")
    // start pool
    pool, err := pb.StartPool(first, second, third)
    if err != nil {
        panic(err)
    }
    // update bars
    wg := new(sync.WaitGroup)
    for _, bar := range []*pb.ProgressBar{first, second, third} {
        wg.Add(1)
        go func(cb *pb.ProgressBar) {
            for n := 0; n < 200; n++ {
                cb.Increment()
                time.Sleep(time.Millisecond * time.Duration(rand.Intn(100)))
            }
            cb.Finish()
            wg.Done()
        }(bar)
    }
    wg.Wait()
    // close pool
    pool.Stop()
}

The result will be as follows:

$ go run example/multiple.go 
First  34 / 200 [=========>---------------------------------------------]  17.00% 00m08s
Second  42 / 200 [===========>------------------------------------------]  21.00% 00m06s
Third  36 / 200 [=========>---------------------------------------------]  18.00% 00m08s

Extension points exported contracts — how you extend this code

Element (Interface)
Element is an interface for bar elements [1 implementers]
v3/element.go
Callback (FuncType)
Callback for custom output For example: bar.Callback = func(s string) { mySuperPrint(s) }
pb.go
ElementFunc (FuncType)
ElementFunc type implements Element interface and created for simplify elements
v3/element.go

Core symbols most depended-on inside this repo

New
called by 31
v3/template.go
String
called by 24
v3/pb.go
Set
called by 19
v3/pb.go
Finish
called by 17
pb.go
New
called by 15
pb.go
String
called by 14
pb.go
Width
called by 14
v3/pb.go
Value
called by 12
v3/pb.go

Shape

Function 125
Method 111
Struct 20
TypeAlias 7
FuncType 2
Interface 1

Languages

Go100%

Modules by API surface

v3/pb.go51 symbols
pb.go35 symbols
v3/element.go14 symbols
v3/element_test.go13 symbols
v3/termutil/term_win.go12 symbols
pb_test.go10 symbols
format.go10 symbols
pb_win.go9 symbols
v3/template.go8 symbols
v3/pb_test.go8 symbols
v3/pool.go7 symbols
pool.go7 symbols

Dependencies from manifests, versioned

github.com/VividCortex/ewmav1.2.0 · 1×
github.com/mattn/go-colorablev0.1.4 · 1×
github.com/mattn/go-isattyv0.0.20 · 1×
github.com/mattn/go-runewidthv0.0.4 · 1×
github.com/rivo/unisegv0.4.7 · 1×
golang.org/x/sysv0.1.0 · 1×

For agents

$ claude mcp add pb \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact