summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-04 19:44:20 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-04 19:50:58 +0900
commite8b5befb8f49acff7de34c3b7230f47344ecc783 (patch)
tree826250f104e7f6c2e3bc438eb8ccf1ae2a6775fe
parentb9f3547ae19ecbb0566cfc08994610abe9e1c78a (diff)
downloadbuildstream-e8b5befb8f49acff7de34c3b7230f47344ecc783.tar.gz
status.py: Control whether to print colors with colors argument
Whether we print status at all is still controlled by whether we are connected to a terminal, we only optionally enable/disable colors in the output here.
-rw-r--r--buildstream/_frontend/status.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/buildstream/_frontend/status.py b/buildstream/_frontend/status.py
index 7a176369f..0372be373 100644
--- a/buildstream/_frontend/status.py
+++ b/buildstream/_frontend/status.py
@@ -38,10 +38,11 @@ from .widget import TimeCode
# format_profile (Profile): Formatting profile for formatting text
# pipeline (Pipeline): The Pipeline
# scheduler (Scheduler): The Scheduler
+# colors (bool): Whether to print the ANSI color codes in the output
#
class Status():
- def __init__(self, content_profile, format_profile, pipeline, scheduler):
+ def __init__(self, content_profile, format_profile, pipeline, scheduler, colors=False):
self.content_profile = content_profile
self.format_profile = format_profile
@@ -51,6 +52,7 @@ class Status():
self.last_lines = 0 # Number of status lines we last printed to console
self.term = Terminal()
self.spacing = 1
+ self.colors = colors
self.header = StatusHeader(content_profile, format_profile, pipeline, scheduler)
self.term_width, _ = click.get_terminal_size()
@@ -144,7 +146,7 @@ class Status():
# Render the one line header
text = self.header.render(self.term_width, elapsed)
- click.echo(text)
+ click.echo(text, color=self.colors)
# Now we have the number of columns, and an allocation for
# alignment of each column
@@ -160,7 +162,7 @@ class Status():
text += ' ' * self.spacing
# Print the line
- click.echo(text)
+ click.echo(text, color=self.colors)
# Track what we printed last, for the next clear
self.last_lines = self.alloc_lines + self.header.lines