indiscipline / zrtstr

Check if stereo WAV files have identical channels (faux-stereo) and convert them to mono.
GNU General Public License v2.0
31 stars 0 forks source link

Redirect progress bar to stderr #9

Open indiscipline opened 1 year ago

maxwell-gisborne commented 2 months ago

Does this want to be the behavior across the board, or turned on with a flag?

indiscipline commented 2 months ago

Progress indication is an interactive element, and as such should always be written to stderr, unless io::stderr().is_terminal() == false.

The pb library we're using is nice as it's minimal-dependencies, but looks a bit stale. I'm open to suggestions for switching to, as long as it's as minimal. I might also look into adding the stderr output to pb itself.

maxwell-gisborne commented 2 months ago

Hi indiscipline,

My first idea is on line 92 of main, to switch ProgressBar::new(dur_samples as u64); To ProgressBar::on(stderr, dur_samples as u64);

To simply switch off the progress bars when io::stderr().is_terminal() == false we can wrap pb into the option pb_option of type Option<ProgressBar<Stderr>>, and replace it's method calls with if let Some(pb) = pb_option { ... }.

If, on the other hand, you want progress bars to be directed into stdout on the eventuality that is_terminal() is false, then I suggest making pb a tagged union, since ProgressBar<T> expose the type of the handel for some reason.

Because of that, I couldn't find a way to make a simple if on line 92 to work. One branch of the if can't return ProgressBar<Stdout> while the other returns ProgressBar<Stderr>, but wrapping in an enum should work.

(About me: I'm learning rust and wanted to jump into some real code to help that process, so feedback is very welcome)