Move collections into collect space
[python_utils.git] / text_utils.py
index 8ea6e196001e795daec223e166e01d9aed33a009..49ff9b979e2db0e26adfd6dc7b6f0e4663e62289 100644 (file)
@@ -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()