Skip to content

Commit

Permalink
fix alembic.util.messaging.msg to properly wrap at terminal width
Browse files Browse the repository at this point in the history
Instead of applying indent manually after using textwrap, simply use the
`textwrap.wrap`'s `initial_indent` / `subsequent_indent` that will taken into
account when wrapping to the specified `width`

Fixes: #1384
  • Loading branch information
saifelse committed Jan 5, 2024
1 parent abc8002 commit ce19b52
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions alembic/util/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,17 @@ def msg(
write_outstream(sys.stdout, "\n")
else:
# left indent output lines
lines = textwrap.wrap(msg, TERMWIDTH)
indent = " "
lines = textwrap.wrap(
msg,
TERMWIDTH,
initial_indent=indent,
subsequent_indent=indent,
)
if len(lines) > 1:
for line in lines[0:-1]:
write_outstream(sys.stdout, " ", line, "\n")
write_outstream(sys.stdout, " ", lines[-1], ("\n" if newline else ""))
write_outstream(sys.stdout, line, "\n")
write_outstream(sys.stdout, lines[-1], ("\n" if newline else ""))
if flush:
sys.stdout.flush()

Expand Down

0 comments on commit ce19b52

Please sign in to comment.