URI: 
       tHandle newline in uiprompt directly - sacc - sacc(omys), simple console gopher client (mirror)
  HTML git clone https://git.parazyd.org/sacc
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit 199205cac2adb7d40a2ef7f4e20ad617e6437323
   DIR parent 21f414d9dc19a291e207562994c35bb9e3df3bc1
  HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Fri, 28 Jul 2017 22:11:21 +0200
       
       Handle newline in uiprompt directly
       
       Diffstat:
         M sacc.c                              |      10 +++-------
         M ui_ti.c                             |       5 ++++-
         M ui_txt.c                            |       6 +++++-
       
       3 files changed, 12 insertions(+), 9 deletions(-)
       ---
   DIR diff --git a/sacc.c b/sacc.c
       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);
   DIR diff --git a/ui_ti.c b/ui_ti.c
       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;
   DIR diff --git a/ui_txt.c b/ui_txt.c
       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;