From ac25043b272aa94c6c1498785fecb110f20e9fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 25 Apr 2023 22:10:48 +0200 Subject: [PATCH] core: add option `split_return` in command `/input` (closes #1916) --- ChangeLog.adoc | 1 + po/cs.po | 4 ++- po/de.po | 60 ++++++++++++++++++++++++++++++++- po/es.po | 4 ++- po/fr.po | 8 +++-- po/hu.po | 4 ++- po/it.po | 4 ++- po/ja.po | 4 ++- po/pl.po | 4 ++- po/pt.po | 4 ++- po/pt_BR.po | 4 ++- po/ru.po | 4 ++- po/sr.po | 4 ++- po/tr.po | 4 ++- po/weechat.pot | 4 ++- src/core/wee-command.c | 6 +++- src/gui/gui-input.c | 76 ++++++++++++++++++++++++++++++++---------- src/gui/gui-input.h | 1 + 18 files changed, 167 insertions(+), 33 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 07b2e27e7..220733fff 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -24,6 +24,7 @@ New features:: * core: render newline characters in chat line messages (issue #1908) * core: don't split on newline characters in printf_date_tags when input_multiline is set (issue #1909) * core: add key @kbd:[l] in cursor mode to quote line, add variable "_chat_focused_line" in function hashtable sent to hook_focus callback (issue #1913, issue #1914) + * core: add option `split_return` in command `/input` (issue #1916) * core: add command `/reset` to reset options to their default values * core: add option `rename` in command `/bar` * core: add relative move of read marker with `/buffer set unread [+/-]N` (issue #1895) diff --git a/po/cs.po b/po/cs.po index a2fbbc992..7a71ba32f 100644 --- a/po/cs.po +++ b/po/cs.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-03-25 21:13+0100\n" "Last-Translator: Ondřej Súkup \n" "Language-Team: weechat-dev \n" @@ -1851,6 +1851,8 @@ msgstr " []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/de.po b/po/de.po index b40a816ee..a1c45dbe3 100644 --- a/po/de.po +++ b/po/de.po @@ -26,7 +26,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-04-22 09:33+0200\n" "Last-Translator: Nils Görs \n" "Language-Team: German - Germany \n" @@ -2273,9 +2273,67 @@ msgstr "Funktionen für die Befehlszeile" msgid " []" msgstr " []" +#, fuzzy +#| msgid "" +#| "list of actions:\n" +#| " return: simulate key \"enter\"\n" +#| " complete_next: complete word with next completion\n" +#| " complete_previous: complete word with previous completion\n" +#| " search_text_here: search text in buffer at current position\n" +#| " search_text: search text in buffer\n" +#| " search_switch_case: switch exact case for search\n" +#| " search_switch_regex: switch search type: string/regular expression\n" +#| " search_switch_where: switch search in messages/prefixes\n" +#| " search_previous: search previous line\n" +#| " search_next: search next line\n" +#| " search_stop_here: stop search at current position\n" +#| " search_stop: stop search\n" +#| " delete_previous_char: delete previous char\n" +#| " delete_next_char: delete next char\n" +#| " delete_previous_word: delete previous word\n" +#| " delete_previous_word_whitespace: delete previous word (until " +#| "whitespace)\n" +#| " delete_next_word: delete next word\n" +#| " delete_beginning_of_line: delete from beginning of line until cursor\n" +#| " delete_beginning_of_input: delete from beginning of input until cursor\n" +#| " delete_end_of_line: delete from cursor until end of line\n" +#| " delete_end_of_input: delete from cursor until end of input\n" +#| " delete_line: delete current line\n" +#| " delete_input: delete entire input\n" +#| " clipboard_paste: paste from the internal clipboard\n" +#| " transpose_chars: transpose two chars\n" +#| " undo: undo last command line action\n" +#| " redo: redo last command line action\n" +#| " move_beginning_of_line: move cursor to beginning of line\n" +#| " move_beginning_of_input: move cursor to beginning of input\n" +#| " move_end_of_line: move cursor to end of line\n" +#| " move_end_of_input: move cursor to end of input\n" +#| " move_previous_char: move cursor to previous char\n" +#| " move_next_char: move cursor to next char\n" +#| " move_previous_word: move cursor to previous word\n" +#| " move_next_word: move cursor to next word\n" +#| " move_previous_line: move cursor to previous line\n" +#| " move_next_line: move cursor to next line\n" +#| " history_previous: recall previous command in current buffer history\n" +#| " history_next: recall next command in current buffer history\n" +#| " history_global_previous: recall previous command in global history\n" +#| " history_global_next: recall next command in global history\n" +#| " grab_key: grab a key (optional argument: delay for end of grab, default " +#| "is 500 milliseconds)\n" +#| " grab_key_command: grab a key with its associated command (optional " +#| "argument: delay for end of grab, default is 500 milliseconds)\n" +#| " grab_mouse: grab mouse event code\n" +#| " grab_mouse_area: grab mouse event code with area\n" +#| " insert: insert text in command line (escaped chars are allowed, see /" +#| "help print)\n" +#| " send: send text to the buffer\n" +#| "\n" +#| "This command is used by key bindings or plugins." msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/es.po b/po/es.po index 73d0b04ff..cb96ba360 100644 --- a/po/es.po +++ b/po/es.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-03-25 21:13+0100\n" "Last-Translator: Santiago Forero \n" "Language-Team: weechat-dev \n" @@ -2318,6 +2318,8 @@ msgstr " []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/fr.po b/po/fr.po index 6c193f6a1..d7410d870 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" -"PO-Revision-Date: 2023-04-22 08:04+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" +"PO-Revision-Date: 2023-04-25 22:07+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" "Language: fr\n" @@ -2232,6 +2232,8 @@ msgstr " []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" @@ -2286,6 +2288,8 @@ msgid "" msgstr "" "liste des actions :\n" " return : simuler la touche \"entrée\"\n" +" split_return : découper la ligne de commande sur les caractères de retour " +"chariot puis simuler la touche \"entrée\" pour chaque ligne\n" " complete_next : compléter le mot avec la complétion suivante\n" " complete_previous : compléter le mot avec la complétion précédente\n" " search_text_here : chercher du texte dans le tampon à la position " diff --git a/po/hu.po b/po/hu.po index 1b231f187..36e9effaa 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2022-10-15 22:51+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -1718,6 +1718,8 @@ msgstr "fogadó típusa [paraméterek]" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/it.po b/po/it.po index 8f8d9687f..8e92394b5 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-03-25 21:13+0100\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: weechat-dev \n" @@ -1913,6 +1913,8 @@ msgstr " []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/ja.po b/po/ja.po index 00fb1db62..ba7b859fa 100644 --- a/po/ja.po +++ b/po/ja.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-03-25 21:13+0100\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/pl.po b/po/pl.po index 8b014c9cc..202ca2f07 100644 --- a/po/pl.po +++ b/po/pl.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-04-13 20:09+0200\n" "Last-Translator: Krzysztof Korościk \n" "Language-Team: Polish \n" @@ -2530,6 +2530,8 @@ msgstr " []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/pt.po b/po/pt.po index 6e711a36d..122f6aef4 100644 --- a/po/pt.po +++ b/po/pt.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-03-25 21:13+0100\n" "Last-Translator: Vasco Almeida \n" "Language-Team: Portuguese <>\n" @@ -2222,6 +2222,8 @@ msgstr " []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/pt_BR.po b/po/pt_BR.po index db8cb1328..d59a7294a 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-03-25 21:13+0100\n" "Last-Translator: Érico Nogueira \n" "Language-Team: weechat-dev \n" @@ -1987,6 +1987,8 @@ msgstr " []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/ru.po b/po/ru.po index a12d6cdf1..55de171ca 100644 --- a/po/ru.po +++ b/po/ru.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-03-25 21:13+0100\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: weechat-dev \n" @@ -1739,6 +1739,8 @@ msgstr "адресат тип [аргументы]" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/sr.po b/po/sr.po index fb7d5b551..e0619ad48 100644 --- a/po/sr.po +++ b/po/sr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-04-13 20:10+0200\n" "Last-Translator: Ivan Pešić \n" "Language-Team: weechat-dev \n" @@ -2516,6 +2516,8 @@ msgstr "<акција> [<аргументи>]" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/tr.po b/po/tr.po index 382ab289d..ae4c4945c 100644 --- a/po/tr.po +++ b/po/tr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-23 16:51+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2023-04-23 16:51+0200\n" "Last-Translator: Emir SARI \n" "Language-Team: weechat-dev \n" @@ -2219,6 +2219,8 @@ msgstr " []" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/po/weechat.pot b/po/weechat.pot index f4c4b029a..6683bebc9 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-04-22 08:03+0200\n" +"POT-Creation-Date: 2023-04-25 22:07+0200\n" "PO-Revision-Date: 2014-08-16 10:27+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -1586,6 +1586,8 @@ msgstr "" msgid "" "list of actions:\n" " return: simulate key \"enter\"\n" +" split_return: split input on newlines then simulate key \"enter\" for each " +"line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" diff --git a/src/core/wee-command.c b/src/core/wee-command.c index c28b376d1..8d753774c 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -3456,6 +3456,8 @@ COMMAND_CALLBACK(input) gui_input_clipboard_paste (buffer); else if (string_strcmp (argv[1], "return") == 0) gui_input_return (buffer); + else if (string_strcmp (argv[1], "split_return") == 0) + gui_input_split_return (buffer); else if (string_strcmp (argv[1], "complete_next") == 0) gui_input_complete_next (buffer); else if (string_strcmp (argv[1], "complete_previous") == 0) @@ -8356,6 +8358,8 @@ command_init () N_(" []"), N_("list of actions:\n" " return: simulate key \"enter\"\n" + " split_return: split input on newlines then simulate key \"enter\" " + "for each line\n" " complete_next: complete word with next completion\n" " complete_previous: complete word with previous completion\n" " search_text_here: search text in buffer at current position\n" @@ -8411,7 +8415,7 @@ command_init () " send: send text to the buffer\n" "\n" "This command is used by key bindings or plugins."), - "return || " + "return || split_return || " "complete_next || complete_previous || search_text_here || " "search_text || search_switch_case || search_switch_regex || " "search_switch_where || search_previous || search_next || " diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index ebc38b1be..02fc5cab6 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -317,7 +317,7 @@ gui_input_clipboard_paste (struct t_gui_buffer *buffer) } /* - * Terminates line: + * Sends data to buffer: * - saves text in history * - stops completion * - frees all undos @@ -325,10 +325,27 @@ gui_input_clipboard_paste (struct t_gui_buffer *buffer) * - sends data to buffer. */ +void +gui_input_send_data_to_buffer (struct t_gui_buffer *buffer, char *data) +{ + gui_history_add (buffer, data); + gui_buffer_undo_free_all (buffer); + buffer->ptr_history = NULL; + gui_history_ptr = NULL; + gui_input_text_changed_modifier_and_signal (buffer, + 0, /* save undo */ + 1); /* stop completion */ + (void) input_data (buffer, data, NULL); +} + +/* + * Sends current input to buffer. + */ + void gui_input_return (struct t_gui_buffer *buffer) { - char *command; + char *data; if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input) && gui_window_bare_display) @@ -340,24 +357,49 @@ gui_input_return (struct t_gui_buffer *buffer) && (buffer->input_get_empty || (buffer->input_buffer_size > 0))) { buffer->input_buffer[buffer->input_buffer_size] = '\0'; - command = strdup (buffer->input_buffer); - if (command) + data = strdup (buffer->input_buffer); + if (gui_input_optimize_size (buffer, 0, 0)) { - gui_history_add (buffer, buffer->input_buffer); - if (gui_input_optimize_size (buffer, 0, 0)) + buffer->input_buffer[0] = '\0'; + buffer->input_buffer_pos = 0; + buffer->input_buffer_1st_display = 0; + } + if (data) + { + gui_input_send_data_to_buffer (buffer, data); + free (data); + } + } +} + +/* + * Splits input on newlines then sends each line to buffer. + */ + +void +gui_input_split_return (struct t_gui_buffer *buffer) +{ + char **lines; + int i, num_lines; + + if (buffer->input + && (buffer->input_get_empty || (buffer->input_buffer_size > 0))) + { + buffer->input_buffer[buffer->input_buffer_size] = '\0'; + lines = string_split (buffer->input_buffer, "\n", NULL, 0, 0, &num_lines); + if (gui_input_optimize_size (buffer, 0, 0)) + { + buffer->input_buffer[0] = '\0'; + buffer->input_buffer_pos = 0; + buffer->input_buffer_1st_display = 0; + } + if (lines) + { + for (i = 0; i < num_lines; i++) { - buffer->input_buffer[0] = '\0'; - buffer->input_buffer_pos = 0; - buffer->input_buffer_1st_display = 0; + gui_input_send_data_to_buffer (buffer, lines[i]); } - gui_buffer_undo_free_all (buffer); - buffer->ptr_history = NULL; - gui_history_ptr = NULL; - gui_input_text_changed_modifier_and_signal (buffer, - 0, /* save undo */ - 1); /* stop completion */ - (void) input_data (buffer, command, NULL); - free (command); + string_free_split (lines); } } } diff --git a/src/gui/gui-input.h b/src/gui/gui-input.h index e6d2172c5..a75459f3b 100644 --- a/src/gui/gui-input.h +++ b/src/gui/gui-input.h @@ -39,6 +39,7 @@ extern void gui_input_insert_string (struct t_gui_buffer *buffer, const char *string); extern void gui_input_clipboard_paste (struct t_gui_buffer *buffer); extern void gui_input_return (struct t_gui_buffer *buffer); +extern void gui_input_split_return (struct t_gui_buffer *buffer); extern void gui_input_complete_next (struct t_gui_buffer *buffer); extern void gui_input_complete_previous (struct t_gui_buffer *buffer); extern void gui_input_search_text_here (struct t_gui_buffer *buffer);