summaryrefslogtreecommitdiff
path: root/compose/cli/colors.py
diff options
context:
space:
mode:
authorMike Seplowitz <mseplowitz@bloomberg.net>2021-01-19 12:17:55 -0500
committerGitHub <noreply@github.com>2021-01-19 18:17:55 +0100
commit4fa72a066a3829c0049bd5f19533972584693d07 (patch)
tree7bf8442d0340629900b4c1d02be5dedf6bcfb3fe /compose/cli/colors.py
parentb9249168bd280429820e2ae72c0b86006ccfc19d (diff)
Improve control over ANSI output (#6858)
* Move global console_handler into function scope Signed-off-by: Mike Seplowitz <mseplowitz@bloomberg.net> * Improve control over ANSI output - Disabled parallel logger ANSI output if not attached to a tty. The console handler and progress stream already checked whether the output stream is a tty, but ParallelStreamWriter did not. - Added --ansi=(never|always|auto) option to allow clearer control over ANSI output. Since --no-ansi is the same as --ansi=never, --no-ansi is now deprecated. Signed-off-by: Mike Seplowitz <mseplowitz@bloomberg.net>
Diffstat (limited to 'compose/cli/colors.py')
-rw-r--r--compose/cli/colors.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/compose/cli/colors.py b/compose/cli/colors.py
index a4983a9f..042403a9 100644
--- a/compose/cli/colors.py
+++ b/compose/cli/colors.py
@@ -1,3 +1,6 @@
+import enum
+import os
+
from ..const import IS_WINDOWS_PLATFORM
NAMES = [
@@ -12,6 +15,21 @@ NAMES = [
]
+@enum.unique
+class AnsiMode(enum.Enum):
+ """Enumeration for when to output ANSI colors."""
+ NEVER = "never"
+ ALWAYS = "always"
+ AUTO = "auto"
+
+ def use_ansi_codes(self, stream):
+ if self is AnsiMode.ALWAYS:
+ return True
+ if self is AnsiMode.NEVER or os.environ.get('CLICOLOR') == '0':
+ return False
+ return stream.isatty()
+
+
def get_pairs():
for i, name in enumerate(NAMES):
yield (name, str(30 + i))