Add hook type "command_run", add new function "string_remove_color" in plugin API (task #9089)

v2.8-utf8proc
Sebastien Helleu 2009-02-08 19:52:16 +01:00
parent a253398165
commit 29bc0276bc
25 changed files with 1153 additions and 205 deletions

View File

@ -5153,6 +5153,99 @@ struct t_hook *my_command_hook =
</para>
</section>
<section id="secPluginCApi_weechat_hook_command_run">
<title>weechat_hook_command_run</title>
<para>
Prototype:
<programlisting>
struct t_hook *weechat_hook_command_run (
const char *command,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
const char *command),
void *callback_data);
</programlisting>
</para>
<para>
Hook a command when WeeChat runs it.
</para>
<para>
Arguments:
<itemizedlist>
<listitem>
<para>
<option>command</option>: command to hook, may start or end with
"*" as joker
</para>
</listitem>
<listitem>
<para>
<option>callback</option>: function called when command is run,
arguments:
<informaltable colsep="0" frame="none">
<tgroup cols="2">
<thead>
<row>
<entry>Type</entry>
<entry>Name</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>void *</entry>
<entry>data</entry>
<entry>pointer</entry>
</row>
<row>
<entry>struct t_gui_buffer *</entry>
<entry>buffer</entry>
<entry>buffer where command is executed</entry>
</row>
<row>
<entry>const char *</entry>
<entry>command</entry>
<entry>the command executed, with its arguments</entry>
</row>
</tbody>
</tgroup>
The callback can return WEECHAT_RC_OK or WEECHAT_RC_OK_EAT (ok
and "eat" command, will not be executed by WeeChat after
callback).
</informaltable>
</para>
</listitem>
<listitem>
<para>
<option>callback_data</option>: pointer given to callback when it
is called by WeeeChat
</para>
</listitem>
</itemizedlist>
</para>
<para>
Return value: pointer to new hook, NULL if error occured.
</para>
<para>
Example:
<screen>
int
my_command_run_cb (void *data, struct t_gui_buffer *buffer,
const char *command)
{
weechat_printf (NULL,
"You wanted to complete? I'm eating the completion ahah!");
return WEECHAT_RC_OK_EAT;
}
struct t_hook *my_command_run_hook =
weechat_hook_command_run ("/input complete*",
&amp;my_command_run_cb, NULL);
</screen>
</para>
</section>
<section id="secPluginCApi_weechat_hook_timer">
<title>weechat_hook_timer</title>
@ -6869,6 +6962,10 @@ const char *weechat_buffer_get_string (struct t_gui_buffer *buffer, const char *
<entry>tilte</entry>
<entry>title of buffer</entry>
</row>
<row>
<entry>input</entry>
<entry>input text</entry>
</row>
<row>
<entry>localvar_xxx</entry>
<entry>

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-01-30 14:55+0100\n"
"POT-Creation-Date: 2009-02-04 18:41+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -436,6 +436,10 @@ msgstr " napsal \"%s\", licence: %s"
msgid " commands hooked:"
msgstr " napojené příkazy:"
#, fuzzy
msgid " command_run hooked:"
msgstr " napojené příkazy:"
msgid " timers hooked:"
msgstr " napojené časovače:"

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-01-30 14:55+0100\n"
"POT-Creation-Date: 2009-02-04 18:41+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Thomas Schuetz <i18n@internet-villa.de>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -477,6 +477,10 @@ msgstr ""
msgid " commands hooked:"
msgstr " Befehls-Handler:\n"
#, fuzzy
msgid " command_run hooked:"
msgstr " Befehls-Handler:\n"
#, fuzzy
msgid " timers hooked:"
msgstr " Timer-Handler:\n"

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-01-30 14:55+0100\n"
"POT-Creation-Date: 2009-02-04 18:41+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Roberto González Cardenete <robert.glez@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -472,6 +472,10 @@ msgstr ""
msgid " commands hooked:"
msgstr " manejadores de comando:\n"
#, fuzzy
msgid " command_run hooked:"
msgstr " manejadores de comando:\n"
#, fuzzy
msgid " timers hooked:"
msgstr " manejadores de temporización:\n"

View File

@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-01-30 14:55+0100\n"
"PO-Revision-Date: 2009-01-30 14:56+0100\n"
"POT-Creation-Date: 2009-02-04 18:41+0100\n"
"PO-Revision-Date: 2009-02-04 18:41+0100\n"
"Last-Translator: FlashCode <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"MIME-Version: 1.0\n"
@ -440,6 +440,9 @@ msgstr " écrit par \"%s\", licence: %s"
msgid " commands hooked:"
msgstr " commandes accrochées:"
msgid " command_run hooked:"
msgstr " command_run accrochés:"
msgid " timers hooked:"
msgstr " gestionnaires de temps accrochés:"
@ -957,9 +960,12 @@ msgstr ""
" add: ajoute un filtre\n"
" del: supprime un filtre\n"
" -all: supprime tous les filtres\n"
"extension.tampon: extension et tampon où le filtre est actif (\"*\" pour tous les tampons)\n"
" tags: liste de tags, séparés par des virgules, par exemple: \"irc_join,irc_part,irc_quit\"\n"
" regex: expressoin régulière à rechercher dans la ligne (utiliser \\t pour séparer le préfixe du message)\n"
"extension.tampon: extension et tampon où le filtre est actif (\"*\" pour "
"tous les tampons)\n"
" tags: liste de tags, séparés par des virgules, par exemple: "
"\"irc_join,irc_part,irc_quit\"\n"
" regex: expressoin régulière à rechercher dans la ligne (utiliser "
"\\t pour séparer le préfixe du message)\n"
"\n"
"Exemples:\n"
" utiliser le filtre intelligent IRC pour les messages join/part/quit:\n"

View File

@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-01-30 14:55+0100\n"
"POT-Creation-Date: 2009-02-04 18:41+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -478,6 +478,10 @@ msgstr ""
msgid " commands hooked:"
msgstr " parancskezelők:\n"
#, fuzzy
msgid " command_run hooked:"
msgstr " parancskezelők:\n"
#, fuzzy
msgid " timers hooked:"
msgstr " időkezelők:\n"

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-01-30 14:55+0100\n"
"POT-Creation-Date: 2009-02-04 18:41+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Pavel Shevchuk <stlwrt@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -473,6 +473,10 @@ msgstr ""
msgid " commands hooked:"
msgstr " обработчики команд:\n"
#, fuzzy
msgid " command_run hooked:"
msgstr " обработчики команд:\n"
#, fuzzy
msgid " timers hooked:"
msgstr " обработчики таймера:\n"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-01-30 14:55+0100\n"
"POT-Creation-Date: 2009-02-04 18:41+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -415,6 +415,9 @@ msgstr ""
msgid " commands hooked:"
msgstr ""
msgid " command_run hooked:"
msgstr ""
msgid " timers hooked:"
msgstr ""

View File

@ -2090,6 +2090,21 @@ command_plugin_list (const char *name, int full)
}
}
/* command_run hooked */
hook_found = 0;
for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND_RUN]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
if (!ptr_hook->deleted && (ptr_hook->plugin == ptr_plugin))
{
if (!hook_found)
gui_chat_printf (NULL, _(" command_run hooked:"));
hook_found = 1;
gui_chat_printf (NULL, " %s",
HOOK_COMMAND_RUN(ptr_hook, command));
}
}
/* timers hooked */
hook_found = 0;
for (ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; ptr_hook;

View File

@ -47,8 +47,8 @@
char *hook_type_string[HOOK_NUM_TYPES] =
{ "command", "timer", "fd", "connect", "print", "signal", "config",
"completion", "modifier", "info", "infolist" };
{ "command", "command_run", "timer", "fd", "connect", "print", "signal",
"config", "completion", "modifier", "info", "infolist" };
struct t_hook *weechat_hooks[HOOK_NUM_TYPES]; /* list of hooks */
struct t_hook *last_weechat_hook[HOOK_NUM_TYPES]; /* last hook */
int hook_exec_recursion = 0; /* 1 when a hook is executed */
@ -328,7 +328,7 @@ hook_command (struct t_weechat_plugin *plugin, const char *command,
const char *completion,
t_hook_callback_command *callback, void *callback_data)
{
struct t_hook *ptr_hook,*new_hook;
struct t_hook *ptr_hook, *new_hook;
struct t_hook_command *new_hook_command;
if ((string_strcasecmp (command, "builtin") == 0)
@ -399,11 +399,15 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
char **argv, **argv_eol;
int argc, rc, command_is_running;
rc = -1;
if (!buffer || !string || !string[0])
return -1;
rc = hook_command_run_exec (buffer, string);
if (rc == WEECHAT_RC_OK_EAT)
return 1;
rc = -1;
argv = string_explode (string, " ", 0, 0, &argc);
if (argc == 0)
{
@ -493,6 +497,74 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
return rc;
}
/*
* hook_command_run: hook a command when it's run by WeeChat
*/
struct t_hook *
hook_command_run (struct t_weechat_plugin *plugin, const char *command,
t_hook_callback_command_run *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_command_run *new_hook_command_run;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_command_run = malloc (sizeof (*new_hook_command_run));
if (!new_hook_command_run)
{
free (new_hook);
return NULL;
}
hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND_RUN, callback_data);
new_hook->hook_data = new_hook_command_run;
new_hook_command_run->callback = callback;
new_hook_command_run->command = (command) ?
strdup (command) : strdup ("");
hook_add_to_list (new_hook);
return new_hook;
}
/*
* hook_command_run_exec: execute command_run hook
*/
int
hook_command_run_exec (struct t_gui_buffer *buffer, const char *command)
{
struct t_hook *ptr_hook, *next_hook;
int rc;
ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND_RUN];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& HOOK_COMMAND_RUN(ptr_hook, command)
&& (string_match (command, HOOK_COMMAND_RUN(ptr_hook, command), 0)))
{
ptr_hook->running = 1;
rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) (ptr_hook->callback_data,
buffer,
command);
ptr_hook->running = 0;
if (rc == WEECHAT_RC_OK_EAT)
return rc;
}
ptr_hook = next_hook;
}
return WEECHAT_RC_OK;
}
/*
* hook_timer_init: init a timer hook
*/
@ -1630,6 +1702,11 @@ unhook (struct t_hook *hook)
free (HOOK_COMMAND(hook, completion));
free ((struct t_hook_command *)hook->hook_data);
break;
case HOOK_TYPE_COMMAND_RUN:
if (HOOK_COMMAND_RUN(hook, command))
free (HOOK_COMMAND_RUN(hook, command));
free ((struct t_hook_command *)hook->hook_data);
break;
case HOOK_TYPE_TIMER:
free ((struct t_hook_timer *)hook->hook_data);
break;
@ -1834,6 +1911,15 @@ hook_add_to_infolist_type (struct t_infolist *infolist,
return 0;
}
break;
case HOOK_TYPE_COMMAND_RUN:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND_RUN(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND_RUN(ptr_hook, command)))
return 0;
}
break;
case HOOK_TYPE_TIMER:
if (!ptr_hook->deleted)
{
@ -2058,6 +2144,14 @@ hook_print_log ()
log_printf (" completion . . . . . : '%s'", HOOK_COMMAND(ptr_hook, completion));
}
break;
case HOOK_TYPE_COMMAND_RUN:
if (!ptr_hook->deleted)
{
log_printf (" command_run data:");
log_printf (" callback . . . . . . : 0x%lx", HOOK_COMMAND_RUN(ptr_hook, callback));
log_printf (" command. . . . . . . : '%s'", HOOK_COMMAND_RUN(ptr_hook, command));
}
break;
case HOOK_TYPE_TIMER:
if (!ptr_hook->deleted)
{

View File

@ -35,6 +35,7 @@ struct t_infolist;
enum t_hook_type
{
HOOK_TYPE_COMMAND = 0, /* new command */
HOOK_TYPE_COMMAND_RUN, /* when a command is executed */
HOOK_TYPE_TIMER, /* timer */
HOOK_TYPE_FD, /* socket of file descriptor */
HOOK_TYPE_CONNECT, /* connect to peer with fork */
@ -59,6 +60,7 @@ enum t_hook_type
/* macros to access hook specific data */
#define HOOK_COMMAND(hook, var) (((struct t_hook_command *)hook->hook_data)->var)
#define HOOK_COMMAND_RUN(hook, var) (((struct t_hook_command_run *)hook->hook_data)->var)
#define HOOK_TIMER(hook, var) (((struct t_hook_timer *)hook->hook_data)->var)
#define HOOK_FD(hook, var) (((struct t_hook_fd *)hook->hook_data)->var)
#define HOOK_CONNECT(hook, var) (((struct t_hook_connect *)hook->hook_data)->var)
@ -101,6 +103,16 @@ struct t_hook_command
char *completion; /* template for completion */
};
typedef int (t_hook_callback_command_run)(void *data,
struct t_gui_buffer *buffer,
const char *command);
struct t_hook_command_run
{
t_hook_callback_command_run *callback; /* command_run callback */
char *command; /* name of command (without '/') */
};
typedef int (t_hook_callback_timer)(void *data);
struct t_hook_timer
@ -232,13 +244,22 @@ extern struct t_hook *last_weechat_hook[];
extern void hook_init ();
extern struct t_hook *hook_command (struct t_weechat_plugin *plugin,
const char *command, const char *description,
const char *args, const char *args_description,
const char *command,
const char *description,
const char *args,
const char *args_description,
const char *completion,
t_hook_callback_command *callback,
void *callback_data);
extern int hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
struct t_weechat_plugin *plugin, const char *string);
struct t_weechat_plugin *plugin,
const char *string);
extern struct t_hook *hook_command_run (struct t_weechat_plugin *plugin,
const char *command,
t_hook_callback_command_run *callback,
void *callback_data);
extern int hook_command_run_exec (struct t_gui_buffer *buffer,
const char *command);
extern struct t_hook *hook_timer (struct t_weechat_plugin *plugin,
long interval, int align_second,
int max_calls,
@ -276,7 +297,8 @@ extern struct t_hook *hook_signal (struct t_weechat_plugin *plugin,
void *callback_data);
extern void hook_signal_send (const char *signal, const char *type_data,
void *signal_data);
extern struct t_hook *hook_config (struct t_weechat_plugin *, const char *option,
extern struct t_hook *hook_config (struct t_weechat_plugin *plugin,
const char *option,
t_hook_callback_config *callback,
void *callback_data);
extern void hook_config_exec (const char *option, const char *value);

View File

@ -51,6 +51,7 @@
#include "weechat.h"
#include "wee-string.h"
#include "wee-utf8.h"
#include "../gui/gui-color.h"
/*
@ -1280,3 +1281,13 @@ string_format_size (unsigned long size)
return strdup (str_size);
}
/*
* string_remove_color: remove WeeChat color codes in string
*/
char *
string_remove_color (const char *string)
{
return (char *)gui_color_decode ((unsigned char *)string);
}

View File

@ -56,5 +56,6 @@ extern char *string_iconv_from_internal (const char *charset,
const char *string);
extern void string_iconv_fprintf (FILE *file, const char *data, ...);
extern char *string_format_size (unsigned long size);
extern char *string_remove_color (const char *string);
#endif /* wee-string.h */

View File

@ -170,161 +170,168 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
while (string && string[0])
{
if (string[0] == GUI_COLOR_COLOR_CHAR)
switch (string[0])
{
string++;
switch (string[0])
{
case GUI_COLOR_FG_CHAR: /* fg color */
if (string[1] && string[2])
{
str_fg[0] = string[1];
str_fg[1] = string[2];
str_fg[2] = '\0';
sscanf (str_fg, "%d", &fg);
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
fg);
string += 3;
}
break;
case GUI_COLOR_BG_CHAR: /* bg color */
if (string[1] && string[2])
{
str_bg[0] = string[1];
str_bg[1] = string[2];
str_bg[2] = '\0';
sscanf (str_bg, "%d", &bg);
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
bg);
string += 3;
}
break;
case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
if (string[1] && string[2] && (string[3] == ',')
&& string[4] && string[5])
{
str_fg[0] = string[1];
str_fg[1] = string[2];
str_fg[2] = '\0';
str_bg[0] = string[4];
str_bg[1] = string[5];
str_bg[2] = '\0';
sscanf (str_fg, "%d", &fg);
sscanf (str_bg, "%d", &bg);
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
fg, bg);
string += 6;
}
break;
case GUI_COLOR_BAR_CHAR: /* bar color */
switch (string[1])
{
case GUI_COLOR_BAR_FG_CHAR:
/* bar foreground */
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
string += 2;
break;
case GUI_COLOR_BAR_DELIM_CHAR:
/* bar delimiter */
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
string += 2;
break;
case GUI_COLOR_BAR_BG_CHAR:
/* bar background */
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
string += 2;
break;
case GUI_COLOR_BAR_START_INPUT_CHAR:
string += 2;
break;
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
/* move cursor to current position on screen */
getyx (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
bar_window->cursor_y, bar_window->cursor_x);
bar_window->cursor_x += bar_window->x;
bar_window->cursor_y += bar_window->y;
string += 2;
break;
default:
string++;
break;
}
break;
default:
if (isdigit (string[0]) && isdigit (string[1]))
{
str_fg[0] = string[0];
str_fg[1] = string[1];
str_fg[2] = '\0';
sscanf (str_fg, "%d", &weechat_color);
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
weechat_color);
string += 2;
}
break;
}
}
else
{
next_char = utf8_next_char (string);
if (!next_char)
break;
memcpy (utf_char, string, next_char - string);
utf_char[next_char - string] = '\0';
if ((((unsigned char)utf_char[0]) < 32) && (!utf_char[1]))
{
low_char = 1;
snprintf (utf_char, sizeof (utf_char), "%c",
'A' + ((unsigned char)utf_char[0]) - 1);
}
else
{
low_char = 0;
if (!gui_window_utf_char_valid (utf_char))
snprintf (utf_char, sizeof (utf_char), ".");
}
size_on_screen = utf8_char_size_screen (utf_char);
if (size_on_screen > 0)
{
if (x_with_hidden < bar_window->scroll_x)
case GUI_COLOR_COLOR_CHAR:
string++;
switch (string[0])
{
/* hidden char (before scroll_x value) */
x_with_hidden++;
case GUI_COLOR_FG_CHAR: /* fg color */
if (string[1] && string[2])
{
str_fg[0] = string[1];
str_fg[1] = string[2];
str_fg[2] = '\0';
sscanf (str_fg, "%d", &fg);
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
fg);
string += 3;
}
break;
case GUI_COLOR_BG_CHAR: /* bg color */
if (string[1] && string[2])
{
str_bg[0] = string[1];
str_bg[1] = string[2];
str_bg[2] = '\0';
sscanf (str_bg, "%d", &bg);
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
bg);
string += 3;
}
break;
case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
if (string[1] && string[2] && (string[3] == ',')
&& string[4] && string[5])
{
str_fg[0] = string[1];
str_fg[1] = string[2];
str_fg[2] = '\0';
str_bg[0] = string[4];
str_bg[1] = string[5];
str_bg[2] = '\0';
sscanf (str_fg, "%d", &fg);
sscanf (str_bg, "%d", &bg);
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
fg, bg);
string += 6;
}
break;
case GUI_COLOR_BAR_CHAR: /* bar color */
switch (string[1])
{
case GUI_COLOR_BAR_FG_CHAR:
/* bar foreground */
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
string += 2;
break;
case GUI_COLOR_BAR_DELIM_CHAR:
/* bar delimiter */
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
string += 2;
break;
case GUI_COLOR_BAR_BG_CHAR:
/* bar background */
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
string += 2;
break;
case GUI_COLOR_BAR_START_INPUT_CHAR:
string += 2;
break;
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
/* move cursor to current position on screen */
getyx (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
bar_window->cursor_y, bar_window->cursor_x);
bar_window->cursor_x += bar_window->x;
bar_window->cursor_y += bar_window->y;
string += 2;
break;
default:
string++;
break;
}
break;
default:
if (isdigit (string[0]) && isdigit (string[1]))
{
str_fg[0] = string[0];
str_fg[1] = string[1];
str_fg[2] = '\0';
sscanf (str_fg, "%d", &weechat_color);
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
weechat_color);
string += 2;
}
break;
}
break;
case GUI_COLOR_RESET_CHAR:
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
string++;
break;
default:
next_char = utf8_next_char (string);
if (!next_char)
break;
memcpy (utf_char, string, next_char - string);
utf_char[next_char - string] = '\0';
if ((((unsigned char)utf_char[0]) < 32) && (!utf_char[1]))
{
low_char = 1;
snprintf (utf_char, sizeof (utf_char), "%c",
'A' + ((unsigned char)utf_char[0]) - 1);
}
else
{
if (*x + size_on_screen > bar_window->width)
{
if (gui_bar_get_filling (bar_window->bar) == GUI_BAR_FILLING_VERTICAL)
return 0;
if (*y >= bar_window->height - 1)
return 0;
*x = 0;
(*y)++;
wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x);
}
output = string_iconv_from_internal (NULL, utf_char);
if (low_char)
wattron (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
wprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, "%s",
(output) ? output : utf_char);
if (low_char)
wattroff (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
if (output)
free (output);
*x += size_on_screen;
low_char = 0;
if (!gui_window_utf_char_valid (utf_char))
snprintf (utf_char, sizeof (utf_char), ".");
}
}
string = next_char;
size_on_screen = utf8_char_size_screen (utf_char);
if (size_on_screen > 0)
{
if (x_with_hidden < bar_window->scroll_x)
{
/* hidden char (before scroll_x value) */
x_with_hidden++;
}
else
{
if (*x + size_on_screen > bar_window->width)
{
if (gui_bar_get_filling (bar_window->bar) == GUI_BAR_FILLING_VERTICAL)
return 0;
if (*y >= bar_window->height - 1)
return 0;
*x = 0;
(*y)++;
wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x);
}
output = string_iconv_from_internal (NULL, utf_char);
if (low_char)
wattron (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
wprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, "%s",
(output) ? output : utf_char);
if (low_char)
wattroff (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
if (output)
free (output);
*x += size_on_screen;
}
}
string = next_char;
break;
}
}
return 1;

