/* line index used for fetching lines from history */
static int line_index = 0;
+static char prompt_buf[10] = "> ";
+static const char *prompt = prompt_buf;
/*
* Moves cursor to right or left
*
* before parsing event though line_len and line_buf_ix are
*/
if (line_len > 0)
- printf(">%s", line_buf);
+ printf("%s%s", prompt, line_buf);
else
- putchar('>');
+ printf("%s", prompt);
/* move cursor to it's place */
terminal_move_cursor(line_buf_ix - line_len);
putchar(' ');
}
/* draw new line */
- printf("\r>%s", line_buf);
+ printf("\r%s%s", prompt, line_buf);
/* set up indexes to new line */
line_len = strlen(line_buf);
line_buf_ix = line_len;
break;
case KEY_HOME:
/* move to beginning of line and update position */
- putchar('\r');
- putchar('>');
+ printf("\r%s", prompt);
line_buf_ix = 0;
break;
case KEY_END:
line_index = -1;
/* print new line */
putchar(c);
+ prompt = "";
process_line(line_buf);
/* clear current line */
line_buf[0] = '\0';
- putchar('>');
+ prompt = prompt_buf;
+ printf("%s", prompt);
break;
case '\t':
/* tab processing */
tcgetattr(0, &tios);
tios.c_lflag &= ~(ICANON | ECHO);
tcsetattr(0, TCSANOW, &tios);
- putchar('>');
+ printf("%s", prompt);
}