Add support for NO_COLOR environment variable #835

Closed
opened 2024-03-03 12:30:02 +00:00 by bubbleguuum ยท 10 comments

What I'd like to do and why

For details see:

https://no-color.org/

Other notes / implementation ideas

No response

### What I'd like to do and why For details see: https://no-color.org/ ### Other notes / implementation ideas _No response_
Owner

Makes sense to me! In the meantime, check out these docs on disabling color if you haven't already.

Makes sense to me! In the meantime, check out [these docs on disabling color](https://torsion.org/borgmatic/docs/how-to/set-up-backups/#colored-output) if you haven't already.

Seems straightforward, I can do this.

Seems straightforward, I can do this.
witten added the
good first issue
label 2024-03-03 23:42:27 +00:00

@witten Should I give preference to PY_COLORS or NO_COLOR in case both are set?
Please refer to should_do_markup in logger.py.

@witten Should I give preference to `PY_COLORS` or `NO_COLOR` in case both are set? Please refer to `should_do_markup` in `logger.py`.
Owner

Good question! I'd recommend preferring NO_COLOR just because it seems a little more popular in a global GitHub search.

Some related background reading is here: https://github.com/Textualize/rich/issues/343

Good question! I'd recommend preferring `NO_COLOR` just because it seems a little more popular in a global GitHub search. Some related background reading is here: https://github.com/Textualize/rich/issues/343
Owner

Released in borgmatic 1.8.9!

Released in borgmatic 1.8.9!
Author

Minor nitpick: if NO_COLOR is defined and empty it disables color while according to spec it should not:

~> NO_COLOR= borgmatic list
ANSWER:borgmatic.actions.list:kimsufi: Listing archives

The spec from no-color.org:

Command-line software which adds ANSI color to its output by default should check for a NO_COLOR environment variable that, when present and not an empty string (regardless of its value), prevents the addition of ANSI color.

Also, without color, lines are prefixed with some text (in that example: ANSWER:borgmatic.actions.list) not present with color. I suppose it is intended since -nc results in the same output but was a bit surprised to see these prefixes.

Minor nitpick: if NO_COLOR is defined and empty it disables color while according to spec it should not: ``` ~> NO_COLOR= borgmatic list ANSWER:borgmatic.actions.list:kimsufi: Listing archives ``` The spec from no-color.org: Command-line software which adds ANSI color to its output by default should check for a NO_COLOR environment variable that, when present **and not an empty string** (regardless of its value), prevents the addition of ANSI color. Also, without color, lines are prefixed with some text (in that example: `ANSWER:borgmatic.actions.list`) not present with color. I suppose it is intended since -nc results in the same output but was a bit surprised to see these prefixes.
Owner

Good catch! Thank you for pointing this out.

Good catch! Thank you for pointing this out.
Owner

This has been fixed in main!

This has been fixed in main!
Author

Thanks !

I created a PR to the no-color git repo, so borgmatic become listed on no-color.org:

https://github.com/jcs/no_color/pull/279

Thanks ! I created a PR to the no-color git repo, so borgmatic become listed on no-color.org: https://github.com/jcs/no_color/pull/279
Owner

Awesome, thank you!

Awesome, thank you!
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#835
No description provided.