progressbar icon indicating copy to clipboard operation
progressbar copied to clipboard

Option to leave progress bar visible after finished

Open vsekhar opened this issue 5 years ago • 13 comments
trafficstars

Option to leave progress bar onscreen when finished. Useful for seeing counts and rates after completing a run.

vsekhar avatar Sep 28 '20 22:09 vsekhar

Great! Would happily accept PR with this

schollz avatar Sep 29 '20 16:09 schollz

Can I try this one for hacktoberfest?

ibraimgm avatar Sep 30 '20 18:09 ibraimgm

@ibraimgm of course!

schollz avatar Sep 30 '20 18:09 schollz

@vsekhar can you giv me more details or a demo where I can better understand your problem? On all the demos, the progress bar remain visible after the run.

ibraimgm avatar Oct 04 '20 00:10 ibraimgm

Wait, but... https://github.com/schollz/progressbar/blob/2ec720b802af37dd2a1cadd64212e5d8777fad27/progressbar.go#L210

shadowspore avatar Oct 04 '20 14:10 shadowspore

Confirming that progressbar.Default(100) keeps the progress bar visible on completion and the below hides it.

	bar := progressbar.NewOptions(100,
		progressbar.OptionClearOnFinish(),
	)

michaeltintiuc avatar Oct 04 '20 15:10 michaeltintiuc

@vsekhar Does this solve your issue?

ibraimgm avatar Oct 04 '20 20:10 ibraimgm

If my program logs after the bar finishes, then depending on the cursor and output stream (I use go-ansi), the bar either disappears or gets merged/garbled with the next log message.

I think the issue is a lack of newline once the bar finishes. I think you need something like

if !p.config.clearOnFinish {
  if _, err := io.WriteString(c.writer, "\n"); err != nil {
    return err
  }
}

inserted here.

vsekhar avatar Oct 05 '20 16:10 vsekhar

Is this issue still open?. If it is can I pick it up?

vidu171 avatar Oct 13 '20 12:10 vidu171

@vidu171 Its open, go ahead!

schollz avatar Oct 13 '20 17:10 schollz

Hi, I am not able to recreate this issue my bar is still visible after and it doesn't get merged/garbled with the next log message. Can you please tell me the steps or sample code to recreate this issue?

vidu171 avatar Oct 14 '20 04:10 vidu171

I was also having this issue, it seems the problem happens with p.config.userANSICodes is set to true only, since it clears the line after it was re-rendered for finish.

I think simple removing lines 628-633 should solve the issue:

https://github.com/schollz/progressbar/blob/master/progressbar.go#L628

Notice that when not using ANSI Codes, the clearing happen before teh re-rendering, here:

https://github.com/schollz/progressbar/blob/master/progressbar.go#L609

janpfeifer avatar Oct 22 '22 10:10 janpfeifer

Simple 0.5 line fix, at least for the case with config.useANSICodes: https://github.com/schollz/progressbar/pull/140

janpfeifer avatar Oct 22 '22 10:10 janpfeifer