From 429e5984c56ab2b7713883298fd9cb1b3905c56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 31 May 2021 02:35:52 +0200 Subject: [PATCH] Disable progress bar on dumb terminals by default The progress bar requires the terminal emulator to support ANSI escape sequences. Normally, TERM is set to dumb to indicate that the terminal emulator doesn't support any ANSI escape sequences. Attempting to use ANSI escape sequences on dumb terminals will lead to weird output. In order to make apk work by default, even on dumb terminals, this commit introduces an additional check which consults $TERM and disables the progress bar if it is set to "dumb". --- src/apk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/apk.c b/src/apk.c index 3de5ca4..0c2482f 100644 --- a/src/apk.c +++ b/src/apk.c @@ -368,7 +368,10 @@ static void setup_automatic_flags(struct apk_ctx *ac) !isatty(STDIN_FILENO)) return; - ac->progress.out = &ac->out; + /* Enable progress bar by default, except on dumb terminals. */ + if (!(tmp = getenv("TERM")) || strcmp(tmp, "dumb") != 0) + ac->progress.out = &ac->out; + if (!(ac->flags & APK_SIMULATE) && access("/etc/apk/interactive", F_OK) == 0) ac->flags |= APK_INTERACTIVE;