aiorepl features: cursor, paste and raw mode. #756
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.