summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-04 17:47:06 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-04 19:13:51 +0900
commit6266321b40603eeaad93bd0043ab9fb411c85f89 (patch)
treef4889fb451760901a42a8f66d6a6d6597f6bf322
parent4a4b2f77c272d26bcbbb221957eaac0c9687e45c (diff)
downloadbuildstream-testing-colors.tar.gz
main.py: Added --ansi-colors/--no-ansi-colors optiontesting-colors
If unspecified, defaults to whether we're connected to a terminal.
-rwxr-xr-xbuildstream/_frontend/main.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py
index 111e10ba9..561cf8d2e 100755
--- a/buildstream/_frontend/main.py
+++ b/buildstream/_frontend/main.py
@@ -77,6 +77,8 @@ _, _, _, _, host_machine = os.uname()
@click.option('--log-file',
type=click.File(mode='w', encoding='UTF-8'),
help="A file to store the main log (allows storing the main log while in interactive mode)")
+@click.option('--ansi-colors/--no-ansi-colors', default=None,
+ help="Force enable/disable ANSI color and control codes in output")
@click.pass_context
def cli(context, **kwargs):
"""Build and manipulate BuildStream projects
@@ -275,7 +277,7 @@ def show(app, target, arch, variant, deps, except_, order, format):
dependencies = sorted(dependencies)
report = app.logger.show_pipeline(dependencies, format)
- click.echo(report)
+ click.echo(report, color=app.colors)
##################################################################
@@ -462,6 +464,14 @@ class App():
click.echo("DEBUG: Early enablement of messages")
self.messaging_enabled = True
+ # Resolve whether to use colors in output
+ if self.main_options['ansi_colors'] is None:
+ self.colors = self.is_a_tty
+ elif self.main_options['ansi_colors']:
+ self.colors = True
+ else:
+ self.colors = False
+
#
# Initialize the main pipeline
#
@@ -706,6 +716,7 @@ class App():
def print_heading(self, deps=None):
self.logger.print_heading(self.pipeline, self.variant,
self.main_options['log_file'],
+ styling=self.colors,
deps=deps)
#
@@ -736,7 +747,7 @@ class App():
self.status.clear()
text = self.logger.render(message)
- click.echo(text, nl=False)
+ click.echo(text, color=self.colors, nl=False)
# Maybe render the status area
self.maybe_render_status()