diff options
Diffstat (limited to 'pw_cli')
-rw-r--r-- | pw_cli/py/pw_cli/color.py | 7 | ||||
-rw-r--r-- | pw_cli/py/pw_cli/envparse.py | 5 |
2 files changed, 9 insertions, 3 deletions
diff --git a/pw_cli/py/pw_cli/color.py b/pw_cli/py/pw_cli/color.py index 5651fa9b7..6b9074bf5 100644 --- a/pw_cli/py/pw_cli/color.py +++ b/pw_cli/py/pw_cli/color.py @@ -78,4 +78,11 @@ def colors(enabled: Optional[bool] = None) -> Union[_Color, _NoColor]: kernel32 = ctypes.windll.kernel32 # type: ignore kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7) + # These are semi-standard ways to turn colors off or on for many projects. + # See https://bixense.com/clicolors/ and https://no-color.org/ for more. + if 'NO_COLOR' in os.environ: + enabled = False + elif 'CLICOLOR_FORCE' in os.environ: + enabled = True + return _Color() if enabled else _NoColor() diff --git a/pw_cli/py/pw_cli/envparse.py b/pw_cli/py/pw_cli/envparse.py index b7cccbba8..182936f2d 100644 --- a/pw_cli/py/pw_cli/envparse.py +++ b/pw_cli/py/pw_cli/envparse.py @@ -22,6 +22,7 @@ from typing import ( Generic, IO, List, + Literal, Mapping, Optional, TypeVar, @@ -205,9 +206,7 @@ def strict_bool(value: str) -> bool: ) -# TODO(mohrr) Switch to Literal when no longer supporting Python 3.7. -# OpenMode = Literal['r', 'rb', 'w', 'wb'] -OpenMode = str +OpenMode = Literal['r', 'rb', 'w', 'wb'] class FileType: |