tree-wide: check colors_enabled() before outputting ANSI color strings

This commit is contained in:
Lennart Poettering
2016-05-30 18:23:08 +02:00
parent 54f8c958f1
commit 7565bb98a4
3 changed files with 15 additions and 8 deletions
+4 -4
View 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);
+7 -2
View 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);
}
+4 -2
View 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);