zsquareplusc / mpy-repl-tool

Yet an other tool to transfer files, execute files and so on via the Python prompt, used for MicroPython
Other
19 stars 5 forks source link

there --interactive doesn't delete removed characters #9

Open cefn opened 6 years ago

cefn commented 6 years ago

Hi there,

I have successfully used there to connect to my Micropython board ( https://vgkits.org/blog/2018/05/08/introductory-video-tutorial/ ) but while I think it's doing everything correctly under the hood, I find that the character grid in CMD.exe is not being updated to reflect deletion.

For example, if I type the word 'hello' into the Micropython prompt, then delete three characters, the cursor goes backwards until it's under the first 'l', but all the 'llo' letters remain visible. The same applies to the behaviour of delete. The remaining characters are redrawn one position to the left, but the disappearing character on the far right is never deleted.

When I press enter I get the reassuring indication that actually the 'llo' were in fact removed (the backspace key logic works) but the 'llo' was never removed from the local visual buffer...

Is this an issue which should properly be filed with colorama, assuming that the proper bytes are being received from the serial link, but that it is not updating the character grid properly for the ANSI codes? I am struggling to unpack the layers here and know which part is responsible for which.

Backspace

C:\Users\cefn\Downloads\mpy-repl-tool-master>python -m there --interactive
--- Patched Miniterm-MPY on COM3  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

MicroPython v1.9.3-8-g63826ac5c on 2017-11-01; ESP module with ESP8266
Type "help()" for more information.
>>> hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'he' is not defined
>>>

(Forward) Deletion

C:\Users\cefn\Downloads\mpy-repl-tool-master>python -m there --interactive
--- Patched Miniterm-MPY on COM3  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

MicroPython v1.9.3-8-g63826ac5c on 2017-11-01; ESP module with ESP8266
Type "help()" for more information.
>>> heooo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'he' is not defined
>>>
zsquareplusc commented 6 years ago

colorama tries to provide facilities to make colorful command line programs portable and only supports a small set of other escape codes. A bigger problem also that it uses regexp to identify escape sequences and thus can not handle cases where it receives the data char by char (as it may happen when receiving from the serial port, there is a hack in mpy_miniterm because of that). So it is not perfect for emulation a terminal... Though it works fine for its intended use case.

I think it would be good to make ma proper terminal with escape handling in pySerial, so that the control sequences can be handled e.g. by Windows API calls (as colorama does) or by other "renderers" such as a wxPython widget or so. But that should be done in a separate project and not within miniterm. Otherwise it can not be called "mini" anymore ;-) and one purpose of miniterm is to debug serial connections so it should be simple and consistent across platforms (that's why it now also filters escape sequences on systems where they would work).