Skip to content

Commit

Permalink
Add support for NO_COLOR environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Nov 19, 2024
1 parent 8ce52fd commit f75f884
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ In the terminal, you can get a tree view of a file::

The names of datasets, groups and links are colour-coded by default.
If you want to disable this, set the environment variable ``H5GLANCE_COLORS=0``.
H5Glance also respects the `NO_COLOR convention <https://no-color.org/>`_.

Inspect a group or dataset inside it::

Expand Down
3 changes: 3 additions & 0 deletions h5glance/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def use_colors():
env = os.environ.get('H5GLANCE_COLORS', '')
if env:
return env != '0'
# any non-empty string works for NO_COLOR - https://no-color.org/
if os.environ.get('NO_COLOR', ''):
return False

Check warning on line 111 in h5glance/terminal.py

View check run for this annotation

Codecov / codecov/patch

h5glance/terminal.py#L110-L111

Added lines #L110 - L111 were not covered by tests
return sys.stdout.isatty()

class TreeViewBuilder:
Expand Down

0 comments on commit f75f884

Please sign in to comment.