From 6447969d0ac774b6dec0f95a0d3d27c27d158690 Mon Sep 17 00:00:00 2001 From: Andrei Pikas Date: Sat, 5 Oct 2024 22:27:44 +0300 Subject: 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. --- gdb/python/py-param.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'gdb/python/py-param.c') diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c index 9741782..0e79d21 100644 --- a/gdb/python/py-param.c +++ b/gdb/python/py-param.c @@ -26,6 +26,7 @@ #include "completer.h" #include "language.h" #include "arch-utils.h" +#include "py-color.h" /* Python parameter types as in PARM_CONSTANTS below. */ @@ -43,6 +44,7 @@ enum py_param_types param_zuinteger, param_zuinteger_unlimited, param_enum, + param_color, }; /* Translation from Python parameters to GDB variable types. Keep in the @@ -69,7 +71,8 @@ param_to_var[] = { var_integer }, { var_uinteger }, { var_pinteger, pinteger_unlimited_literals }, - { var_enum } + { var_enum }, + { var_color } }; /* Parameter constants and their values. */ @@ -90,6 +93,7 @@ static struct { { "PARAM_ZUINTEGER", param_zuinteger }, { "PARAM_ZUINTEGER_UNLIMITED", param_zuinteger_unlimited }, { "PARAM_ENUM", param_enum }, + { "PARAM_COLOR", param_color }, { NULL, 0 } }; @@ -114,6 +118,9 @@ union parmpy_variable /* Hold a string, for enums. */ const char *cstringval; + + /* Hold a color. */ + ui_file_style::color color; }; /* A GDB parameter. */ @@ -157,6 +164,8 @@ make_setting (parmpy_object *s) return setting (type, s->value.stringval); else if (var_type_uses (type)) return setting (type, &s->value.cstringval); + else if (var_type_uses (s->type)) + return setting (s->type, &s->value.color); else gdb_assert_not_reached ("unhandled var type"); } @@ -248,6 +257,19 @@ set_parameter_value (parmpy_object *self, PyObject *value) break; } + case var_color: + { + if (gdbpy_is_color (value)) + self->value.color = gdbpy_get_color (value); + else + { + PyErr_SetString (PyExc_RuntimeError, + _("color argument must be a gdb.Color object.")); + return -1; + } + } + break; + case var_boolean: if (! PyBool_Check (value)) { @@ -707,6 +729,15 @@ add_setshow_generic (enum var_types type, const literal_def *extra_literals, get_show_value, set_list, show_list); break; + case var_color: + /* Initialize the value, just in case. */ + self->value.color = ui_file_style::NONE; + commands = add_setshow_color_cmd (cmd_name.get (), cmdclass, + &self->value.color, set_doc, + show_doc, help_doc, get_set_value, + get_show_value, set_list, show_list); + break; + default: gdb_assert_not_reached ("Unhandled parameter class."); } @@ -830,7 +861,8 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds) && parmclass != param_string && parmclass != param_string_noescape && parmclass != param_optional_filename && parmclass != param_filename && parmclass != param_zinteger && parmclass != param_zuinteger - && parmclass != param_zuinteger_unlimited && parmclass != param_enum) + && parmclass != param_zuinteger_unlimited && parmclass != param_enum + && parmclass != param_color) { PyErr_SetString (PyExc_RuntimeError, _("Invalid parameter class argument.")); @@ -854,7 +886,7 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds) extra_literals = param_to_var[parmclass].extra_literals; obj->type = type; obj->extra_literals = extra_literals; - memset (&obj->value, 0, sizeof (obj->value)); + obj->value = {}; /* zeros initialization */ if (var_type_uses (obj->type)) obj->value.stringval = new std::string; @@ -900,6 +932,8 @@ parmpy_dealloc (PyObject *obj) if (var_type_uses (parm_obj->type)) delete parm_obj->value.stringval; + else if (var_type_uses (parm_obj->type)) + parm_obj->value.color.~color(); } /* Initialize the 'parameters' module. */ -- cgit v1.1