From 83c1e0d04fe2e78963c8b508e8b7d0ae03bfcb16 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Fri, 10 Sep 2021 13:23:31 -0700 Subject: Adding more tests, working on the test harness. --- text_utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'text_utils.py') diff --git a/text_utils.py b/text_utils.py index 8ea6e19..49ff9b9 100644 --- a/text_utils.py +++ b/text_utils.py @@ -268,6 +268,28 @@ class Indenter: print(self.pad_prefix + self.padding * self.level + text, end='') +def header(title: str, *, width: int = 80, color: str = ''): + """ + Returns a nice header line with a title. + + >>> header('title', width=60, color='') + '----[ title ]-----------------------------------------------' + + """ + w = width + w -= (len(title) + 4) + if w >= 4: + left = 4 * '-' + right = (w - 4) * '-' + if color != '' and color is not None: + r = reset() + else: + r = '' + return f'{left}[ {color}{title}{r} ]{right}' + else: + return '' + + if __name__ == '__main__': import doctest doctest.testmod() -- cgit v1.3