From 021068a8b7461a62ed4ce68ab558bc94786e0550 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 21 Jan 2021 12:25:46 +0100 Subject: [PATCH] mlog: add __len__ to AnsiDecorator --- mesonbuild/interpreter.py | 10 +--------- mesonbuild/mlog.py | 3 +++ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index c7049c31c..817204fd2 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1876,14 +1876,6 @@ class Summary: self.sections[section][k] = (formatted_values, list_sep) self.max_key_len = max(self.max_key_len, len(k)) - def text_len(self, v): - if isinstance(v, str): - return len(v) - elif isinstance(v, mlog.AnsiDecorator): - return len(v.text) - else: - raise RuntimeError('Expecting only strings or AnsiDecorator') - def dump(self): mlog.log(self.project_name, mlog.normal_cyan(self.project_version)) for section, values in self.sections.items(): @@ -1909,7 +1901,7 @@ class Summary: line_len = indent lines_sep = list_sep.rstrip() + lines_sep for v in arr: - v_len = self.text_len(v) + len(list_sep) + v_len = len(v) + len(list_sep) if line and line_len + v_len > max_len: mlog.log(*line, sep=list_sep, end=lines_sep) line_len = indent diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 6207d98a4..a6aa2b563 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -130,6 +130,9 @@ class AnsiDecorator: text = '"{}"'.format(text) return text + def __len__(self) -> int: + return len(self.text) + def __str__(self) -> str: return self.get_text(colorize_console())