Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
17d299b7
Commit
17d299b7
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
lib/mp-readline: Use simple VT100 commands to speed up line redraw.
parent
4b35a546
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/mp-readline/readline.c
+24
-15
24 additions, 15 deletions
lib/mp-readline/readline.c
with
24 additions
and
15 deletions
lib/mp-readline/readline.c
+
24
−
15
View file @
17d299b7
...
...
@@ -57,6 +57,25 @@ STATIC char *str_dup_maybe(const char *str) {
return
s2
;
}
STATIC
void
move_cursor_back
(
uint
pos
)
{
if
(
pos
<=
4
)
{
// fast path for most common case of 1 step back
stdout_tx_strn
(
"
\b\b\b\b
"
,
pos
);
}
else
{
char
vt100_command
[
6
];
// snprintf needs space for the terminating null character
int
n
=
snprintf
(
&
vt100_command
[
0
],
sizeof
(
vt100_command
),
"
\x1b
[%u"
,
pos
);
if
(
n
>
0
)
{
vt100_command
[
n
]
=
'D'
;
// replace null char
stdout_tx_strn
(
vt100_command
,
n
+
1
);
}
}
}
STATIC
void
erase_line_from_cursor
(
void
)
{
stdout_tx_strn
(
"
\x1b
[K"
,
3
);
}
typedef
struct
_readline_t
{
vstr_t
*
line
;
int
orig_line_len
;
...
...
@@ -66,7 +85,7 @@ typedef struct _readline_t {
char
escape_seq_buf
[
1
];
}
readline_t
;
readline_t
rl
;
STATIC
readline_t
rl
;
int
readline_process_char
(
int
c
)
{
int
last_line_len
=
rl
.
line
->
len
;
...
...
@@ -215,30 +234,20 @@ end_key:
}
// redraw command prompt, efficiently
// TODO we can probably use some more sophisticated VT100 commands here
if
(
redraw_step_back
>
0
)
{
for
(
int
i
=
0
;
i
<
redraw_step_back
;
i
++
)
{
stdout_tx_str
(
"
\b
"
);
}
move_cursor_back
(
redraw_step_back
);
rl
.
cursor_pos
-=
redraw_step_back
;
}
if
(
redraw_from_cursor
)
{
if
(
rl
.
line
->
len
<
last_line_len
)
{
// erase old chars
for
(
int
i
=
rl
.
cursor_pos
;
i
<
last_line_len
;
i
++
)
{
stdout_tx_str
(
" "
);
}
// step back
for
(
int
i
=
rl
.
cursor_pos
;
i
<
last_line_len
;
i
++
)
{
stdout_tx_str
(
"
\b
"
);
}
// (number of chars to erase: last_line_len - rl.cursor_pos)
erase_line_from_cursor
();
}
// draw new chars
stdout_tx_strn
(
rl
.
line
->
buf
+
rl
.
cursor_pos
,
rl
.
line
->
len
-
rl
.
cursor_pos
);
// move cursor forward if needed (already moved forward by length of line, so move it back)
for
(
int
i
=
rl
.
cursor_pos
+
redraw_step_forward
;
i
<
rl
.
line
->
len
;
i
++
)
{
stdout_tx_str
(
"
\b
"
);
}
move_cursor_back
(
rl
.
line
->
len
-
(
rl
.
cursor_pos
+
redraw_step_forward
));
rl
.
cursor_pos
+=
redraw_step_forward
;
}
else
if
(
redraw_step_forward
>
0
)
{
// draw over old chars to move cursor forwards
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment