mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 17:53:13 +02:00
Add new IRC modifiers: irc_color_decode/irc_color_encode, add IRC color support in xfer DCC chat (bug #25974)
This commit is contained in:
@@ -356,3 +356,31 @@ irc_color_encode (const char *string, int keep_colors)
|
||||
|
||||
return (char *)out;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_color_modifier_cb: callback for modifiers "irc_color_decode" and
|
||||
* "irc_color_encode"
|
||||
* This modifier can be used by other plugins to
|
||||
* decode/encode IRC colors in messages
|
||||
*/
|
||||
|
||||
char *
|
||||
irc_color_modifier_cb (void *data, const char *modifier,
|
||||
const char *modifier_data, const char *string)
|
||||
{
|
||||
int keep_colors;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
keep_colors = (modifier_data && (strcmp (modifier_data, "1") == 0)) ? 1 : 0;
|
||||
|
||||
if (strcmp (modifier, "irc_color_decode") == 0)
|
||||
return irc_color_decode (string, keep_colors);
|
||||
|
||||
if (strcmp (modifier, "irc_color_encode") == 0)
|
||||
return irc_color_decode (string, keep_colors);
|
||||
|
||||
/* unknown modifier */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -56,5 +56,8 @@
|
||||
extern char *irc_color_decode (const char *string, int keep_colors);
|
||||
extern char *irc_color_decode_for_user_entry (const char *string);
|
||||
extern char *irc_color_encode (const char *string, int keep_colors);
|
||||
extern char *irc_color_modifier_cb (void *data, const char *modifier,
|
||||
const char *modifier_data,
|
||||
const char *string);
|
||||
|
||||
#endif /* irc-color.h */
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "irc.h"
|
||||
#include "irc-bar-item.h"
|
||||
#include "irc-buffer.h"
|
||||
#include "irc-color.h"
|
||||
#include "irc-command.h"
|
||||
#include "irc-completion.h"
|
||||
#include "irc-config.h"
|
||||
@@ -165,6 +166,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
weechat_hook_signal ("xfer_resume_ready", &irc_server_xfer_resume_ready_cb, NULL);
|
||||
weechat_hook_signal ("xfer_send_accept_resume", &irc_server_xfer_send_accept_resume_cb, NULL);
|
||||
|
||||
/* modifiers */
|
||||
weechat_hook_modifier ("irc_color_decode", &irc_color_modifier_cb, NULL);
|
||||
weechat_hook_modifier ("irc_color_encode", &irc_color_modifier_cb, NULL);
|
||||
|
||||
/* hook completions */
|
||||
irc_completion_init ();
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ xfer_chat_recv_cb (void *arg_xfer, int fd)
|
||||
struct t_xfer *xfer;
|
||||
static char buffer[4096 + 2];
|
||||
char *buf2, *pos, *ptr_buf, *next_ptr_buf;
|
||||
char *ptr_buf_without_weechat_colors, *ptr_buf_color;
|
||||
int num_read;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -136,8 +137,19 @@ xfer_chat_recv_cb (void *arg_xfer, int fd)
|
||||
|
||||
if (ptr_buf)
|
||||
{
|
||||
ptr_buf_without_weechat_colors = weechat_string_remove_color (ptr_buf, "?");
|
||||
ptr_buf_color = weechat_hook_modifier_exec ("irc_color_decode",
|
||||
"1",
|
||||
(ptr_buf_without_weechat_colors) ?
|
||||
ptr_buf_without_weechat_colors : ptr_buf);
|
||||
weechat_printf_tags (xfer->buffer, "notify_message", "%s\t%s",
|
||||
xfer->remote_nick, ptr_buf);
|
||||
xfer->remote_nick,
|
||||
(ptr_buf_color) ?
|
||||
ptr_buf_color : ((ptr_buf_without_weechat_colors) ? ptr_buf_without_weechat_colors : ptr_buf));
|
||||
if (ptr_buf_without_weechat_colors)
|
||||
free (ptr_buf_without_weechat_colors);
|
||||
if (ptr_buf_color)
|
||||
free (ptr_buf_color);
|
||||
}
|
||||
|
||||
ptr_buf = next_ptr_buf;
|
||||
@@ -165,6 +177,7 @@ xfer_chat_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
|
||||
const char *input_data)
|
||||
{
|
||||
struct t_xfer *ptr_xfer;
|
||||
char *input_data_color;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -185,10 +198,15 @@ xfer_chat_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
|
||||
xfer_chat_sendf (ptr_xfer, "%s\n", input_data);
|
||||
if (!XFER_HAS_ENDED(ptr_xfer->status))
|
||||
{
|
||||
input_data_color = weechat_hook_modifier_exec ("irc_color_decode",
|
||||
"1",
|
||||
input_data);
|
||||
weechat_printf (buffer,
|
||||
"%s\t%s",
|
||||
ptr_xfer->local_nick,
|
||||
input_data);
|
||||
(input_data_color) ? input_data_color : input_data);
|
||||
if (input_data_color)
|
||||
free (input_data_color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user