View File

@ -636,9 +636,10 @@ char *
gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item,
struct t_gui_window *window)
{
char *ptr_input, str_buffer[128], str_start_input[16], str_cursor[16], *buf;
char *ptr_input, *ptr_input2, str_buffer[128], str_start_input[16];
char str_cursor[16], *buf;
const char *pos_cursor;
int length, buf_pos;
int length, length_cursor, length_start_input, buf_pos;
/* make C compiler happy */
(void) data;
@ -647,9 +648,22 @@ gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item,
if (!window)
window = gui_current_window;
snprintf (str_cursor, sizeof (str_cursor), "%c%c%c",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_BAR_CHAR,
GUI_COLOR_BAR_MOVE_CURSOR_CHAR);
length_cursor = strlen (str_cursor);
snprintf (str_start_input, sizeof (str_start_input), "%c%c%c",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_BAR_CHAR,
GUI_COLOR_BAR_START_INPUT_CHAR);
length_start_input = strlen (str_start_input);
/* for modifiers */
snprintf (str_buffer, sizeof (str_buffer),
"0x%lx", (long unsigned int)(window->buffer));
/* execute modifier with basic string (without cursor tag) */
ptr_input = hook_modifier_exec (NULL,
"weechat_input_text_display",
str_buffer,
@ -660,46 +674,71 @@ gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item,
ptr_input = (window->buffer->input_buffer) ?
strdup (window->buffer->input_buffer) : NULL;
}
if (!ptr_input)
return NULL;
/* insert "move cursor" id in string */
snprintf (str_start_input, sizeof (str_start_input), "%c%c%c",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_BAR_CHAR,
GUI_COLOR_BAR_START_INPUT_CHAR);
snprintf (str_cursor, sizeof (str_cursor), "%c%c%c",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_BAR_CHAR,
GUI_COLOR_BAR_MOVE_CURSOR_CHAR);
pos_cursor = gui_chat_string_add_offset (ptr_input,
window->buffer->input_buffer_pos);
length = strlen (str_start_input)+ strlen (ptr_input) +
strlen (str_cursor) + 1;
buf = malloc (length);
if (buf)
if (ptr_input)
{
snprintf (buf, length, "%s", str_start_input);
buf_pos = strlen (buf);
if (!pos_cursor)
pos_cursor = ptr_input;
/* add beginning of buffer */
if (pos_cursor != ptr_input)
pos_cursor = gui_chat_string_add_offset (ptr_input,
window->buffer->input_buffer_pos);
length = strlen (ptr_input) + length_cursor + 1;
buf = malloc (length);
if (buf)
{
memmove (buf + buf_pos, ptr_input, pos_cursor - ptr_input);
buf_pos += (pos_cursor - ptr_input);
buf_pos = 0;
if (!pos_cursor)
pos_cursor = ptr_input;
/* add beginning of buffer */
if (pos_cursor != ptr_input)
{
memmove (buf + buf_pos, ptr_input, pos_cursor - ptr_input);
buf_pos += (pos_cursor - ptr_input);
}
/* add "move cursor here" identifier in string */
snprintf (buf + buf_pos, length - buf_pos, "%s",
str_cursor);
/* add end of buffer */
strcat (buf, pos_cursor);
free (ptr_input);
ptr_input = buf;
}
/* add "move cursor here" identifier in string */
snprintf (buf + buf_pos, length - buf_pos, "%s",
str_cursor);
/* add end of buffer */
strcat (buf, pos_cursor);
}
else
{
ptr_input = strdup (str_cursor);
}
/* execute modifier with cursor in string */
ptr_input2 = hook_modifier_exec (NULL,
"weechat_input_text_display_with_cursor",
str_buffer,
(ptr_input) ? ptr_input : "");
if (ptr_input)
free (ptr_input);
ptr_input = buf;
ptr_input = ptr_input2;
/* insert "start input" at beginning of string */
if (ptr_input)
{
length = strlen (ptr_input) + length_start_input + 1;
buf = malloc (length);
if (buf)
{
snprintf (buf, length, "%s%s", str_start_input, ptr_input);
free (ptr_input);
ptr_input = buf;
}
}
else
{
length = length_start_input + length_cursor + 1;
ptr_input = malloc (length);
if (ptr_input)
{
snprintf (ptr_input, length, "%s%s", str_start_input, str_cursor);
}
}
return ptr_input;

View File

@ -350,6 +350,7 @@ plugin_load (const char *filename)
new_plugin->string_split_command = &string_split_command;
new_plugin->string_free_splitted_command = &string_free_splitted_command;
new_plugin->string_format_size = &string_format_size;
new_plugin->string_remove_color = &string_remove_color;
new_plugin->utf8_has_8bits = &utf8_has_8bits;
new_plugin->utf8_is_valid = &utf8_is_valid;
@ -435,6 +436,7 @@ plugin_load (const char *filename)
new_plugin->log_printf = &log_printf;
new_plugin->hook_command = &hook_command;
new_plugin->hook_command_run = &hook_command_run;
new_plugin->hook_timer = &hook_timer;
new_plugin->hook_fd = &hook_fd;
new_plugin->hook_connect = &hook_connect;

View File

@ -361,6 +361,43 @@ weechat_lua_api_ngettext (lua_State *L)
LUA_RETURN_STRING(result);
}
/*
* weechat_lua_api_string_remove_color: remove WeeChat color codes from string
*/
static int
weechat_lua_api_string_remove_color (lua_State *L)
{
const char *string;
char *result;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color");
LUA_RETURN_EMPTY;
}
string = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
LUA_RETURN_EMPTY;
}
string = lua_tostring (lua_current_interpreter, -1);
result = weechat_string_remove_color (string);
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_mkdir_home: create a directory in WeeChat home
*/
@ -2739,6 +2776,85 @@ weechat_lua_api_hook_command (lua_State *L)
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_command_run_cb: callback for command_run hooked
*/
int
weechat_lua_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer,
const char *command)
{
struct t_script_callback *script_callback;
char *lua_argv[3];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
lua_argv[0] = script_ptr2str (buffer);
lua_argv[1] = (char *)command;
lua_argv[2] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
lua_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (lua_argv[0])
free (lua_argv[0]);
return ret;
}
/*
* weechat_lua_api_hook_command_run: hook a command_run
*/
static int
weechat_lua_api_hook_command_run (lua_State *L)
{
const char *command, *function;
char *result;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run");
LUA_RETURN_EMPTY;
}
command = NULL;
function = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run");
LUA_RETURN_EMPTY;
}
command = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
result = script_ptr2str (script_api_hook_command_run (weechat_lua_plugin,
lua_current_script,
command,
&weechat_lua_api_hook_command_run_cb,
function));
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_timer_cb: callback for timer hooked
*/
@ -5689,6 +5805,16 @@ weechat_lua_api_constant_weechat_rc_ok (lua_State *L)
return 1;
}
static int
weechat_lua_api_constant_weechat_rc_ok_eat (lua_State *L)
{
/* make C compiler happy */
(void) L;
lua_pushnumber (lua_current_interpreter, WEECHAT_RC_OK_EAT);
return 1;
}
static int
weechat_lua_api_constant_weechat_rc_error (lua_State *L)
{
@ -6041,6 +6167,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "iconv_from_internal", &weechat_lua_api_iconv_from_internal },
{ "gettext", &weechat_lua_api_gettext },
{ "ngettext", &weechat_lua_api_ngettext },
{ "string_remove_color", &weechat_lua_api_string_remove_color },
{ "mkdir_home", &weechat_lua_api_mkdir_home },
{ "mkdir", &weechat_lua_api_mkdir },
{ "mkdir_parents", &weechat_lua_api_mkdir_parents },
@ -6091,6 +6218,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "print_y", &weechat_lua_api_print_y },
{ "log_print", &weechat_lua_api_log_print },
{ "hook_command", &weechat_lua_api_hook_command },
{ "hook_command_run", &weechat_lua_api_hook_command_run },
{ "hook_timer", &weechat_lua_api_hook_timer },
{ "hook_fd", &weechat_lua_api_hook_fd },
{ "hook_connect", &weechat_lua_api_hook_connect },
@ -6155,6 +6283,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
/* define constants as function which returns values */
{ "WEECHAT_RC_OK", &weechat_lua_api_constant_weechat_rc_ok },
{ "WEECHAT_RC_OK_EAT", &weechat_lua_api_constant_weechat_rc_ok_eat },
{ "WEECHAT_RC_ERROR", &weechat_lua_api_constant_weechat_rc_error },
{ "WEECHAT_CONFIG_READ_OK", &weechat_lua_api_constant_weechat_config_read_ok },

