console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.36k stars 241 forks source link

Support for multi-line progress messages #442

Closed happenslol closed 1 year ago

happenslol commented 2 years ago

First of all, thanks for the awesome library! It's been a joy to use so far.

Recently, I've had a few usecases where my CLI apps are running bash scripts or something similar in the background. Of course, I could just show an indeterminate progress spinner here to show that a script is running. However, after using buildkit, which basically shows the last few lines of output for each step being run, and clears them when the step is done, I thought about how to achieve this with this library.

The simplest way to show recent output for progress bars would be to just have multiline progress bars. I could then take e.g. the last three lines of the script output and display them below the progress message. I tried this but newlines are not handled at all by indicatif, resulting in duplicated lines whenever a newline is printed.

I would be open to working on this if this functionality is something you would consider adding in this library. If you need more details or examples of this behavior in other CLI tools, I can provide that.

djc commented 2 years ago

Which version did you try? It might be helpful to try the latest 0.17 rc. I'm fairly certain there is at least some newline handling in indicatif, although I haven't really tried it myself. I would definitely be open to have something like this in the library, happy to answer questions about the code base if you have any.

happenslol commented 2 years ago

I actually checked out the latest main branch, and tried inserting newlines into a bunch of the examples, which just resulted in a whole lot of output :-P I suppose it's possible that it works for a single progress bar though, I'm not sure I tried that.

I'll have a closer look at the codebase and see if I can whip something up. Thanks!

happenslol commented 2 years ago

I've tried to implement this, see #443. I'd be happy about any feedback!

djc commented 1 year ago

This was merged, going to close this.