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
7d588b0c
Commit
7d588b0c
authored
Jul 09, 2015
by
Tom Soulanille
Committed by
Damien George
Jul 26, 2015
Browse files
lib/mp-readline: Add emacs-style control characters for cursor movement.
Disabled by default. Adds 108 bytes to Thumb2 arch when enabled.
parent
cd14188b
Changes
5
Show whitespace changes
Inline
Side-by-side
lib/mp-readline/readline.c
View file @
7d588b0c
...
@@ -111,12 +111,44 @@ int readline_process_char(int c) {
...
@@ -111,12 +111,44 @@ int readline_process_char(int c) {
}
else
if
(
c
==
CHAR_CTRL_A
)
{
}
else
if
(
c
==
CHAR_CTRL_A
)
{
// CTRL-A with non-empty line is go-to-start-of-line
// CTRL-A with non-empty line is go-to-start-of-line
goto
home_key
;
goto
home_key
;
#if MICROPY_REPL_EMACS_KEYS
}
else
if
(
c
==
CHAR_CTRL_B
)
{
// CTRL-B with non-empty line is go-back-one-char
goto
left_arrow_key
;
#endif
}
else
if
(
c
==
CHAR_CTRL_C
)
{
}
else
if
(
c
==
CHAR_CTRL_C
)
{
// CTRL-C with non-empty line is cancel
// CTRL-C with non-empty line is cancel
return
c
;
return
c
;
#if MICROPY_REPL_EMACS_KEYS
}
else
if
(
c
==
CHAR_CTRL_D
)
{
// CTRL-D with non-empty line is delete-at-cursor
goto
delete_key
;
#endif
}
else
if
(
c
==
CHAR_CTRL_E
)
{
}
else
if
(
c
==
CHAR_CTRL_E
)
{
// CTRL-E is go-to-end-of-line
// CTRL-E is go-to-end-of-line
goto
end_key
;
goto
end_key
;
#if MICROPY_REPL_EMACS_KEYS
}
else
if
(
c
==
CHAR_CTRL_F
)
{
// CTRL-F with non-empty line is go-forward-one-char
goto
right_arrow_key
;
}
else
if
(
c
==
CHAR_CTRL_K
)
{
// CTRL-K is kill from cursor to end-of-line, inclusive
vstr_cut_tail_bytes
(
rl
.
line
,
last_line_len
-
rl
.
cursor_pos
);
// set redraw parameters
redraw_from_cursor
=
true
;
}
else
if
(
c
==
CHAR_CTRL_N
)
{
// CTRL-N is go to next line in history
goto
down_arrow_key
;
}
else
if
(
c
==
CHAR_CTRL_P
)
{
// CTRL-P is go to previous line in history
goto
up_arrow_key
;
}
else
if
(
c
==
CHAR_CTRL_U
)
{
// CTRL-U is kill from beginning-of-line up to cursor
vstr_cut_out_bytes
(
rl
.
line
,
rl
.
orig_line_len
,
rl
.
cursor_pos
-
rl
.
orig_line_len
);
// set redraw parameters
redraw_step_back
=
rl
.
cursor_pos
-
rl
.
orig_line_len
;
redraw_from_cursor
=
true
;
#endif
}
else
if
(
c
==
'\r'
)
{
}
else
if
(
c
==
'\r'
)
{
// newline
// newline
mp_hal_stdout_tx_str
(
"
\r\n
"
);
mp_hal_stdout_tx_str
(
"
\r\n
"
);
...
@@ -181,6 +213,9 @@ int readline_process_char(int c) {
...
@@ -181,6 +213,9 @@ int readline_process_char(int c) {
}
else
{
}
else
{
rl
.
escape_seq
=
ESEQ_NONE
;
rl
.
escape_seq
=
ESEQ_NONE
;
if
(
c
==
'A'
)
{
if
(
c
==
'A'
)
{
#if MICROPY_REPL_EMACS_KEYS
up_arrow_key:
#endif
// up arrow
// up arrow
if
(
rl
.
hist_cur
+
1
<
(
int
)
READLINE_HIST_SIZE
&&
MP_STATE_PORT
(
readline_hist
)[
rl
.
hist_cur
+
1
]
!=
NULL
)
{
if
(
rl
.
hist_cur
+
1
<
(
int
)
READLINE_HIST_SIZE
&&
MP_STATE_PORT
(
readline_hist
)[
rl
.
hist_cur
+
1
]
!=
NULL
)
{
// increase hist num
// increase hist num
...
@@ -194,6 +229,9 @@ int readline_process_char(int c) {
...
@@ -194,6 +229,9 @@ int readline_process_char(int c) {
redraw_step_forward
=
rl
.
line
->
len
-
rl
.
orig_line_len
;
redraw_step_forward
=
rl
.
line
->
len
-
rl
.
orig_line_len
;
}
}
}
else
if
(
c
==
'B'
)
{
}
else
if
(
c
==
'B'
)
{
#if MICROPY_REPL_EMACS_KEYS
down_arrow_key:
#endif
// down arrow
// down arrow
if
(
rl
.
hist_cur
>=
0
)
{
if
(
rl
.
hist_cur
>=
0
)
{
// decrease hist num
// decrease hist num
...
@@ -209,11 +247,17 @@ int readline_process_char(int c) {
...
@@ -209,11 +247,17 @@ int readline_process_char(int c) {
redraw_step_forward
=
rl
.
line
->
len
-
rl
.
orig_line_len
;
redraw_step_forward
=
rl
.
line
->
len
-
rl
.
orig_line_len
;
}
}
}
else
if
(
c
==
'C'
)
{
}
else
if
(
c
==
'C'
)
{
#if MICROPY_REPL_EMACS_KEYS
right_arrow_key:
#endif
// right arrow
// right arrow
if
(
rl
.
cursor_pos
<
rl
.
line
->
len
)
{
if
(
rl
.
cursor_pos
<
rl
.
line
->
len
)
{
redraw_step_forward
=
1
;
redraw_step_forward
=
1
;
}
}
}
else
if
(
c
==
'D'
)
{
}
else
if
(
c
==
'D'
)
{
#if MICROPY_REPL_EMACS_KEYS
left_arrow_key:
#endif
// left arrow
// left arrow
if
(
rl
.
cursor_pos
>
rl
.
orig_line_len
)
{
if
(
rl
.
cursor_pos
>
rl
.
orig_line_len
)
{
redraw_step_back
=
1
;
redraw_step_back
=
1
;
...
@@ -238,7 +282,10 @@ end_key:
...
@@ -238,7 +282,10 @@ end_key:
redraw_step_forward
=
rl
.
line
->
len
-
rl
.
cursor_pos
;
redraw_step_forward
=
rl
.
line
->
len
-
rl
.
cursor_pos
;
}
else
if
(
rl
.
escape_seq_buf
[
0
]
==
'3'
)
{
}
else
if
(
rl
.
escape_seq_buf
[
0
]
==
'3'
)
{
// delete
// delete
if
(
rl
.
cursor_pos
>=
rl
.
orig_line_len
&&
rl
.
cursor_pos
<
rl
.
line
->
len
)
{
#if MICROPY_REPL_EMACS_KEYS
delete_key:
#endif
if
(
rl
.
cursor_pos
<
rl
.
line
->
len
)
{
vstr_cut_out_bytes
(
rl
.
line
,
rl
.
cursor_pos
,
1
);
vstr_cut_out_bytes
(
rl
.
line
,
rl
.
cursor_pos
,
1
);
redraw_from_cursor
=
true
;
redraw_from_cursor
=
true
;
}
}
...
...
lib/mp-readline/readline.h
View file @
7d588b0c
...
@@ -29,6 +29,11 @@
...
@@ -29,6 +29,11 @@
#define CHAR_CTRL_C (3)
#define CHAR_CTRL_C (3)
#define CHAR_CTRL_D (4)
#define CHAR_CTRL_D (4)
#define CHAR_CTRL_E (5)
#define CHAR_CTRL_E (5)
#define CHAR_CTRL_F (6)
#define CHAR_CTRL_K (11)
#define CHAR_CTRL_N (14)
#define CHAR_CTRL_P (16)
#define CHAR_CTRL_U (21)
void
readline_init0
(
void
);
void
readline_init0
(
void
);
int
readline
(
vstr_t
*
line
,
const
char
*
prompt
);
int
readline
(
vstr_t
*
line
,
const
char
*
prompt
);
...
...
py/mpconfig.h
View file @
7d588b0c
...
@@ -303,6 +303,11 @@
...
@@ -303,6 +303,11 @@
#define MICROPY_HELPER_REPL (0)
#define MICROPY_HELPER_REPL (0)
#endif
#endif
// Whether to include emacs-style readline behavior in REPL
#ifndef MICROPY_REPL_EMACS_KEYS
#define MICROPY_REPL_EMACS_KEYS (1)
#endif
// Whether port requires event-driven REPL functions
// Whether port requires event-driven REPL functions
#ifndef MICROPY_REPL_EVENT_DRIVEN
#ifndef MICROPY_REPL_EVENT_DRIVEN
#define MICROPY_REPL_EVENT_DRIVEN (0)
#define MICROPY_REPL_EVENT_DRIVEN (0)
...
...
stmhal/mpconfigport.h
View file @
7d588b0c
...
@@ -39,6 +39,7 @@
...
@@ -39,6 +39,7 @@
#define MICROPY_ENABLE_FINALISER (1)
#define MICROPY_ENABLE_FINALISER (1)
#define MICROPY_STACK_CHECK (1)
#define MICROPY_STACK_CHECK (1)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_REPL_EMACS_KEYS (1)
#define MICROPY_ENABLE_SOURCE_LINE (1)
#define MICROPY_ENABLE_SOURCE_LINE (1)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
...
...
unix/mpconfigport.h
View file @
7d588b0c
...
@@ -52,6 +52,7 @@
...
@@ -52,6 +52,7 @@
#define MICROPY_DEBUG_PRINTERS (1)
#define MICROPY_DEBUG_PRINTERS (1)
#define MICROPY_USE_READLINE_HISTORY (1)
#define MICROPY_USE_READLINE_HISTORY (1)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_REPL_EMACS_KEYS (1)
#define MICROPY_HELPER_LEXER_UNIX (1)
#define MICROPY_HELPER_LEXER_UNIX (1)
#define MICROPY_ENABLE_SOURCE_LINE (1)
#define MICROPY_ENABLE_SOURCE_LINE (1)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
...
...
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