From 6d1d8f66e03a141b985f456f33b36bf01cebb2d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=20R=C3=B8dseth?= Date: Thu, 1 Mar 2018 18:23:05 +0100 Subject: [PATCH 1/3] Organize the ANSI codes and add missing colors For consistency. --- src/basic/terminal-util.h | 44 ++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index f6e6020b66..8e6f668c25 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -28,21 +28,45 @@ #include "macro.h" #include "time-util.h" -#define ANSI_RED "\x1B[0;31m" -#define ANSI_GREEN "\x1B[0;32m" +/* Regular colors */ +#define ANSI_BLACK "\x1B[0;30m" +#define ANSI_RED "\x1B[0;31m" +#define ANSI_GREEN "\x1B[0;32m" +#define ANSI_YELLOW "\x1B[0;33m" +#define ANSI_BLUE "\x1B[0;34m" +#define ANSI_MAGENTA "\x1B[0;35m" +#define ANSI_CYAN "\x1B[0;36m" +#define ANSI_WHITE "\x1B[0;37m" + +/* Bold/highlighted */ +#define ANSI_HIGHLIGHT_BLACK "\x1B[0;1;30m" +#define ANSI_HIGHLIGHT_RED "\x1B[0;1;31m" +#define ANSI_HIGHLIGHT_GREEN "\x1B[0;1;32m" +#define ANSI_HIGHLIGHT_YELLOW "\x1B[0;1;33m" +#define ANSI_HIGHLIGHT_BLUE "\x1B[0;1;34m" +#define ANSI_HIGHLIGHT_MAGENTA "\x1B[0;1;35m" +#define ANSI_HIGHLIGHT_CYAN "\x1B[0;1;36m" +#define ANSI_HIGHLIGHT_WHITE "\x1B[0;1;37m" + +/* Underlined */ +#define ANSI_HIGHLIGHT_BLACK_UNDERLINE "\x1B[0;1;4;30m" +#define ANSI_HIGHLIGHT_RED_UNDERLINE "\x1B[0;1;4;31m" +#define ANSI_HIGHLIGHT_GREEN_UNDERLINE "\x1B[0;1;4;32m" +#define ANSI_HIGHLIGHT_YELLOW_UNDERLINE "\x1B[0;1;4;33m" +#define ANSI_HIGHLIGHT_BLUE_UNDERLINE "\x1B[0;1;4;34m" +#define ANSI_HIGHLIGHT_MAGENTA_UNDERLINE "\x1B[0;1;4;35m" +#define ANSI_HIGHLIGHT_CYAN_UNDERLINE "\x1B[0;1;4;36m" +#define ANSI_HIGHLIGHT_WHITE_UNDERLINE "\x1B[0;1;4;37m" + +/* Other ANSI codes */ #define ANSI_UNDERLINE "\x1B[0;4m" #define ANSI_HIGHLIGHT "\x1B[0;1;39m" -#define ANSI_HIGHLIGHT_RED "\x1B[0;1;31m" -#define ANSI_HIGHLIGHT_GREEN "\x1B[0;1;32m" -#define ANSI_HIGHLIGHT_YELLOW "\x1B[0;1;33m" -#define ANSI_HIGHLIGHT_BLUE "\x1B[0;1;34m" #define ANSI_HIGHLIGHT_UNDERLINE "\x1B[0;1;4m" -#define ANSI_HIGHLIGHT_RED_UNDERLINE "\x1B[0;1;4;31m" -#define ANSI_HIGHLIGHT_GREEN_UNDERLINE "\x1B[0;1;4;32m" -#define ANSI_HIGHLIGHT_YELLOW_UNDERLINE "\x1B[0;1;4;33m" -#define ANSI_HIGHLIGHT_BLUE_UNDERLINE "\x1B[0;1;4;34m" + +/* Reset/clear ANSI styles */ #define ANSI_NORMAL "\x1B[0m" +/* Erase characters until the end of the line */ #define ANSI_ERASE_TO_END_OF_LINE "\x1B[K" /* Set cursor to top left corner and clear screen */ From 96164a3936af2dc2103d4d1ffa3b3b36b5017bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=20R=C3=B8dseth?= Date: Thu, 1 Mar 2018 13:12:02 +0100 Subject: [PATCH 2/3] Add build-time option to change the color of the "OK" status text --- meson.build | 3 +++ meson_options.txt | 8 ++++++++ src/core/job.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index def2351f21..5aa46cd579 100644 --- a/meson.build +++ b/meson.build @@ -182,6 +182,9 @@ conf.set_quoted('SYSTEM_SYSVINIT_PATH', sysvinit_path) conf.set_quoted('SYSTEM_SYSVRCND_PATH', sysvrcnd_path) conf.set_quoted('RC_LOCAL_SCRIPT_PATH_START', get_option('rc-local')) conf.set_quoted('RC_LOCAL_SCRIPT_PATH_STOP', get_option('halt-local')) + +conf.set('ANSI_OK_COLOR', 'ANSI_' + get_option('ok-color').to_upper()) + conf.set_quoted('USER_CONFIG_UNIT_PATH', join_paths(pkgsysconfdir, 'user')) conf.set_quoted('USER_DATA_UNIT_PATH', userunitdir) conf.set_quoted('CERTIFICATE_ROOT', get_option('certificate-root')) diff --git a/meson_options.txt b/meson_options.txt index dca9dfc16c..59fb20b0a4 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -298,6 +298,14 @@ option('slow-tests', type : 'boolean', value : 'false', option('install-tests', type : 'boolean', value : 'false', description : 'install test executables') +option('ok-color', type: 'combo', + choices : ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', + 'white', 'highlight_black', 'highlight_red', 'highlight_green', + 'highlight_yellow', 'highlight_blue', 'highlight_magenta', + 'highlight_cyan', 'highlight_white'], + value : 'green', + description: 'color of the "OK" status message') + option('oss-fuzz', type : 'boolean', value : 'false', description : 'build against oss-fuzz') option('llvm-fuzz', type : 'boolean', value : 'false', diff --git a/src/core/job.c b/src/core/job.c index 249016f8b8..1b3534a7a6 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -696,7 +696,7 @@ _pure_ static const char *job_get_status_message_format(Unit *u, JobType t, JobR static const struct { const char *color, *word; } job_print_status_messages [_JOB_RESULT_MAX] = { - [JOB_DONE] = { ANSI_GREEN, " OK " }, + [JOB_DONE] = { ANSI_OK_COLOR, " OK " }, [JOB_TIMEOUT] = { ANSI_HIGHLIGHT_RED, " TIME " }, [JOB_FAILED] = { ANSI_HIGHLIGHT_RED, "FAILED" }, [JOB_DEPENDENCY] = { ANSI_HIGHLIGHT_YELLOW, "DEPEND" }, From f7c5427c28bf180309eaf7b098957c1da4c31628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 2 Mar 2018 09:09:29 +0100 Subject: [PATCH 3/3] meson: use dashes in colour names --- meson.build | 2 +- meson_options.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 5aa46cd579..d9308c28bc 100644 --- a/meson.build +++ b/meson.build @@ -183,7 +183,7 @@ conf.set_quoted('SYSTEM_SYSVRCND_PATH', sysvrcnd_path) conf.set_quoted('RC_LOCAL_SCRIPT_PATH_START', get_option('rc-local')) conf.set_quoted('RC_LOCAL_SCRIPT_PATH_STOP', get_option('halt-local')) -conf.set('ANSI_OK_COLOR', 'ANSI_' + get_option('ok-color').to_upper()) +conf.set('ANSI_OK_COLOR', 'ANSI_' + get_option('ok-color').underscorify().to_upper()) conf.set_quoted('USER_CONFIG_UNIT_PATH', join_paths(pkgsysconfdir, 'user')) conf.set_quoted('USER_DATA_UNIT_PATH', userunitdir) diff --git a/meson_options.txt b/meson_options.txt index 59fb20b0a4..cdd7edd450 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -300,9 +300,9 @@ option('install-tests', type : 'boolean', value : 'false', option('ok-color', type: 'combo', choices : ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', - 'white', 'highlight_black', 'highlight_red', 'highlight_green', - 'highlight_yellow', 'highlight_blue', 'highlight_magenta', - 'highlight_cyan', 'highlight_white'], + 'white', 'highlight-black', 'highlight-red', 'highlight-green', + 'highlight-yellow', 'highlight-blue', 'highlight-magenta', + 'highlight-cyan', 'highlight-white'], value : 'green', description: 'color of the "OK" status message')