X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=text_utils.py;h=bc05dd9cd791636e8d8ff0a90e9444817ce33af3;hb=22be1f3055cb905aa0b371779e6ab3098f57e4a2;hp=9a9eb54702b25783abdc8100124b173790c00c5b;hpb=b29be4f1750fd20bd2eada88e751dfae85817882;p=python_utils.git 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(