From e2b1ec0d293fd3d17854194189ed5ee1c28f705f Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 24 Jan 2022 08:47:00 -0800 Subject: [PATCH] This stuff all still sucks but this is slightly better. --- text_utils.py | 15 +++++++-------- 1 file 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( -- 2.46.0