diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2020-05-09 18:06:01 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-05-09 18:07:36 +0200 |
commit | 63714855d3cbedc49747b099533a5a259cbd74c2 (patch) | |
tree | 02b320fe54b0153fcabd0eb0e51dbfb0454d528c /src | |
parent | 30afb3debe18645fd8bf645a735e3c033478913b (diff) | |
download | weechat-63714855d3cbedc49747b099533a5a259cbd74c2.zip |
core: add an option for multiline input in a buffer (closes #984)
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-input.c | 3 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 2 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 37 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 2 |
4 files changed, 39 insertions, 5 deletions
diff --git a/src/core/wee-input.c b/src/core/wee-input.c index 1ac2c82ed..3a8cd0113 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -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'; diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 4f3234e4a..e4226233f 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -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) { diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 00d254cf3..41a6791e0 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -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[] = @@ -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 }; @@ -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 */ @@ -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) @@ -1906,6 +1910,20 @@ gui_buffer_set_input_get_empty (struct t_gui_buffer *buffer, } /* + * 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. */ @@ -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) @@ -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); @@ -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)) @@ -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); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index fb2ac43b6..bc7dfec7f 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -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 */ |