int script_buffer_input_cb (void *data, struct t_gui_buffer *buffer, const char *input_data) { char *actions[][2] = { { "A", "toggleautoload" }, { "l", "load" }, { "u", "unload" }, { "L", "reload" }, { "i", "install" }, { "r", "remove" }, { "h", "hold" }, { "v", "show" }, { "d", "showdiff" }, { NULL, NULL } }; char str_command[64]; int i; /* make C compiler happy */ (void) data; /* close buffer */ if (strcmp (input_data, "q") == 0) { weechat_buffer_close (buffer); return WEECHAT_RC_OK; } if (!script_buffer_detail_script) { /* change sort keys on buffer */ if (strncmp (input_data, "s:", 2) == 0) { if (input_data[2]) weechat_config_option_set (script_config_look_sort, input_data + 2, 1); else weechat_config_option_reset (script_config_look_sort, 1); return WEECHAT_RC_OK; } /* refresh buffer */ if (strcmp (input_data, "$") == 0) { script_get_loaded_plugins_and_scripts (); script_repo_remove_all (); script_repo_file_read (1); script_buffer_refresh (1); return WEECHAT_RC_OK; } } /* execute action on a script */ for (i = 0; actions[i][0]; i++) { if (strcmp (input_data, actions[i][0]) == 0) { snprintf (str_command, sizeof (str_command), "/script %s", actions[i][1]); weechat_command (buffer, str_command); return WEECHAT_RC_OK; } } /* filter scripts with given text */ if (!script_buffer_detail_script) script_repo_filter_scripts (input_data); return WEECHAT_RC_OK; }
int script_command_script (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *error; long value; int line; /* make C compiler happy */ (void) data; if (argc == 1) { script_action_schedule ("buffer", 1, 0); return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "go") == 0) { if ((argc > 2) && script_buffer && !script_buffer_detail_script) { error = NULL; value = strtol (argv[2], &error, 10); if (error && !error[0]) { script_buffer_set_current_line (value); } } return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "search") == 0) { if (scripts_repo) script_repo_filter_scripts ((argc > 2) ? argv_eol[2] : NULL); else script_repo_set_filter ((argc > 2) ? argv_eol[2] : NULL); script_action_schedule ("buffer", 1, 0); return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "list") == 0) { script_action_schedule (argv_eol[1], 1, 0); return WEECHAT_RC_OK; } if ((weechat_strcasecmp (argv[1], "load") == 0) || (weechat_strcasecmp (argv[1], "unload") == 0) || (weechat_strcasecmp (argv[1], "reload") == 0)) { script_command_action (buffer, argv[1], (argc > 2) ? argv_eol[2] : NULL, 0); return WEECHAT_RC_OK; } if ((weechat_strcasecmp (argv[1], "install") == 0) || (weechat_strcasecmp (argv[1], "remove") == 0) || (weechat_strcasecmp (argv[1], "installremove") == 0) || (weechat_strcasecmp (argv[1], "hold") == 0) || (weechat_strcasecmp (argv[1], "show") == 0) || (weechat_strcasecmp (argv[1], "showdiff") == 0)) { script_command_action (buffer, argv[1], (argc > 2) ? argv_eol[2] : NULL, 1); return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "upgrade") == 0) { script_action_schedule ("upgrade", 1, 0); return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "update") == 0) { script_repo_file_update (0); return WEECHAT_RC_OK; } if (!script_buffer) script_buffer_open (); if (script_buffer) { weechat_buffer_set (script_buffer, "display", "1"); if (argc > 1) { if (!script_buffer_detail_script && (script_buffer_selected_line >= 0) && (script_repo_count_displayed > 0)) { if (strcmp (argv[1], "up") == 0) { value = 1; if (argc > 2) { error = NULL; value = strtol (argv[2], &error, 10); if (!error || error[0]) value = 1; } line = script_buffer_selected_line - value; if (line < 0) line = 0; if (line != script_buffer_selected_line) { script_buffer_set_current_line (line); script_buffer_check_line_outside_window (); } return WEECHAT_RC_OK; } else if (strcmp (argv[1], "down") == 0) { value = 1; if (argc > 2) { error = NULL; value = strtol (argv[2], &error, 10); if (!error || error[0]) value = 1; } line = script_buffer_selected_line + value; if (line >= script_repo_count_displayed) line = script_repo_count_displayed - 1; if (line != script_buffer_selected_line) { script_buffer_set_current_line (line); script_buffer_check_line_outside_window (); } return WEECHAT_RC_OK; } } } } script_buffer_refresh (0); return WEECHAT_RC_OK; }