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

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

View file

@ -65,7 +65,7 @@ struct option_t option =
.timestamp = TIMESTAMP_NONE,
.socket = NULL,
.map = "",
.color = 15,
.color = 256, // Bold
.hex_mode = false,
.prefix_code = 20, // ctrl-t
.prefix_key = 't',
@ -95,7 +95,7 @@ void print_help(char *argv[])
printf(" --log-file <filename> Set log filename\n");
printf(" --log-strip Strip control characters and escape sequences\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(" -x, --hexadecimal Enable hexadecimal mode\n");
printf(" -v, --version Display version\n");
@ -333,7 +333,13 @@ void options_parse(int argc, char *argv[])
if (!strcmp(optarg, "none"))
{
option.color = -1;
option.color = -1; // No color
break;
}
if (!strcmp(optarg, "bold"))
{
option.color = 256; // Bold
break;
}

View file

@ -39,6 +39,14 @@ void print_normal(char c)
void print_init_ansi_formatting()
{
// Set bold text with user defined ANSI color
sprintf(ansi_format, "\e[1;38;5;%dm", option.color);
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
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...) \
{ \
if (option.color < 0) \
fprintf (stdout, "\r" format "\r\n", ## args); \
fprintf (stderr, "\r" format "\r\n", ## args); \
else \
fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
fflush(stderr); \