mp-readline: Save "prompt" string in readline state.
This commit is contained in:
parent
ad9daadf8a
commit
b7a4f15b34
|
@ -85,6 +85,7 @@ typedef struct _readline_t {
|
|||
int hist_cur;
|
||||
int cursor_pos;
|
||||
char escape_seq_buf[1];
|
||||
const char *prompt;
|
||||
} readline_t;
|
||||
|
||||
STATIC readline_t rl;
|
||||
|
@ -260,23 +261,26 @@ end_key:
|
|||
return -1;
|
||||
}
|
||||
|
||||
void readline_note_newline(void) {
|
||||
void readline_note_newline(const char *prompt) {
|
||||
rl.orig_line_len = rl.line->len;
|
||||
rl.cursor_pos = rl.orig_line_len;
|
||||
rl.prompt = prompt;
|
||||
mp_hal_stdout_tx_str(prompt);
|
||||
}
|
||||
|
||||
void readline_init(vstr_t *line) {
|
||||
void readline_init(vstr_t *line, const char *prompt) {
|
||||
rl.line = line;
|
||||
rl.orig_line_len = line->len;
|
||||
rl.escape_seq = ESEQ_NONE;
|
||||
rl.escape_seq_buf[0] = 0;
|
||||
rl.hist_cur = -1;
|
||||
rl.cursor_pos = rl.orig_line_len;
|
||||
rl.prompt = prompt;
|
||||
mp_hal_stdout_tx_str(prompt);
|
||||
}
|
||||
|
||||
int readline(vstr_t *line, const char *prompt) {
|
||||
mp_hal_stdout_tx_str(prompt);
|
||||
readline_init(line);
|
||||
readline_init(line, prompt);
|
||||
for (;;) {
|
||||
int c = mp_hal_stdin_rx_chr();
|
||||
int r = readline_process_char(c);
|
||||
|
|
|
@ -33,6 +33,6 @@
|
|||
void readline_init0(void);
|
||||
int readline(vstr_t *line, const char *prompt);
|
||||
|
||||
void readline_init(vstr_t *line);
|
||||
void readline_note_newline(void);
|
||||
void readline_init(vstr_t *line, const char *prompt);
|
||||
void readline_note_newline(const char *prompt);
|
||||
int readline_process_char(int c);
|
||||
|
|
|
@ -181,14 +181,13 @@ friendly_repl_t repl;
|
|||
void pyexec_friendly_repl_init(void) {
|
||||
vstr_init(&repl.line, 32);
|
||||
repl.cont_line = false;
|
||||
readline_init(&repl.line);
|
||||
mp_hal_stdout_tx_str(">>> ");
|
||||
readline_init(&repl.line, ">>> ");
|
||||
}
|
||||
|
||||
void pyexec_friendly_repl_reset() {
|
||||
repl.cont_line = false;
|
||||
void pyexec_friendly_repl_reset(void) {
|
||||
vstr_reset(&repl.line);
|
||||
readline_init(&repl.line);
|
||||
repl.cont_line = false;
|
||||
readline_init(&repl.line, ">>> ");
|
||||
}
|
||||
|
||||
int pyexec_friendly_repl_process_char(int c) {
|
||||
|
@ -229,8 +228,7 @@ int pyexec_friendly_repl_process_char(int c) {
|
|||
|
||||
vstr_add_byte(&repl.line, '\n');
|
||||
repl.cont_line = true;
|
||||
mp_hal_stdout_tx_str("... ");
|
||||
readline_note_newline();
|
||||
readline_note_newline("... ");
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
|
@ -251,8 +249,7 @@ int pyexec_friendly_repl_process_char(int c) {
|
|||
|
||||
if (mp_repl_continue_with_input(vstr_null_terminated_str(&repl.line))) {
|
||||
vstr_add_byte(&repl.line, '\n');
|
||||
mp_hal_stdout_tx_str("... ");
|
||||
readline_note_newline();
|
||||
readline_note_newline("... ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -270,7 +267,6 @@ exec: ;
|
|||
friendly_repl_reset: // TODO
|
||||
input_restart:
|
||||
pyexec_friendly_repl_reset();
|
||||
mp_hal_stdout_tx_str(">>> ");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue