Skip to content
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

Black background text options #441

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
>
> Add: "FX25TX 1" (or 16 or 32 or 64)

- Two additional color modes added to the -t command line option. 5 uses default background color and basic color commands. This should obey most terminal emulator color themes. 6 uses the RGB color mode and is stark black background. -t 2 on Windows implements a dark background mode as well.



### Bugs Fixed: ###
Expand Down
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