ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
957 stars 34 forks source link

How to create a progress bar that changes its text on each interation? #121

Closed sschuberth closed 6 months ago

sschuberth commented 11 months ago

I struggle to create a simple progress bar that shows the progress when iterating over a list of files. I'd like to show the name of the current file, it's index relative to the total count, and the percentage. So something like

first.file 1/50 2% ➡️ second.file 2/50 4% ➡️ ...

Is this possible currently, or does the text() need to remain static?

ajalt commented 11 months ago

It's not currently possible to pass in an object to modify the progress layout like that, but it's a good idea and should be added.

For now, if you aren't using any of the animated columns like progressBar() you can use a textAnimation that you update manually.

You could also clear the animation and create a new one each time the file changes, but that will cause the progress bar to reset too, so that's not ideal.

CharlyRien commented 7 months ago

Hello, I would like to express my interest in having this feature as well.

In my particular use case, I generate intermediate results from an algorithm over a specific duration. (the duration is from the user's input) These results are presented as a matching percentage also based on the user’s input. Unfortunately, with the current progress bar, I am unable to display the fluctuating match percentage over time. (Or maybe there is a way that I did not see)

Anyway, I would like to thank you for the work that has been accomplished thus far. It is greatly appreciated. :-)

ajalt commented 7 months ago

@CharlyRien I'm working on this right now on the multi-progress branch. If you're able to build and test it out, I'd love any feedback you have. I gave an example of the new API in https://github.com/ajalt/mordant/pull/149#issuecomment-1887860181, or you can look at the sample.

CharlyRien commented 7 months ago

Hey @ajalt I'll probably test this out this week.