Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Output plain template when NO_COLOR environment variable is set #475

Merged
merged 2 commits into from Dec 8, 2022

Conversation

zimeg
Copy link
Contributor

@zimeg zimeg commented Dec 3, 2022

Summary

This PR checks for a non-empty NO_COLOR environment variable and displays templates without color if one is present, as specified by the references in #447.

Fixes #447

Preview

NO_COLOR.mov

Reviewers

The following steps can be used to inspect these changes:

  1. Checkout this branch
  2. In a project using survey, append the following to your go.mod, pointing to your local survey source:
replace github.com/AlecAivazis/survey/v2 v2.3.6 => ../../go-survey/survey
  1. Run your project with color support by ensuring NO_COLOR is not set:
$ unset NO_COLOR
$ ./your-survey-project
  1. Run your project with colors removed from survey outputs:
$ export NO_COLOR=true
$ ./your-survey-project

Notes

  • No modifications are made to user-passed prompt values such as Message, Options, Help, and so forth. Removing color from these values is instead left to the caller of this package.

Copy link
Collaborator

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you!

Would you additionally support environment variables CLICOLOR and CLICOLOR_FORCE? https://bixense.com/clicolors/

Reference implementation: https://github.com/cli/go-gh/blob/5f59c9cf4618f1b8074e381209e2f4c0ef9bf25e/pkg/term/env.go#L145-L153

Comment on lines +34 to +35
val, ok := os.LookupEnv("CLICOLOR_FORCE")
return ok && val != "0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to change this to match the reference if that's preferred, but wanted to share a way to check if the environment variable is present then check for a != 0 value instead of checking that the variable isn't the empty value.

Copy link
Collaborator

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you! Looks great.

@AlecAivazis How do you feel about having Survey respect environment variables by default?

@AlecAivazis
Copy link
Owner

Seems totally fine to me 👍

@mislav mislav merged commit fa37277 into AlecAivazis:master Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support NO_COLOR Environment Variable
3 participants