Ejemplo n.º 1
0
func printProgress(c *clif.Command, count int, out clif.Output) {
	out.Printf("<headline>Progressing</headline>\n")
	var wg sync.WaitGroup
	pb := out.ProgressBars()
	if width := c.Option("width").Int(); width > 0 {
		pb.Width(width)
	}
	interval := c.Option("interval").Int()
	style := clif.ProgressBarStyleUtf8
	if c.Option("ascii-style").Bool() {
		style = clif.ProgressBarStyleAscii
	}
	style.Count = clif.PROGRESS_BAR_ADDON_APPEND
	style.Estimate = clif.PROGRESS_BAR_ADDON_PREPEND
	pb.Style(style)
	pb.Start()
	for i := 0; i < count; i++ {
		name := fmt.Sprintf("bar%d", i)
		bar, _ := pb.Init(name, 200)
		wg.Add(1)
		go func(b clif.ProgressBar, t int) {
			defer wg.Done()
			for i := 0; i < 200; i++ {
				b.Increment()
				//<-time.After(time.Millisecond * time.Duration((t+1)*3))
				<-time.After(time.Millisecond * time.Duration(interval*(t+1)))
			}
		}(bar, i)
	}
	wg.Wait()
	pb.Finish()
}
Ejemplo n.º 2
0
func cmdProgress3(c *clif.Command, out clif.Output) {
	pbs := out.ProgressBars()
	pbs.Style(clif.ProgressBarStyleAscii)
	if width := c.Option("width").Int(); width > 0 {
		pbs.Width(width)
	}
	pb, _ := pbs.Init("default", 200)
	interval := c.Option("interval").Int()
	pbs.Start()
	var wg sync.WaitGroup
	wg.Add(1)
	go func(b clif.ProgressBar) {
		defer wg.Done()
		for i := 0; i < 200; i++ {
			b.Increment()
			<-time.After(time.Millisecond * time.Duration(interval))
		}
	}(pb)
	wg.Wait()
	<-pbs.Finish()
}
Ejemplo n.º 3
0
func cmdProgress4(c *clif.Command, out clif.Output) {
	pbs := out.ProgressBars()
	if width := c.Option("width").Int(); width > 0 {
		pbs.Width(width)
	}
	interval := c.Option("interval").Int()
	pbs.Start()
	var wg sync.WaitGroup
	amount := c.Option("amount").Int()
	for i := 0; i < amount; i++ {
		wg.Add(1)
		pb, _ := pbs.Init(fmt.Sprintf("bar-%d", i+1), 200)
		go func(b clif.ProgressBar, ii int) {
			defer wg.Done()
			for i := 0; i < 200; i++ {
				b.Increment()
				<-time.After(time.Millisecond * time.Duration(interval*ii))
			}
		}(pb, i)
	}
	wg.Wait()
	<-pbs.Finish()
}