mirror of https://github.com/wb2osz/direwolf.git
Add text color options with black background.
This commit is contained in:
parent
ab834f338b
commit
2157d2a7f9
|
@ -89,7 +89,13 @@
|
||||||
|
|
||||||
#if __WIN32__
|
#if __WIN32__
|
||||||
|
|
||||||
|
// For Windows platform:
|
||||||
|
// -t 0 disables color
|
||||||
|
// -t 1 enables with white background (default)
|
||||||
|
// -t 2 enables with black background
|
||||||
|
|
||||||
#define BACKGROUND_WHITE (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY)
|
#define BACKGROUND_WHITE (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY)
|
||||||
|
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
|
||||||
|
|
||||||
#else /* Linux, BSD, Mac OSX */
|
#else /* Linux, BSD, Mac OSX */
|
||||||
|
|
||||||
|
@ -133,18 +139,28 @@
|
||||||
// In recent tests, background is always gray, not white like it should be.
|
// In recent tests, background is always gray, not white like it should be.
|
||||||
|
|
||||||
|
|
||||||
#define MAX_T 4
|
// Alternative 5:
|
||||||
|
|
||||||
static const char *t_background_white[MAX_T+1] = { "", "\e[48;2;255;255;255m", "\e[48;2;255;255;255m", "\e[5;47m", "\e[1;47m" };
|
// This uses the 8-color foreground colors like alternative 2, but with a reset background color.
|
||||||
|
// For people that prefer dark backgrounds or use terminals with color theming.
|
||||||
|
|
||||||
static const char *t_black[MAX_T+1] = { "", "\e[38;2;0;0;0m", "\e[0;30m" "\e[48;2;255;255;255m", "\e[0;30m" "\e[5;47m", "\e[0;30m" "\e[1;47m" };
|
|
||||||
static const char *t_red[MAX_T+1] = { "", "\e[38;2;255;0;0m", "\e[1;31m" "\e[48;2;255;255;255m", "\e[1;31m" "\e[5;47m", "\e[1;31m" "\e[1;47m" };
|
// Alternative 6:
|
||||||
static const char *t_green[MAX_T+1] = { "", "\e[38;2;0;255;0m", "\e[1;32m" "\e[48;2;255;255;255m", "\e[1;32m" "\e[5;47m", "\e[1;32m" "\e[1;47m" };
|
|
||||||
static const char *t_dark_green[MAX_T+1]= { "", "\e[38;2;0;192;0m", "\e[0;32m" "\e[48;2;255;255;255m", "\e[0;32m" "\e[5;47m", "\e[0;32m" "\e[1;47m" };
|
// This uses the RGB color setting like alternative 1, but with a black background.
|
||||||
static const char *t_yellow[MAX_T+1] = { "", "\e[38;2;255;255;0m", "\e[1;33m" "\e[48;2;255;255;255m", "\e[1;33m" "\e[5;47m", "\e[1;33m" "\e[1;47m" };
|
|
||||||
static const char *t_blue[MAX_T+1] = { "", "\e[38;2;0;0;255m", "\e[1;34m" "\e[48;2;255;255;255m", "\e[1;34m" "\e[5;47m", "\e[1;34m" "\e[1;47m" };
|
#define MAX_T 6
|
||||||
static const char *t_magenta[MAX_T+1] = { "", "\e[38;2;255;0;255m", "\e[1;35m" "\e[48;2;255;255;255m", "\e[1;35m" "\e[5;47m", "\e[1;35m" "\e[1;47m" };
|
|
||||||
static const char *t_cyan[MAX_T+1] = { "", "\e[38;2;0;255;255m", "\e[0;36m" "\e[48;2;255;255;255m", "\e[0;36m" "\e[5;47m", "\e[0;36m" "\e[1;47m" };
|
static const char *t_background_white[MAX_T+1] = { "", "\e[48;2;255;255;255m", "\e[48;2;255;255;255m", "\e[5;47m", "\e[1;47m", "\e[0;49m" , "\e[48;2;0;0;0m" };
|
||||||
|
|
||||||
|
static const char *t_black[MAX_T+1] = { "", "\e[38;2;0;0;0m", "\e[0;30m" "\e[48;2;255;255;255m", "\e[0;30m" "\e[5;47m", "\e[0;30m" "\e[1;47m", "\e[0;49m" "\e[0;39m", "\e[38;2;255;255;255m" };
|
||||||
|
static const char *t_red[MAX_T+1] = { "", "\e[38;2;255;0;0m", "\e[1;31m" "\e[48;2;255;255;255m", "\e[1;31m" "\e[5;47m", "\e[1;31m" "\e[1;47m", "\e[0;49m" "\e[1;31m", "\e[38;2;255;0;0m"};
|
||||||
|
static const char *t_green[MAX_T+1] = { "", "\e[38;2;0;255;0m", "\e[1;32m" "\e[48;2;255;255;255m", "\e[1;32m" "\e[5;47m", "\e[1;32m" "\e[1;47m", "\e[0;49m" "\e[1;32m", "\e[38;2;0;255;0m"};
|
||||||
|
static const char *t_dark_green[MAX_T+1]= { "", "\e[38;2;0;192;0m", "\e[0;32m" "\e[48;2;255;255;255m", "\e[0;32m" "\e[5;47m", "\e[0;32m" "\e[1;47m", "\e[0;49m" "\e[0;32m", "\e[38;2;0;192;0m"};
|
||||||
|
static const char *t_yellow[MAX_T+1] = { "", "\e[38;2;255;255;0m", "\e[1;33m" "\e[48;2;255;255;255m", "\e[1;33m" "\e[5;47m", "\e[1;33m" "\e[1;47m", "\e[0;49m" "\e[1;33m", "\e[38;2;255;255;0m"};
|
||||||
|
static const char *t_blue[MAX_T+1] = { "", "\e[38;2;0;0;255m", "\e[1;34m" "\e[48;2;255;255;255m", "\e[1;34m" "\e[5;47m", "\e[1;34m" "\e[1;47m", "\e[0;49m" "\e[1;34m", "\e[38;2;0;0;255m"};
|
||||||
|
static const char *t_magenta[MAX_T+1] = { "", "\e[38;2;255;0;255m", "\e[1;35m" "\e[48;2;255;255;255m", "\e[1;35m" "\e[5;47m", "\e[1;35m" "\e[1;47m", "\e[0;49m" "\e[1;35m", "\e[38;2;255;0;255m"};
|
||||||
|
static const char *t_cyan[MAX_T+1] = { "", "\e[38;2;0;255;255m", "\e[0;36m" "\e[48;2;255;255;255m", "\e[0;36m" "\e[5;47m", "\e[0;36m" "\e[1;47m", "\e[0;49m" "\e[0;36m", "\e[38;2;0;255;255m"};
|
||||||
|
|
||||||
|
|
||||||
/* Clear from cursor to end of screen. */
|
/* Clear from cursor to end of screen. */
|
||||||
|
@ -179,6 +195,7 @@ void text_color_init (int enable_color)
|
||||||
|
|
||||||
#if __WIN32__
|
#if __WIN32__
|
||||||
|
|
||||||
|
g_enable_color = enable_color;
|
||||||
|
|
||||||
if (g_enable_color != 0) {
|
if (g_enable_color != 0) {
|
||||||
|
|
||||||
|
@ -189,6 +206,10 @@ void text_color_init (int enable_color)
|
||||||
COORD coord;
|
COORD coord;
|
||||||
DWORD nwritten;
|
DWORD nwritten;
|
||||||
|
|
||||||
|
if (g_enable_color > 1) {
|
||||||
|
attr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
h = GetStdHandle(STD_OUTPUT_HANDLE);
|
h = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
if (h != NULL && h != INVALID_HANDLE_VALUE) {
|
if (h != NULL && h != INVALID_HANDLE_VALUE) {
|
||||||
|
|
||||||
|
@ -210,7 +231,7 @@ void text_color_init (int enable_color)
|
||||||
for (t = 0; t <= MAX_T; t++) {
|
for (t = 0; t <= MAX_T; t++) {
|
||||||
text_color_init (t);
|
text_color_init (t);
|
||||||
printf ("-t %d", t);
|
printf ("-t %d", t);
|
||||||
if (t) printf (" [white background] ");
|
if (t < 5) printf (" [white background] ");
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
printf ("%sBlack ", t_black[t]);
|
printf ("%sBlack ", t_black[t]);
|
||||||
printf ("%sRed ", t_red[t]);
|
printf ("%sRed ", t_red[t]);
|
||||||
|
@ -254,34 +275,41 @@ void text_color_set ( enum dw_color_e c )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WORD info_fg = 0;
|
||||||
|
WORD background = BACKGROUND_WHITE;
|
||||||
|
if (g_enable_color > 1) {
|
||||||
|
info_fg = FOREGROUND_WHITE;
|
||||||
|
background = 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
case DW_COLOR_INFO:
|
case DW_COLOR_INFO:
|
||||||
attr = BACKGROUND_WHITE;
|
attr = info_fg | background;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DW_COLOR_ERROR:
|
case DW_COLOR_ERROR:
|
||||||
attr = FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
|
attr = FOREGROUND_RED | FOREGROUND_INTENSITY | background;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DW_COLOR_REC:
|
case DW_COLOR_REC:
|
||||||
// Release 1.6. Dark green, same as for debug.
|
// Release 1.6. Dark green, same as for debug.
|
||||||
// Bright green is too hard to see with white background,
|
// Bright green is too hard to see with white background,
|
||||||
// attr = FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
|
// attr = FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
|
||||||
attr = FOREGROUND_GREEN | BACKGROUND_WHITE;
|
attr = FOREGROUND_GREEN | background;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DW_COLOR_DECODED:
|
case DW_COLOR_DECODED:
|
||||||
attr = FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
|
attr = FOREGROUND_BLUE | FOREGROUND_INTENSITY | background;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DW_COLOR_XMIT:
|
case DW_COLOR_XMIT:
|
||||||
attr = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
|
attr = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY | background;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DW_COLOR_DEBUG:
|
case DW_COLOR_DEBUG:
|
||||||
attr = FOREGROUND_GREEN | BACKGROUND_WHITE;
|
attr = FOREGROUND_GREEN | background;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue