Skip to content

Commit

Permalink
Suppress the usage of ANSI color when indicated by the user
Browse files Browse the repository at this point in the history
When `$TLDR_MAN_NO_COLOR` or `$NO_COLOR` is present and not an empty
string, prevents the usage of ANSI color.

For more, see <https://no-color.org/>.
  • Loading branch information
superatomic committed Aug 19, 2023
1 parent c01172e commit 9c228dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/tldr_man/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from pathlib import Path
from contextlib import suppress
from os import remove
from os import remove, getenv
from functools import wraps

import click
Expand Down Expand Up @@ -128,7 +128,11 @@ def subcommand_manpath(locales, page_sections):
print(':'.join(unique(str(man_dir.parent) for man_dir in pages.get_dir_search_order(locales, page_sections))))


@command(cls=HelpColorsCommand, help_headers_color='yellow', help_options_color='green', no_args_is_help=True)
@command(cls=HelpColorsCommand,
help_headers_color='yellow',
help_options_color='green',
context_settings={'color': False if getenv('TLDR_MAN_NO_COLOR') or getenv('NO_COLOR') else None},
no_args_is_help=True)
@argument('page', nargs=-1, required=True, shell_complete=page_shell_complete)
@option('-p', '--platform',
metavar='PLATFORM',
Expand Down
7 changes: 7 additions & 0 deletions tldr-man.1
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ The location of the page cache directory. This directory is created by the
command and is accessed by other commands.
If this variable is not set or is not an absolute path, this defaults back to the value of
.BR $XDG_CACHE_HOME/tldr-man .
.TP
.BR TLDR_MAN_NO_COLOR ", " NO_COLOR
When present and not an empty string (regardless of its value), prevents the usage of ANSI color.
.SH "FILES"
.TP
.BR $XDG_CACHE_HOME/tldr_man
Expand All @@ -183,6 +186,10 @@ TLDR\-Pages Client Specification
.UR https://standards.freedesktop.org/basedir-spec/basedir-spec-latest
XDG Base Directory Specification
.UE .
.PP
.UR https://no-color.org/
NO_COLOR
.UE .
.SH "EXAMPLES"
.PP
Display the tldr\-page for
Expand Down

0 comments on commit 9c228dc

Please sign in to comment.