mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 15:26:37 +02:00
script: add options "-ol" and "-il" in command /script, display "No scripts loaded" if no scripts are loaded
This commit is contained in:
@@ -96,21 +96,21 @@ script_action_list ()
|
||||
* Lists loaded scripts (all languages) in input.
|
||||
*
|
||||
* Sends input to buffer if send_to_buffer == 1.
|
||||
* String is translated if translated == 1 (otherwise it's English).
|
||||
*/
|
||||
|
||||
void
|
||||
script_action_list_input (int send_to_buffer)
|
||||
script_action_list_input (int send_to_buffer, int translated)
|
||||
{
|
||||
int i, length;
|
||||
char hdata_name[128], *buf, str_pos[16];
|
||||
char hdata_name[128], **buf, str_pos[16];
|
||||
struct t_hdata *hdata;
|
||||
void *ptr_script;
|
||||
|
||||
buf = malloc (16384);
|
||||
buf = weechat_string_dyn_alloc (256);
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
buf[0] = '\0';
|
||||
length = 0;
|
||||
|
||||
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
|
||||
@@ -121,35 +121,51 @@ script_action_list_input (int send_to_buffer)
|
||||
ptr_script = weechat_hdata_get_list (hdata, "scripts");
|
||||
while (ptr_script)
|
||||
{
|
||||
if (buf[0])
|
||||
strcat (buf, ", ");
|
||||
strcat (buf, weechat_hdata_string (hdata, ptr_script, "name"));
|
||||
strcat (buf, ".");
|
||||
strcat (buf, script_extension[i]);
|
||||
strcat (buf, " ");
|
||||
strcat (buf, weechat_hdata_string (hdata, ptr_script, "version"));
|
||||
length = strlen (buf);
|
||||
if (length > 16384 - 64)
|
||||
if (*buf[0])
|
||||
{
|
||||
strcat (buf, "...");
|
||||
length += 3;
|
||||
break;
|
||||
weechat_string_dyn_concat (buf, ", ");
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_string_dyn_concat (
|
||||
buf,
|
||||
(translated) ? _("Scripts loaded:") : "Scripts loaded:");
|
||||
weechat_string_dyn_concat (buf, " ");
|
||||
}
|
||||
weechat_string_dyn_concat (buf,
|
||||
weechat_hdata_string (hdata,
|
||||
ptr_script,
|
||||
"name"));
|
||||
weechat_string_dyn_concat (buf, ".");
|
||||
weechat_string_dyn_concat (buf, script_extension[i]);
|
||||
weechat_string_dyn_concat (buf, " ");
|
||||
weechat_string_dyn_concat (buf, weechat_hdata_string (hdata,
|
||||
ptr_script,
|
||||
"version"));
|
||||
ptr_script = weechat_hdata_move (hdata, ptr_script, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (buf[0])
|
||||
if (!*buf[0])
|
||||
{
|
||||
if (send_to_buffer)
|
||||
weechat_command (weechat_current_buffer (), buf);
|
||||
else
|
||||
{
|
||||
weechat_buffer_set (weechat_current_buffer (), "input", buf);
|
||||
snprintf (str_pos, sizeof (str_pos), "%d", length);
|
||||
weechat_buffer_set (weechat_current_buffer (), "input_pos", str_pos);
|
||||
}
|
||||
weechat_string_dyn_concat (
|
||||
buf,
|
||||
(translated) ? _("No scripts loaded") : "No scripts loaded");
|
||||
}
|
||||
|
||||
if (send_to_buffer)
|
||||
{
|
||||
weechat_command (weechat_current_buffer (), *buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_buffer_set (weechat_current_buffer (), "input", *buf);
|
||||
length = strlen (*buf);
|
||||
snprintf (str_pos, sizeof (str_pos), "%d", length);
|
||||
weechat_buffer_set (weechat_current_buffer (), "input_pos", str_pos);
|
||||
}
|
||||
|
||||
weechat_string_dyn_free (buf, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1250,9 +1266,13 @@ script_action_run ()
|
||||
if (argc > 1)
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "-i") == 0)
|
||||
script_action_list_input (0);
|
||||
script_action_list_input (0, 0);
|
||||
if (weechat_strcasecmp (argv[1], "-il") == 0)
|
||||
script_action_list_input (0, 1);
|
||||
else if (weechat_strcasecmp (argv[1], "-o") == 0)
|
||||
script_action_list_input (1);
|
||||
script_action_list_input (1, 0);
|
||||
else if (weechat_strcasecmp (argv[1], "-ol") == 0)
|
||||
script_action_list_input (1, 1);
|
||||
else
|
||||
script_action_list ();
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ script_command_init ()
|
||||
weechat_hook_command (
|
||||
"script",
|
||||
N_("WeeChat script manager"),
|
||||
N_("list [-o|-i]"
|
||||
N_("list [-o|-ol|-i|-il]"
|
||||
" || search <text>"
|
||||
" || show <script>"
|
||||
" || load|unload|reload <script> [<script>...]"
|
||||
@@ -299,9 +299,14 @@ script_command_init ()
|
||||
" || upgrade"
|
||||
" || update"),
|
||||
N_(" list: list loaded scripts (all languages)\n"
|
||||
" -o: send list of loaded scripts to buffer\n"
|
||||
" -o: send list of loaded scripts to buffer "
|
||||
"(string in English)\n"
|
||||
" -ol: send list of loaded scripts to buffer "
|
||||
"(translated string)\n"
|
||||
" -i: copy list of loaded scripts in command line (for "
|
||||
"sending to buffer)\n"
|
||||
"sending to buffer) (string in English)\n"
|
||||
" -il: copy list of loaded scripts in command line (for "
|
||||
"sending to buffer) (translated string)\n"
|
||||
" search: search scripts by tags, language (python, "
|
||||
"perl, ...), filename extension (py, pl, ...) or text; result is "
|
||||
"displayed on scripts buffer\n"
|
||||
|
||||
Reference in New Issue
Block a user