From 1415cd2d07477158bcc03a333a78522a3c972938 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 5 Jul 2018 23:22:15 +0530 Subject: mlog: Add built-in support for quoting bolded messages This allows us to drop wonky sep='' hacks and manual addition of spaces across the codebase. --- mesonbuild/mlog.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'mesonbuild/mlog.py') diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index d17b889..3baa07a 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -57,17 +57,21 @@ def shutdown(): class AnsiDecorator: plain_code = "\033[0m" - def __init__(self, text, code): + def __init__(self, text, code, quoted=False): self.text = text self.code = code + self.quoted = quoted def get_text(self, with_codes): + text = self.text if with_codes: - return self.code + self.text + AnsiDecorator.plain_code - return self.text + text = self.code + self.text + AnsiDecorator.plain_code + if self.quoted: + text = '"{}"'.format(text) + return text -def bold(text): - return AnsiDecorator(text, "\033[1m") +def bold(text, quoted=False): + return AnsiDecorator(text, "\033[1m", quoted=quoted) def red(text): return AnsiDecorator(text, "\033[1;31m") -- cgit v1.1