Skip to content

injoyai/bar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

实现控制台上的进度条

如何使用

  • 正常使用
import (
    "github.com/injoyai/bar"
    "time"
)

func main() {
    x := bar.New(
        bar.WithTotal(60),  
        bar.WithFormatDefault(func(p *bar.Plan) {
            p.SetStyle("■")
            p.SetPadding(".")
        }),
    )
    for {
        time.Sleep(time.Millisecond * 100)
        x.Add(1)
        if x.Flush() {
            break
        }
    }
}
[■■■■■■■■■■■■■■■■■.................................]  21/60  9.1/s  4s
  • 协程模式
import (
    "github.com/injoyai/bar"
	"time"
)

func main() {
    // 协程数量
    limit:=2
    // 能自动增长,和并发数量控制
    b := bar.NewCoroutine(100,limit)
    for i := 0; i < 100; i++ {
        b.Go(func () {
            <-time.After(time.Second * 1)
        })
    }
    b.Wait()
}
[■■■■■■■■■■■■■■■■■                                 ]  21/100  9.1/s  4s
  • 动画效果
import (
	"github.com/injoyai/bar"
	"time"
)

func main() {
	b := bar.New(
		bar.WithTotal(100),
		bar.WithFormat(
			bar.WithAnimationMoon(),
			bar.WithText("|"),
			bar.WithAnimation(bar.Animations[69]),
			bar.WithText("|"),
			bar.WithAnimationSnake(),
			bar.WithRate(),
		),
	)
	for i := 0; i < 100; i++ {
		b.Add(1)
		b.Flush()
		time.Sleep(time.Millisecond * 500)
	}
}
🌓  |  ∙∙∙  |  ⣻  10.0%

About

进度条工具

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages