Skip to content

Conversation

@andrewleech
Copy link
Contributor

@andrewleech andrewleech commented Oct 24, 2023

I've been using aiorepl daily on my work project and could no longer live without it. I have however been missing some features of the built in repl, so worked to add them here!

The most regular issue I run into is needing to update / fix the line I've just typed! So this PR adds left/right cursor support with character insertion / deletion. This includes the redraw-to-end-of line stuff needed to keep the terminal looking correct.

I considered adding some python functions to the existing readline functionality in micropython, however I think trying to break out a suitable api of readline / repl interface parts suitable for use in something like this would take some effort and and code bulk not used by many users.

Another limitation I've found quite difficult lately is the inability to handle multi-line input, particularly for defining functions etc inline, or pasting a few lines of list creation. Rather than implementing full mulitline handling by detection when an "open" command is interered, I thought just adding paste mode would be simpler - it was quite clean really, though I don't print the == prompt on each line like the builtin repl does.

Lastly, I really wanted more mpremote support for my running instrument with aiorepl active, so reimplemented raw / raw-paste mode from pyexec.c. Again it'd be more efficient to expose some of the underlying c functions for this but they'd need to be refactored to allow passing in received characters which would be very messy. So, pure-python versions have been written and seem to "just work" for the current master branch mpremote for file copy and mount functionality!

@jimmo would you prefer some/all of this in an extension module? it does make the module a reasonable bit bigger....


This work was funded by Planet Innovation.

@andrewleech
Copy link
Contributor Author

Worth noting that while mpremote mount works, I've ignored soft-reset requests so not all standard usage works correctly.

@andrewleech andrewleech force-pushed the aiorepl_expand branch 2 times, most recently from 3019e90 to c2680ac Compare October 25, 2023 04:16
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Allows modifying current line, adding/deleting characters in the middle
etc.  Includes home/end keys to move to start/end of current line.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Provides support for mpremote features like cp and mount.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
@dpgeorge
Copy link
Member

Thank you, this is a great addition!

Eventually it might be a good idea to factor the C code for raw-paste to a helper function that's exposed to Python. But that can happen in the future.

@dpgeorge dpgeorge merged commit f672baa into micropython:master Dec 20, 2023
@andrewleech andrewleech deleted the aiorepl_expand branch September 6, 2024 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants