From 9bdde453b721fe2c9dd53de189fd5fd9aa4ab937 Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Fri, 23 Jul 2021 14:54:04 +0300 Subject: 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". [TT: backported to 2.12] --- src/apk.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/apk.c b/src/apk.c index baa2b94..ad48916 100644 --- a/src/apk.c +++ b/src/apk.c @@ -489,11 +489,16 @@ static void setup_terminal(void) static void setup_automatic_flags(void) { + const char *tmp; + if (!isatty(STDOUT_FILENO) || !isatty(STDERR_FILENO) || !isatty(STDIN_FILENO)) return; - apk_flags |= APK_PROGRESS; + /* Enable progress bar by default, except on dumb terminals. */ + if (!(tmp = getenv("TERM")) || strcmp(tmp, "dumb") != 0) + apk_flags |= APK_PROGRESS; + if (!(apk_flags & APK_SIMULATE) && access("/etc/apk/interactive", F_OK) == 0) apk_flags |= APK_INTERACTIVE; -- cgit v1.2.3-70-g09d2