1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 16:23:14 +02:00

Convert colors codes to %B, %C with /topic completion (if option irc_colors_send

is ON)
This commit is contained in:
Sebastien Helleu
2005-11-05 13:21:48 +00:00
parent bea5769a05
commit d94a7d05ea
6 changed files with 142 additions and 4 deletions
+4 -1
View File
@@ -647,7 +647,10 @@ completion_build_list (t_completion *completion, void *channel)
completion_stop (completion);
else
{
string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0);
if (cfg_irc_colors_send)
string = (char *)gui_color_decode_for_user_entry ((unsigned char *)((t_irc_channel *)channel)->topic);
else
string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0);
string2 = weechat_convert_encoding ((local_utf8) ?
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
+66 -1
View File
@@ -129,7 +129,7 @@ gui_get_color_name (int num_color)
* - remove any color/style in message
* or:
* - change colors by codes to be compatible with
* other IRC clients
* other IRC clients
* After use, string returned has to be free()
*/
@@ -272,6 +272,71 @@ gui_color_decode (unsigned char *string, int keep_colors)
return out;
}
/*
* gui_color_decode_for_user_entry: parses a message (coming from IRC server),
* and replaces colors/bold/.. by %C, %B, ..
* After use, string returned has to be free()
*/
unsigned char *
gui_color_decode_for_user_entry (unsigned char *string)
{
unsigned char *out;
int out_length, out_pos;
out_length = (strlen ((char *)string) * 2) + 1;
out = (unsigned char *)malloc (out_length);
if (!out)
return NULL;
out_pos = 0;
while (string[0] && (out_pos < out_length - 1))
{
switch (string[0])
{
case GUI_ATTR_BOLD_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'B';
string++;
break;
case GUI_ATTR_RESET_CHAR:
string++;
break;
case GUI_ATTR_FIXED_CHAR:
string++;
break;
case GUI_ATTR_REVERSE_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'R';
string++;
break;
case GUI_ATTR_REVERSE2_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'R';
string++;
break;
case GUI_ATTR_ITALIC_CHAR:
string++;
break;
case GUI_ATTR_UNDERLINE_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'R';
string++;
break;
case GUI_ATTR_COLOR_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'C';
string++;
break;
default:
out[out_pos++] = string[0];
string++;
}
}
out[out_pos] = '\0';
return out;
}
/*
* gui_color_encode: parses a message (entered by user), and
* encode special chars (%B, %C, ..) in IRC colors
+1
View File
@@ -458,6 +458,7 @@ extern void gui_key_free_all ();
extern int gui_assign_color (int *, char *);
extern char *gui_get_color_name (int);
extern unsigned char *gui_color_decode (unsigned char *, int);
extern unsigned char *gui_color_decode_for_user_entry (unsigned char *);
extern unsigned char *gui_color_encode (unsigned char *);
extern int gui_buffer_has_nicklist (t_gui_buffer *);
extern void gui_calculate_pos_size (t_gui_window *);
+4 -1
View File
@@ -647,7 +647,10 @@ completion_build_list (t_completion *completion, void *channel)
completion_stop (completion);
else
{
string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0);
if (cfg_irc_colors_send)
string = (char *)gui_color_decode_for_user_entry ((unsigned char *)((t_irc_channel *)channel)->topic);
else
string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0);
string2 = weechat_convert_encoding ((local_utf8) ?
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
+66 -1
View File
@@ -129,7 +129,7 @@ gui_get_color_name (int num_color)
* - remove any color/style in message
* or:
* - change colors by codes to be compatible with
* other IRC clients
* other IRC clients
* After use, string returned has to be free()
*/
@@ -272,6 +272,71 @@ gui_color_decode (unsigned char *string, int keep_colors)
return out;
}
/*
* gui_color_decode_for_user_entry: parses a message (coming from IRC server),
* and replaces colors/bold/.. by %C, %B, ..
* After use, string returned has to be free()
*/
unsigned char *
gui_color_decode_for_user_entry (unsigned char *string)
{
unsigned char *out;
int out_length, out_pos;
out_length = (strlen ((char *)string) * 2) + 1;
out = (unsigned char *)malloc (out_length);
if (!out)
return NULL;
out_pos = 0;
while (string[0] && (out_pos < out_length - 1))
{
switch (string[0])
{
case GUI_ATTR_BOLD_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'B';
string++;
break;
case GUI_ATTR_RESET_CHAR:
string++;
break;
case GUI_ATTR_FIXED_CHAR:
string++;
break;
case GUI_ATTR_REVERSE_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'R';
string++;
break;
case GUI_ATTR_REVERSE2_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'R';
string++;
break;
case GUI_ATTR_ITALIC_CHAR:
string++;
break;
case GUI_ATTR_UNDERLINE_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'R';
string++;
break;
case GUI_ATTR_COLOR_CHAR:
out[out_pos++] = '%';
out[out_pos++] = 'C';
string++;
break;
default:
out[out_pos++] = string[0];
string++;
}
}
out[out_pos] = '\0';
return out;
}
/*
* gui_color_encode: parses a message (entered by user), and
* encode special chars (%B, %C, ..) in IRC colors
+1
View File
@@ -458,6 +458,7 @@ extern void gui_key_free_all ();
extern int gui_assign_color (int *, char *);
extern char *gui_get_color_name (int);
extern unsigned char *gui_color_decode (unsigned char *, int);
extern unsigned char *gui_color_decode_for_user_entry (unsigned char *);
extern unsigned char *gui_color_encode (unsigned char *);
extern int gui_buffer_has_nicklist (t_gui_buffer *);
extern void gui_calculate_pos_size (t_gui_window *);