mu-editor / mu

A small, simple editor for beginner Python programmers. Written in Python and Qt5.
http://codewith.mu
GNU General Public License v3.0
1.41k stars 437 forks source link

Clearing the output console #750

Open dowski opened 5 years ago

dowski commented 5 years ago

It would be useful to be able to clear the output section of the editor while running a script. Maybe via an API that Mu provides? This would be similar to calling os.system('clear') or os.system('cls') or display.clear() on the micro:bit.

dybber commented 4 years ago

Hi @dowski,

I believe the way support this in, Mu would amount to extending the support for VT100 escape codes, that Mu can receive from a MicroPython script, to also support clear or reset commands.

Then on the microbit side, users would write their own function, such as:

from microbit import uart

VT100_CLEAR = b"\x1b[2j"
def clear_repl():
    uart.write(VT100_CLEAR)

VT100_RESET = b"\x1bc"
def reset_repl():
    uart.write(VT100_RESET)

Currently, these doesn't do anything, but Mu should then be extended to support receiving and interpreting those VT100 escape codes as "clear the repl".

This parsing of VT100 codes happens as part of the MicroPythonREPLPane class in mu/interface/panes.py, but it will probably be easier to wait until PR #1026 has been merged, as it refactors a lot of the code involved.