mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 01:26:58 +00:00
auto remove spaces from tab completion
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15986 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -429,17 +429,57 @@ static void set_fn_keys(cli_profile_t *profile)
|
||||
|
||||
|
||||
#ifdef HAVE_EDITLINE
|
||||
#define end_of_p(_s) (*_s == '\0' ? _s : _s + strlen(_s) - 1)
|
||||
|
||||
static unsigned char complete(EditLine * el, int ch)
|
||||
{
|
||||
const LineInfo *lf = el_line(el);
|
||||
char cmd_str[2048] = "";
|
||||
unsigned char ret = CC_REDISPLAY;
|
||||
char *dup = strdup(lf->buffer);
|
||||
char *buf = dup;
|
||||
int pos = 0, sc = 0;
|
||||
char *p;
|
||||
|
||||
if (!esl_strlen_zero(lf->cursor) && !esl_strlen_zero(lf->buffer)) {
|
||||
pos = (lf->cursor - lf->buffer);
|
||||
}
|
||||
if (pos > 0) {
|
||||
*(buf + pos) = '\0';
|
||||
}
|
||||
|
||||
if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
while (*buf == ' ') {
|
||||
buf++;
|
||||
sc++;
|
||||
}
|
||||
|
||||
if (!*buf && sc) {
|
||||
el_deletestr(el, sc);
|
||||
}
|
||||
|
||||
sc = 0;
|
||||
|
||||
p = end_of_p(buf);
|
||||
while(p >= buf && *p == ' ') {
|
||||
sc++;
|
||||
p--;
|
||||
}
|
||||
|
||||
if (sc > 1) {
|
||||
el_deletestr(el, sc - 1);
|
||||
*(p + 2) = '\0';
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (*lf->cursor) {
|
||||
snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", (long int)(lf->cursor - lf->buffer), lf->buffer);
|
||||
snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", (long)pos, buf);
|
||||
} else {
|
||||
snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", lf->buffer);
|
||||
snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", buf);
|
||||
}
|
||||
|
||||
esl_send_recv(global_handle, cmd_str);
|
||||
@@ -474,6 +514,8 @@ static unsigned char complete(EditLine * el, int ch)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
esl_safe_free(dup);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user