diff options
Diffstat (limited to 'src/buildstream/_frontend/widget.py')
-rw-r--r-- | src/buildstream/_frontend/widget.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/buildstream/_frontend/widget.py b/src/buildstream/_frontend/widget.py index fbde249a9..b0472bd45 100644 --- a/src/buildstream/_frontend/widget.py +++ b/src/buildstream/_frontend/widget.py @@ -801,3 +801,39 @@ class LogLine(Widget): text += '\n' return text + + # _pretty_print_dictionary() + # + # Formats a dictionary so it can be easily read by the user + # + # Args: + # values: A dictionary + # style_value: Whether to use the content profile for the values + # + # Returns: + # (str): The formatted values + # + def _pretty_print_dictionary(self, values, style_value=True): + text = '' + max_key_len = 0 + for key, value in values.items(): + max_key_len = max(len(key), max_key_len) + + for key, value in values.items(): + if isinstance(value, str) and '\n' in value: + text += self.format_profile.fmt(" {}:".format(key)) + text += textwrap.indent(value, self._indent) + continue + + text += self.format_profile.fmt(" {}:{}".format(key, ' ' * (max_key_len - len(key)))) + + value_list = '' + for item in value: + value_list += "\n\t{}".format(item) + if style_value: + text += self.content_profile.fmt(value_list) + else: + text += value_list + text += '\n' + + return text |