| Date: Fri, 28 Jul 2017 22:11:21 +0200
Handle newline in uiprompt directly
Diffstat:
sacc.c | 10 +++-------
ui_ti.c | 5 ++++-
ui_txt.c | 6 +++++-
3 files changed, 12 insertions(+), 9 deletions(-)
--- |
| t@@ -412,9 +412,7 @@ downloaditem(Item *item)
if (!(path = uiprompt("Download to [%s] (^D cancel): ", file)))
return;
- if (path[1])
- path[strlen(path)-1] = '\0';
- else
+ if (!path[0])
path = xstrdup(file);
if (tag = item->tag) {
t@@ -499,9 +497,7 @@ plumbitem(Item *item)
tag = NULL;
}
- if (path[1]) {
- path[strlen(path)-1] = '\0';
-
+ if (path[0]) {
if (tag && !strcmp(tag, path))
goto cleanup;
t@@ -594,7 +590,7 @@ searchselector(Item *item)
if (!(exp = uiprompt("Enter search string (^D cancel) [%s]: ", pexp)))
return NULL;
- if (strcmp(exp, pexp) && exp[1]) {
+ if (exp[0] && strcmp(exp, pexp)) {
n += 1 + strlen(exp);
tag = xmalloc(n);
snprintf(tag, n, "%s\t%s", selector, exp); |
| t@@ -81,8 +81,11 @@ uiprompt(char *fmt, ...)
putp(tparm(restore_cursor));
fflush(stdout);
- if (r > 0)
+ if (r > 0) {
+ if (input[r - 1] == '\n')
+ input[--r] = '\0';
return input;
+ }
free(input);
return NULL; |
| t@@ -75,6 +75,7 @@ uiprompt(char *fmt, ...)
va_list ap;
char *input = NULL;
size_t n = 0;
+ ssize_t r;
va_start(ap, fmt);
vprintf(fmt, ap);
t@@ -82,8 +83,11 @@ uiprompt(char *fmt, ...)
fflush(stdout);
- if (getline(&input, &n, stdin) > 0)
+ if ((r = getline(&input, &n, stdin)) > 0) {
+ if (input[r - 1] == '\n')
+ input[--r] = '\0';
return input;
+ }
free(input);
return NULL; |