diff options
| author | Scott <[email protected]> | 2022-01-24 08:47:00 -0800 |
|---|---|---|
| committer | Scott <[email protected]> | 2022-01-24 08:47:00 -0800 |
| commit | e2b1ec0d293fd3d17854194189ed5ee1c28f705f (patch) | |
| tree | 16b0130f2e9c4f3590fa14168389bf84ddf26be4 /text_utils.py | |
| parent | 6887fe6aaa9d844fe421d2ccdf87f6d03249da9a (diff) | |
This stuff all still sucks but this is slightly better.
Diffstat (limited to 'text_utils.py')
| -rw-r--r-- | text_utils.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/text_utils.py b/text_utils.py index 9a9eb54..bc05dd9 100644 --- a/text_utils.py +++ b/text_utils.py @@ -26,7 +26,7 @@ def get_console_rows_columns() -> RowsColumns: try: rows, columns = cmd_with_timeout( "stty size", - timeout_seconds=5.0, + timeout_seconds=1.0, ).split() except Exception as e: logger.exception(e) @@ -128,6 +128,10 @@ def distribute_strings( string, width=subwidth, alignment=alignment, padding=padding ) retval += string + while(len(retval) > width): + retval = retval.replace(' ', ' ', 1) + while(len(retval) < width): + retval = retval.replace(' ', ' ', 1) return retval @@ -146,13 +150,8 @@ def justify_string_by_chunk( padding = padding[0] first, *rest, last = string.split() w = width - (len(first) + 1 + len(last) + 1) - retval = ( - first + padding + distribute_strings(rest, width=w, padding=padding) - ) - while len(retval) + len(last) < width: - retval += padding - retval += last - return retval + ret = first + padding + distribute_strings(rest, width=w, padding=padding) + padding + last + return ret def justify_string( |
