Skip to content

Commit 99c5fb8

Browse files
committed
message: don't write progress-bar escape to non-TTY stderr
msg() prefixed every line with the \r\033[K progress-line eraser even when stderr was a pipe or file. Progress bars are drawn only on a TTY (all draw_* helpers gate on sys.stderr.isatty()), so off a TTY there is never a partial line to clear — the escape merely injected control characters into redirected logs (e.g. 'pd list 2>out.txt'). Emit the eraser only when stderr is a TTY.
1 parent 2b37734 commit 99c5fb8

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

proot_distro/message.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,21 @@ def msg(*args):
172172
173173
Suppressed when the TTY is currently being used by another program
174174
(pinentry, curses) — see tty_safe_for_writes for the rationale.
175+
176+
The `\\r\\033[K` progress-line eraser is only emitted when stderr is
177+
a TTY: progress bars are drawn exclusively on a TTY, so off a TTY
178+
there is no partial line to clear and the escape would only inject
179+
control characters into a redirected log.
175180
"""
176181
if not tty_safe_for_writes():
177182
return
178-
sys.stderr.write("\r\033[K")
179-
sys.stderr.flush()
183+
try:
184+
is_tty = sys.stderr.isatty()
185+
except (AttributeError, OSError, ValueError):
186+
is_tty = False
187+
if is_tty:
188+
sys.stderr.write("\r\033[K")
189+
sys.stderr.flush()
180190
print(*args, file=sys.stderr)
181191

182192

0 commit comments

Comments
 (0)