basic/terminal-util: define all foreground colors
We would add and remove definitions based on which colors were used by other code. Let's just define all of them to simplify tests and allow easy comparisons which colors look good.
This commit is contained in:
parent
82ff544160
commit
66bb00590f
|
@ -11,19 +11,36 @@
|
|||
#include "time-util.h"
|
||||
|
||||
/* Regular colors */
|
||||
#define ANSI_BLACK "\x1B[0;30m" /* Some type of grey usually. */
|
||||
#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" /* This is actually rendered as light grey, legible even on a white
|
||||
* background. See ANSI_HIGHLIGHT_WHITE for real white. */
|
||||
|
||||
#define ANSI_BRIGHT_BLACK "\x1B[0;90m"
|
||||
#define ANSI_BRIGHT_RED "\x1B[0;91m"
|
||||
#define ANSI_BRIGHT_GREEN "\x1B[0;92m"
|
||||
#define ANSI_BRIGHT_YELLOW "\x1B[0;93m"
|
||||
#define ANSI_BRIGHT_BLUE "\x1B[0;94m"
|
||||
#define ANSI_BRIGHT_MAGENTA "\x1B[0;95m"
|
||||
#define ANSI_BRIGHT_CYAN "\x1B[0;96m"
|
||||
#define ANSI_BRIGHT_WHITE "\x1B[0;97m"
|
||||
|
||||
#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;38;5;185m"
|
||||
#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"
|
||||
#define ANSI_HIGHLIGHT_YELLOW4 "\x1B[0;1;38;5;100m"
|
||||
|
||||
|
@ -124,18 +141,34 @@ bool dev_console_colors_enabled(void);
|
|||
|
||||
DEFINE_ANSI_FUNC(normal, NORMAL);
|
||||
DEFINE_ANSI_FUNC(highlight, HIGHLIGHT);
|
||||
DEFINE_ANSI_FUNC(black, BLACK);
|
||||
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(cyan, CYAN);
|
||||
DEFINE_ANSI_FUNC(white, WHITE);
|
||||
DEFINE_ANSI_FUNC(grey, GREY);
|
||||
|
||||
DEFINE_ANSI_FUNC(bright_black, BRIGHT_BLACK);
|
||||
DEFINE_ANSI_FUNC(bright_red, BRIGHT_RED);
|
||||
DEFINE_ANSI_FUNC(bright_green, BRIGHT_GREEN);
|
||||
DEFINE_ANSI_FUNC(bright_yellow, BRIGHT_YELLOW);
|
||||
DEFINE_ANSI_FUNC(bright_blue, BRIGHT_BLUE);
|
||||
DEFINE_ANSI_FUNC(bright_magenta, BRIGHT_MAGENTA);
|
||||
DEFINE_ANSI_FUNC(bright_cyan, BRIGHT_CYAN);
|
||||
DEFINE_ANSI_FUNC(bright_white, BRIGHT_WHITE);
|
||||
|
||||
DEFINE_ANSI_FUNC(highlight_black, HIGHLIGHT_BLACK);
|
||||
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_cyan, HIGHLIGHT_CYAN);
|
||||
DEFINE_ANSI_FUNC(highlight_grey, HIGHLIGHT_GREY);
|
||||
DEFINE_ANSI_FUNC(highlight_white, HIGHLIGHT_WHITE);
|
||||
|
||||
DEFINE_ANSI_FUNC_UNDERLINE(underline, UNDERLINE, NORMAL);
|
||||
DEFINE_ANSI_FUNC_UNDERLINE(highlight_underline, HIGHLIGHT_UNDERLINE, HIGHLIGHT);
|
||||
|
|
|
@ -75,36 +75,58 @@ 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());
|
||||
}
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char* (*func)(void);
|
||||
} Color;
|
||||
|
||||
static const Color colors[] = {
|
||||
{ "normal", ansi_normal },
|
||||
{ "highlight", ansi_highlight },
|
||||
{ "black", ansi_black },
|
||||
{ "red", ansi_red },
|
||||
{ "green", ansi_green },
|
||||
{ "yellow", ansi_yellow },
|
||||
{ "blue", ansi_blue },
|
||||
{ "magenta", ansi_magenta },
|
||||
{ "cyan", ansi_cyan },
|
||||
{ "white", ansi_white },
|
||||
{ "grey", ansi_grey },
|
||||
|
||||
{ "bright-black", ansi_bright_black },
|
||||
{ "bright-red", ansi_bright_red },
|
||||
{ "bright-green", ansi_bright_green },
|
||||
{ "bright-yellow", ansi_bright_yellow },
|
||||
{ "bright-blue", ansi_bright_blue },
|
||||
{ "bright-magenta", ansi_bright_magenta },
|
||||
{ "bright-cyan", ansi_bright_cyan },
|
||||
{ "bright-white", ansi_bright_white },
|
||||
|
||||
{ "highlight-black", ansi_highlight_black },
|
||||
{ "highlight-red", ansi_highlight_red },
|
||||
{ "highlight-green", ansi_highlight_green },
|
||||
{ "highlight-yellow", ansi_highlight_yellow },
|
||||
{ "highlight-blue", ansi_highlight_blue },
|
||||
{ "highlight-magenta", ansi_highlight_magenta },
|
||||
{ "highlight-cyan", ansi_highlight_cyan },
|
||||
{ "highlight-white", ansi_highlight_white },
|
||||
{ "highlight-grey", ansi_highlight_grey },
|
||||
|
||||
{ "underline", ansi_underline },
|
||||
{ "highlight-underline", ansi_highlight_underline },
|
||||
{ "highlight-red-underline", ansi_highlight_red_underline },
|
||||
{ "highlight-green-underline", ansi_highlight_green_underline },
|
||||
{ "highlight-yellow-underline", ansi_highlight_yellow_underline },
|
||||
{ "highlight-blue-underline", ansi_highlight_blue_underline },
|
||||
{ "highlight-magenta-underline", ansi_highlight_magenta_underline },
|
||||
{ "highlight-grey-underline", ansi_highlight_grey_underline },
|
||||
};
|
||||
|
||||
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("magenta", 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());
|
||||
for (size_t i = 0; i < ELEMENTSOF(colors); i++)
|
||||
printf("<%s%s%s>\n", colors[i].func(), colors[i].name, ansi_normal());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
|
Loading…
Reference in a new issue