chiark / gitweb /
journalctl: no color for --reboot-- when not on tty
[elogind.git] / src / journal / journalctl.c
index f404e414f46f8d9b25c4fb0993f212aa3c786691..af0f4ba3c8b9f289d0d6a35eb4f61d6ed9b08529 100644 (file)
@@ -1333,12 +1333,14 @@ int main(int argc, char *argv[]) {
 
                         if (!arg_merge) {
                                 sd_id128_t boot_id;
+                                const char *color_on = on_tty() ? ANSI_HIGHLIGHT_ON : "",
+                                           *color_off = on_tty() ? ANSI_HIGHLIGHT_OFF : "";
 
                                 r = sd_journal_get_monotonic_usec(j, NULL, &boot_id);
                                 if (r >= 0) {
                                         if (previous_boot_id_valid &&
                                             !sd_id128_equal(boot_id, previous_boot_id))
-                                                printf(ANSI_HIGHLIGHT_ON "-- Reboot --" ANSI_HIGHLIGHT_OFF "\n");
+                                                printf("%s-- Reboot --%s\n", color_on, color_off);
 
                                         previous_boot_id = boot_id;
                                         previous_boot_id_valid = true;