From f9e15cd60b98444a2ca50ecaaf9812cadfd63e66 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 2 Jun 2014 03:19:59 -0400 Subject: [PATCH] no trailing space for command tab-complete --- src/main.c | 2 +- src/toxic_strings.c | 23 +++++++++++++++++------ src/windows.c | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index c85c57a..0cc86e7 100644 --- a/src/main.c +++ b/src/main.c @@ -212,7 +212,7 @@ static int nodelist_load(char *filename) if (name == NULL || port == NULL || key_ascii == NULL) continue; - strncpy(nodes[linecnt], name, NODELEN); + snprintf(nodes[linecnt], sizeof(nodes[linecnt]), "%s", name); nodes[linecnt][NODELEN - 1] = 0; ports[linecnt] = htons(atoi(port)); diff --git a/src/toxic_strings.c b/src/toxic_strings.c index 994c0fd..329791f 100644 --- a/src/toxic_strings.c +++ b/src/toxic_strings.c @@ -195,19 +195,31 @@ 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; - - if (sub[0] != '/') /* make sure it's not a command */ - n_endchrs = 2; + n_endchrs = sub[0] == '/' ? 0 : 2; /* no end chars if command */ } 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; @@ -225,9 +237,8 @@ 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 = (int) * pos - s_len; + int strt = *pos - s_len; int diff = m_len - s_len + n_endchrs; if (*len + diff > MAX_STR_SIZE) diff --git a/src/windows.c b/src/windows.c index 4f4310b..ce2cd06 100644 --- a/src/windows.c +++ b/src/windows.c @@ -435,7 +435,7 @@ void refresh_inactive_windows(void) for (i = 0; i < MAX_WINDOWS_NUM; ++i) { ToxWindow *a = &windows[i]; - if (a->active && a != active_window && !a->is_prompt) /* if prompt doesn't have scroll mode */ + if (a->active && a != active_window && (a->is_chat || a->is_groupchat)) line_info_print(a); } }