pb icon indicating copy to clipboard operation
pb copied to clipboard

How to print text when bar is running?

Open violarulan opened this issue 7 years ago • 4 comments

Hello, thanks for your work. I want to print some log when the progress bar is running. But I run in to trouble.

What I want to achieve:

some log 0
some log 1
some log 2
some log 3
some log 4
some log 5
some log 6
some log 7
some log 8
some log 9
 10 / 10 [=================================================] 100.00% 4s
The End!

I got this:

 0 / 10 [-----------------------------------------------------]   0.00%some log 0
 1 / 10 [====>---------------------------------------------]  10.00% 1ssome log 1
 2 / 10 [=========>----------------------------------------]  20.00% 2ssome log 2
 3 / 10 [==============>-----------------------------------]  30.00% 2ssome log 3
 4 / 10 [===================>------------------------------]  40.00% 2ssome log 4
 5 / 10 [========================>-------------------------]  50.00% 1ssome log 5
 6 / 10 [=============================>--------------------]  60.00% 1ssome log 6
 7 / 10 [==================================>---------------]  70.00% 1ssome log 7
 8 / 10 [=======================================>----------]  80.00% 0ssome log 8
 9 / 10 [============================================>-----]  90.00% 0ssome log 9
 10 / 10 [=================================================] 100.00% 4s
The End!

my code:

package main

import (
	"gopkg.in/cheggaaa/pb.v1"
	"time"
	"fmt"
)

func main() {
	count := 10
	bar := pb.StartNew(count)
	for i := 0; i < count; i++ {
		fmt.Println("some log", i)
		bar.Increment()
		time.Sleep(400 * time.Millisecond)
	}
	bar.FinishPrint("The End!")
}

have tested on Ubuntu 14.04 with zsh 5.0.2

is there any direction I can look for?

Thanks in advance!

violarulan avatar Aug 05 '17 12:08 violarulan

This behavior is not yet available and is difficult to implement. But you can simply call bar.Prefix ("some log")

cheggaaa avatar Oct 17 '17 14:10 cheggaaa

Maybe later (in v2) I will make a similar feature with ability to set absolute bar position (top, bottom, etc.).

cheggaaa avatar Oct 17 '17 14:10 cheggaaa

Бро, все с нетерпением ждём этого нововведения!

101usb avatar Oct 02 '18 07:10 101usb

Bro, everyone is looking forward to this innovation!

secoba avatar Feb 16 '20 07:02 secoba