This stuff all still sucks but this is slightly better.
authorScott <[email protected]>
Mon, 24 Jan 2022 16:47:00 +0000 (08:47 -0800)
committerScott <[email protected]>
Mon, 24 Jan 2022 16:47:00 +0000 (08:47 -0800)
text_utils.py

index 9a9eb54702b25783abdc8100124b173790c00c5b..bc05dd9cd791636e8d8ff0a90e9444817ce33af3 100644 (file)
@@ -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(