mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 03:33:12 +02:00
core: add option split_return in command /input (closes #1916)
This commit is contained in:
@@ -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_("<action> [<arguments>]"),
|
||||
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 || "
|
||||
|
||||
+59
-17
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user