]> git.pond.sub.org Git - empserver/commitdiff
client: Redistribute work among prompt() and its callers
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Dec 2015 07:29:17 +0000 (08:29 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 09:22:29 +0000 (11:22 +0200)
Two out of three callers want an extra newline.  Letting the callers
do that is simpler, especially now that readline added another case to
prompt().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/client/servcmd.c

index a8cce6fd44cc3c86a569b7a64ac63043e8afbd1f..75ec60b38629eeb009020c93c7ccab6f9e839138 100644 (file)
@@ -89,6 +89,7 @@ servercmd(int code, char *arg, int len)
                (void)fclose(redir_fp);
            redir_fp = NULL;
        }
+       outch('\n');
        prompt(code, the_prompt, teles);
        executing = 0;
        break;
@@ -115,6 +116,7 @@ servercmd(int code, char *arg, int len)
        if (arg[0] != '\n') {
            snprintf(teles, sizeof(teles), "(%.*s) ", len - 1, arg);
            if (!redir_fp) {
+               outch('\n');
                putchar('\07');
                prompt(code, the_prompt, teles);
            }
@@ -138,21 +140,18 @@ servercmd(int code, char *arg, int len)
 static void
 prompt(int code, char *prompt, char *teles)
 {
-    char *nl;
     char pr[1024];
 
-    nl = code == C_PROMPT || code == C_INFORM ? "\n" : "";
     snprintf(pr, sizeof(pr), "%s%s", teles, prompt);
 #ifdef HAVE_LIBREADLINE
     rl_set_prompt(pr);
-    printf("%s", nl);
     rl_forced_update_display();
 #else  /* !HAVE_LIBREADLINE */
-    printf("%s%s", nl, pr);
+    printf("%s", pr);
     fflush(stdout);
 #endif /* !HAVE_LIBREADLINE */
     if (auxfp) {
-       fprintf(auxfp, "%s%s%s", nl, teles, prompt);
+       fprintf(auxfp, "%s%s", teles, prompt);
        fflush(auxfp);
     }
 }