diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-12-20 10:13:37 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-12-20 10:13:37 +0100 |
commit | cd7a02bec5ce87e8e1aa26b9fffc3caa0cda8ae8 (patch) | |
tree | 3b662ba9fec186745e48b24b4663555320f93575 /src/core | |
parent | e80d6b93a557446a42bf5eb5826798be12c046f0 (diff) | |
download | weechat-cd7a02bec5ce87e8e1aa26b9fffc3caa0cda8ae8.zip |
Add 256 colors support
Changes:
- new section "palette" in weechat.conf
- new API functions: list_search_pos and list_casesearch_pos
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-completion.c | 25 | ||||
-rw-r--r-- | src/core/wee-config-file.c | 18 | ||||
-rw-r--r-- | src/core/wee-config.c | 145 | ||||
-rw-r--r-- | src/core/wee-config.h | 1 | ||||
-rw-r--r-- | src/core/wee-list.c | 51 | ||||
-rw-r--r-- | src/core/wee-list.h | 2 |
6 files changed, 228 insertions, 14 deletions
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c index cd4bbf576..eb2749472 100644 --- a/src/core/wee-completion.c +++ b/src/core/wee-completion.c @@ -37,6 +37,7 @@ #include "weechat.h" #include "wee-config.h" +#include "wee-hashtable.h" #include "wee-hook.h" #include "wee-list.h" #include "wee-proxy.h" @@ -706,6 +707,24 @@ completion_list_add_plugins_commands_cb (void *data, } /* + * completion_list_add_color_alias_cb: add color alias in completion + */ + +void +completion_list_add_color_alias_cb (void *data, + struct t_hashtable *hashtable, + const void *key, const void *value) +{ + /* make C compiler happy */ + (void) hashtable; + (void) value; + + gui_completion_list_add ((struct t_gui_completion *)data, + (char *)key, + 0, WEECHAT_LIST_POS_SORT); +} + +/* * completion_list_add_config_option_values_cb: add option value to completion * list */ @@ -888,6 +907,12 @@ completion_list_add_config_option_values_cb (void *data, color_name, 0, WEECHAT_LIST_POS_SORT); } + if (gui_color_hash_palette_alias) + { + hashtable_map (gui_color_hash_palette_alias, + &completion_list_add_color_alias_cb, + completion); + } gui_completion_list_add (completion, "++1", 0, WEECHAT_LIST_POS_END); gui_completion_list_add (completion, "--1", diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 2d4a08079..651a1752a 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -1260,12 +1260,9 @@ config_file_option_set (struct t_config_option *option, const char *value, number = strtol (value + 2, &error, 10); if (error && !error[0]) { - number = number % (num_colors + 1); - value_int = (old_value + number) % - (num_colors + 1); - if (value_int > num_colors - 1) - value_int -= num_colors; - if (value_int <= num_colors - 1) + if (gui_color_assign_by_diff (&value_int, + gui_color_get_name (old_value), + number)) new_value_ok = 1; } } @@ -1275,12 +1272,9 @@ config_file_option_set (struct t_config_option *option, const char *value, number = strtol (value + 2, &error, 10); if (error && !error[0]) { - number = number % (num_colors + 1); - value_int = (old_value + num_colors - number) % - num_colors; - if (value_int < 0) - value_int += num_colors; - if (value_int >= 0) + if (gui_color_assign_by_diff (&value_int, + gui_color_get_name (old_value), + -1 * number)) new_value_ok = 1; } } diff --git a/src/core/wee-config.c b/src/core/wee-config.c index e101fbd04..719cf21dd 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -61,6 +61,7 @@ struct t_config_file *weechat_config_file = NULL; struct t_config_section *weechat_config_section_debug = NULL; +struct t_config_section *weechat_config_section_color = NULL; struct t_config_section *weechat_config_section_proxy = NULL; struct t_config_section *weechat_config_section_bar = NULL; struct t_config_section *weechat_config_section_notify = NULL; @@ -661,6 +662,130 @@ config_weechat_debug_set (const char *plugin_name, const char *value) } /* + * config_weechat_palette_change_cb: called when a palette option is changed + */ + +void +config_weechat_palette_change_cb (void *data, + struct t_config_option *option) +{ + char *error; + int number; + + /* make C compiler happy */ + (void) data; + (void) option; + + error = NULL; + number = (int)strtol (option->name, &error, 10); + if (error && !error[0]) + { + gui_color_palette_change (number, CONFIG_STRING(option)); + } +} + +/* + * config_weechat_palette_create_option_cb: create option in "palette" section + */ + +int +config_weechat_palette_create_option_cb (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, + const char *value) +{ + struct t_config_option *ptr_option; + char *error; + int rc, number; + + /* make C compiler happy */ + (void) data; + + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; + + error = NULL; + number = (int)strtol (option_name, &error, 10); + if (error && !error[0]) + { + if (option_name) + { + ptr_option = config_file_search_option (config_file, section, + option_name); + if (ptr_option) + { + if (value) + rc = config_file_option_set (ptr_option, value, 1); + else + { + config_file_option_free (ptr_option); + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + } + else + { + if (value) + { + ptr_option = config_file_new_option ( + config_file, section, + option_name, "string", + _("custom color in palette, format is: \"alias;fg,bg;r/g/b\" " + "where alias is color name, fg,bg is \"foreground,background\" " + "(example: \"200,-1\"), r/g/b is redefinition of color " + "(terminal must support it) (everything is optional " + "in this format)"), + NULL, 0, 0, "", value, 0, NULL, NULL, + &config_weechat_palette_change_cb, NULL, + NULL, NULL); + rc = (ptr_option) ? + WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; + if (ptr_option) + gui_color_palette_add (number, value); + } + else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + } + } + else + { + gui_chat_printf (NULL, + _("%sError: palette option must be numeric"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); + } + + return rc; +} + +/* + * config_weechat_palette_delete_option_cb: delete option in "palette" section + */ + +int +config_weechat_palette_delete_option_cb (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + char *error; + int number; + + /* make C compiler happy */ + (void) data; + (void) config_file; + (void) section; + + error = NULL; + number = (int)strtol (option->name, &error, 10); + if (error && !error[0]) + gui_color_palette_remove (number); + + config_file_option_free (option); + + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; +} + +/* * config_weechat_proxy_read_cb: read proxy option in config file */ @@ -1606,6 +1731,19 @@ config_weechat_init_options () "messages"), NULL, 0, 0, "%a, %d %b %Y %T", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); + /* palette */ + ptr_section = config_file_new_section (weechat_config_file, "palette", + 1, 1, + NULL, NULL, NULL, NULL, + NULL, NULL, + &config_weechat_palette_create_option_cb, NULL, + &config_weechat_palette_delete_option_cb, NULL); + if (!ptr_section) + { + config_file_free (weechat_config_file); + return 0; + } + /* colors */ ptr_section = config_file_new_section (weechat_config_file, "color", 0, 0, @@ -1617,6 +1755,8 @@ config_weechat_init_options () return 0; } + weechat_config_section_color = ptr_section; + /* general color settings */ config_color_separator = config_file_new_option ( weechat_config_file, ptr_section, @@ -2232,9 +2372,9 @@ config_weechat_init () _("FATAL: error initializing configuration options")); } - /* create timer to check if day has changed */ if (!config_day_change_timer) { + /* create timer to check if day has changed */ gettimeofday (&tv_time, NULL); local_time = localtime (&tv_time.tv_sec); config_day_change_old_day = local_time->tm_mday; @@ -2244,8 +2384,9 @@ config_weechat_init () 0, &config_day_change_timer_cb, NULL); - config_change_highlight_regex (NULL, NULL); } + if (!config_highlight_regex) + config_change_highlight_regex (NULL, NULL); return rc; } diff --git a/src/core/wee-config.h b/src/core/wee-config.h index ed7d45dde..659f0910f 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -94,6 +94,7 @@ enum t_config_look_save_layout_on_exit }; extern struct t_config_file *weechat_config_file; +extern struct t_config_section *weechat_config_section_color; extern struct t_config_section *weechat_config_section_proxy; extern struct t_config_section *weechat_config_section_bar; extern struct t_config_section *weechat_config_section_notify; diff --git a/src/core/wee-list.c b/src/core/wee-list.c index 599b93a4e..411f71616 100644 --- a/src/core/wee-list.c +++ b/src/core/wee-list.c @@ -183,6 +183,32 @@ weelist_search (struct t_weelist *weelist, const char *data) } /* + * weelist_search_pos: search data in a list (case sensitive), return position + * of item found, -1 if not found + */ + +int +weelist_search_pos (struct t_weelist *weelist, const char *data) +{ + struct t_weelist_item *ptr_item; + int i; + + if (!weelist || !data) + return -1; + + i = 0; + for (ptr_item = weelist->items; ptr_item; + ptr_item = ptr_item->next_item) + { + if (strcmp (data, ptr_item->data) == 0) + return i; + i++; + } + /* data not found in list */ + return -1; +} + +/* * weelist_casesearch: search data in a list (case unsensitive) */ @@ -205,6 +231,31 @@ weelist_casesearch (struct t_weelist *weelist, const char *data) } /* + * weelist_casesearch_pos: search data in a list (case unsensitive), return + * position of item found, -1 if not found + */ + +int +weelist_casesearch_pos (struct t_weelist *weelist, const char *data) +{ + struct t_weelist_item *ptr_item; + int i; + + if (!weelist || !data) + return -1; + + for (ptr_item = weelist->items; ptr_item; + ptr_item = ptr_item->next_item) + { + if (string_strcasecmp (data, ptr_item->data) == 0) + return i; + i++; + } + /* data not found in list */ + return -1; +} + +/* * weelist_get: get an item in a list by position (0 is first element) */ diff --git a/src/core/wee-list.h b/src/core/wee-list.h index 7b8f60328..a2efff0fc 100644 --- a/src/core/wee-list.h +++ b/src/core/wee-list.h @@ -41,8 +41,10 @@ extern struct t_weelist_item *weelist_add (struct t_weelist *weelist, void *user_data); extern struct t_weelist_item *weelist_search (struct t_weelist *weelist, const char *data); +extern int weelist_search_pos (struct t_weelist *weelist, const char *data); extern struct t_weelist_item *weelist_casesearch (struct t_weelist *weelist, const char *data); +extern int weelist_casesearch_pos (struct t_weelist *weelist, const char *data); extern struct t_weelist_item *weelist_get (struct t_weelist *weelist, int position); extern void weelist_set (struct t_weelist_item *item, const char *value); |