[Question] Manually updatable progress bars #399
-
Hi, first let me just say this lib looks awesome. I am currently using something else to render a histogram like this to command line and was trying in vain to animate it. It looks to me like I could use something like the multi progress bar example, but looking at the code it was not immediately obvious to my how to do this. Each bin would be a "task" that I could then update. I suppose I'd have to create subclass of BarColumn to change the looks and somehow plug it into the Progress class? Could you point me in the right direction? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
You could render this with the Progress class, by having a task for each data point, but I suspect it would be simpler for you to generate a Table with a row for labels and a row for bars. Start by creating a grid (table with no lines): my_table = Table.grid()
my_table.title = "Samples" Then add rows consisting of the label and a Bar. for i, x in enumerate(data):
my_table.add_row(str(i), Bar(size=100, end=y)) As for animation, the simplest solution would be to clear the screen and redraw. Something along these lines: while True:
with console:
console.clear()
console.print(my_table)
update_data() See examples/table_movie.py for an example of this kind of animation. |
Beta Was this translation helpful? Give feedback.
-
The BarColumn accepts You can also set If you don't want to clear the entire screen, you can use |
Beta Was this translation helpful? Give feedback.
-
Awesome, it worked in the end just using the base progress class. The only quirks are the flickering which seems to happen from the fifth line onwards and I am not entirely sure the background style is behaving correctly. I got the right look by passing |
Beta Was this translation helpful? Give feedback.
-
Afraid not. The shadow bar is drawn with a character, and there is no way to tell the terminal that the foreground color should be the same as the background. There's also no way to query it. It would be fairly simple to modify the ProgressBar class to not have a background. I see a hint of flickering on MacOS iTerm, but nothing on Hyper or Terminal. I don't see any flickering on MS Terminal. So not sure why you get so much flickering. You could try setting auto_refresh to False, and call progress.update() manually, once per loop. |
Beta Was this translation helpful? Give feedback.
The BarColumn accepts
bar_width
, which you can set to your desired width, orNone
for maximum available width.You can also set
style
for the shadow color. See the BarColumn reference for details. You can subclass BarColumn or any other column class.If you don't want to clear the entire screen, you can use
rich.live_render
which is what Progress uses under the hood. It's not documented yet, but it's straight forward to use.