Commit e898cd5d authored by Joshua Tauberer's avatar Joshua Tauberer

whats_next: wrap output to the actual width of the terminal

parent 6a231d44
...@@ -281,13 +281,17 @@ def print_ok(message): ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment