bowl over previous commit that nearly conflicted out 2 hours of coding (grrr) hook new complete api up to FSAPI and export tab completion down to fs_cli

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15956 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-12-15 00:19:30 +00:00
parent ed317e3d4a
commit a0479189b2
3 changed files with 80 additions and 1 deletions

View File

@ -428,6 +428,57 @@ static void set_fn_keys(cli_profile_t *profile)
}
#ifdef HAVE_EDITLINE
static unsigned char complete(EditLine * el, int ch)
{
const LineInfo *lf = el_line(el);
char cmd_str[2048] = "";
unsigned char ret = CC_REDISPLAY;
if (*lf->cursor) {
snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", lf->cursor - lf->buffer, lf->buffer);
} else {
snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", lf->buffer);
}
esl_send_recv(global_handle, cmd_str);
if (global_handle->last_sr_event && global_handle->last_sr_event->body) {
char *r = global_handle->last_sr_event->body;
char *w, *p;
if (r) {
if ((w = strstr(r, "\n\nwrite="))) {
int len = 0;
*w = '\0';
w += 8;
len = atoi(w);
if ((p = strchr(w, ':'))) {
w = p + 1;
}
printf("%s\n\n\n", r);
el_deletestr(el, len);
el_insertstr(el, w);
} else {
printf("%s\n", r);
}
}
fflush(stdout);
}
return ret;
}
#endif
int main(int argc, char *argv[])
{
esl_handle_t handle = {{0}};
@ -673,6 +724,7 @@ int main(int argc, char *argv[])
el = el_init(__FILE__, stdout, stdout, stdout);
el_set(el, EL_PROMPT, &prompt);
el_set(el, EL_EDITOR, "emacs");
myhistory = history_init();
el_set(el, EL_ADDFN, "f1-key", "F1 KEY PRESS", console_f1key);
@ -711,6 +763,9 @@ int main(int argc, char *argv[])
el_set(el, EL_BIND, "\004", "EOF-key", NULL);
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
el_set(el, EL_BIND, "^I", "ed-complete", NULL);
if (myhistory == 0) {
esl_log(ESL_LOG_ERROR, "history could not be initialized\n");
goto done;

View File

@ -82,9 +82,10 @@ SWITCH_DECLARE(switch_status_t) switch_console_shutdown(void);
SWITCH_DECLARE(switch_status_t) switch_console_add_complete_func(const char *name, switch_console_complete_callback_t cb);
SWITCH_DECLARE(switch_status_t) switch_console_del_complete_func(const char *name);
SWITCH_DECLARE(switch_status_t) switch_console_run_complete_func(const char *func, const char *line,
const char *cursor, switch_console_callback_match_t **matches);
const char *last_word, switch_console_callback_match_t **matches);
SWITCH_DECLARE(void) switch_console_push_match(switch_console_callback_match_t **matches, const char *new_val);
SWITCH_DECLARE(void) switch_console_free_matches(switch_console_callback_match_t **matches);
SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *last_word, FILE *console_out, switch_stream_handle_t *stream);
SWITCH_END_EXTERN_C
#endif

View File

@ -767,6 +767,28 @@ SWITCH_STANDARD_API(expand_function)
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(console_complete_function)
{
const char *p, *cursor = NULL;
int c;
if (zstr(cmd)) {
cmd = " ";
}
if ((p = strstr(cmd, "c="))) {
p += 2;
c = atoi(p);
if ((p = strchr(p, ';'))) {
cmd = p + 1;
cursor = cmd + c;
}
}
switch_console_complete(cmd, cursor, NULL, stream);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(eval_function)
{
@ -3791,6 +3813,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "break", "Break", break_function, BREAK_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "complete", "Complete", complete_function, COMPLETE_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "cond", "Eval a conditional", cond_function, "<expr> ? <true val> : <false val>");
SWITCH_ADD_API(commands_api_interface, "console_complete", "", console_complete_function, "<line>");
SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "db_cache", "db cache management", db_cache_function, "status");
SWITCH_ADD_API(commands_api_interface, "domain_exists", "check if a domain exists", domain_exists_function, "<domain>");