Skip to content

[Feature Request] ProgressStyle: enable/disable colorized output based on draw target #698

@tonywu6

Description

@tonywu6

Hello! This is a follow up to #86:

It seems that the default implementation draws to stderr, but whether the output is colorized is dependent on whether stdout is a tty, so if you do something like foo > log, you get progress bars, but they're uncolored.

... which is a bit surprising for programs that intend their stdout to be piped but also use stderr for progress reporting. Right now I'm manually doing a set_colors_enabled(colors_enabled_stderr()) to convince indicatif to print colors.

I'm wondering if you'd be interested in a PR to make it configurable for ProgressStyle, now that console has features like for_stderr for differentiating color support on stdout vs. stderr.

How I imagine this to work:

  1. Have a ProgressStyle::for_stderr() that explicitly sets color detection for its TemplateParts; this could be a public API or just pub(crate);
  2. Within ProgressBar::set_style(), implicitly call ProgressStyle::for_stderr() based on whether the bar's ProgressDrawTarget is TermTarget::Stderr (I'm not sure if doing this makes sense for other types of target though)

Thank you for this crate!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions