1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-12-21 07:07:05 +00:00

whats_next: wrap output to the actual width of the terminal

This commit is contained in:
Joshua Tauberer 2014-07-07 02:03:01 +00:00
parent 6a231d4409
commit e898cd5d2a

View File

@ -281,13 +281,17 @@ def print_ok(message):
def print_error(message):
print_block(message, first_line="")
try:
terminal_columns = int(shell('check_output', ['stty', 'size']).split()[1])
except:
terminal_columns = 76
def print_block(message, first_line=" "):
print(first_line, end='')
message = re.sub("\n\s*", " ", message)
words = re.split("(\s+)", message)
linelen = 0
for w in words:
if linelen + len(w) > 75:
if linelen + len(w) > terminal_columns-1-len(first_line):
print()
print(" ", end="")
linelen = 0