1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

core: add signals "buffer_user_{input|closing}_xxx" for buffers created with /buffer add (closes #1848)

This commit is contained in:
Sébastien Helleu
2022-11-08 20:34:04 +01:00
parent 2e4a033f0d
commit 24665ae878
8 changed files with 234 additions and 12 deletions
+1
View File
@@ -21,6 +21,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
New features::
* core: allow command `/toggle` to create option before setting the value, if allowed in the section (issue #1837)
* core: add signals "buffer_user_input_xxx" and "buffer_user_closing_xxx" for buffers created with `/buffer add` (issue #1848)
* trigger: add regex command "y" to translate chars, set default regex command to "s" (regex replace) (issue #1510)
Bug fixes::
+12 -1
View File
@@ -10959,6 +10959,16 @@ List of signals sent by WeeChat and plugins:
| Pointer: buffer.
| Merged buffer unzoomed.
| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8
| String: text sent to buffer.
| Text sent to a user buffer as input (sent only for buffers created with `/buffer add`). +
If the return code of a callback is _WEECHAT_RC_OK_EAT_, then the string "q"
can not be used any more to close the buffer.
| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8
| -
| User buffer is closing (sent only for buffers created with `/buffer add`).
| weechat | [[hook_signal_cursor_start]] cursor_start | 3.2
| -
| Start cursor mode.
@@ -11198,7 +11208,8 @@ List of signals sent by WeeChat and plugins:
|===
[NOTE]
^(1)^ _xxx_ is IRC server name, _yyy_ is IRC command name.
^(1)^ _xxx_ is IRC server name, _yyy_ is IRC command name. +
^(2)^ _xxx_ is buffer name.
C example:
+12
View File
@@ -11180,6 +11180,18 @@ Liste des signaux envoyés par WeeChat et les extensions :
| Pointeur : tampon.
| Fin du zoom sur un tampon mélangé.
| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8
| Chaîne : texte envoyé au tampon.
| Texte envoyé au tampon utilisateur (envoyé seulement sur les tampons créés
avec `/buffer add`). +
Si le code retour d'une fonction de rappel est _WEECHAT_RC_OK_EAT_, alors
la chaîne "q" ne peut plus être utilisée pour fermer le tampon.
| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8
| -
| Fermeture du tampon utilisateur en cours (envoyé seulement sur les tampons créés
avec `/buffer add`).
| weechat | [[hook_signal_cursor_start]] cursor_start | 3.2
| -
| Début du mode curseur.
+12
View File
@@ -11373,6 +11373,18 @@ List of signals sent by WeeChat and plugins:
| Puntatore: buffer.
| Merged buffer unzoomed.
// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8
| String: text sent to buffer.
| Text sent to a user buffer as input (sent only for buffers created with `/buffer add`). +
If the return code of a callback is _WEECHAT_RC_OK_EAT_, then the string "q"
can not be used any more to close the buffer.
// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8
| -
| User buffer is closing (sent only for buffers created with `/buffer add`).
// TRANSLATION MISSING
| weechat | [[hook_signal_cursor_start]] cursor_start | 3.2
| -
+12
View File
@@ -11021,6 +11021,18 @@ WeeChat とプラグインが送信するシグナルのリスト:
| Pointer: バッファ
| マージされたバッファをアンズーム
// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8
| String: text sent to buffer.
| Text sent to a user buffer as input (sent only for buffers created with `/buffer add`). +
If the return code of a callback is _WEECHAT_RC_OK_EAT_, then the string "q"
can not be used any more to close the buffer.
// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8
| -
| User buffer is closing (sent only for buffers created with `/buffer add`).
// TRANSLATION MISSING
| weechat | [[hook_signal_cursor_start]] cursor_start | 3.2
| -
+12
View File
@@ -10602,6 +10602,18 @@ struct t_hook *weechat_hook_signal (const char *signal,
| Показивач: бафер.
| Одзумиран је спојени бафер.
// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8
| String: text sent to buffer.
| Text sent to a user buffer as input (sent only for buffers created with `/buffer add`). +
If the return code of a callback is _WEECHAT_RC_OK_EAT_, then the string "q"
can not be used any more to close the buffer.
// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8
| -
| User buffer is closing (sent only for buffers created with `/buffer add`).
| weechat | [[hook_signal_cursor_start]] cursor_start | 3.2
| - |
Почетак режима померања курсора.
+36 -1
View File
@@ -903,10 +903,22 @@ int
gui_buffer_user_input_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer, const char *input_data)
{
char str_signal[1024];
int rc;
/* make C compiler happy */
(void) pointer;
(void) data;
snprintf (str_signal, sizeof (str_signal),
"buffer_user_input_%s",
buffer->name);
rc = hook_signal_send (str_signal,
WEECHAT_HOOK_SIGNAL_STRING, (void *)input_data);
if (rc == WEECHAT_RC_OK_EAT)
return WEECHAT_RC_OK;
if (string_strcasecmp (input_data, "q") == 0)
{
gui_buffer_close (buffer);
@@ -915,6 +927,29 @@ gui_buffer_user_input_cb (const void *pointer, void *data,
return WEECHAT_RC_OK;
}
/*
* Close callback for user buffers.
*/
int
gui_buffer_user_close_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer)
{
char str_signal[1024];
/* make C compiler happy */
(void) pointer;
(void) data;
snprintf (str_signal, sizeof (str_signal),
"buffer_user_closing_%s",
buffer->name);
hook_signal_send (str_signal,
WEECHAT_HOOK_SIGNAL_STRING, NULL);
return WEECHAT_RC_OK;
}
/*
* Creates a new user buffer in current window.
*
@@ -944,7 +979,7 @@ gui_buffer_new_user (const char *name, enum t_gui_buffer_type buffer_type)
new_buffer = gui_buffer_new_props (NULL, name, properties,
&gui_buffer_user_input_cb, NULL, NULL,
NULL, NULL, NULL);
&gui_buffer_user_close_cb, NULL, NULL);
if (properties)
hashtable_free (properties);
+137 -10
View File
@@ -25,17 +25,85 @@ extern "C"
{
#include <string.h>
#include "src/core/wee-hashtable.h"
#include "src/core/wee-hook.h"
#include "src/core/wee-input.h"
#include "src/gui/gui-buffer.h"
#include "src/gui/gui-key.h"
#include "src/gui/gui-line.h"
#include "src/gui/gui-nicklist.h"
#include "src/plugins/plugin.h"
extern int gui_buffer_user_input_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
const char *input_data);
extern int gui_buffer_user_close_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer);
}
#define TEST_BUFFER_NAME "test"
char signal_buffer_user_input[256];
int signal_buffer_user_closing = 0;
TEST_GROUP(GuiBuffer)
{
static int signal_buffer_user_input_cb (const void *pointer, void *data,
const char *signal,
const char *type_data,
void *signal_data)
{
/* make C++ compiler happy */
(void) pointer;
(void) data;
(void) signal;
(void) type_data;
if (signal_data)
{
snprintf (signal_buffer_user_input,
sizeof (signal_buffer_user_input),
"%s",
(const char *)signal_data);
}
return WEECHAT_RC_OK;
}
static int signal_buffer_user_input_eat_cb (const void *pointer, void *data,
const char *signal,
const char *type_data,
void *signal_data)
{
/* make C++ compiler happy */
(void) pointer;
(void) data;
(void) signal;
(void) type_data;
if (signal_data)
{
snprintf (signal_buffer_user_input,
sizeof (signal_buffer_user_input),
"%s",
(const char *)signal_data);
}
return WEECHAT_RC_OK_EAT;
}
static int signal_buffer_user_closing_cb (const void *pointer, void *data,
const char *signal,
const char *type_data,
void *signal_data)
{
/* make C++ compiler happy */
(void) pointer;
(void) data;
(void) signal;
(void) type_data;
(void) signal_data;
signal_buffer_user_closing = 1;
return WEECHAT_RC_OK_EAT;
}
};
/*
@@ -435,21 +503,80 @@ TEST(GuiBuffer, New)
/*
* Tests functions:
* gui_buffer_user_input_cb
*/
TEST(GuiBuffer, UserInputCb)
{
/* TODO: write tests */
}
/*
* Tests functions:
* gui_buffer_user_close_cb
* gui_buffer_new_user
*/
TEST(GuiBuffer, NewUser)
{
/* TODO: write tests */
int type;
struct t_gui_buffer *buffer;
struct t_hook *signal_input, *signal_closing;
for (type = 0; type < GUI_BUFFER_NUM_TYPES; type++)
{
signal_input = hook_signal (NULL,
"buffer_user_input_" TEST_BUFFER_NAME,
&signal_buffer_user_input_cb, NULL, NULL);
signal_closing = hook_signal (NULL,
"buffer_user_closing_" TEST_BUFFER_NAME,
&signal_buffer_user_closing_cb, NULL, NULL);
/* test creation of user buffer */
buffer = gui_buffer_new_user (TEST_BUFFER_NAME,
(enum t_gui_buffer_type)type);
CHECK(buffer);
STRCMP_EQUAL(TEST_BUFFER_NAME, buffer->name);
STRCMP_EQUAL("core." TEST_BUFFER_NAME, buffer->full_name);
POINTERS_EQUAL(&gui_buffer_user_input_cb, buffer->input_callback);
POINTERS_EQUAL(&gui_buffer_user_close_cb, buffer->close_callback);
/* test signal "buffer_user_input_test" */
signal_buffer_user_input[0] = '\0';
input_data (buffer, "something", NULL);
STRCMP_EQUAL("something", signal_buffer_user_input);
/* test signal "buffer_user_closing_test" */
signal_buffer_user_closing = 0;
gui_buffer_close (buffer);
LONGS_EQUAL(1, signal_buffer_user_closing);
/* create the buffer again */
buffer = gui_buffer_new_user (TEST_BUFFER_NAME,
(enum t_gui_buffer_type)type);
/* close the buffer by sending "q" */
signal_buffer_user_input[0] = '\0';
signal_buffer_user_closing = 0;
input_data (buffer, "q", NULL);
STRCMP_EQUAL("q", signal_buffer_user_input);
LONGS_EQUAL(1, signal_buffer_user_closing);
/* create the buffer again */
buffer = gui_buffer_new_user (TEST_BUFFER_NAME,
(enum t_gui_buffer_type)type);
/* hook a signal that eats the input */
unhook (signal_input);
signal_input = hook_signal (NULL,
"buffer_user_input_" TEST_BUFFER_NAME,
&signal_buffer_user_input_eat_cb, NULL, NULL);
/*
* try to close the buffer by sending "q": it should not close it
* because the input signal callback as returned WEECHAT_RC_OK_EAT
*/
signal_buffer_user_input[0] = '\0';
signal_buffer_user_closing = 0;
input_data (buffer, "q", NULL);
STRCMP_EQUAL("q", signal_buffer_user_input);
LONGS_EQUAL(0, signal_buffer_user_closing);
gui_buffer_close (buffer);
unhook (signal_input);
unhook (signal_closing);
}
}
/*