]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
edit: Add support for prompt string with internal line edit
authorJouni Malinen <j@w1.fi>
Sun, 5 Aug 2012 17:48:25 +0000 (20:48 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 5 Aug 2012 17:48:25 +0000 (20:48 +0300)
Signed-hostap: Jouni Malinen <j@w1.fi>

src/utils/edit.c

index 4ccef21aab0a1f3007ee336886454ab3df2fd395..b01e08dfc2a92775fd6ec11cc6525ac5c285b301 100644 (file)
@@ -20,6 +20,7 @@ static int cmdbuf_pos = 0;
 static int cmdbuf_len = 0;
 static char currbuf[CMD_BUF_LEN];
 static int currbuf_valid = 0;
+static const char *ps2 = NULL;
 
 #define HISTORY_MAX 100
 
@@ -47,7 +48,7 @@ void edit_clear_line(void)
 {
        int i;
        putchar('\r');
-       for (i = 0; i < cmdbuf_len + 2; i++)
+       for (i = 0; i < cmdbuf_len + 2 + (ps2 ? (int) os_strlen(ps2) : 0); i++)
                putchar(' ');
 }
 
@@ -346,7 +347,7 @@ static void process_cmd(void)
 {
 
        if (cmdbuf_len == 0) {
-               printf("\n");
+               printf("\n%s> ", ps2 ? ps2 : "");
                fflush(stdout);
                return;
        }
@@ -356,7 +357,7 @@ static void process_cmd(void)
        cmdbuf_pos = 0;
        cmdbuf_len = 0;
        edit_cmd_cb(edit_cb_ctx, cmdbuf);
-       printf("");
+       printf("%s> ", ps2 ? ps2 : "");
        fflush(stdout);
 }
 
@@ -1132,7 +1133,8 @@ int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
 
        eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL);
 
-       printf("> ");
+       ps2 = ps;
+       printf("%s> ", ps2 ? ps2 : "");
        fflush(stdout);
 
        return 0;
@@ -1161,11 +1163,11 @@ void edit_redraw(void)
 {
        char tmp;
        cmdbuf[cmdbuf_len] = '\0';
-       printf("\r> %s", cmdbuf);
+       printf("\r%s> %s", ps2 ? ps2 : "", cmdbuf);
        if (cmdbuf_pos != cmdbuf_len) {
                tmp = cmdbuf[cmdbuf_pos];
                cmdbuf[cmdbuf_pos] = '\0';
-               printf("\r> %s", cmdbuf);
+               printf("\r%s> %s", ps2 ? ps2 : "", cmdbuf);
                cmdbuf[cmdbuf_pos] = tmp;
        }
        fflush(stdout);