From ce19b5249280bacf0b20ceaab81221eefac9c483 Mon Sep 17 00:00:00 2001 From: Saif Hakim Date: Thu, 4 Jan 2024 19:54:48 -0800 Subject: [PATCH] fix alembic.util.messaging.msg to properly wrap at terminal width 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 --- alembic/util/messaging.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/alembic/util/messaging.py b/alembic/util/messaging.py index 5f14d597..6618fa7f 100644 --- a/alembic/util/messaging.py +++ b/alembic/util/messaging.py @@ -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()