]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: check colors_enabled() before outputting ANSI color strings
authorLennart Poettering <lennart@poettering.net>
Mon, 30 May 2016 16:23:08 +0000 (18:23 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 30 May 2016 16:23:08 +0000 (18:23 +0200)
src/basic/terminal-util.c
src/journal/journal-verify.c
src/shared/ask-password-api.c

index 3189b8789dcbae94d526d8403eee3187004ce0fc..2b90f2e5a1e9060fc77c98961fe3038b720d7ecc 100644 (file)
@@ -155,14 +155,14 @@ int ask_char(char *ret, const char *replies, const char *text, ...) {
                 char c;
                 bool need_nl = true;
 
-                if (on_tty())
+                if (colors_enabled())
                         fputs(ANSI_HIGHLIGHT, stdout);
 
                 va_start(ap, text);
                 vprintf(text, ap);
                 va_end(ap);
 
-                if (on_tty())
+                if (colors_enabled())
                         fputs(ANSI_NORMAL, stdout);
 
                 fflush(stdout);
@@ -199,14 +199,14 @@ int ask_string(char **ret, const char *text, ...) {
                 char line[LINE_MAX];
                 va_list ap;
 
-                if (on_tty())
+                if (colors_enabled())
                         fputs(ANSI_HIGHLIGHT, stdout);
 
                 va_start(ap, text);
                 vprintf(text, ap);
                 va_end(ap);
 
-                if (on_tty())
+                if (colors_enabled())
                         fputs(ANSI_NORMAL, stdout);
 
                 fflush(stdout);
index 26572ddd76931319c0fe561f9d370d118f54b06e..a37316b8f9d6d57042d0059517fcb093e04a6ba2 100644 (file)
@@ -54,7 +54,9 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
         j = (n * (unsigned) p) / 65535ULL;
         k = n - j;
 
-        fputs("\r\x1B[?25l" ANSI_HIGHLIGHT_GREEN, stdout);
+        fputs("\r", stdout);
+        if (colors_enabled())
+                fputs("\x1B[?25l" ANSI_HIGHLIGHT_GREEN, stdout);
 
         for (i = 0; i < j; i++)
                 fputs("\xe2\x96\x88", stdout);
@@ -66,7 +68,10 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
 
         printf(" %3"PRIu64"%%", 100U * p / 65535U);
 
-        fputs("\r\x1B[?25h", stdout);
+        fputs("\r", stdout);
+        if (colors_enabled())
+                fputs("\x1B[?25h", stdout);
+
         fflush(stdout);
 }
 
index 4a4bd8d3b8ae8c82cb845eaf267205d73e433034..a86b0db5544c89f5a1425107cf2199a9973f7b2a 100644 (file)
@@ -253,10 +253,12 @@ int ask_password_tty(
                         goto finish;
                 }
 
-                loop_write(ttyfd, ANSI_HIGHLIGHT, strlen(ANSI_HIGHLIGHT), false);
+                if (colors_enabled())
+                        loop_write(ttyfd, ANSI_HIGHLIGHT, strlen(ANSI_HIGHLIGHT), false);
                 loop_write(ttyfd, message, strlen(message), false);
                 loop_write(ttyfd, " ", 1, false);
-                loop_write(ttyfd, ANSI_NORMAL, strlen(ANSI_NORMAL), false);
+                if (colors_enabled())
+                        loop_write(ttyfd, ANSI_NORMAL, strlen(ANSI_NORMAL), false);
 
                 new_termios = old_termios;
                 new_termios.c_lflag &= ~(ICANON|ECHO);