hirc

IRC client
Log | Files | Refs

commit 563841de291762c24fa2b6ad09ad505ea3350590
parent 7386eb81b251c464e600efd6cca32c707610595d
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 12 Jun 2022 21:12:01 +0100

Remove spaces inserted by tab completion if enter is hit next

Diffstat:
Msrc/commands.c | 17+----------------
Msrc/ui.c | 20++++++++++++++++++++
2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -689,14 +689,11 @@ command_set) { COMMAND( command_toggle) { struct Config *conf; - char *p; if (!str) { command_toofew("toggle"); return; } - if ((p = strrchr(str, ' ')) && *(p+1) == '\0') - *p = '\0'; if (strchr(str, ' ')) { command_toomany("toggle"); return; @@ -1097,7 +1094,6 @@ command_alias) { COMMAND( command_help) { - char *p; int cmdonly = 0; int found = 0; int i, j; @@ -1107,10 +1103,6 @@ command_help) { return; } - p = strrchr(str, ' '); - if (p && *(p+1) == '\0') - *p = '\0'; - if (strcmp(str, "commands") == 0) { hist_format(selected.history, Activity_none, HIST_UI, "SELF_HELP_START :%s", str); for (i=0; commands[i].name && commands[i].func; i++) @@ -1364,14 +1356,10 @@ narg: COMMAND( command_source) { - char *p; if (!str) { command_toofew("source"); return; } - p = strrchr(str, ' '); - if (p && *(p+1) == '\0') - *p = '\0'; /* remove trailing spaces */ config_read(homepath(str)); } @@ -1381,7 +1369,7 @@ command_dump) { int selected = 0; int def = 0, ret; int i; - char **aup, *p; + char **aup; struct Server *sp; struct Channel *chp; struct Alias *ap; @@ -1441,9 +1429,6 @@ command_dump) { return; } str = homepath(str); - p = strrchr(str, ' '); - if (p && *(p+1) == '\0') - *p = '\0'; if ((file = fopen(str, "wb")) == NULL) { ui_error("cannot open file '%s': %s", str, strerror(errno)); diff --git a/src/ui.c b/src/ui.c @@ -164,6 +164,7 @@ ui_placewindow(struct Window *window) { void ui_read(void) { static wchar_t *backup = NULL; + static int didcomplete = 0; struct Keybind *kp; char *str; wint_t key; @@ -259,6 +260,8 @@ ui_read(void) { break; case KEY_ENTER: case '\r': + if (didcomplete && input.string[input.counter - 1] == L' ') + input.string[input.counter - 1] = '\0'; if (*input.string != L'\0') { /* no need to free str as assigned to input.history[0] */ str = wctos(input.string); @@ -280,6 +283,23 @@ ui_read(void) { } break; } + + /* Completion adds a space after the completed text: this + * serves the purpose of showing the user that it has been + * completely successfully and unambiguously, and allowing them + * to begin writing quickly without having to type a space + * (this is common in most tab-completion systems). + * + * The problem is that if something is completed at the end of + * a command, and the user then hits enter, that space would be + * passed to command_* functions (previous versions of hirc did + * this, and put the onus on commands to strip trailing + * spaces). + * + * Instead, this variable is set so that trailing spaces will + * be stripped when tab completed, but not ones inserted + * manually, inside ui_read() - see the KEY_ENTER case. */ + didcomplete = (key == '\t'); } }