View File

@ -307,6 +307,36 @@ static XS (XS_weechat_api_ngettext)
PERL_RETURN_STRING(result);
}
/*
* weechat::string_remove_color: remove WeeChat color codes from string
*/
static XS (XS_weechat_api_string_remove_color)
{
char *result, *string;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color");
PERL_RETURN_EMPTY;
}
if (items < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
PERL_RETURN_EMPTY;
}
string = SvPV (ST (0), PL_na);
result = weechat_string_remove_color (string);
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::mkdir_home: create a directory in WeeChat home
*/
@ -2281,6 +2311,77 @@ static XS (XS_weechat_api_hook_command)
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat_perl_api_hook_command_run_cb: callback for command_run hooked
*/
int
weechat_perl_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer,
const char *command)
{
struct t_script_callback *script_callback;
char *perl_argv[3];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
perl_argv[0] = script_ptr2str (buffer);
perl_argv[1] = (char *)command;
perl_argv[2] = NULL;
rc = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
perl_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (perl_argv[0])
free (perl_argv[0]);
return ret;
}
/*
* weechat::hook_command_run: hook a command_run
*/
static XS (XS_weechat_api_hook_command_run)
{
char *result, *command, *function;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run");
PERL_RETURN_EMPTY;
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run");
PERL_RETURN_EMPTY;
}
command = SvPV (ST (0), PL_na);
function = SvPV (ST (1), PL_na);
result = script_ptr2str (script_api_hook_command_run (weechat_perl_plugin,
perl_current_script,
command,
&weechat_perl_api_hook_command_run_cb,
function));
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat_perl_api_hook_timer_cb: callback for timer hooked
*/
@ -4750,6 +4851,7 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::iconv_from_internal", XS_weechat_api_iconv_from_internal, "weechat");
newXS ("weechat::gettext", XS_weechat_api_gettext, "weechat");
newXS ("weechat::ngettext", XS_weechat_api_ngettext, "weechat");
newXS ("weechat::string_remove_color", XS_weechat_api_string_remove_color, "weechat");
newXS ("weechat::mkdir_home", XS_weechat_api_mkdir_home, "weechat");
newXS ("weechat::mkdir", XS_weechat_api_mkdir, "weechat");
newXS ("weechat::mkdir_parents", XS_weechat_api_mkdir_parents, "weechat");
@ -4800,6 +4902,7 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::print_y", XS_weechat_api_print_y, "weechat");
newXS ("weechat::log_print", XS_weechat_api_log_print, "weechat");
newXS ("weechat::hook_command", XS_weechat_api_hook_command, "weechat");
newXS ("weechat::hook_command_run", XS_weechat_api_hook_command_run, "weechat");
newXS ("weechat::hook_timer", XS_weechat_api_hook_timer, "weechat");
newXS ("weechat::hook_fd", XS_weechat_api_hook_fd, "weechat");
newXS ("weechat::hook_connect", XS_weechat_api_hook_connect, "weechat");
@ -4864,6 +4967,7 @@ weechat_perl_api_init (pTHX)
/* interface constants */
stash = gv_stashpv ("weechat", TRUE);
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK", newSViv (WEECHAT_RC_OK));
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_EAT", newSViv (WEECHAT_RC_OK_EAT));
newCONSTSUB (stash, "weechat::WEECHAT_RC_ERROR", newSViv (WEECHAT_RC_ERROR));
newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_READ_OK", newSViv (WEECHAT_CONFIG_READ_OK));

