From e56f2a0cff5ad1151cd887b9e75b872be6f90996 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sat, 4 Jan 2014 20:49:57 -0500 Subject: [PATCH] util: use semantic names for colorization Replace ANSI_* with ANSI_COLOR_ --- src/analyze/analyze.c | 8 ++-- src/cgtop/cgtop.c | 4 +- src/core/job.c | 14 +++---- src/core/manager.c | 12 +++--- src/core/transaction.c | 2 +- src/delta/delta.c | 10 ++--- src/journal/journal-verify.c | 4 +- src/journal/journalctl.c | 10 ++--- src/journal/test-journal-verify.c | 2 +- src/libsystemd-bus/bus-dump.c | 48 +++++++++++----------- src/shared/ask-password-api.c | 4 +- src/shared/log.c | 4 +- src/shared/logs-show.c | 12 +++--- src/shared/util.c | 4 +- src/shared/util.h | 40 +++++++++---------- src/systemctl/systemctl.c | 84 +++++++++++++++++++-------------------- src/test/test-strip-tab-ansi.c | 4 +- src/timedate/timedatectl.c | 4 +- 18 files changed, 135 insertions(+), 135 deletions(-) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 459f879..31c1331 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -648,9 +648,9 @@ static int list_dependencies_print(const char *name, unsigned int level, unsigne if (times) { if (times->time) - printf("%s%s @%s +%s%s", ANSI_HIGHLIGHT_RED_ON, name, + printf("%s%s @%s +%s%s", ANSI_COLOR_BAD, name, format_timespan(ts, sizeof(ts), times->activating - boot->userspace_time, USEC_PER_MSEC), - format_timespan(ts2, sizeof(ts2), times->time, USEC_PER_MSEC), ANSI_HIGHLIGHT_OFF); + format_timespan(ts2, sizeof(ts2), times->time, USEC_PER_MSEC), ANSI_COLOR_OFF); else if (times->activated > boot->userspace_time) printf("%s @%s", name, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC)); else @@ -818,8 +818,8 @@ static int list_dependencies(sd_bus *bus, const char *name) { if (times) { if (times->time) - printf("%s%s +%s%s\n", ANSI_HIGHLIGHT_RED_ON, id, - format_timespan(ts, sizeof(ts), times->time, USEC_PER_MSEC), ANSI_HIGHLIGHT_OFF); + printf("%s%s +%s%s\n", ANSI_COLOR_BAD, id, + format_timespan(ts, sizeof(ts), times->time, USEC_PER_MSEC), ANSI_COLOR_OFF); else if (times->activated > boot->userspace_time) printf("%s @%s\n", id, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC)); else diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index c56f7a8..c9dc0c1 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -437,8 +437,8 @@ static int group_compare(const void*a, const void *b) { return strcmp(x->path, y->path); } -#define ON ANSI_HIGHLIGHT_ON -#define OFF ANSI_HIGHLIGHT_OFF +#define ON ANSI_COLOR_EMPHASIZE +#define OFF ANSI_COLOR_OFF static int display(Hashmap *a) { Iterator i; diff --git a/src/core/job.c b/src/core/job.c index 7faa8da..5ca3f83 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -628,20 +628,20 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) { case JOB_DONE: if (u->condition_result) - unit_status_printf(u, ANSI_GREEN_ON " OK " ANSI_HIGHLIGHT_OFF, format); + unit_status_printf(u, ANSI_COLOR_OK " OK " ANSI_COLOR_OFF, format); break; case JOB_FAILED: - unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON "FAILED" ANSI_HIGHLIGHT_OFF, format); + unit_status_printf(u, ANSI_COLOR_BAD "FAILED" ANSI_COLOR_OFF, format); manager_status_printf(u->manager, false, NULL, "See 'systemctl status %s' for details.", u->id); break; case JOB_DEPENDENCY: - unit_status_printf(u, ANSI_HIGHLIGHT_YELLOW_ON "DEPEND" ANSI_HIGHLIGHT_OFF, format); + unit_status_printf(u, ANSI_COLOR_WARN "DEPEND" ANSI_COLOR_OFF, format); break; case JOB_TIMEOUT: - unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " TIME " ANSI_HIGHLIGHT_OFF, format); + unit_status_printf(u, ANSI_COLOR_BAD " TIME " ANSI_COLOR_OFF, format); break; default: @@ -657,12 +657,12 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) { switch (result) { case JOB_TIMEOUT: - unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " TIME " ANSI_HIGHLIGHT_OFF, format); + unit_status_printf(u, ANSI_COLOR_BAD " TIME " ANSI_COLOR_OFF, format); break; case JOB_DONE: case JOB_FAILED: - unit_status_printf(u, ANSI_GREEN_ON " OK " ANSI_HIGHLIGHT_OFF, format); + unit_status_printf(u, ANSI_COLOR_OK " OK " ANSI_COLOR_OFF, format); break; default: @@ -675,7 +675,7 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) { * Most likely a DEPEND warning from a requisiting unit will * occur next and it's nice to see what was requisited. */ if (result == JOB_SKIPPED) - unit_status_printf(u, ANSI_HIGHLIGHT_ON " INFO " ANSI_HIGHLIGHT_OFF, "%s is not active."); + unit_status_printf(u, ANSI_COLOR_EMPHASIZE " INFO " ANSI_COLOR_OFF, "%s is not active."); } } #pragma GCC diagnostic pop diff --git a/src/core/manager.c b/src/core/manager.c index bbe5efa..4a05cad 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -105,7 +105,7 @@ static int manager_watch_jobs_in_progress(Manager *m) { return sd_event_add_monotonic(m->event, JOBS_IN_PROGRESS_WAIT_SEC, 0, manager_dispatch_jobs_in_progress, m, &m->jobs_in_progress_event_source); } -#define CYLON_BUFFER_EXTRA (2*(sizeof(ANSI_RED_ON)-1) + sizeof(ANSI_HIGHLIGHT_RED_ON)-1 + 2*(sizeof(ANSI_HIGHLIGHT_OFF)-1)) +#define CYLON_BUFFER_EXTRA (2*(sizeof(ANSI_COLOR_RED)-1) + sizeof(ANSI_COLOR_BAD)-1 + 2*(sizeof(ANSI_COLOR_OFF)-1)) static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned pos) { char *p = buffer; @@ -116,23 +116,23 @@ static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned po if (pos > 1) { if (pos > 2) p = mempset(p, ' ', pos-2); - p = stpcpy(p, ANSI_RED_ON); + p = stpcpy(p, ANSI_COLOR_RED); *p++ = '*'; } if (pos > 0 && pos <= width) { - p = stpcpy(p, ANSI_HIGHLIGHT_RED_ON); + p = stpcpy(p, ANSI_COLOR_BAD); *p++ = '*'; } - p = stpcpy(p, ANSI_HIGHLIGHT_OFF); + p = stpcpy(p, ANSI_COLOR_OFF); if (pos < width) { - p = stpcpy(p, ANSI_RED_ON); + p = stpcpy(p, ANSI_COLOR_RED); *p++ = '*'; if (pos < width-1) p = mempset(p, ' ', width-1-pos); - strcpy(p, ANSI_HIGHLIGHT_OFF); + strcpy(p, ANSI_COLOR_OFF); } } diff --git a/src/core/transaction.c b/src/core/transaction.c index 36e31c4..97f72da 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -399,7 +399,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi "Job %s/%s deleted to break ordering cycle starting with %s/%s", delete->unit->id, job_type_to_string(delete->type), j->unit->id, job_type_to_string(j->type)); - unit_status_printf(delete->unit, ANSI_HIGHLIGHT_RED_ON " SKIP " ANSI_HIGHLIGHT_OFF, + unit_status_printf(delete->unit, ANSI_COLOR_BAD " SKIP " ANSI_COLOR_OFF, "Ordering cycle found, skipping %s"); transaction_delete_unit(tr, delete->unit); return -EAGAIN; diff --git a/src/delta/delta.c b/src/delta/delta.c index 19eaed3..a02e91d 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -104,7 +104,7 @@ static int notify_override_masked(const char *top, const char *bottom) { return 0; printf("%s%s%s %s → %s\n", - ansi_highlight_red(), "[MASKED]", ansi_highlight_off(), top, bottom); + ansi_color_bad(), "[MASKED]", ansi_color_off(), top, bottom); return 1; } @@ -113,7 +113,7 @@ static int notify_override_equivalent(const char *top, const char *bottom) { return 0; printf("%s%s%s %s → %s\n", - ansi_highlight_green(), "[EQUIVALENT]", ansi_highlight_off(), top, bottom); + ansi_color_good(), "[EQUIVALENT]", ansi_color_off(), top, bottom); return 1; } @@ -122,7 +122,7 @@ static int notify_override_redirected(const char *top, const char *bottom) { return 0; printf("%s%s%s %s → %s\n", - ansi_highlight(), "[REDIRECTED]", ansi_highlight_off(), top, bottom); + ansi_color_emphasize(), "[REDIRECTED]", ansi_color_off(), top, bottom); return 1; } @@ -131,7 +131,7 @@ static int notify_override_overridden(const char *top, const char *bottom) { return 0; printf("%s%s%s %s → %s\n", - ansi_highlight(), "[OVERRIDDEN]", ansi_highlight_off(), top, bottom); + ansi_color_emphasize(), "[OVERRIDDEN]", ansi_color_off(), top, bottom); return 1; } @@ -140,7 +140,7 @@ static int notify_override_extended(const char *top, const char *bottom) { return 0; printf("%s%s%s %s → %s\n", - ansi_highlight(), "[EXTENDED]", ansi_highlight_off(), top, bottom); + ansi_color_emphasize(), "[EXTENDED]", ansi_color_off(), top, bottom); return 1; } diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index 3405811..335e9a4 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -300,12 +300,12 @@ 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_ON, stdout); + fputs("\r\x1B[?25l" ANSI_COLOR_GOOD, stdout); for (i = 0; i < j; i++) fputs("\xe2\x96\x88", stdout); - fputs(ANSI_HIGHLIGHT_OFF, stdout); + fputs(ANSI_COLOR_OFF, stdout); for (i = 0; i < k; i++) fputs("\xe2\x96\x91", stdout); diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 42c16f6..b43cc98 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1197,15 +1197,15 @@ static int setup_keys(void) { if (on_tty()) { fprintf(stderr, "\n" - "The new key pair has been generated. The " ANSI_HIGHLIGHT_ON "secret sealing key" ANSI_HIGHLIGHT_OFF " has been written to\n" + "The new key pair has been generated. The " ANSI_COLOR_EMPHASIZE "secret sealing key" ANSI_COLOR_OFF " has been written to\n" "the following local file. This key file is automatically updated when the\n" "sealing key is advanced. It should not be used on multiple hosts.\n" "\n" "\t%s\n" "\n" - "Please write down the following " ANSI_HIGHLIGHT_ON "secret verification key" ANSI_HIGHLIGHT_OFF ". It should be stored\n" + "Please write down the following " ANSI_COLOR_EMPHASIZE "secret verification key" ANSI_COLOR_OFF ". It should be stored\n" "at a safe location and should not be saved locally on disk.\n" - "\n\t" ANSI_HIGHLIGHT_RED_ON, p); + "\n\t" ANSI_COLOR_BAD, p); fflush(stderr); } for (i = 0; i < seed_size; i++) { @@ -1220,7 +1220,7 @@ static int setup_keys(void) { char tsb[FORMAT_TIMESPAN_MAX], *hn; fprintf(stderr, - ANSI_HIGHLIGHT_OFF "\n" + ANSI_COLOR_OFF "\n" "The sealing key is automatically changed every %s.\n", format_timespan(tsb, sizeof(tsb), arg_interval, 0)); @@ -1739,7 +1739,7 @@ int main(int argc, char *argv[]) { if (previous_boot_id_valid && !sd_id128_equal(boot_id, previous_boot_id)) printf("%s-- Reboot --%s\n", - ansi_highlight(), ansi_highlight_off()); + ansi_color_emphasize(), ansi_color_off()); previous_boot_id = boot_id; previous_boot_id_valid = true; diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c index 0540074..3da9176 100644 --- a/src/journal/test-journal-verify.c +++ b/src/journal/test-journal-verify.c @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) { log_info("[ %"PRIu64"+%"PRIu64"]", p / 8, p % 8); if (raw_verify("test.journal", verification_key) >= 0) - log_notice(ANSI_HIGHLIGHT_RED_ON ">>>> %"PRIu64" (bit %"PRIu64") can be toggled without detection." ANSI_HIGHLIGHT_OFF, p / 8, p % 8); + log_notice(ANSI_COLOR_BAD ">>>> %"PRIu64" (bit %"PRIu64") can be toggled without detection." ANSI_COLOR_OFF, p / 8, p % 8); bit_toggle("test.journal", p); } diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c index 78e7597..6898294 100644 --- a/src/libsystemd-bus/bus-dump.c +++ b/src/libsystemd-bus/bus-dump.c @@ -55,10 +55,10 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) { if (with_header) { fprintf(f, "%s%s%sType=%s%s%s Endian=%c Flags=%u Version=%u", - m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? ansi_highlight_red() : - m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? ansi_highlight_green() : - m->header->type != SD_BUS_MESSAGE_SIGNAL ? ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), ansi_highlight_off(), - ansi_highlight(), bus_message_type_to_string(m->header->type), ansi_highlight_off(), + m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? ansi_color_bad() : + m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? ansi_color_good() : + m->header->type != SD_BUS_MESSAGE_SIGNAL ? ansi_color_emphasize() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), ansi_color_off(), + ansi_color_emphasize(), bus_message_type_to_string(m->header->type), ansi_color_off(), m->header->endian, m->header->flags, m->header->version); @@ -76,15 +76,15 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) { fputs("\n", f); if (m->sender) - fprintf(f, " Sender=%s%s%s", ansi_highlight(), m->sender, ansi_highlight_off()); + fprintf(f, " Sender=%s%s%s", ansi_color_emphasize(), m->sender, ansi_color_off()); if (m->destination) - fprintf(f, " Destination=%s%s%s", ansi_highlight(), m->destination, ansi_highlight_off()); + fprintf(f, " Destination=%s%s%s", ansi_color_emphasize(), m->destination, ansi_color_off()); if (m->path) - fprintf(f, " Path=%s%s%s", ansi_highlight(), m->path, ansi_highlight_off()); + fprintf(f, " Path=%s%s%s", ansi_color_emphasize(), m->path, ansi_color_off()); if (m->interface) - fprintf(f, " Interface=%s%s%s", ansi_highlight(), m->interface, ansi_highlight_off()); + fprintf(f, " Interface=%s%s%s", ansi_color_emphasize(), m->interface, ansi_color_off()); if (m->member) - fprintf(f, " Member=%s%s%s", ansi_highlight(), m->member, ansi_highlight_off()); + fprintf(f, " Member=%s%s%s", ansi_color_emphasize(), m->member, ansi_color_off()); if (m->sender || m->destination || m->path || m->interface || m->member) fputs("\n", f); @@ -93,8 +93,8 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) { fprintf(f, " ErrorName=%s%s%s" " ErrorMessage=%s\"%s\"%s\n", - ansi_highlight_red(), strna(m->error.name), ansi_highlight_off(), - ansi_highlight_red(), strna(m->error.message), ansi_highlight_off()); + ansi_color_bad(), strna(m->error.name), ansi_color_off(), + ansi_color_bad(), strna(m->error.message), ansi_color_off()); if (m->monotonic != 0) fprintf(f, " Monotonic=%llu", (unsigned long long) m->monotonic); @@ -194,55 +194,55 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) { switch (type) { case SD_BUS_TYPE_BYTE: - fprintf(f, "%sBYTE %s%u%s;\n", prefix, ansi_highlight(), basic.u8, ansi_highlight_off()); + fprintf(f, "%sBYTE %s%u%s;\n", prefix, ansi_color_emphasize(), basic.u8, ansi_color_off()); break; case SD_BUS_TYPE_BOOLEAN: - fprintf(f, "%sBOOLEAN %s%s%s;\n", prefix, ansi_highlight(), true_false(basic.i), ansi_highlight_off()); + fprintf(f, "%sBOOLEAN %s%s%s;\n", prefix, ansi_color_emphasize(), true_false(basic.i), ansi_color_off()); break; case SD_BUS_TYPE_INT16: - fprintf(f, "%sINT16 %s%i%s;\n", prefix, ansi_highlight(), basic.s16, ansi_highlight_off()); + fprintf(f, "%sINT16 %s%i%s;\n", prefix, ansi_color_emphasize(), basic.s16, ansi_color_off()); break; case SD_BUS_TYPE_UINT16: - fprintf(f, "%sUINT16 %s%u%s;\n", prefix, ansi_highlight(), basic.u16, ansi_highlight_off()); + fprintf(f, "%sUINT16 %s%u%s;\n", prefix, ansi_color_emphasize(), basic.u16, ansi_color_off()); break; case SD_BUS_TYPE_INT32: - fprintf(f, "%sINT32 %s%i%s;\n", prefix, ansi_highlight(), basic.s32, ansi_highlight_off()); + fprintf(f, "%sINT32 %s%i%s;\n", prefix, ansi_color_emphasize(), basic.s32, ansi_color_off()); break; case SD_BUS_TYPE_UINT32: - fprintf(f, "%sUINT32 %s%u%s;\n", prefix, ansi_highlight(), basic.u32, ansi_highlight_off()); + fprintf(f, "%sUINT32 %s%u%s;\n", prefix, ansi_color_emphasize(), basic.u32, ansi_color_off()); break; case SD_BUS_TYPE_INT64: - fprintf(f, "%sINT64 %s%lli%s;\n", prefix, ansi_highlight(), (long long) basic.s64, ansi_highlight_off()); + fprintf(f, "%sINT64 %s%lli%s;\n", prefix, ansi_color_emphasize(), (long long) basic.s64, ansi_color_off()); break; case SD_BUS_TYPE_UINT64: - fprintf(f, "%sUINT64 %s%llu%s;\n", prefix, ansi_highlight(), (unsigned long long) basic.u64, ansi_highlight_off()); + fprintf(f, "%sUINT64 %s%llu%s;\n", prefix, ansi_color_emphasize(), (unsigned long long) basic.u64, ansi_color_off()); break; case SD_BUS_TYPE_DOUBLE: - fprintf(f, "%sDOUBLE %s%g%s;\n", prefix, ansi_highlight(), basic.d64, ansi_highlight_off()); + fprintf(f, "%sDOUBLE %s%g%s;\n", prefix, ansi_color_emphasize(), basic.d64, ansi_color_off()); break; case SD_BUS_TYPE_STRING: - fprintf(f, "%sSTRING \"%s%s%s\";\n", prefix, ansi_highlight(), basic.string, ansi_highlight_off()); + fprintf(f, "%sSTRING \"%s%s%s\";\n", prefix, ansi_color_emphasize(), basic.string, ansi_color_off()); break; case SD_BUS_TYPE_OBJECT_PATH: - fprintf(f, "%sOBJECT_PATH \"%s%s%s\";\n", prefix, ansi_highlight(), basic.string, ansi_highlight_off()); + fprintf(f, "%sOBJECT_PATH \"%s%s%s\";\n", prefix, ansi_color_emphasize(), basic.string, ansi_color_off()); break; case SD_BUS_TYPE_SIGNATURE: - fprintf(f, "%sSIGNATURE \"%s%s%s\";\n", prefix, ansi_highlight(), basic.string, ansi_highlight_off()); + fprintf(f, "%sSIGNATURE \"%s%s%s\";\n", prefix, ansi_color_emphasize(), basic.string, ansi_color_off()); break; case SD_BUS_TYPE_UNIX_FD: - fprintf(f, "%sUNIX_FD %s%i%s;\n", prefix, ansi_highlight(), basic.i, ansi_highlight_off()); + fprintf(f, "%sUNIX_FD %s%i%s;\n", prefix, ansi_color_emphasize(), basic.i, ansi_color_off()); break; default: diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index c9c82b2..e168b03 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -90,10 +90,10 @@ int ask_password_tty( goto finish; } - loop_write(ttyfd, ANSI_HIGHLIGHT_ON, sizeof(ANSI_HIGHLIGHT_ON)-1, false); + loop_write(ttyfd, ANSI_COLOR_EMPHASIZE, sizeof(ANSI_COLOR_EMPHASIZE)-1, false); loop_write(ttyfd, message, strlen(message), false); loop_write(ttyfd, " ", 1, false); - loop_write(ttyfd, ANSI_HIGHLIGHT_OFF, sizeof(ANSI_HIGHLIGHT_OFF)-1, false); + loop_write(ttyfd, ANSI_COLOR_OFF, sizeof(ANSI_COLOR_OFF)-1, false); new_termios = old_termios; new_termios.c_lflag &= ~(ICANON|ECHO); diff --git a/src/shared/log.c b/src/shared/log.c index 2a075ff..bd70970 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -332,10 +332,10 @@ static int write_to_console( } if (highlight) - IOVEC_SET_STRING(iovec[n++], ANSI_HIGHLIGHT_RED_ON); + IOVEC_SET_STRING(iovec[n++], ANSI_COLOR_BAD); IOVEC_SET_STRING(iovec[n++], buffer); if (highlight) - IOVEC_SET_STRING(iovec[n++], ANSI_HIGHLIGHT_OFF); + IOVEC_SET_STRING(iovec[n++], ANSI_COLOR_OFF); IOVEC_SET_STRING(iovec[n++], "\n"); if (writev(console_fd, iovec, n) < 0) { diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 61c3652..1a05ca2 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -116,11 +116,11 @@ static bool print_multiline(FILE *f, unsigned prefix, unsigned n_columns, Output if (flags & OUTPUT_COLOR) { if (priority <= LOG_ERR) { - color_on = ANSI_HIGHLIGHT_RED_ON; - color_off = ANSI_HIGHLIGHT_OFF; + color_on = ANSI_COLOR_BAD; + color_off = ANSI_COLOR_OFF; } else if (priority <= LOG_NOTICE) { - color_on = ANSI_HIGHLIGHT_ON; - color_off = ANSI_HIGHLIGHT_OFF; + color_on = ANSI_COLOR_EMPHASIZE; + color_off = ANSI_COLOR_OFF; } } @@ -456,8 +456,8 @@ static int output_verbose( fieldlen = c - (const char*) data; if (flags & OUTPUT_COLOR && startswith(data, "MESSAGE=")) { - on = ANSI_HIGHLIGHT_ON; - off = ANSI_HIGHLIGHT_OFF; + on = ANSI_COLOR_EMPHASIZE; + off = ANSI_COLOR_OFF; } if (flags & OUTPUT_SHOW_ALL || diff --git a/src/shared/util.c b/src/shared/util.c index f491708..6c8d348 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1641,14 +1641,14 @@ int ask(char *ret, const char *replies, const char *text, ...) { bool need_nl = true; if (on_tty()) - fputs(ANSI_HIGHLIGHT_ON, stdout); + fputs(ANSI_COLOR_EMPHASIZE, stdout); va_start(ap, text); vprintf(text, ap); va_end(ap); if (on_tty()) - fputs(ANSI_HIGHLIGHT_OFF, stdout); + fputs(ANSI_COLOR_OFF, stdout); fflush(stdout); diff --git a/src/shared/util.h b/src/shared/util.h index d9720d0..8f106ae 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -70,14 +70,14 @@ #define FORMAT_BYTES_MAX 8 -#define ANSI_HIGHLIGHT_ON "\x1B[1;39m" -#define ANSI_RED_ON "\x1B[31m" -#define ANSI_HIGHLIGHT_RED_ON "\x1B[1;31m" -#define ANSI_GREEN_ON "\x1B[32m" -#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m" -#define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m" -#define ANSI_HIGHLIGHT_BLUE_ON "\x1B[1;34m" -#define ANSI_HIGHLIGHT_OFF "\x1B[0m" +#define ANSI_COLOR_EMPHASIZE "\x1B[1;39m" //highlight-normal +#define ANSI_COLOR_RED "\x1B[31m" //Only for graphics +#define ANSI_COLOR_BAD "\x1B[1;31m" //highlight-red +#define ANSI_COLOR_OK "\x1B[32m" //green +#define ANSI_COLOR_GOOD "\x1B[1;32m" //highlight-green +#define ANSI_COLOR_WARN "\x1B[1;33m" //highlight-yellow +#define ANSI_COLOR_DEEMPHASIZE "\x1B[1;34m" //highlight-blue +#define ANSI_COLOR_OFF "\x1B[0m" //remove coloring #define ANSI_ERASE_TO_END_OF_LINE "\x1B[K" size_t page_size(void); @@ -411,28 +411,28 @@ void columns_lines_cache_reset(int _unused_ signum); bool on_tty(void); -static inline const char *ansi_highlight(void) { - return on_tty() ? ANSI_HIGHLIGHT_ON : ""; +static inline const char *ansi_color_emphasize(void) { + return on_tty() ? ANSI_COLOR_EMPHASIZE : ""; } -static inline const char *ansi_highlight_red(void) { - return on_tty() ? ANSI_HIGHLIGHT_RED_ON : ""; +static inline const char *ansi_color_bad(void) { + return on_tty() ? ANSI_COLOR_BAD : ""; } -static inline const char *ansi_highlight_green(void) { - return on_tty() ? ANSI_HIGHLIGHT_GREEN_ON : ""; +static inline const char *ansi_color_good(void) { + return on_tty() ? ANSI_COLOR_GOOD : ""; } -static inline const char *ansi_highlight_yellow(void) { - return on_tty() ? ANSI_HIGHLIGHT_YELLOW_ON : ""; +static inline const char *ansi_color_warn(void) { + return on_tty() ? ANSI_COLOR_WARN : ""; } -static inline const char *ansi_highlight_blue(void) { - return on_tty() ? ANSI_HIGHLIGHT_BLUE_ON : ""; +static inline const char *ansi_color_deemphasize(void) { + return on_tty() ? ANSI_COLOR_DEEMPHASIZE : ""; } -static inline const char *ansi_highlight_off(void) { - return on_tty() ? ANSI_HIGHLIGHT_OFF : ""; +static inline const char *ansi_color_off(void) { + return on_tty() ? ANSI_COLOR_OFF : ""; } int running_in_chroot(void); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 01a4489..e80864a 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -407,14 +407,14 @@ static void output_units_list(const UnitInfo *unit_infos, unsigned c) { if (streq(u->load_state, "error") || streq(u->load_state, "not-found")) { - on_loaded = on = ansi_highlight_red(); - off_loaded = off = ansi_highlight_off(); + on_loaded = on = ansi_color_bad(); + off_loaded = off = ansi_color_off(); } else on_loaded = off_loaded = ""; if (streq(u->active_state, "failed")) { - on_active = on = ansi_highlight_red(); - off_active = off = ansi_highlight_off(); + on_active = on = ansi_color_bad(); + off_active = off = ansi_color_off(); } else on_active = off_active = ""; @@ -441,11 +441,11 @@ static void output_units_list(const UnitInfo *unit_infos, unsigned c) { "ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n" "SUB = The low-level unit activation state, values depend on unit type."); puts(job_count ? "JOB = Pending job for the unit.\n" : ""); - on = ansi_highlight(); - off = ansi_highlight_off(); + on = ansi_color_emphasize(); + off = ansi_color_off(); } else { - on = ansi_highlight_red(); - off = ansi_highlight_off(); + on = ansi_color_bad(); + off = ansi_color_off(); } if (arg_all) @@ -682,13 +682,13 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) { printf("\n"); } - on = ansi_highlight(); - off = ansi_highlight_off(); + on = ansi_color_emphasize(); + off = ansi_color_off(); if (!arg_no_legend) printf("\n"); } else { - on = ansi_highlight_red(); - off = ansi_highlight_off(); + on = ansi_color_bad(); + off = ansi_color_off(); } if (!arg_no_legend) { @@ -890,13 +890,13 @@ static int output_timers_list(struct timer_info *timer_infos, unsigned n) { printf("\n"); } - on = ansi_highlight(); - off = ansi_highlight_off(); + on = ansi_color_emphasize(); + off = ansi_color_off(); if (!arg_no_legend) printf("\n"); } else { - on = ansi_highlight_red(); - off = ansi_highlight_off(); + on = ansi_color_bad(); + off = ansi_color_off(); } if (!arg_no_legend) { @@ -1056,11 +1056,11 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { u->state == UNIT_FILE_MASKED_RUNTIME || u->state == UNIT_FILE_DISABLED || u->state == UNIT_FILE_INVALID) { - on = ansi_highlight_red(); - off = ansi_highlight_off(); + on = ansi_color_bad(); + off = ansi_color_off(); } else if (u->state == UNIT_FILE_ENABLED) { - on = ansi_highlight_green(); - off = ansi_highlight_off(); + on = ansi_color_good(); + off = ansi_color_off(); } else on = off = ""; @@ -1359,9 +1359,9 @@ static int list_dependencies_one( state = check_one_unit(bus, *c, "activating\0active\0reloading\0", true); if (state > 0) - printf("%s%s%s", ansi_highlight_green(), draw_special_char(DRAW_BLACK_CIRCLE), ansi_highlight_off()); + printf("%s%s%s", ansi_color_good(), draw_special_char(DRAW_BLACK_CIRCLE), ansi_color_off()); else - printf("%s%s%s", ansi_highlight_red(), draw_special_char(DRAW_BLACK_CIRCLE), ansi_highlight_off()); + printf("%s%s%s", ansi_color_bad(), draw_special_char(DRAW_BLACK_CIRCLE), ansi_color_off()); r = list_dependencies_print(*c, level, branches, c[1] == NULL); if (r < 0) @@ -1554,8 +1554,8 @@ static void output_jobs_list(const struct job_info* jobs, unsigned n, bool skipp assert(n == 0 || jobs); if (n == 0) { - on = ansi_highlight_green(); - off = ansi_highlight_off(); + on = ansi_color_good(); + off = ansi_color_off(); printf("%sNo jobs %s.%s\n", on, skipped ? "listed" : "running", off); return; @@ -1594,8 +1594,8 @@ static void output_jobs_list(const struct job_info* jobs, unsigned n, bool skipp _cleanup_free_ char *e = NULL; if (streq(j->state, "running")) { - on = ansi_highlight(); - off = ansi_highlight_off(); + on = ansi_color_emphasize(); + off = ansi_color_off(); } else on = off = ""; @@ -1608,8 +1608,8 @@ static void output_jobs_list(const struct job_info* jobs, unsigned n, bool skipp } if (!arg_no_legend) { - on = ansi_highlight(); - off = ansi_highlight_off(); + on = ansi_color_emphasize(); + off = ansi_color_off(); printf("\n%s%u jobs listed%s.\n", on, n, off); } @@ -2762,8 +2762,8 @@ static void print_status_info( printf(" Follow: unit currently follows state of %s\n", i->following); if (streq_ptr(i->load_state, "error")) { - on = ansi_highlight_red(); - off = ansi_highlight_off(); + on = ansi_color_bad(); + off = ansi_color_off(); } else on = off = ""; @@ -2812,11 +2812,11 @@ static void print_status_info( ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state; if (streq_ptr(i->active_state, "failed")) { - on = ansi_highlight_red(); - off = ansi_highlight_off(); + on = ansi_color_bad(); + off = ansi_color_off(); } else if (streq_ptr(i->active_state, "active") || streq_ptr(i->active_state, "reloading")) { - on = ansi_highlight_green(); - off = ansi_highlight_off(); + on = ansi_color_good(); + off = ansi_color_off(); } else on = off = ""; @@ -2891,8 +2891,8 @@ static void print_status_info( good = is_clean_exit_lsb(p->code, p->status, NULL); if (!good) { - on = ansi_highlight_red(); - off = ansi_highlight_off(); + on = ansi_color_bad(); + off = ansi_color_off(); } else on = off = ""; @@ -3012,8 +3012,8 @@ static void print_status_info( if (i->need_daemon_reload) printf("\n%sWarning:%s Unit file changed on disk, 'systemctl %sdaemon-reload' recommended.\n", - ansi_highlight_red(), - ansi_highlight_off(), + ansi_color_bad(), + ansi_color_off(), arg_scope == UNIT_FILE_SYSTEM ? "" : "--user "); } @@ -3861,9 +3861,9 @@ static int cat(sd_bus *bus, char **args) { if (!isempty(fragment_path)) { printf("%s# %s%s\n", - ansi_highlight_blue(), + ansi_color_deemphasize(), fragment_path, - ansi_highlight_off()); + ansi_color_off()); fflush(stdout); r = sendfile_full(STDOUT_FILENO, fragment_path); @@ -3876,9 +3876,9 @@ static int cat(sd_bus *bus, char **args) { STRV_FOREACH(path, dropin_paths) { printf("%s%s# %s%s\n", isempty(fragment_path) && path == dropin_paths ? "" : "\n", - ansi_highlight_blue(), + ansi_color_deemphasize(), *path, - ansi_highlight_off()); + ansi_color_off()); fflush(stdout); r = sendfile_full(STDOUT_FILENO, *path); diff --git a/src/test/test-strip-tab-ansi.c b/src/test/test-strip-tab-ansi.c index 5016906..2e6c907 100644 --- a/src/test/test-strip-tab-ansi.c +++ b/src/test/test-strip-tab-ansi.c @@ -32,13 +32,13 @@ int main(int argc, char *argv[]) { assert_se(streq(p, " Foobar bar waldo ")); free(p); - assert_se(p = strdup(ANSI_HIGHLIGHT_ON "Hello" ANSI_HIGHLIGHT_OFF ANSI_HIGHLIGHT_RED_ON " world!" ANSI_HIGHLIGHT_OFF)); + assert_se(p = strdup(ANSI_COLOR_EMPHASIZE "Hello" ANSI_COLOR_OFF ANSI_COLOR_BAD " world!" ANSI_COLOR_OFF)); assert_se(strip_tab_ansi(&p, NULL)); fprintf(stdout, "<%s>\n", p); assert_se(streq(p, "Hello world!")); free(p); - assert_se(p = strdup("\x1B[\x1B[\t\x1B[" ANSI_HIGHLIGHT_ON "\x1B[" "Hello" ANSI_HIGHLIGHT_OFF ANSI_HIGHLIGHT_RED_ON " world!" ANSI_HIGHLIGHT_OFF)); + assert_se(p = strdup("\x1B[\x1B[\t\x1B[" ANSI_COLOR_EMPHASIZE "\x1B[" "Hello" ANSI_COLOR_OFF ANSI_COLOR_BAD " world!" ANSI_COLOR_OFF)); assert_se(strip_tab_ansi(&p, NULL)); assert_se(streq(p, "\x1B[\x1B[ \x1B[\x1B[Hello world!")); free(p); diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c index 2c24b78..7343878 100644 --- a/src/timedate/timedatectl.c +++ b/src/timedate/timedatectl.c @@ -200,11 +200,11 @@ static void print_status_info(const StatusInfo *i) { printf(" DST active: %s\n", yes_no(is_dstc)); if (i->rtc_local) - fputs("\n" ANSI_HIGHLIGHT_ON + fputs("\n" ANSI_COLOR_EMPHASIZE "Warning: The RTC is configured to maintain time in the local timezone. This\n" " mode is not fully supported and will create various problems with time\n" " zone changes and daylight saving adjustments. If at all possible use\n" - " RTC in UTC, by calling 'timedatectl set-local-rtc 0'" ANSI_HIGHLIGHT_OFF ".\n", stdout); + " RTC in UTC, by calling 'timedatectl set-local-rtc 0'" ANSI_COLOR_OFF ".\n", stdout); } static int show_status(sd_bus *bus, char **args, unsigned n) { -- 1.8.3.2