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

Fixed --no-color flag behaviour in non-tty environments #1339

Merged
merged 1 commit into from
Jul 17, 2024

Conversation

Prashansa-K
Copy link
Contributor

This fixes issue #1313 and makes the flag behaviour consistent across tty and non-tty.

Screenshot 2024-07-17 at 11 11 02 AM

The attached image shows the changed behaviour.
Now, the non-tty output also comes up as colored by default, same as tty output. This can be overridden by passing the --no-color flag.

I have a doubt though.
If our customers pass the deck output to a non-tty (may be a file), this can cause things to break if --no-color is not passed, as the colorised output may cause formatting issues in a file.
Is this doubt valid?
Should I check for non-tty environments separately and handle this, if this is indeed a valid usecase?
@GGabriele @mheap

@Prashansa-K Prashansa-K self-assigned this Jul 17, 2024
@Prashansa-K Prashansa-K linked an issue Jul 17, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 22.39%. Comparing base (200a471) to head (ded0121).

Files Patch % Lines
cmd/root.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1339      +/-   ##
==========================================
- Coverage   22.39%   22.39%   -0.01%     
==========================================
  Files          54       54              
  Lines        4514     4515       +1     
==========================================
  Hits         1011     1011              
- Misses       3403     3404       +1     
  Partials      100      100              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GGabriele
Copy link
Collaborator

If our customers pass the deck output to a non-tty (may be a file), this can cause things to break if --no-color is not passed, as the colorised output may cause formatting issues in a file.
Is this doubt valid?

I'd worried only if this commit changes the default behaviour of the tool. Is it the case?

Should I check for non-tty environments separately and handle this, if this is indeed a valid usecase?

I'd let @mheap chime in, but I believe predictability is a very important feature. I'd vote against doing special handling on a case-by-case way since we should let the input define the expected behaviour.

===

On a side note: please check here for the convention we use for commit messages. This will help us have a consistent and clear "git story".

Thanks!

@mheap
Copy link
Member

mheap commented Jul 17, 2024

This does change the default behaviour. The expected behaviour from the issue is as follows:

  • Default: TTY gets colour, non-TTY doesn't
  • --no-color=true: Both TTY and non-TTY don't get colour
  • --no-color=false: Both TTY and non-TTY get colour

There may not be a way to differentiate --no-color=false from the default.If so, how would you recommend explicitly enabling colours without changing the default behaviour?

The non-tty environments had no option of getting a colorised output. This change retains the default behaviour of showing colors in tty and no colors in non-tty if no flag is passed. However, on passing the --no-color=false, non-tty environments can also get colored output.

Fix #1313
@Prashansa-K
Copy link
Contributor Author

For retaining the default behaviour, I can check if the flag was passed or not before changing the value for color.NoColor.
Submitted the new change with commit message as per conventions.

Copy link
Collaborator

@GGabriele GGabriele left a comment

Choose a reason for hiding this comment

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

I didn't know about viper.IsSet, nice!!

Good job!

@Prashansa-K Prashansa-K merged commit 0cdef1e into main Jul 17, 2024
41 checks passed
@Prashansa-K Prashansa-K deleted the fix/non-tty-colors branch July 17, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

decK colours do not work correctly in non-tty environment
4 participants