Commit 3641ddb0 authored by Jiří Klimeš's avatar Jiří Klimeš

cli: take color name arguments for "nmcli prompt-color" in editor (bgo #744936)

Adjust nmcli prompt-color description and make it more friendly for
translators.

nmcli> nmcli prompt-color green

https://bugzilla.gnome.org/show_bug.cgi?id=744936
parent 5eba53cd
......@@ -6861,10 +6861,15 @@ editor_main_help (const char *command)
case NMC_EDITOR_MAIN_CMD_NMCLI:
g_print (_("nmcli [<conf-option> <value>] :: nmcli configuration\n\n"
"Configures nmcli. The following options are available:\n"
"status-line yes | no [default: no]\n"
"save-confirmation yes | no [default: yes]\n"
"show-secrets yes | no [default: no]\n"
"prompt-color <0-8> [default: 0]\n"
"status-line yes | no [default: no]\n"
"save-confirmation yes | no [default: yes]\n"
"show-secrets yes | no [default: no]\n"
"prompt-color <color> | <0-8> [default: 0]\n"
"%s" /* color table description */
"\n"
"Examples: nmcli> nmcli status-line yes\n"
" nmcli> nmcli save-confirmation no\n"
" nmcli> nmcli prompt-color 3\n"),
" 0 = normal\n"
" 1 = \33[30mblack\33[0m\n"
" 2 = \33[31mred\33[0m\n"
......@@ -6873,11 +6878,7 @@ editor_main_help (const char *command)
" 5 = \33[34mblue\33[0m\n"
" 6 = \33[35mmagenta\33[0m\n"
" 7 = \33[36mcyan\33[0m\n"
" 8 = \33[37mwhite\33[0m\n"
"\n"
"Examples: nmcli> nmcli status-line yes\n"
" nmcli> nmcli save-confirmation no\n"
" nmcli> nmcli prompt-color 3\n"));
" 8 = \33[37mwhite\33[0m\n");
break;
case NMC_EDITOR_MAIN_CMD_QUIT:
g_print (_("quit :: exit nmcli\n\n"
......@@ -8330,12 +8331,13 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
} else
nmc->editor_show_secrets = bb;
} else if (cmd_arg_p && matches (cmd_arg_p, "prompt-color") == 0) {
unsigned long color;
if (!nmc_string_to_uint (cmd_arg_v ? g_strstrip (cmd_arg_v) : "X",
TRUE, 0, 8, &color))
g_print (_("Error: bad color number: '%s'; use <0-8>\n"),
cmd_arg_v ? cmd_arg_v : "");
else {
GError *tmp_err = NULL;
NmcTermColor color;
color = nmc_term_color_parse_string (cmd_arg_v ? g_strstrip (cmd_arg_v) : " ", &tmp_err);
if (tmp_err) {
g_print (_("Error: bad color: %s\n"), tmp_err->message);
g_clear_error (&tmp_err);
} else {
nmc->editor_prompt_color = color;
g_free (menu_ctx.main_prompt);
if (menu_ctx.level == 0)
......
......@@ -307,6 +307,29 @@ nmc_term_color_sequence (NmcTermColor color)
}
}
/* Parses @str for color as string or number */
NmcTermColor
nmc_term_color_parse_string (const char *str, GError **error)
{
unsigned long color_int;
static const char *colors[] = { "normal", "black", "red", "green", "yellow",
"blue", "magenta", "cyan", "white", NULL };
if (nmc_string_to_uint (str, TRUE, 0, 8, &color_int)) {
return (NmcTermColor) color_int;
} else {
const char *color, **p;
int i;
color = nmc_string_is_valid (str, colors, error);
for (p = colors, i = 0; *p != NULL; p++, i++) {
if (*p == color)
return (NmcTermColor) i;
}
return -1;
}
}
const char *
nmc_term_format_sequence (NmcTermFormat format)
{
......
......@@ -75,6 +75,7 @@ void nmc_terminal_erase_line (void);
void nmc_terminal_show_progress (const char *str);
const char *nmc_term_color_sequence (NmcTermColor color);
const char *nmc_term_format_sequence (NmcTermFormat format);
NmcTermColor nmc_term_color_parse_string (const char *str, GError **error);
char *nmc_colorize (NmcTermColor color, NmcTermFormat format, const char * fmt, ...);
void nmc_filter_out_colors_inplace (char *str);
char *nmc_filter_out_colors (const char *str);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment