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

Add CLI options to handle colouring #22

Closed
7 tasks
chshersh opened this issue May 25, 2022 · 3 comments · Fixed by #93
Closed
7 tasks

Add CLI options to handle colouring #22

chshersh opened this issue May 25, 2022 · 3 comments · Fixed by #93
Labels
cli-options CLI options, parsers good first issue Good for newcomers hacktoberfest https://hacktoberfest.com/

Comments

@chshersh
Copy link
Owner

chshersh commented May 25, 2022

Currently, Iris checks stdout and stderr handles to decide whether they support colouring or not. And that's all. This issue is about improving the detection of colouring via CLI options.

Description

Following CLI Guidelines, the new logic for detecting colouring should be as follows:

  • Disable colouring if the NO_COLOR / NO_COLOUR environment variable is set
  • Disable colouring if the <MY_APP_NAME>_NO_COLOR / <MY_APP_NAME>_NO_COLOUR environment variable is set
  • Disable colouring if the TERM environment variable is set to dumb
  • Disable colouring if one of --no-color / --no-colour / --disable-color / --disable-colour options is provided
    • Iris should display only --no-color with the description. Other options shouldn't be displayed. Use internal for other options.

Additionally, Iris should provide the --color option (with the --colour option as well being hidden via internal) with the following values:

  • auto (default): detects colouring automatically by checking handles, environment variables and disabling CLI options
  • never: disables colouring

    Colour disabling options should behave exactly as --colour=never

  • always: always prints colours; has higher priority than any other option

Implementation

  • Add a config option for my application name
  • Add new module Iris.Cli.Colour
    • Enum type for always / auto / never options
    • CLI parsers for above-mentioned colours
    • Add this option by default to env
  • Add a new module Iris.Colour.Detect with the implementation of the colouring detection logic described in the beginning of this issue
  • There should be no separate option for stdout and stderr. In other words, env variables and CLI disable / enable options apply to both stdout and stderr. The only different part is whether the specific handle supports colouring or not
@chshersh chshersh added the cli-options CLI options, parsers label May 25, 2022
@chshersh chshersh moved this to Todo in Iris Project May 27, 2022
@chshersh chshersh added the good first issue Good for newcomers label Aug 8, 2022
@chshersh chshersh added the hacktoberfest https://hacktoberfest.com/ label Sep 27, 2022
@marcellourbani
Copy link
Contributor

I'll have a go

@marcellourbani
Copy link
Contributor

marcellourbani commented Oct 6, 2022

@chshersh I'm a bit confused by strings:

  • Iris.Colour.Formatting uses Bytestring
  • Iris.Tool uses Text

As I understand the former is about output and the latter about command line parsing, so they will probably coexist smoothly, but still feels a bit odd

Is this deliberate?

@chshersh
Copy link
Owner Author

chshersh commented Oct 6, 2022

Since text-2.0, Text is now a UTF-8 array of bytes. I'd love to move the entire API towards Text for consistency so yes, the existing situation around having both ByteString and Text is a bit unfortunately 😞

If you feel like it, you can create a separate issue to change types in Iris.Colour.Formatting from ByteString to Text and work on it separately. It'll be a breaking change but that's okay at this stage.

marcellourbani added a commit to marcellourbani/iris that referenced this issue Oct 16, 2022
marcellourbani added a commit to marcellourbani/iris that referenced this issue Oct 16, 2022
marcellourbani added a commit to marcellourbani/iris that referenced this issue Oct 16, 2022
marcellourbani added a commit to marcellourbani/iris that referenced this issue Oct 16, 2022
marcellourbani added a commit to marcellourbani/iris that referenced this issue Oct 16, 2022
marcellourbani added a commit to marcellourbani/iris that referenced this issue Oct 16, 2022
marcellourbani added a commit to marcellourbani/iris that referenced this issue Jan 12, 2023
@chshersh chshersh added this to the v0.1.0.0: Improved UX milestone Jan 12, 2023
chshersh pushed a commit that referenced this issue Jan 12, 2023
Fixes #22

* Add CLI options to handle colouring
* tests, fixes
* changelog
* fixed args
* added dumb terminal check
* spacing
* refactor colour option -> triple option
* cleanup
@github-project-automation github-project-automation bot moved this from Todo to Done in Iris Project Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli-options CLI options, parsers good first issue Good for newcomers hacktoberfest https://hacktoberfest.com/
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants