Skip to content

Commit

Permalink
core: add an option for multiline input in a buffer (closes #984)
Browse files Browse the repository at this point in the history
This allows the input callback function for a buffer to receive multiple
lines at once, instead of the message being split on newline before
being sent to the callback. It adds a new flag, input_multiline, to
control this. This flag defaults to 0 which is the current behavior.
  • Loading branch information
trygveaa authored and flashcode committed May 9, 2020
1 parent 30afb3d commit 6371485
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]

New features::

* core: add flag "input_multiline" in buffer (issue #984, issue #1063)
* core: add a scalable WeeChat logo (SVG) (issue #1454, issue #1456)
* core: add case sensitive wildcard matching comparison operator (`+==*+` and `+!!*+`) and case sensitive/insensitive include comparison operators (`+==-+`, `+!!-+`, `+=-+`, `+!-+`) in evaluation of expressions
* core: add default key kbd:[Alt+Shift+N] to toggle nicklist bar
Expand Down
1 change: 1 addition & 0 deletions doc/de/includes/autogen_api_hdata.de.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ _input_callback_pointer_   (pointer) +
_input_callback_data_   (pointer) +
_input_get_unknown_commands_   (integer) +
_input_get_empty_   (integer) +
_input_multiline_   (integer) +
_input_buffer_   (string) +
_input_buffer_alloc_   (integer) +
_input_buffer_size_   (integer) +
Expand Down
1 change: 1 addition & 0 deletions doc/en/includes/autogen_api_hdata.en.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ _input_callback_pointer_   (pointer) +
_input_callback_data_   (pointer) +
_input_get_unknown_commands_   (integer) +
_input_get_empty_   (integer) +
_input_multiline_   (integer) +
_input_buffer_   (string) +
_input_buffer_alloc_   (integer) +
_input_buffer_size_   (integer) +
Expand Down
6 changes: 6 additions & 0 deletions doc/en/weechat_plugin_api.en.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12782,6 +12782,8 @@ Arguments:
** _input_get_unknown_commands_: 1 if unknown commands are sent to input
callback, otherwise 0
** _input_get_empty_: 1 if empty input is sent to input callback, otherwise 0
** _input_multiline_: 1 if multiple lines are sent as one message to input
callback, otherwise 0
** _input_size_: input size (in bytes)
** _input_length_: input length (number of chars)
** _input_pos_: cursor position in buffer input
Expand Down Expand Up @@ -13083,6 +13085,10 @@ Properties:
| input_get_empty | "0" or "1" |
"0" to disable empty input on this buffer (default behavior), "1" to get empty input.

| input_multiline | "0" or "1" |
"0" to send each line separately to this buffer (default behavior), "1" to
send multiple lines as a single message.

| localvar_set_xxx | any string |
Set new value for local variable _xxx_ (variable is created if it does not
exist).
Expand Down
1 change: 1 addition & 0 deletions doc/en/weechat_relay_protocol.en.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ inl:
input: 1
input_get_unknown_commands: 0
input_get_empty: 0
input_multiline: 0
input_buffer: ''
input_buffer_alloc: 256
input_buffer_size: 0
Expand Down
1 change: 1 addition & 0 deletions doc/fr/includes/autogen_api_hdata.fr.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ _input_callback_pointer_   (pointer) +
_input_callback_data_   (pointer) +
_input_get_unknown_commands_   (integer) +
_input_get_empty_   (integer) +
_input_multiline_   (integer) +
_input_buffer_   (string) +
_input_buffer_alloc_   (integer) +
_input_buffer_size_   (integer) +
Expand Down
6 changes: 6 additions & 0 deletions doc/fr/weechat_plugin_api.fr.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13055,6 +13055,8 @@ Paramètres :
à la fonction de rappel "input", sinon 0
** _input_get_empty_ : 1 si une entrée vide est envoyée à la fonction de rappel
"input", sinon 0
** _input_multiline_ : 1 si plusieurs lignes sont envoyées comme un seul message
à la fonction de rappel "input", sinon 0
** _input_size_ : taille de la zone de saisie (en octets)
** _input_length_ : longueur de la zone de saisie (nombre de caractères)
** _input_pos_ : position du curseur dans la zone de saisie
Expand Down Expand Up @@ -13370,6 +13372,10 @@ Propriétés :
"0" pour désactiver l'entrée vide sur ce tampon (comportement par défaut),
"1" pour recevoir l'entrée vide.

| input_multiline | "0" ou "1" |
"0" pour envoyer chaque ligne séparément au tampon (comportement par défaut),
"1" pour envoyer plusieurs lignes comme un seul message.

| localvar_set_xxx | toute chaîne |
Change la valeur de la variable locale _xxx_ (la variable est créée si elle
n'existe pas).
Expand Down
1 change: 1 addition & 0 deletions doc/fr/weechat_relay_protocol.fr.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ inl:
input: 1
input_get_unknown_commands: 0
input_get_empty: 0
input_multiline: 0
input_buffer: ''
input_buffer_alloc: 256
input_buffer_size: 0
Expand Down
1 change: 1 addition & 0 deletions doc/it/includes/autogen_api_hdata.it.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ _input_callback_pointer_   (pointer) +
_input_callback_data_   (pointer) +
_input_get_unknown_commands_   (integer) +
_input_get_empty_   (integer) +
_input_multiline_   (integer) +
_input_buffer_   (string) +
_input_buffer_alloc_   (integer) +
_input_buffer_size_   (integer) +
Expand Down
8 changes: 8 additions & 0 deletions doc/it/weechat_plugin_api.it.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13305,6 +13305,9 @@ Argomenti:
alla callback di input, altrimenti 0
// TRANSLATION MISSING
** _input_get_empty_: 1 if empty input is sent to input callback, otherwise 0
// TRANSLATION MISSING
** _input_multiline_: 1 if multiple lines are sent as one message to input
callback, otherwise 0
** _input_size_: dimensione per l'input (in byte)
** _input_length_: lunghezza dell'input (numero di caratteri)
** _input_pos_: posizione del cursore nell'input del buffer
Expand Down Expand Up @@ -13634,6 +13637,11 @@ Properties:
| input_get_empty | "0" oppure "1" |
"0" to disable empty input on this buffer (default behavior), "1" to get empty input.

// TRANSLATION MISSING
| input_multiline | "0" or "1" |
"0" to send each line separately to this buffer (default behavior), "1" to
send multiple lines as a single message.

| localvar_set_xxx | qualsiasi stringa |
Imposta il nuovo valore per la variabile locale _xxx_ (la variabile verrà
creata se non esiste).
Expand Down
1 change: 1 addition & 0 deletions doc/ja/includes/autogen_api_hdata.ja.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ _input_callback_pointer_   (pointer) +
_input_callback_data_   (pointer) +
_input_get_unknown_commands_   (integer) +
_input_get_empty_   (integer) +
_input_multiline_   (integer) +
_input_buffer_   (string) +
_input_buffer_alloc_   (integer) +
_input_buffer_size_   (integer) +
Expand Down
8 changes: 8 additions & 0 deletions doc/ja/weechat_plugin_api.ja.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12777,6 +12777,9 @@ int weechat_buffer_get_integer (struct t_gui_buffer *buffer,
** _input_get_unknown_commands_: 未定義のコマンドを入力コールバックに送信する場合は
1、そうでない場合は 0
** _input_get_empty_: 入力コールバックに何も送信されなかった場合は 1、そうでない場合は 0
// TRANSLATION MISSING
** _input_multiline_: 1 if multiple lines are sent as one message to input
callback, otherwise 0
** _input_size_: 入力サイズ (バイト単位)
** _input_length_: 入力長 (文字数)
** _input_pos_: バッファ入力におけるカーソル位置
Expand Down Expand Up @@ -13076,6 +13079,11 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property,
| input_get_empty | "0" または "1" |
バッファに対する空入力を受け取らない場合は "0" (デフォルト)、空入力を受け取る場合は "1"

// TRANSLATION MISSING
| input_multiline | "0" または "1" |
"0" to send each line separately to this buffer (default behavior), "1" to
send multiple lines as a single message.

| localvar_set_xxx | 任意の文字列 |
ローカル変数 _xxx_ の新しい値を設定
(存在しない変数の場合は変数を作成する)
Expand Down
1 change: 1 addition & 0 deletions doc/ja/weechat_relay_protocol.ja.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ inl:
input: 1
input_get_unknown_commands: 0
input_get_empty: 0
input_multiline: 0
input_buffer: ''
input_buffer_alloc: 256
input_buffer_size: 0
Expand Down
1 change: 1 addition & 0 deletions doc/pl/includes/autogen_api_hdata.pl.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ _input_callback_pointer_   (pointer) +
_input_callback_data_   (pointer) +
_input_get_unknown_commands_   (integer) +
_input_get_empty_   (integer) +
_input_multiline_   (integer) +
_input_buffer_   (string) +
_input_buffer_alloc_   (integer) +
_input_buffer_size_   (integer) +
Expand Down
3 changes: 2 additions & 1 deletion src/core/wee-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ input_data (struct t_gui_buffer *buffer, const char *data,
break;
}

pos = strchr (ptr_data, '\n');
pos = (buffer->input_multiline) ? NULL : strchr (ptr_data, '\n');

if (pos)
pos[0] = '\0';

Expand Down
2 changes: 2 additions & 0 deletions src/core/wee-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ upgrade_weechat_read_buffer (struct t_infolist *infolist)
infolist_integer (infolist, "input_get_unknown_commands");
ptr_buffer->input_get_empty =
infolist_integer (infolist, "input_get_empty");
ptr_buffer->input_multiline =
infolist_integer (infolist, "input_multiline");

if (infolist_integer (infolist, "input_buffer_alloc") > 0)
{
Expand Down
37 changes: 33 additions & 4 deletions src/gui/gui-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ char *gui_buffer_properties_get_integer[] =
"nicklist_case_sensitive", "nicklist_max_length", "nicklist_display_groups",
"nicklist_count", "nicklist_groups_count", "nicklist_nicks_count",
"nicklist_visible_count", "input", "input_get_unknown_commands",
"input_get_empty", "input_size", "input_length", "input_pos",
"input_1st_display", "num_history", "text_search", "text_search_exact",
"text_search_regex", "text_search_where", "text_search_found",
"input_get_empty", "input_multiline", "input_size", "input_length",
"input_pos", "input_1st_display", "num_history", "text_search",
"text_search_exact", "text_search_regex", "text_search_where",
"text_search_found",
NULL
};
char *gui_buffer_properties_get_string[] =
Expand All @@ -116,7 +117,7 @@ char *gui_buffer_properties_set[] =
"highlight_words_del", "highlight_regex", "highlight_tags_restrict",
"highlight_tags", "hotlist_max_level_nicks", "hotlist_max_level_nicks_add",
"hotlist_max_level_nicks_del", "input", "input_pos",
"input_get_unknown_commands", "input_get_empty",
"input_get_unknown_commands", "input_get_empty", "input_multiline",
NULL
};

Expand Down Expand Up @@ -742,6 +743,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin,
new_buffer->input_callback_data = input_callback_data;
new_buffer->input_get_unknown_commands = 0;
new_buffer->input_get_empty = 0;
new_buffer->input_multiline = 0;
gui_buffer_input_buffer_init (new_buffer);

/* undo for input */
Expand Down Expand Up @@ -1174,6 +1176,8 @@ gui_buffer_get_integer (struct t_gui_buffer *buffer, const char *property)
return buffer->input_get_unknown_commands;
else if (string_strcasecmp (property, "input_get_empty") == 0)
return buffer->input_get_empty;
else if (string_strcasecmp (property, "input_multiline") == 0)
return buffer->input_multiline;
else if (string_strcasecmp (property, "input_size") == 0)
return buffer->input_buffer_size;
else if (string_strcasecmp (property, "input_length") == 0)
Expand Down Expand Up @@ -1905,6 +1909,20 @@ gui_buffer_set_input_get_empty (struct t_gui_buffer *buffer,
buffer->input_get_empty = (input_get_empty) ? 1 : 0;
}

/*
* Sets flag "input_multiline" for a buffer.
*/

void
gui_buffer_set_input_multiline (struct t_gui_buffer *buffer,
int input_multiline)
{
if (!buffer)
return;

buffer->input_multiline = (input_multiline) ? 1 : 0;
}

/*
* Sets unread marker for a buffer.
*/
Expand Down Expand Up @@ -2192,6 +2210,13 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
if (error && !error[0])
gui_buffer_set_input_get_empty (buffer, number);
}
else if (string_strcasecmp (property, "input_multiline") == 0)
{
error = NULL;
number = strtol (value, &error, 10);
if (error && !error[0])
gui_buffer_set_input_multiline (buffer, number);
}
else if (string_strncasecmp (property, "localvar_set_", 13) == 0)
{
if (value)
Expand Down Expand Up @@ -4284,6 +4309,7 @@ gui_buffer_hdata_buffer_cb (const void *pointer, void *data,
HDATA_VAR(struct t_gui_buffer, input_callback_data, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, input_get_unknown_commands, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, input_get_empty, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, input_multiline, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, input_buffer, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, input_buffer_alloc, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, input_buffer_size, INTEGER, 0, NULL, NULL);
Expand Down Expand Up @@ -4484,6 +4510,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!infolist_new_var_integer (ptr_item, "input_get_empty", buffer->input_get_empty))
return 0;
if (!infolist_new_var_integer (ptr_item, "input_multiline", buffer->input_multiline))
return 0;
if (!infolist_new_var_string (ptr_item, "input_buffer", buffer->input_buffer))
return 0;
if (!infolist_new_var_integer (ptr_item, "input_buffer_alloc", buffer->input_buffer_alloc))
Expand Down Expand Up @@ -4699,6 +4727,7 @@ gui_buffer_print_log ()
log_printf (" input_callback_data . . : 0x%lx", ptr_buffer->input_callback_data);
log_printf (" input_get_unknown_cmd . : %d", ptr_buffer->input_get_unknown_commands);
log_printf (" input_get_empty . . . . : %d", ptr_buffer->input_get_empty);
log_printf (" input_multiline . . . . : %d", ptr_buffer->input_multiline);
log_printf (" input_buffer. . . . . . : '%s'", ptr_buffer->input_buffer);
log_printf (" input_buffer_alloc. . . : %d", ptr_buffer->input_buffer_alloc);
log_printf (" input_buffer_size . . . : %d", ptr_buffer->input_buffer_size);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/gui-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ struct t_gui_buffer
/* input_callback */
int input_get_empty; /* 1 if empty input is sent to */
/* input_callback */
int input_multiline; /* 1 if multiple lines are sent as */
/* one message to input_callback */
char *input_buffer; /* input buffer */
int input_buffer_alloc; /* input buffer: allocated size */
int input_buffer_size; /* buffer size in bytes */
Expand Down

0 comments on commit 6371485

Please sign in to comment.