Open dowski opened 5 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.
clear
and cls
in a shell basically sends a <ESC>[2j
or as a Python string b"\x1b[2j"
to the terminal, which then interprets it and clears the screen<ESC>c
or in Python b"\x1bc"
, which resets the terminalThen 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.
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')
oros.system('cls')
ordisplay.clear()
on the micro:bit.