aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-option.c
diff options
context:
space:
mode:
authorAndrei Pikas <gdb@mail.api.win>2024-10-05 22:27:44 +0300
committerTom Tromey <tom@tromey.com>2025-01-12 13:30:43 -0700
commit6447969d0ac774b6dec0f95a0d3d27c27d158690 (patch)
treee9812cfdd956f4c8e89f596b276ddc1c4ad8da45 /gdb/cli/cli-option.c
parent338e0b05d8f2dd404eb0015bee31461dfe5ba307 (diff)
downloadbinutils-6447969d0ac774b6dec0f95a0d3d27c27d158690.zip
binutils-6447969d0ac774b6dec0f95a0d3d27c27d158690.tar.gz
binutils-6447969d0ac774b6dec0f95a0d3d27c27d158690.tar.bz2
Add an option with a color type.
Colors can be specified as "none" for terminal's default color, as a name of one of the eight standard colors of ISO/IEC 6429 "black", "red", "green", etc., as an RGB hexadecimal tripplet #RRGGBB for 24-bit TrueColor, or as an integer from 0 to 255. Integers 0 to 7 are the synonyms for the standard colors. Integers 8-15 are used for the so-called bright colors from the aixterm extended 16-color palette. Integers 16-255 are the indexes into xterm extended 256-color palette (usually 6x6x6 cube plus gray ramp). In general, 256-color palette is terminal dependent and sometimes can be changed with OSC 4 sequences, e.g. "\033]4;1;rgb:00/FF/00\033\\". It is the responsibility of the user to verify that the terminal supports the specified colors. PATCH v5 changes: documentation fixed. PATCH v6 changes: documentation fixed. PATCH v7 changes: rebase onto master and fixes after review. PATCH v8 changes: fixes after review.
Diffstat (limited to 'gdb/cli/cli-option.c')
-rw-r--r--gdb/cli/cli-option.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/gdb/cli/cli-option.c b/gdb/cli/cli-option.c
index fa00b91..10a5944 100644
--- a/gdb/cli/cli-option.c
+++ b/gdb/cli/cli-option.c
@@ -45,6 +45,9 @@ union option_value
/* For var_string and var_filename options. This is allocated with new. */
std::string *string;
+
+ /* For var_color options. */
+ ui_file_style::color color = ui_file_style::NONE;
};
/* Holds an options definition and its value. */
@@ -433,6 +436,35 @@ parse_option (gdb::array_view<const option_def_group> options_group,
val.enumeration = parse_cli_var_enum (args, match->enums);
return option_def_and_value {*match, match_ctx, val};
}
+ case var_color:
+ {
+ if (completion != nullptr)
+ {
+ const char *after_arg = skip_to_space (*args);
+ if (*after_arg == '\0')
+ {
+ complete_on_color (completion->tracker, *args, *args);
+
+ if (completion->tracker.have_completions ())
+ return {};
+ }
+ }
+
+ if (check_for_argument (args, "--"))
+ {
+ /* Treat e.g., "backtrace -entry-values --" as if there
+ was no argument after "-entry-values". This makes
+ parse_cli_var_color throw an error with a suggestion of
+ what are the valid options. */
+ args = nullptr;
+ }
+
+ option_value val;
+ ui_file_style::color color = parse_cli_var_color (args);
+ ui_file_style::color approx_color = color.approximate (colorsupport ());
+ val.color = approx_color;
+ return option_def_and_value {*match, match_ctx, val};
+ }
case var_string:
{
if (check_for_argument (args, "--"))
@@ -683,6 +715,10 @@ save_option_value_in_ctx (std::optional<option_def_and_value> &ov)
*ov->option.var_address.enumeration (ov->option, ov->ctx)
= ov->value->enumeration;
break;
+ case var_color:
+ *ov->option.var_address.color (ov->option, ov->ctx)
+ = ov->value->color;
+ break;
case var_string:
case var_filename:
*ov->option.var_address.string (ov->option, ov->ctx)
@@ -789,6 +825,12 @@ append_val_type_str (std::string &help, const option_def &opt,
}
}
break;
+ case var_color:
+ help += ' ';
+ for (size_t i = 0; ui_file_style::basic_color_enums[i]; ++i)
+ help.append (ui_file_style::basic_color_enums[i]).append ("|");
+ help += "NUMBER|#RRGGBB";
+ break;
case var_string:
help += "STRING";
break;