console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.22k stars 238 forks source link

How to print progressbar when redirecting output to file? #530

Open c19 opened 1 year ago

c19 commented 1 year ago

I'm using this to run my program: nohup ./target/release/main > main.log &.

But this cause all the progressbars are gone from the logfile. Any method to preserve it?

chris-laplante commented 1 year ago

I don't think there is anything built-in to indicatif to support this. You may however give unbuffer (https://linux.die.net/man/1/unbuffer) a try. That might do what you want.

djc commented 1 year ago

indicatif more or less inherits this behavior from the console crate which it uses under the cover. An indicatif ProgressDrawTarget can be initialized using a caller-provided console::Term (but a cursory reading of the console API did not allow me to find an option to override their detection of whether the used file descriptor is a terminal).

nyurik commented 7 months ago

@djc I think most of the CLI apps are also used in non-interactive (headless?) mode, and could use some support from indicatif. Even without the auto-detection support, would it make sense to have a "linear log" formatter? It could print current status: 5% out of 100% style messages instead of using ansi control characters once per (second/minute/10min/...?). I have seen this behavior with aria2c, wget, and possibly others.

djc commented 6 months ago

Well, if someone wants to propose a design for something like that I'd be willing to review it.