Introduce bold color option

Introduce "bold" color option which only apply bold color formatting to
existing system color.

Also make "bold" the default color option.

Fixes all white issue with black on white tio text.
This commit is contained in:
Martin Lund 2022-07-15 18:36:46 +02:00
parent 9db7bb4fbb
commit 9733bdf19c
6 changed files with 31 additions and 10 deletions

View file

@ -82,7 +82,7 @@ The command-line interface is straightforward as reflected in the output from
--log-file <filename> Set log filename --log-file <filename> Set log filename
--log-strip Strip control characters and escape sequences --log-strip Strip control characters and escape sequences
-m, --map <flags> Map characters -m, --map <flags> Map characters
-c, --color 0..255|none|list Colorize tio text (default: 15) -c, --color 0..255|bold|none|list Colorize tio text (default: bold)
-S, --socket <socket> Redirect I/O to file or network socket -S, --socket <socket> Redirect I/O to file or network socket
-x, --hexadecimal Enable hexadecimal mode -x, --hexadecimal Enable hexadecimal mode
-v, --version Display version -v, --version Display version

View file

@ -155,14 +155,15 @@ If defining more than one flag, the flags must be comma separated.
Enable hexadecimal mode. Enable hexadecimal mode.
.TP .TP
.BR \-c ", " "\-\-color " \fI0..255|none|list .BR \-c ", " "\-\-color " \fI0..255|bold|none|list
Colorize tio text using ANSI color code value ranging from 0 to 255 or use Colorize tio text using ANSI color code value ranging from 0 to 255 or use
"none" for no color. "none" for no color or use "bold" to apply bold formatting to existing system
color.
Use "list" to print a list of available ANSI color codes. Use "list" to print a list of available ANSI color codes.
Default value is 15. Default value is "bold".
.TP .TP
.BR \-S ", " "\-\-socket \fI<socket>\fR\fB .BR \-S ", " "\-\-socket \fI<socket>\fR\fB

View file

@ -226,6 +226,12 @@ static int data_handler(void *user, const char *section, const char *name,
return 0; return 0;
} }
if (!strcmp(value, "bold"))
{
option.color = 256; // Bold
return 0;
}
option.color = atoi(value); option.color = atoi(value);
if ((option.color < 0) || (option.color > 255)) if ((option.color < 0) || (option.color > 255))
{ {

View file

@ -65,7 +65,7 @@ struct option_t option =
.timestamp = TIMESTAMP_NONE, .timestamp = TIMESTAMP_NONE,
.socket = NULL, .socket = NULL,
.map = "", .map = "",
.color = 15, .color = 256, // Bold
.hex_mode = false, .hex_mode = false,
.prefix_code = 20, // ctrl-t .prefix_code = 20, // ctrl-t
.prefix_key = 't', .prefix_key = 't',
@ -95,7 +95,7 @@ void print_help(char *argv[])
printf(" --log-file <filename> Set log filename\n"); printf(" --log-file <filename> Set log filename\n");
printf(" --log-strip Strip control characters and escape sequences\n"); printf(" --log-strip Strip control characters and escape sequences\n");
printf(" -m, --map <flags> Map characters\n"); printf(" -m, --map <flags> Map characters\n");
printf(" -c, --color 0..255|none|list Colorize tio text (default: 15)\n"); printf(" -c, --color 0..255|bold|none|list Colorize tio text (default: bold)\n");
printf(" -S, --socket <socket> Redirect I/O to file or network socket\n"); printf(" -S, --socket <socket> Redirect I/O to file or network socket\n");
printf(" -x, --hexadecimal Enable hexadecimal mode\n"); printf(" -x, --hexadecimal Enable hexadecimal mode\n");
printf(" -v, --version Display version\n"); printf(" -v, --version Display version\n");
@ -333,7 +333,13 @@ void options_parse(int argc, char *argv[])
if (!strcmp(optarg, "none")) if (!strcmp(optarg, "none"))
{ {
option.color = -1; option.color = -1; // No color
break;
}
if (!strcmp(optarg, "bold"))
{
option.color = 256; // Bold
break; break;
} }

View file

@ -38,7 +38,15 @@ void print_normal(char c)
} }
void print_init_ansi_formatting() void print_init_ansi_formatting()
{
if (option.color == 256)
{
// Set bold text with no color changes
sprintf(ansi_format, "\e[1m");
}
else
{ {
// Set bold text with user defined ANSI color // Set bold text with user defined ANSI color
sprintf(ansi_format, "\e[1;38;5;%dm", option.color); sprintf(ansi_format, "\e[1;38;5;%dm", option.color);
} }
}

View file

@ -42,7 +42,7 @@ extern char ansi_format[];
#define ansi_error_printf(format, args...) \ #define ansi_error_printf(format, args...) \
{ \ { \
if (option.color < 0) \ if (option.color < 0) \
fprintf (stdout, "\r" format "\r\n", ## args); \ fprintf (stderr, "\r" format "\r\n", ## args); \
else \ else \
fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \ fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
fflush(stderr); \ fflush(stderr); \