scripts: fix duplicated lines in output of script eval (python, perl, ruby, lua and guile)

When there was a call to a hook callback during the eval, the output buffer was
cleared too late, and displayed multiple times in the buffer.

This commit clears the buffer even before we display it (this display can
trigger a hook callback).
v2.8-utf8proc
Sébastien Helleu 2018-07-25 20:19:26 +02:00
parent df27a3b76a
commit b7d6be5936
6 changed files with 96 additions and 65 deletions

View File

@ -21,6 +21,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
Bug fixes::
* core: send signal "key_pressed" for mouse code only if the string is UTF-8 valid (issue #1220)
* scripts: fix duplicated lines in output of script eval (python, perl, ruby, lua and guile)
[[v2.2]]
== Version 2.2 (2018-07-14)

View File

@ -118,36 +118,42 @@ void
weechat_guile_output_flush ()
{
const char *ptr_command;
char *command;
char *temp_buffer, *command;
int length;
if (!*guile_buffer_output[0])
return;
/* if there's no buffer, we catch the output, so there's no flush */
if (guile_eval_mode && !guile_eval_buffer)
return;
temp_buffer = strdup (*guile_buffer_output);
if (!temp_buffer)
return;
weechat_string_dyn_copy (guile_buffer_output, NULL);
if (guile_eval_mode)
{
/* if there's no buffer, we catch the output, so there's no flush */
if (!guile_eval_buffer)
return;
if (guile_eval_send_input)
{
if (guile_eval_exec_commands)
ptr_command = *guile_buffer_output;
ptr_command = temp_buffer;
else
ptr_command = weechat_string_input_for_buffer (*guile_buffer_output);
ptr_command = weechat_string_input_for_buffer (temp_buffer);
if (ptr_command)
{
weechat_command (guile_eval_buffer, *guile_buffer_output);
weechat_command (guile_eval_buffer, temp_buffer);
}
else
{
length = 1 + strlen (*guile_buffer_output) + 1;
length = 1 + strlen (temp_buffer) + 1;
command = malloc (length);
if (command)
{
snprintf (command, length, "%c%s",
*guile_buffer_output[0], *guile_buffer_output);
temp_buffer[0], temp_buffer);
weechat_command (guile_eval_buffer,
(command[0]) ? command : " ");
free (command);
@ -156,7 +162,7 @@ weechat_guile_output_flush ()
}
else
{
weechat_printf (guile_eval_buffer, "%s", *guile_buffer_output);
weechat_printf (guile_eval_buffer, "%s", temp_buffer);
}
}
else
@ -167,10 +173,10 @@ weechat_guile_output_flush ()
weechat_gettext ("%s: stdout/stderr (%s): %s"),
GUILE_PLUGIN_NAME,
(guile_current_script) ? guile_current_script->name : "?",
*guile_buffer_output);
temp_buffer);
}
weechat_string_dyn_copy (guile_buffer_output, NULL);
free (temp_buffer);
}
/*

View File

@ -190,36 +190,42 @@ void
weechat_lua_output_flush ()
{
const char *ptr_command;
char *command;
char *temp_buffer, *command;
int length;
if (!*lua_buffer_output[0])
return;
/* if there's no buffer, we catch the output, so there's no flush */
if (lua_eval_mode && !lua_eval_buffer)
return;
temp_buffer = strdup (*lua_buffer_output);
if (!temp_buffer)
return;
weechat_string_dyn_copy (lua_buffer_output, NULL);
if (lua_eval_mode)
{
/* if there's no buffer, we catch the output, so there's no flush */
if (!lua_eval_buffer)
return;
if (lua_eval_send_input)
{
if (lua_eval_exec_commands)
ptr_command = *lua_buffer_output;
ptr_command = temp_buffer;
else
ptr_command = weechat_string_input_for_buffer (*lua_buffer_output);
ptr_command = weechat_string_input_for_buffer (temp_buffer);
if (ptr_command)
{
weechat_command (lua_eval_buffer, *lua_buffer_output);
weechat_command (lua_eval_buffer, temp_buffer);
}
else
{
length = 1 + strlen (*lua_buffer_output) + 1;
length = 1 + strlen (temp_buffer) + 1;
command = malloc (length);
if (command)
{
snprintf (command, length, "%c%s",
*lua_buffer_output[0], *lua_buffer_output);
temp_buffer[0], temp_buffer);
weechat_command (lua_eval_buffer,
(command[0]) ? command : " ");
free (command);
@ -228,7 +234,7 @@ weechat_lua_output_flush ()
}
else
{
weechat_printf (lua_eval_buffer, "%s", *lua_buffer_output);
weechat_printf (lua_eval_buffer, "%s", temp_buffer);
}
}
else
@ -239,10 +245,10 @@ weechat_lua_output_flush ()
weechat_gettext ("%s: stdout/stderr (%s): %s"),
LUA_PLUGIN_NAME,
(lua_current_script) ? lua_current_script->name : "?",
*lua_buffer_output);
temp_buffer);
}
weechat_string_dyn_copy (lua_buffer_output, NULL);
free (temp_buffer);
}
/*

View File

@ -226,36 +226,42 @@ void
weechat_perl_output_flush ()
{
const char *ptr_command;
char *command;
char *temp_buffer, *command;
int length;
if (!*perl_buffer_output[0])
return;
/* if there's no buffer, we catch the output, so there's no flush */
if (perl_eval_mode && !perl_eval_buffer)
return;
temp_buffer = strdup (*perl_buffer_output);
if (!temp_buffer)
return;
weechat_string_dyn_copy (perl_buffer_output, NULL);
if (perl_eval_mode)
{
/* if there's no buffer, we catch the output, so there's no flush */
if (!perl_eval_buffer)
return;
if (perl_eval_send_input)
{
if (perl_eval_exec_commands)
ptr_command = *perl_buffer_output;
ptr_command = temp_buffer;
else
ptr_command = weechat_string_input_for_buffer (*perl_buffer_output);
ptr_command = weechat_string_input_for_buffer (temp_buffer);
if (ptr_command)
{
weechat_command (perl_eval_buffer, *perl_buffer_output);
weechat_command (perl_eval_buffer, temp_buffer);
}
else
{
length = 1 + strlen (*perl_buffer_output) + 1;
length = 1 + strlen (temp_buffer) + 1;
command = malloc (length);
if (command)
{
snprintf (command, length, "%c%s",
*perl_buffer_output[0], *perl_buffer_output);
temp_buffer[0], temp_buffer);
weechat_command (perl_eval_buffer,
(command[0]) ? command : " ");
free (command);
@ -264,7 +270,7 @@ weechat_perl_output_flush ()
}
else
{
weechat_printf (perl_eval_buffer, "%s", *perl_buffer_output);
weechat_printf (perl_eval_buffer, "%s", temp_buffer);
}
}
else
@ -275,10 +281,10 @@ weechat_perl_output_flush ()
weechat_gettext ("%s: stdout/stderr (%s): %s"),
PERL_PLUGIN_NAME,
(perl_current_script) ? perl_current_script->name : "?",
*perl_buffer_output);
temp_buffer);
}
weechat_string_dyn_copy (perl_buffer_output, NULL);
free (temp_buffer);
}
/*

View File

@ -337,36 +337,42 @@ void
weechat_python_output_flush ()
{
const char *ptr_command;
char *command;
char *temp_buffer, *command;
int length;
if (!*python_buffer_output[0])
return;
/* if there's no buffer, we catch the output, so there's no flush */
if (python_eval_mode && !python_eval_buffer)
return;
temp_buffer = strdup (*python_buffer_output);
if (!temp_buffer)
return;
weechat_string_dyn_copy (python_buffer_output, NULL);
if (python_eval_mode)
{
/* if there's no buffer, we catch the output, so there's no flush */
if (!python_eval_buffer)
return;
if (python_eval_send_input)
{
if (python_eval_exec_commands)
ptr_command = *python_buffer_output;
ptr_command = temp_buffer;
else
ptr_command = weechat_string_input_for_buffer (*python_buffer_output);
ptr_command = weechat_string_input_for_buffer (temp_buffer);
if (ptr_command)
{
weechat_command (python_eval_buffer, *python_buffer_output);
weechat_command (python_eval_buffer, temp_buffer);
}
else
{
length = 1 + strlen (*python_buffer_output) + 1;
length = 1 + strlen (temp_buffer) + 1;
command = malloc (length);
if (command)
{
snprintf (command, length, "%c%s",
*python_buffer_output[0], *python_buffer_output);
temp_buffer[0], temp_buffer);
weechat_command (python_eval_buffer,
(command[0]) ? command : " ");
free (command);
@ -375,7 +381,7 @@ weechat_python_output_flush ()
}
else
{
weechat_printf (python_eval_buffer, "%s", *python_buffer_output);
weechat_printf (python_eval_buffer, "%s", temp_buffer);
}
}
else
@ -386,10 +392,10 @@ weechat_python_output_flush ()
weechat_gettext ("%s: stdout/stderr (%s): %s"),
PYTHON_PLUGIN_NAME,
(python_current_script) ? python_current_script->name : "?",
*python_buffer_output);
temp_buffer);
}
weechat_string_dyn_copy (python_buffer_output, NULL);
free (temp_buffer);
}
/*

View File

@ -362,36 +362,42 @@ void
weechat_ruby_output_flush ()
{
const char *ptr_command;
char *command;
char *temp_buffer, *command;
int length;
if (!*ruby_buffer_output[0])
return;
/* if there's no buffer, we catch the output, so there's no flush */
if (ruby_eval_mode && !ruby_eval_buffer)
return;
temp_buffer = strdup (*ruby_buffer_output);
if (!temp_buffer)
return;
weechat_string_dyn_copy (ruby_buffer_output, NULL);
if (ruby_eval_mode)
{
/* if there's no buffer, we catch the output, so there's no flush */
if (!ruby_eval_buffer)
return;
if (ruby_eval_send_input)
{
if (ruby_eval_exec_commands)
ptr_command = *ruby_buffer_output;
ptr_command = temp_buffer;
else
ptr_command = weechat_string_input_for_buffer (*ruby_buffer_output);
ptr_command = weechat_string_input_for_buffer (temp_buffer);
if (ptr_command)
{
weechat_command (ruby_eval_buffer, *ruby_buffer_output);
weechat_command (ruby_eval_buffer, temp_buffer);
}
else
{
length = 1 + strlen (*ruby_buffer_output) + 1;
length = 1 + strlen (temp_buffer) + 1;
command = malloc (length);
if (command)
{
snprintf (command, length, "%c%s",
*ruby_buffer_output[0], *ruby_buffer_output);
temp_buffer[0], temp_buffer);
weechat_command (ruby_eval_buffer,
(command[0]) ? command : " ");
free (command);
@ -400,7 +406,7 @@ weechat_ruby_output_flush ()
}
else
{
weechat_printf (ruby_eval_buffer, "%s", *ruby_buffer_output);
weechat_printf (ruby_eval_buffer, "%s", temp_buffer);
}
}
else
@ -411,10 +417,10 @@ weechat_ruby_output_flush ()
weechat_gettext ("%s: stdout/stderr (%s): %s"),
RUBY_PLUGIN_NAME,
(ruby_current_script) ? ruby_current_script->name : "?",
*ruby_buffer_output);
temp_buffer);
}
weechat_string_dyn_copy (ruby_buffer_output, NULL);
free (temp_buffer);
}
/*