Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
b7a4f15b
Commit
b7a4f15b
authored
Apr 26, 2015
by
Damien George
Browse files
mp-readline: Save "prompt" string in readline state.
parent
ad9daadf
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/mp-readline/readline.c
View file @
b7a4f15b
...
...
@@ -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
);
...
...
lib/mp-readline/readline.h
View file @
b7a4f15b
...
...
@@ -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
);
stmhal/pyexec.c
View file @
b7a4f15b
...
...
@@ -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
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment