1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 10:13:12 +02:00

Added completion with possible values for /set, new possible values "++n" and "--n" for integers and colors

This commit is contained in:
Sebastien Helleu
2008-04-24 17:20:07 +02:00
parent 16e11ef25e
commit cf4f869174
6 changed files with 206 additions and 34 deletions
+10
View File
@@ -248,6 +248,16 @@ gui_color_assign (t_gui_color **color, char *fg_and_bg)
free (color_bg);
}*/
/*
* gui_color_get_number: get number of available colors
*/
int
gui_color_get_number ()
{
return GUI_CURSES_NUM_WEECHAT_COLORS;
}
/*
* gui_color_get_name: get color name
*/
+10
View File
@@ -100,6 +100,16 @@ gui_color_assign (int *color, char *color_name)
return 0;
}
/*
* gui_color_get_number: get number of available colors
*/
int
gui_color_get_number ()
{
return 0;
}
/*
* gui_color_get_name: get color name
*/
+39 -15
View File
@@ -376,6 +376,7 @@ gui_bar_config_check_size (void *data, struct t_config_option *option,
struct t_gui_bar *ptr_bar;
long number;
char *error;
int new_value;
/* make C compiler happy */
(void) data;
@@ -383,24 +384,47 @@ gui_bar_config_check_size (void *data, struct t_config_option *option,
ptr_bar = gui_bar_search_with_option_name (option->name);
if (ptr_bar)
{
error = NULL;
number = strtol (value, &error, 10);
if (error && !error[0])
new_value = -1;
if (strncmp (value, "++", 2) == 0)
{
if (number < 0)
return 0;
if ((number != 0) &&
((CONFIG_INTEGER(ptr_bar->size) == 0)
|| (number > CONFIG_INTEGER(ptr_bar->size))))
error = NULL;
number = strtol (value + 2, &error, 10);
if (error && !error[0])
{
if (!gui_bar_check_size_add (ptr_bar,
number - CONFIG_INTEGER(ptr_bar->size)))
return 0;
new_value = CONFIG_INTEGER(ptr_bar->size) + number;
}
return 1;
}
else if (strncmp (value, "--", 2) == 0)
{
error = NULL;
number = strtol (value + 2, &error, 10);
if (error && !error[0])
{
new_value = CONFIG_INTEGER(ptr_bar->size) - number;
}
}
else
{
error = NULL;
number = strtol (value, &error, 10);
if (error && !error[0])
{
new_value = number;
}
}
if (new_value < 0)
return 0;
if ((new_value > 0) &&
((CONFIG_INTEGER(ptr_bar->size) == 0)
|| (new_value > CONFIG_INTEGER(ptr_bar->size))))
{
if (!gui_bar_check_size_add (ptr_bar,
new_value - CONFIG_INTEGER(ptr_bar->size)))
return 0;
}
return 1;
}
return 0;
@@ -422,7 +446,7 @@ gui_bar_config_change_size (void *data, struct t_config_option *option)
if (ptr_bar)
{
gui_bar_window_set_current_size (ptr_bar,
CONFIG_INTEGER(ptr_bar->size_max));
CONFIG_INTEGER(ptr_bar->size));
gui_window_refresh_needed = 1;
}
}
+1
View File
@@ -154,6 +154,7 @@ extern void gui_color_free (struct t_gui_color *color);
extern int gui_color_search (char *color_name);
extern int gui_color_assign (int *color, char *color_name);
extern int gui_color_get_number ();
extern char *gui_color_get_name (int num_color);
extern void gui_color_init_pairs ();
extern void gui_color_rebuild_weechat ();
+48 -6
View File
@@ -637,7 +637,7 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion)
{
char *pos_space, *option_full_name, *color_name, *pos_section, *pos_option;
char *file, *section, *value_string;
int length;
int length, i, num_colors;
struct t_config_file *ptr_config;
struct t_config_section *ptr_section, *section_found;
struct t_config_option *option_found;
@@ -687,12 +687,18 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion)
switch (option_found->type)
{
case CONFIG_OPTION_TYPE_BOOLEAN:
gui_completion_list_add (completion, "on",
0, WEECHAT_LIST_POS_SORT);
gui_completion_list_add (completion, "off",
0, WEECHAT_LIST_POS_SORT);
gui_completion_list_add (completion, "toggle",
0, WEECHAT_LIST_POS_END);
if (CONFIG_BOOLEAN(option_found) == CONFIG_BOOLEAN_TRUE)
gui_completion_list_add (completion, "on",
0, WEECHAT_LIST_POS_SORT);
0, WEECHAT_LIST_POS_BEGINNING);
else
gui_completion_list_add (completion, "off",
0, WEECHAT_LIST_POS_SORT);
0, WEECHAT_LIST_POS_BEGINNING);
break;
case CONFIG_OPTION_TYPE_INTEGER:
length = 64;
@@ -700,19 +706,42 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion)
if (value_string)
{
if (option_found->string_values)
{
for (i = 0; option_found->string_values[i]; i++)
{
gui_completion_list_add (completion,
option_found->string_values[i],
0, WEECHAT_LIST_POS_SORT);
}
gui_completion_list_add (completion, "++1",
0, WEECHAT_LIST_POS_END);
gui_completion_list_add (completion, "--1",
0, WEECHAT_LIST_POS_END);
snprintf (value_string, length,
"%s",
option_found->string_values[CONFIG_INTEGER(option_found)]);
}
else
{
if (CONFIG_INTEGER(option_found) > option_found->min)
gui_completion_list_add (completion, "--1",
0, WEECHAT_LIST_POS_BEGINNING);
if (CONFIG_INTEGER(option_found) < option_found->max)
gui_completion_list_add (completion, "++1",
0, WEECHAT_LIST_POS_BEGINNING);
snprintf (value_string, length,
"%d", CONFIG_INTEGER(option_found));
}
gui_completion_list_add (completion,
value_string,
0, WEECHAT_LIST_POS_SORT);
0, WEECHAT_LIST_POS_BEGINNING);
free (value_string);
}
break;
case CONFIG_OPTION_TYPE_STRING:
gui_completion_list_add (completion,
"\"\"",
0, WEECHAT_LIST_POS_BEGINNING);
length = strlen (CONFIG_STRING(option_found)) + 2 + 1;
value_string = malloc (length);
if (value_string)
@@ -722,17 +751,30 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion)
CONFIG_STRING(option_found));
gui_completion_list_add (completion,
value_string,
0, WEECHAT_LIST_POS_SORT);
0, WEECHAT_LIST_POS_BEGINNING);
free (value_string);
}
break;
case CONFIG_OPTION_TYPE_COLOR:
num_colors = gui_color_get_number ();
for (i = 0; i < num_colors; i++)
{
color_name = gui_color_get_name (i);
if (color_name)
gui_completion_list_add (completion,
color_name,
0, WEECHAT_LIST_POS_SORT);
}
gui_completion_list_add (completion, "++1",
0, WEECHAT_LIST_POS_END);
gui_completion_list_add (completion, "--1",
0, WEECHAT_LIST_POS_END);
color_name = gui_color_get_name (CONFIG_INTEGER(option_found));
if (color_name)
{
gui_completion_list_add (completion,
color_name,
0, WEECHAT_LIST_POS_SORT);
0, WEECHAT_LIST_POS_BEGINNING);
}
break;
case CONFIG_NUM_OPTION_TYPES: