summaryrefslogtreecommitdiff
path: root/text_utils.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-07-16 21:43:44 -0700
committerScott Gasch <[email protected]>2021-07-16 21:43:44 -0700
commit1574e8a3a8982fab9278ad534f9427d464e4bffb (patch)
treeec6e6428ce43f2af64598f2023de3f7d784c5fe3 /text_utils.py
parent0e451d3b3bf899b3d9ac0c38e3c3cd9d9be170ba (diff)
Various
Diffstat (limited to 'text_utils.py')
-rw-r--r--text_utils.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/text_utils.py b/text_utils.py
index 93e4b63..1a8fa18 100644
--- a/text_utils.py
+++ b/text_utils.py
@@ -5,7 +5,7 @@
from collections import defaultdict
import math
import sys
-from typing import List, NamedTuple
+from typing import List, NamedTuple, Optional
from ansi import fg, reset
@@ -171,15 +171,24 @@ def generate_padded_columns(text: List[str]) -> str:
class Indenter:
"""
- with Indenter() as i:
- i.print('test')
- with i:
- i.print('-ing')
+ with Indenter(pad_count = 8) as i:
+ i.print('test')
with i:
- i.print('1, 2, 3')
+ i.print('-ing')
+ with i:
+ i.print('1, 2, 3')
"""
- def __init__(self):
+ def __init__(self,
+ *,
+ pad_prefix: Optional[str] = None,
+ pad_char: str = ' ',
+ pad_count: int = 4):
self.level = -1
+ if pad_prefix is not None:
+ self.pad_prefix = pad_prefix
+ else:
+ self.pad_prefix = ''
+ self.padding = pad_char * pad_count
def __enter__(self):
self.level += 1
@@ -193,4 +202,4 @@ class Indenter:
def print(self, *arg, **kwargs):
import string_utils
text = string_utils.sprintf(*arg, **kwargs)
- print(" " * self.level + text)
+ print(self.pad_prefix + self.padding * self.level + text, end='')