projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Adds unscrambler which contains the guts of a jumble/scrabble player
[python_utils.git]
/
text_utils.py
diff --git
a/text_utils.py
b/text_utils.py
index 9a9eb54702b25783abdc8100124b173790c00c5b..bc05dd9cd791636e8d8ff0a90e9444817ce33af3 100644
(file)
--- 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",
try:
rows, columns = cmd_with_timeout(
"stty size",
- timeout_seconds=
5
.0,
+ timeout_seconds=
1
.0,
).split()
except Exception as e:
logger.exception(e)
).split()
except Exception as e:
logger.exception(e)
@@
-128,6
+128,10
@@
def distribute_strings(
string, width=subwidth, alignment=alignment, padding=padding
)
retval += string
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
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)
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(
def justify_string(