"""Utilities for dealing with "text"."""
+import contextlib
import logging
import math
import sys
from collections import defaultdict
-from typing import Dict, Generator, List, NamedTuple, Optional, Tuple
+from dataclasses import dataclass
+from typing import Dict, Generator, List, Literal, Optional, Tuple
from ansi import fg, reset
logger = logging.getLogger(__file__)
-class RowsColumns(NamedTuple):
+@dataclass
+class RowsColumns:
"""Row + Column"""
- rows: int
- columns: int
+ rows: int = 0
+ columns: int = 0
def get_console_rows_columns() -> RowsColumns:
include_text=True,
width=70,
fgcolor=fg("school bus yellow"),
- reset=reset(),
+ reset_seq=reset(),
left_end="[",
right_end="]",
) -> str:
"""Returns a string containing a bar graph.
- >>> bar_graph(0.5, fgcolor='', reset='')
+ >>> bar_graph(0.5, fgcolor='', reset_seq='')
'[███████████████████████████████████ ] 50.0%'
"""
+ "█" * whole_width
+ part_char
+ " " * (width - whole_width - 1)
- + reset
+ + reset_seq
+ right_end
+ " "
+ text
return out
-class Indenter(object):
+class Indenter(contextlib.AbstractContextManager):
"""
with Indenter(pad_count = 8) as i:
i.print('test')
self.level += 1
return self
- def __exit__(self, exc_type, exc_value, exc_tb):
+ def __exit__(self, exc_type, exc_value, exc_tb) -> Literal[False]:
self.level -= 1
if self.level < -1:
self.level = -1
+ return False
def print(self, *arg, **kwargs):
import string_utils