View File

@ -314,6 +314,38 @@ weechat_python_api_ngettext (PyObject *self, PyObject *args)
PYTHON_RETURN_STRING(result);
}
/*
* weechat_python_api_string_remove_color: remove WeeChat color codes from string
*/
static PyObject *
weechat_python_api_string_remove_color (PyObject *self, PyObject *args)
{
char *string, *result;
PyObject *object;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color");
PYTHON_RETURN_EMPTY;
}
string = NULL;
if (!PyArg_ParseTuple (args, "s", &string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
PYTHON_RETURN_EMPTY;
}
result = weechat_string_remove_color (string);
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_mkdir_home: create a directory in WeeChat home
*/
@ -2429,6 +2461,79 @@ weechat_python_api_hook_command (PyObject *self, PyObject *args)
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_command_run_cb: callback for command_run hooked
*/
int
weechat_python_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer,
const char *command)
{
struct t_script_callback *script_callback;
char *python_argv[3];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
python_argv[0] = script_ptr2str (buffer);
python_argv[1] = (char *)command;
python_argv[2] = NULL;
rc = (int *) weechat_python_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
python_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (python_argv[0])
free (python_argv[0]);
return ret;
}
/*
* weechat_python_api_hook_command_run: hook a command_run
*/
static PyObject *
weechat_python_api_hook_command_run (PyObject *self, PyObject *args)
{
char *command, *function, *result;
PyObject *object;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run");
PYTHON_RETURN_EMPTY;
}
command = NULL;
function = NULL;
if (!PyArg_ParseTuple (args, "ss", &command, &function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run");
PYTHON_RETURN_EMPTY;
}
result = script_ptr2str (script_api_hook_command_run (weechat_python_plugin,
python_current_script,
command,
&weechat_python_api_hook_command_run_cb,
function));
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_timer_cb: callback for timer hooked
*/
@ -5049,6 +5154,7 @@ PyMethodDef weechat_python_funcs[] =
{ "iconv_from_internal", &weechat_python_api_iconv_from_internal, METH_VARARGS, "" },
{ "gettext", &weechat_python_api_gettext, METH_VARARGS, "" },
{ "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" },
{ "string_remove_color", &weechat_python_api_string_remove_color, METH_VARARGS, "" },
{ "mkdir_home", &weechat_python_api_mkdir_home, METH_VARARGS, "" },
{ "mkdir", &weechat_python_api_mkdir, METH_VARARGS, "" },
{ "mkdir_parents", &weechat_python_api_mkdir_parents, METH_VARARGS, "" },
@ -5099,6 +5205,7 @@ PyMethodDef weechat_python_funcs[] =
{ "prnt_y", &weechat_python_api_prnt_y, METH_VARARGS, "" },
{ "log_print", &weechat_python_api_log_print, METH_VARARGS, "" },
{ "hook_command", &weechat_python_api_hook_command, METH_VARARGS, "" },
{ "hook_command_run", &weechat_python_api_hook_command_run, METH_VARARGS, "" },
{ "hook_timer", &weechat_python_api_hook_timer, METH_VARARGS, "" },
{ "hook_fd", &weechat_python_api_hook_fd, METH_VARARGS, "" },
{ "hook_connect", &weechat_python_api_hook_connect, METH_VARARGS, "" },

View File

@ -356,6 +356,7 @@ weechat_python_load (const char *filename)
/* define some constants */
weechat_dict = PyModule_GetDict(weechat_module);
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK", PyInt_FromLong((long) WEECHAT_RC_OK));
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_EAT", PyInt_FromLong((long) WEECHAT_RC_OK_EAT));
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_ERROR", PyInt_FromLong((long) WEECHAT_RC_ERROR));
PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_READ_OK", PyInt_FromLong((long) WEECHAT_CONFIG_READ_OK));

View File

@ -364,6 +364,42 @@ weechat_ruby_api_ngettext (VALUE class, VALUE single, VALUE plural,
RUBY_RETURN_STRING(result);
}
/*
* weechat_ruby_api_string_remove_color: remove WeeChat color codes from string
*/
static VALUE
weechat_ruby_api_string_remove_color (VALUE class, VALUE string)
{
char *c_string, *result;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color");
RUBY_RETURN_EMPTY;
}
c_string = NULL;
if (NIL_P (string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
RUBY_RETURN_EMPTY;
}
Check_Type (string, T_STRING);
c_string = STR2CSTR (string);
result = weechat_string_remove_color (c_string);
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_mkdir_home: create a directory in WeeChat home
*/
@ -2795,6 +2831,85 @@ weechat_ruby_api_hook_command (VALUE class, VALUE command, VALUE description,
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_command_run_cb: callback for command_run hooked
*/
int
weechat_ruby_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer,
const char *command)
{
struct t_script_callback *script_callback;
char *ruby_argv[3];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
ruby_argv[0] = script_ptr2str (buffer);
ruby_argv[1] = (char *)command;
ruby_argv[2] = NULL;
rc = (int *) weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
ruby_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (ruby_argv[0])
free (ruby_argv[0]);
return ret;
}
/*
* weechat_ruby_api_hook_command_run: hook a command_run
*/
static VALUE
weechat_ruby_api_hook_command_run (VALUE class, VALUE command, VALUE function)
{
char *c_command, *c_function, *result;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run");
RUBY_RETURN_EMPTY;
}
c_command = NULL;
c_function = NULL;
if (NIL_P (command) || NIL_P (function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run");
RUBY_RETURN_EMPTY;
}
Check_Type (command, T_STRING);
Check_Type (function, T_STRING);
c_command = STR2CSTR (command);
c_function = STR2CSTR (function);
result = script_ptr2str (script_api_hook_command_run (weechat_ruby_plugin,
ruby_current_script,
c_command,
&weechat_ruby_api_hook_command_run_cb,
c_function));
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_timer_cb: callback for timer hooked
*/
@ -5757,6 +5872,7 @@ void
weechat_ruby_api_init (VALUE ruby_mWeechat)
{
rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK", INT2NUM(WEECHAT_RC_OK));
rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK_EAT", INT2NUM(WEECHAT_RC_OK_EAT));
rb_define_const(ruby_mWeechat, "WEECHAT_RC_ERROR", INT2NUM(WEECHAT_RC_ERROR));
rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_READ_OK", INT2NUM(WEECHAT_CONFIG_READ_OK));
@ -5804,6 +5920,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "iconv_from_internal", &weechat_ruby_api_iconv_from_internal, 2);
rb_define_module_function (ruby_mWeechat, "gettext", &weechat_ruby_api_gettext, 1);
rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3);
rb_define_module_function (ruby_mWeechat, "string_remove_color", &weechat_ruby_api_string_remove_color, 1);
rb_define_module_function (ruby_mWeechat, "mkdir_home", &weechat_ruby_api_mkdir_home, 2);
rb_define_module_function (ruby_mWeechat, "mkdir", &weechat_ruby_api_mkdir, 2);
rb_define_module_function (ruby_mWeechat, "mkdir_parents", &weechat_ruby_api_mkdir_parents, 2);
@ -5854,6 +5971,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "print_y", &weechat_ruby_api_print_y, 3);
rb_define_module_function (ruby_mWeechat, "log_print", &weechat_ruby_api_log_print, 1);
rb_define_module_function (ruby_mWeechat, "hook_command", &weechat_ruby_api_hook_command, 6);
rb_define_module_function (ruby_mWeechat, "hook_command_run", &weechat_ruby_api_hook_command_run, 2);
rb_define_module_function (ruby_mWeechat, "hook_timer", &weechat_ruby_api_hook_timer, 4);
rb_define_module_function (ruby_mWeechat, "hook_fd", &weechat_ruby_api_hook_fd, 5);
rb_define_module_function (ruby_mWeechat, "hook_connect", &weechat_ruby_api_hook_connect, 7);

View File

@ -663,6 +663,45 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
return new_hook;
}
/*
* script_api_hook_command_run: hook a command_run
* return new hook, NULL if error
*/
struct t_hook *
script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *command,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
const char *command),
const char *function)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
new_hook = weechat_hook_command_run (command,
callback, new_script_callback);
if (!new_hook)
{
script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
return new_hook;
}
/*
* script_api_hook_timer: hook a timer
* return new hook, NULL if error

View File

@ -108,6 +108,13 @@ extern struct t_hook *script_api_hook_command (struct t_weechat_plugin *weechat_
int argc, char **argv,
char **argv_eol),
const char *function);
extern struct t_hook *script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *command,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
const char *command),
const char *function);
extern struct t_hook *script_api_hook_timer (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
int interval, int align_second,

View File

@ -431,6 +431,39 @@ weechat_tcl_api_ngettext (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_STRING(result);
}
/*
* weechat_tcl_api_string_remove_color: remove WeeChat color codes from string
*/
static int
weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj* objp;
char *result, *string;
int i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color");
TCL_RETURN_EMPTY;
}
if (objc < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
TCL_RETURN_EMPTY;
}
string = Tcl_GetStringFromObj (objv[1], &i);
result = weechat_string_remove_color (string);
TCL_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_mkdir_home: create a directory in WeeChat home
*/
@ -2635,6 +2668,80 @@ weechat_tcl_api_hook_command (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_hook_command_run_cb: callback for command_run hooked
*/
int
weechat_tcl_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer,
const char *command)
{
struct t_script_callback *script_callback;
char *tcl_argv[3];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
tcl_argv[0] = script_ptr2str (buffer);
tcl_argv[1] = (char *)command;
tcl_argv[2] = NULL;
rc = (int *) weechat_tcl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
tcl_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (tcl_argv[0])
free (tcl_argv[0]);
return ret;
}
/*
* weechat_tcl_api_hook_command_run: hook a command_run
*/
static int
weechat_tcl_api_hook_command_run (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
char *result, *command, *function;
int i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run");
TCL_RETURN_EMPTY;
}
if (objc < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run");
TCL_RETURN_EMPTY;
}
command = Tcl_GetStringFromObj (objv[1], &i);
function = Tcl_GetStringFromObj (objv[2], &i);
result = script_ptr2str (script_api_hook_command_run (weechat_tcl_plugin,
tcl_current_script,
command,
&weechat_tcl_api_hook_command_run_cb,
function));
TCL_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_hook_timer_cb: callback for timer hooked
*/
@ -5353,6 +5460,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) {
Tcl_IncrRefCount (objp);
Tcl_SetVar (interp, "weechat::WEECHAT_RC_OK", Tcl_GetStringFromObj (objp, &i),0);
Tcl_SetIntObj (objp,WEECHAT_RC_OK_EAT);
Tcl_SetVar (interp, "weechat::WEECHAT_RC_OK_EAT", Tcl_GetStringFromObj (objp, &i),0);
Tcl_SetIntObj (objp,WEECHAT_RC_ERROR);
Tcl_SetVar (interp, "weechat::WEECHAT_RC_ERROR", Tcl_GetStringFromObj (objp, &i),0);
@ -5444,6 +5553,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) {
weechat_tcl_api_gettext, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::ngettext",
weechat_tcl_api_ngettext, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::string_remove_color",
weechat_tcl_api_string_remove_color, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::mkdir_home",
weechat_tcl_api_mkdir_home, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::mkdir",
@ -5544,6 +5655,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) {
weechat_tcl_api_log_print, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::hook_command",
weechat_tcl_api_hook_command, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::hook_command_run",
weechat_tcl_api_hook_command_run, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::hook_timer",
weechat_tcl_api_hook_timer, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::hook_fd",

View File

@ -48,6 +48,7 @@ struct t_weelist;
/* return codes for plugin functions */
#define WEECHAT_RC_OK 0
#define WEECHAT_RC_OK_EAT 1
#define WEECHAT_RC_ERROR -1
/* return codes for config read functions/callbacks */
@ -159,6 +160,7 @@ struct t_weechat_plugin
char **(*string_split_command) (const char *command, char separator);
void (*string_free_splitted_command) (char **splitted_command);
char *(*string_format_size) (unsigned long size);
char *(*string_remove_color) (const char *string);
/* UTF-8 strings */
int (*utf8_has_8bits) (const char *string);
@ -345,6 +347,12 @@ struct t_weechat_plugin
int argc, char **argv,
char **argv_eol),
void *callback_data);
struct t_hook *(*hook_command_run) (struct t_weechat_plugin *plugin,
const char *command,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
const char *command),
void *callback_data);
struct t_hook *(*hook_timer) (struct t_weechat_plugin *plugin,
long interval,
int align_second,
@ -667,6 +675,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->string_free_splitted_command(__splitted_command)
#define weechat_string_format_size(__size) \
weechat_plugin->string_format_size(__size)
#define weechat_string_remove_color(__string) \
weechat_plugin->string_remove_color(__string)
/* UTF-8 strings */
#define weechat_utf8_has_8bits(__string) \
@ -901,6 +911,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->hook_command(weechat_plugin, __command, \
__description, __args, __args_desc, \
__completion, __callback, __data)
#define weechat_hook_command_run(__command, __callback, __data) \
weechat_plugin->hook_command_run(weechat_plugin, __command, \
__callback, __data)
#define weechat_hook_timer(__interval, __align_second, __max_calls, \
__callback, __data) \
weechat_plugin->hook_timer(weechat_plugin, __interval, \