Skip to content

Black background text options #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add text color options with black background.
  • Loading branch information
ars-ka0s committed Sep 25, 2023
commit 2157d2a7f99e5fce7438a3c804e1c4c119746717
62 changes: 45 additions & 17 deletions src/textcolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@

#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 FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)

#else /* Linux, BSD, Mac OSX */

Expand Down Expand Up @@ -133,18 +139,28 @@
// In recent tests, background is always gray, not white like it should be.


#define MAX_T 4
// Alternative 5:

// 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.


// Alternative 6:

// This uses the RGB color setting like alternative 1, but with a black background.

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" };
#define MAX_T 6

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" };
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" };
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" };
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. */
Expand Down Expand Up @@ -179,6 +195,7 @@ void text_color_init (int enable_color)

#if __WIN32__

g_enable_color = enable_color;

if (g_enable_color != 0) {

Expand All @@ -189,6 +206,10 @@ void text_color_init (int enable_color)
COORD coord;
DWORD nwritten;

if (g_enable_color > 1) {
attr = 0;
}

h = GetStdHandle(STD_OUTPUT_HANDLE);
if (h != NULL && h != INVALID_HANDLE_VALUE) {

Expand All @@ -210,7 +231,7 @@ void text_color_init (int enable_color)
for (t = 0; t <= MAX_T; t++) {
text_color_init (t);
printf ("-t %d", t);
if (t) printf (" [white background] ");
if (t < 5) printf (" [white background] ");
printf ("\n");
printf ("%sBlack ", t_black[t]);
printf ("%sRed ", t_red[t]);
Expand Down Expand Up @@ -254,34 +275,41 @@ void text_color_set ( enum dw_color_e c )
return;
}

WORD info_fg = 0;
WORD background = BACKGROUND_WHITE;
if (g_enable_color > 1) {
info_fg = FOREGROUND_WHITE;
background = 0;
}

switch (c) {

default:
case DW_COLOR_INFO:
attr = BACKGROUND_WHITE;
attr = info_fg | background;
break;

case DW_COLOR_ERROR:
attr = FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
attr = FOREGROUND_RED | FOREGROUND_INTENSITY | background;
break;

case DW_COLOR_REC:
// Release 1.6. Dark green, same as for debug.
// Bright green is too hard to see with white background,
// attr = FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
attr = FOREGROUND_GREEN | BACKGROUND_WHITE;
attr = FOREGROUND_GREEN | background;
break;

case DW_COLOR_DECODED:
attr = FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
attr = FOREGROUND_BLUE | FOREGROUND_INTENSITY | background;
break;

case DW_COLOR_XMIT:
attr = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_WHITE;
attr = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY | background;
break;

case DW_COLOR_DEBUG:
attr = FOREGROUND_GREEN | BACKGROUND_WHITE;
attr = FOREGROUND_GREEN | background;
break;
}

Expand Down