1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-01 16:06:44 +02:00

better fix for trailing spaces issue

This commit is contained in:
Jfreegman
2014-06-03 20:35:00 -04:00
parent 789c491c1e
commit 97dedd32fb
6 changed files with 31 additions and 16 deletions

View File

@ -111,6 +111,22 @@ void reset_buf(wchar_t *buf, size_t *pos, size_t *len)
*len = 0;
}
/* Removes trailing spaces from buf. */
void rm_trailing_spaces_buf(wchar_t *buf, size_t *pos, size_t *len)
{
if (*len <= 0)
return;
if (buf[*len - 1] != ' ')
return;
if (*pos == *len)
--(*pos);
buf[--(*len)] = L'\0';
rm_trailing_spaces_buf(buf, pos, len);
}
#define HIST_PURGE MAX_LINE_HIST / 4
/* shifts hist items back and makes room for HIST_PURGE new entries */
@ -195,31 +211,19 @@ int complete_line(wchar_t *buf, size_t *pos, size_t *len, const void *list, int
uint8_t tmp[MAX_STR_SIZE];
snprintf(tmp, sizeof(tmp), "%s", ubuf);
tmp[*pos] = '\0';
int n_endchrs = 1; /* 1 = append space to end of match, 2 = append ": ", 0 = append nothing */
const uint8_t *endchrs;
uint8_t *sub = strrchr(tmp, ' ');
int n_endchrs = 1; /* 1 = append space to end of match, 2 = append ": " */
if (!sub++) {
sub = tmp;
n_endchrs = sub[0] == '/' ? 0 : 2; /* no end chars if command */
if (sub[0] != '/') /* make sure it's not a command */
n_endchrs = 2;
}
if (string_is_empty(sub))
return -1;
switch(n_endchrs) {
case 0:
endchrs = "";
break;
case 1:
endchrs = " ";
break;
case 2:
endchrs = ": ";
break;
}
int s_len = strlen(sub);
const uint8_t *match;
bool is_match = false;
@ -237,6 +241,7 @@ int complete_line(wchar_t *buf, size_t *pos, size_t *len, const void *list, int
return -1;
/* put match in correct spot in buf and append endchars (space or ": ") */
const uint8_t *endchrs = n_endchrs == 1 ? " " : ": ";
int m_len = strlen(match);
int strt = *pos - s_len;
int diff = m_len - s_len + n_endchrs;