Merge pull request #12535 from poettering/color-grey

redefine how we select the ANSI color grey
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-05-16 21:15:06 +02:00 committed by GitHub
commit e6042f682f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 25 deletions

View file

@ -11,35 +11,28 @@
#include "time-util.h"
/* 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"
#define ANSI_GREY "\x1B[0;2;37m"
#define ANSI_GREY "\x1B[0;38;5;245m"
/* 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"
#define ANSI_HIGHLIGHT_GREY "\x1B[0;1;38;5;245m"
/* 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"
#define ANSI_HIGHLIGHT_GREY_UNDERLINE "\x1B[0;1;4;38;5;245m"
/* Other ANSI codes */
#define ANSI_UNDERLINE "\x1B[0;4m"
@ -127,21 +120,29 @@ bool dev_console_colors_enabled(void);
colors_enabled() ? ANSI_##REPLACEMENT : ""; \
}
DEFINE_ANSI_FUNC(highlight, HIGHLIGHT);
DEFINE_ANSI_FUNC(highlight_red, HIGHLIGHT_RED);
DEFINE_ANSI_FUNC(highlight_green, HIGHLIGHT_GREEN);
DEFINE_ANSI_FUNC(highlight_yellow, HIGHLIGHT_YELLOW);
DEFINE_ANSI_FUNC(highlight_blue, HIGHLIGHT_BLUE);
DEFINE_ANSI_FUNC(highlight_magenta, HIGHLIGHT_MAGENTA);
DEFINE_ANSI_FUNC(normal, NORMAL);
DEFINE_ANSI_FUNC(grey, GREY);
DEFINE_ANSI_FUNC(normal, NORMAL);
DEFINE_ANSI_FUNC(highlight, HIGHLIGHT);
DEFINE_ANSI_FUNC(red, RED);
DEFINE_ANSI_FUNC(green, GREEN);
DEFINE_ANSI_FUNC(yellow, YELLOW);
DEFINE_ANSI_FUNC(blue, BLUE);
DEFINE_ANSI_FUNC(magenta, MAGENTA);
DEFINE_ANSI_FUNC(grey, GREY);
DEFINE_ANSI_FUNC(highlight_red, HIGHLIGHT_RED);
DEFINE_ANSI_FUNC(highlight_green, HIGHLIGHT_GREEN);
DEFINE_ANSI_FUNC(highlight_yellow, HIGHLIGHT_YELLOW);
DEFINE_ANSI_FUNC(highlight_blue, HIGHLIGHT_BLUE);
DEFINE_ANSI_FUNC(highlight_magenta, HIGHLIGHT_MAGENTA);
DEFINE_ANSI_FUNC(highlight_grey, HIGHLIGHT_GREY);
DEFINE_ANSI_FUNC_UNDERLINE(underline, UNDERLINE, NORMAL);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_underline, HIGHLIGHT_UNDERLINE, HIGHLIGHT);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_red_underline, HIGHLIGHT_RED_UNDERLINE, HIGHLIGHT_RED);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_green_underline, HIGHLIGHT_GREEN_UNDERLINE, HIGHLIGHT_GREEN);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_yellow_underline, HIGHLIGHT_YELLOW_UNDERLINE, HIGHLIGHT_YELLOW);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_blue_underline, HIGHLIGHT_BLUE_UNDERLINE, HIGHLIGHT_BLUE);
DEFINE_ANSI_FUNC_UNDERLINE(underline, UNDERLINE, NORMAL);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_underline, HIGHLIGHT_UNDERLINE, HIGHLIGHT);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_red_underline, HIGHLIGHT_RED_UNDERLINE, HIGHLIGHT_RED);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_green_underline, HIGHLIGHT_GREEN_UNDERLINE, HIGHLIGHT_GREEN);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_yellow_underline, HIGHLIGHT_YELLOW_UNDERLINE, HIGHLIGHT_YELLOW);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_blue_underline, HIGHLIGHT_BLUE_UNDERLINE, HIGHLIGHT_BLUE);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_magenta_underline, HIGHLIGHT_MAGENTA_UNDERLINE, HIGHLIGHT_MAGENTA);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_grey_underline, HIGHLIGHT_GREY_UNDERLINE, HIGHLIGHT_GREY);
int get_ctty_devnr(pid_t pid, dev_t *d);
int get_ctty(pid_t, dev_t *_devnr, char **r);

View file

@ -46,7 +46,7 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
for (i = 0; i < j; i++)
fputs("\xe2\x96\x88", stdout);
fputs(ANSI_NORMAL, stdout);
fputs(ansi_normal(), stdout);
for (i = 0; i < k; i++)
fputs("\xe2\x96\x91", stdout);

View file

@ -75,12 +75,45 @@ static void test_getttyname_malloc(void) {
assert_se(PATH_IN_SET(ttyname, "ptmx", "pts/ptmx"));
}
static void test_one_color(const char *name, const char *color) {
printf("<%s%s%s>\n", color, name, ansi_normal());
}
static void test_colors(void) {
log_info("/* %s */", __func__);
test_one_color("normal", ansi_normal());
test_one_color("highlight", ansi_highlight());
test_one_color("red", ansi_red());
test_one_color("green", ansi_green());
test_one_color("yellow", ansi_yellow());
test_one_color("blue", ansi_blue());
test_one_color("megenta", ansi_magenta());
test_one_color("grey", ansi_grey());
test_one_color("highlight-red", ansi_highlight_red());
test_one_color("highlight-green", ansi_highlight_green());
test_one_color("highlight-yellow", ansi_highlight_yellow());
test_one_color("highlight-blue", ansi_highlight_blue());
test_one_color("highlight-magenta", ansi_highlight_magenta());
test_one_color("highlight-grey", ansi_highlight_grey());
test_one_color("underline", ansi_underline());
test_one_color("highlight-underline", ansi_highlight_underline());
test_one_color("highlight-red-underline", ansi_highlight_red_underline());
test_one_color("highlight-green-underline", ansi_highlight_green_underline());
test_one_color("highlight-yellow-underline", ansi_highlight_yellow_underline());
test_one_color("highlight-blue-underline", ansi_highlight_blue_underline());
test_one_color("highlight-magenta-underline", ansi_highlight_magenta_underline());
test_one_color("highlight-grey-underline", ansi_highlight_grey_underline());
}
int main(int argc, char *argv[]) {
test_setup_logging(LOG_INFO);
test_default_term_for_tty();
test_read_one_char();
test_getttyname_malloc();
test_colors();
return 0;
}