Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure --no-color applies to all Supervisor output #4334

Merged
merged 5 commits into from
Dec 19, 2017
Merged

Conversation

christophermaier
Copy link
Contributor

This should ensure that the --no-color option truly does eliminate all ANSI color codes from Supervisor output (note that this does not apply to any ANSI codes that might be present in the output of any supervised services).

There are a few key points:

  1. We were embedding color codes directly in log messages to emphasize certain parts. This was done in a way that completely bypassed any --no-color option; the color would always be there.

  2. The Launcher is responsible for routing standard output and error from supervised services, and uses our core output library. However, that library is currently driven by a global variable that is not set in the Launcher (because it's a completely separate process). Now, we ensure that the Launcher uses whatever colorization option is specified by the Supervisor

  3. Some places in the Supervisor commands were using the UI::default() function to set up their outputs, but this does not honor the --no-color option. Now, all uses of UI in the Supervisor commands goes through a common setup function that does honor this option.

Starting up the Supervisor with --no-color now should truly configure things so there is no colored output. Future work still exists, though, including but not limited to:

  • Trying to unify our output logic in a single place
  • re-introducing "emphasis" coloring, but in a semantically-clean way
  • Making --no-color the default behavior for non-interactive uses

Further details are in the commit messages.

Note that for users to fully experience this, a new Launcher package will need to be built and promoted.

Fixes #997

@thesentinels
Copy link
Contributor

Thanks for the pull request! Here is what will happen next:

  1. Your PR will be reviewed by the maintainers
  2. If everything looks good, one of them will approve it, and your PR will be merged.

Thank you for contributing!

@christophermaier
Copy link
Contributor Author

cc: @bixu

//
// There is currently no short option to check; just the long
// name.
if args.contains(&String::from("--no-color")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant and could be simplified

if args.contains("--no-color") {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow

In several places we were directly embedding ANSI color codes in a log
message as a way to emphasize certain parts of that message. However,
this bypasses the existing controls we have over whether or not to
colorize the Supervisor's output; regardless of your settings, these
emphasized parts would *always* be colored.

As an initial step to bring colored output under control, we are
simply removing all these embedded "emphasis colors". A possible
long-term solution would be to introduce a minimal templating language
of sorts that allows us to mark particular bits of text for emphasis
of one kind or another, allowing the final formatting of a message to
be handled centrally. Think of an HTML/CSS-style separation of
concerns, but for fancy colored log output.

Signed-off-by: Christopher Maier <[email protected]>
The `core::output` colorization logic hinges on the value of a global
atomic variable. However, the Launcher is a separate process from the
Supervisor; any value set in the Supervisor is completely distinct
from what the Launcher sees. As a result, the Launcher would *always*
colorize output, because colorization currently defaults to `true`.

Since the Launcher always has access to the arguments used to start
the Supervisor, and since there is only a single option we care about
here, it's a simple matter to just check if a `--no-color` argument
was passed and then take action accordingly. There's no need to bring
`clap` in for something like this.

Signed-off-by: Christopher Maier <[email protected]>
Just cuts down on repetition

Signed-off-by: Christopher Maier <[email protected]>
We were using `UI::default()` everywhere, which doesn't honor the
`--no-color` flag.

We still have two different mechanisms governing output (our `output`
module and our `ui` module), and should try and unify those as much as
is practical. In the meantime, however, we can bridge the gap here.

Signed-off-by: Christopher Maier <[email protected]>
Copy link
Collaborator

@fnichol fnichol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, pretty straight forward. In the new year we can look into how to support (re)colorizing some messaging but in a way that is reactive to the environment and wishes of a user.

Merge when ready!

};

let isatty = if env::var(NONINTERACTIVE_ENVVAR)
// Keep string boolean for backwards-compatibility
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not exactly backwards-compatibility, it's current 😄

@@ -372,7 +371,7 @@ impl CfgRenderer {
cfg_dest.display()
);
outputln!(preamble ctx.svc.group, "Updated {} {}",
Purple.bold().paint(template.as_str()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purple, wow, we were using all the colors!

@christophermaier
Copy link
Contributor Author

@thesentinels approve

@thesentinels
Copy link
Contributor

🤘 I am testing your branch against master before merging it. We do this to ensure that the master branch is never failing tests.

@thesentinels
Copy link
Contributor

:neckbeard: Travis CI has started testing this PR.

@thesentinels
Copy link
Contributor

💖 Travis CI reports this PR passed.

It always makes me feel nice when humans approve of one anothers work. I'm merging this PR now.

I just want you and the contributor to answer me one question:

gif-keyboard-3280869874741411265

@thesentinels thesentinels merged commit ec05715 into master Dec 19, 2017
@thesentinels thesentinels deleted the cm/no-color branch December 19, 2017 21:12
@christophermaier christophermaier added Focus:Supervisor Related to the Habitat Supervisor (core/hab-sup) component and removed A-supervisor labels Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Focus:Supervisor Related to the Habitat Supervisor (core/hab-sup) component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hab-sup --no-color doesn't strip color from all output
6 participants