"""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 typing import Dict, Generator, List, Literal, NamedTuple, Optional, Tuple
from ansi import fg, reset
class RowsColumns(NamedTuple):
+ """Row + Column"""
+
rows: int
columns: int
).split()
except Exception as e:
logger.exception(e)
- raise Exception('Can\'t determine console size?!')
+ raise Exception('Can\'t determine console size?!') from e
return RowsColumns(int(rows), int(columns))
barcount = len(_bar)
min_num, max_num = min(numbers), max(numbers)
span = max_num - min_num
- sparkline = ''.join(
+ sline = ''.join(
_bar[min([barcount - 1, int((n - min_num) / span * barcount)])] for n in numbers
)
- return min_num, max_num, sparkline
+ return min_num, max_num, sline
def distribute_strings(
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