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
1 changed files with 5 additions and 1 deletions

View File

@ -281,13 +281,17 @@ def print_ok(message):
def print_error(message): def print_error(message):
print_block(message, first_line="") 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=" "): def print_block(message, first_line=" "):
print(first_line, end='') print(first_line, end='')
message = re.sub("\n\s*", " ", message) message = re.sub("\n\s*", " ", message)
words = re.split("(\s+)", message) words = re.split("(\s+)", message)
linelen = 0 linelen = 0
for w in words: for w in words:
if linelen + len(w) > 75: if linelen + len(w) > terminal_columns-1-len(first_line):
print() print()
print(" ", end="") print(" ", end="")
linelen = 0 linelen = 0