mirror of
https://github.com/tio/tio.git
synced 2026-05-01 23:07:58 +02:00
Rework color option
Rework the color option to support setting ANSI color code values ranging from 0..255 or "none" for no color or "list" to print a list of available ANSI colors codes. Also, disables color when piping.
This commit is contained in:
parent
2519e2081a
commit
46b5783789
8 changed files with 67 additions and 32 deletions
|
|
@ -60,7 +60,7 @@ struct option_t option =
|
|||
.log_filename = NULL,
|
||||
.socket = NULL,
|
||||
.map = "",
|
||||
.color = -1,
|
||||
.color = 15,
|
||||
.hex_mode = false,
|
||||
};
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ void print_help(char *argv[])
|
|||
printf(" -l, --log Enable log to file\n");
|
||||
printf(" --log-filename <filename> Set log filename\n");
|
||||
printf(" -m, --map <flags> Map special characters\n");
|
||||
printf(" -c, --color <code> Colorize tio text\n");
|
||||
printf(" -c, --color 0..255|none|list Colorize tio text (default: 15)\n");
|
||||
printf(" -S, --socket <socket> Listen on socket\n");
|
||||
printf(" -x, --hex Enable hexadecimal mode\n");
|
||||
printf(" -v, --version Display version\n");
|
||||
|
|
@ -284,13 +284,7 @@ void options_parse(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'c':
|
||||
option.color = string_to_long(optarg);
|
||||
if (option.color > 255)
|
||||
{
|
||||
printf("Error: Invalid color code\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (option.color < 0)
|
||||
if (!strcmp(optarg, "list"))
|
||||
{
|
||||
// Print available color codes
|
||||
printf("Available color codes:\n");
|
||||
|
|
@ -300,6 +294,19 @@ void options_parse(int argc, char *argv[])
|
|||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (!strcmp(optarg, "none"))
|
||||
{
|
||||
option.color = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
option.color = string_to_long(optarg);
|
||||
if ((option.color < 0) || (option.color > 255))
|
||||
{
|
||||
printf("Error: Invalid color code\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue