diff options
author | Chandan Singh <chandan@chandansingh.net> | 2019-11-11 23:18:56 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-11-12 11:28:21 +0000 |
commit | 104cfe224c4be2343e67ad1c46d84553034eab89 (patch) | |
tree | 34e5d6212ab1ab136288992bd4b61922e52071b9 /src | |
parent | 149c2c26470c42bbc4d3ee38fbcb3a94078b26df (diff) | |
download | buildstream-104cfe224c4be2343e67ad1c46d84553034eab89.tar.gz |
_frontend: Simplify color handling
Currently we store color configuration in our App object, and have to
remember to pass it around to `click.echo()` when printing things on the
screen. This is error-prone as we can forget to do so. This leads to
bugs like #1200, where `bst init` was not respecting `--no-colors` flag.
Instead of doing that, this patch controls colors in output by
configuring the `click.Context` object.
Fixes #1200.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildstream/_frontend/app.py | 10 | ||||
-rw-r--r-- | src/buildstream/_frontend/cli.py | 5 | ||||
-rw-r--r-- | src/buildstream/_frontend/widget.py | 10 |
3 files changed, 12 insertions, 13 deletions
diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py index 596ef168a..99e164358 100644 --- a/src/buildstream/_frontend/app.py +++ b/src/buildstream/_frontend/app.py @@ -251,7 +251,7 @@ class App(): self._status = Status(self.context, self._state, self._content_profile, self._format_profile, self._success_profile, self._error_profile, - self.stream, colors=self.colors) + self.stream) # Mark the beginning of the session if session_name: @@ -680,8 +680,7 @@ class App(): if self._session_name: self.logger.print_heading(self.project, self.stream, - log_file=self._main_options['log_file'], - styling=self.colors) + log_file=self._main_options['log_file']) # # Print a summary of the queues @@ -689,8 +688,7 @@ class App(): def _print_summary(self): click.echo("", err=True) self.logger.print_summary(self.stream, - self._main_options['log_file'], - styling=self.colors) + self._main_options['log_file']) # _error_exit() # @@ -749,7 +747,7 @@ class App(): self._status.clear() text = self.logger.render(message) - click.echo(text, color=self.colors, nl=False, err=True) + click.echo(text, nl=False, err=True) # Maybe render the status area self._maybe_render_status() diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 67ea02d59..5c0293589 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -353,6 +353,9 @@ def cli(context, **kwargs): context.obj = App.create(dict(kwargs)) context.call_on_close(context.obj.cleanup) + # Configure colors + context.color = context.obj.colors + ################################################################## # Help Command # @@ -544,7 +547,7 @@ def show(app, elements, deps, except_, order, format_): format_ = app.context.log_element_format report = app.logger.show_pipeline(dependencies, format_) - click.echo(report, color=app.colors) + click.echo(report) ################################################################## diff --git a/src/buildstream/_frontend/widget.py b/src/buildstream/_frontend/widget.py index 181ee7d2e..0a268b717 100644 --- a/src/buildstream/_frontend/widget.py +++ b/src/buildstream/_frontend/widget.py @@ -459,9 +459,8 @@ class LogLine(Widget): # project (Project): The toplevel project we were invoked from # stream (Stream): The stream # log_file (file): An optional file handle for additional logging - # styling (bool): Whether to enable ansi escape codes in the output # - def print_heading(self, project, stream, *, log_file, styling=False): + def print_heading(self, project, stream, *, log_file): context = self.context starttime = datetime.datetime.now() text = '' @@ -518,7 +517,7 @@ class LogLine(Widget): # Separator line before following output text += self.format_profile.fmt("=" * 79 + '\n') - click.echo(text, color=styling, nl=False, err=True) + click.echo(text, nl=False, err=True) if log_file: click.echo(text, file=log_file, color=False, nl=False) @@ -529,9 +528,8 @@ class LogLine(Widget): # Args: # stream (Stream): The Stream # log_file (file): An optional file handle for additional logging - # styling (bool): Whether to enable ansi escape codes in the output # - def print_summary(self, stream, log_file, styling=False): + def print_summary(self, stream, log_file): # Early silent return if there are no queues, can happen # only in the case that the stream early returned due to @@ -599,7 +597,7 @@ class LogLine(Widget): text += self._format_values(values, style_value=False) - click.echo(text, color=styling, nl=False, err=True) + click.echo(text, nl=False, err=True) if log_file: click.echo(text, file=log_file, color=False, nl=False) |