summaryrefslogtreecommitdiff
path: root/text_utils.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-09-10 13:23:31 -0700
committerScott Gasch <[email protected]>2021-09-10 13:23:31 -0700
commit83c1e0d04fe2e78963c8b508e8b7d0ae03bfcb16 (patch)
treedadcd5f5a9fbd50f468a0f07ee28963ca4a3cf54 /text_utils.py
parent6f132c0342ab7aa438ed88d7c5f987cb52d8ca05 (diff)
Adding more tests, working on the test harness.
Diffstat (limited to 'text_utils.py')
-rw-r--r--text_utils.py22
1 files changed, 22 insertions, 0 deletions
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()