Skip to content

Commit

Permalink
Add a standard parser option for color formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Bansal <[email protected]>
  • Loading branch information
NishantBansal2003 committed Nov 2, 2024
1 parent d75e81a commit 4fa1857
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
5 changes: 3 additions & 2 deletions include/grass/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@ typedef enum {
G_OPT_F_OUTPUT, /*!< new output file */
G_OPT_F_SEP, /*!< data field separator */

G_OPT_C, /*!< color */
G_OPT_CN, /*!< color or none */
G_OPT_C, /*!< color */
G_OPT_CN, /*!< color or none */
G_OPT_C_FORMAT, /*!< set color format to rgb,hex,hsv or xterm */

G_OPT_M_UNITS, /*!< units */
G_OPT_M_DATATYPE, /*!< datatype */
Expand Down
15 changes: 15 additions & 0 deletions lib/gis/parser_standard_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,21 @@ struct Option *G_define_standard_option(int opt)
Opt->description =
_("Either a standard color name, R:G:B triplet, or \"none\"");
break;
case G_OPT_C_FORMAT:
Opt->key = "color_format";
Opt->type = TYPE_STRING;
Opt->key_desc = "name";
Opt->required = YES;
Opt->multiple = NO;
Opt->answer = "xterm";
Opt->options = "rgb,hex,hsv,xterm";
Opt->label = _("Color format");
Opt->description = _("Color format for output values.");
G_asprintf(
(char **)&(Opt->descriptions), "rgb;%s;hex;%s;hsv;%s;xterm;%s",
_("output color in RGB format"), _("output color in HEX format"),
_("output color in HSV format"), _("output color in XTERM format"));
break;

/* misc */

Expand Down
18 changes: 1 addition & 17 deletions raster/r.colors.out/raster3d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,7 @@ int main(int argc, char **argv)
opt.format = G_define_standard_option(G_OPT_F_FORMAT);
opt.format->guisection = _("Print");

opt.color_format = G_define_option();
opt.color_format->key = "color_format";
opt.color_format->type = TYPE_STRING;
opt.color_format->key_desc = "name";
opt.color_format->required = YES;
opt.color_format->multiple = NO;
opt.color_format->answer = "xterm";
opt.color_format->options = "rgb,hex,hsv,xterm";
opt.color_format->label = _("Color format");
opt.color_format->description =
_("Color format output for raster3d values.");
char *desc = NULL;
G_asprintf(&desc, "rgb;%s;hex;%s;hsv;%s;xterm;%s",
_("output color in RGB format"), _("output color in HEX format"),
_("output color in HSV format"),
_("output color in XTERM format"));
opt.color_format->descriptions = desc;
opt.color_format = G_define_standard_option(G_OPT_C_FORMAT);
opt.color_format->guisection = _("Color");

flag.p = G_define_flag();
Expand Down
17 changes: 1 addition & 16 deletions raster/r.colors.out/raster_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,7 @@ int main(int argc, char **argv)
opt.format = G_define_standard_option(G_OPT_F_FORMAT);
opt.format->guisection = _("Print");

opt.color_format = G_define_option();
opt.color_format->key = "color_format";
opt.color_format->type = TYPE_STRING;
opt.color_format->key_desc = "name";
opt.color_format->required = YES;
opt.color_format->multiple = NO;
opt.color_format->answer = "xterm";
opt.color_format->options = "rgb,hex,hsv,xterm";
opt.color_format->label = _("Color format");
opt.color_format->description = _("Color format output for raster values.");
char *desc = NULL;
G_asprintf(&desc, "rgb;%s;hex;%s;hsv;%s;xterm;%s",
_("output color in RGB format"), _("output color in HEX format"),
_("output color in HSV format"),
_("output color in XTERM format"));
opt.color_format->descriptions = desc;
opt.color_format = G_define_standard_option(G_OPT_C_FORMAT);
opt.color_format->guisection = _("Color");

flag.p = G_define_flag();
Expand Down

0 comments on commit 4fa1857

Please sign in to comment.