1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 21:36:37 +02:00

Add 256 colors support

Changes:
- new section "palette" in weechat.conf
- new API functions: list_search_pos and list_casesearch_pos
This commit is contained in:
Sebastien Helleu
2010-12-20 10:13:37 +01:00
parent e80d6b93a5
commit cd7a02bec5
35 changed files with 1650 additions and 139 deletions
+25
View File
@@ -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"
@@ -705,6 +706,24 @@ completion_list_add_plugins_commands_cb (void *data,
return WEECHAT_RC_OK;
}
/*
* 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",
+6 -12
View File
@@ -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;
}
}
+143 -2
View File
@@ -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;
@@ -660,6 +661,130 @@ config_weechat_debug_set (const char *plugin_name, const char *value)
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;
}
+1
View File
@@ -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;
+51
View File
@@ -182,6 +182,32 @@ weelist_search (struct t_weelist *weelist, const char *data)
return NULL;
}
/*
* 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)
*/
@@ -204,6 +230,31 @@ weelist_casesearch (struct t_weelist *weelist, const char *data)
return NULL;
}
/*
* 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)
*/
+2
View File
@@ -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);