I'm looking for a way to replace printed text in serial.
Does MicroPython allows to send special characters?
In Python its:
sys.stdout.write("\033[F") # Cursor up one line
sys.stdout.write("\033[K") # Clear to the end of line
Remove and Replace Printed characters in serial terminal
Re: Remove and Replace Printed characters in serial terminal
It should be the same in MicroPython. What you're actually doing here is sending ANSI escape codes -- \033 puts the escape byte (i.e. it's octal for 27).
What's probably going wrong here is that whatever terminal you're using to view the output doesn't understand the escape sequences. What are you using to access the serial console?
What's probably going wrong here is that whatever terminal you're using to view the output doesn't understand the escape sequences. What are you using to access the serial console?
Re: Remove and Replace Printed characters in serial terminal
I use "mpfshell -n -c 'open ttyUSB0;repl"
Re: Remove and Replace Printed characters in serial terminal
Can you try using screen?
screen /dev/ttyUSB0 115200
(If you're new to screen, use "Ctrl-A k y" to quit)
screen /dev/ttyUSB0 115200
(If you're new to screen, use "Ctrl-A k y" to quit)
Re: Remove and Replace Printed characters in serial terminal
I don't know if this is the same, but using '\r' and "print(msg, end=' ')" should work. e.g.
Code: Select all
>> def print_and_clear(msg):
... msg_list = ['This', 'is', 'a', 'message', 'that', 'replaces', 'itself']
... print(msg, end='')
... time.sleep(1)
... print('\r'+' '*len(msg), end='\r') # This clears previous line
... for ms in msg_list:
... print(ms, end='')
... time.sleep(1)
... print('\r'+' '*len(ms), end='\r') # This clears previous line
Re: Remove and Replace Printed characters in serial terminal
Thank you for help, the carrige return "\r" works indeed.
I also found that mpfshell supports:
print("\033[XA"); // Move up X lines;
print("\033[XB"); // Move down X lines;
print("\033[XC"); // Move right X column;
print("\033[XD"); // Move left X column;
print("\033[2J"); // Clear screen
I also found that mpfshell supports:
print("\033[XA"); // Move up X lines;
print("\033[XB"); // Move down X lines;
print("\033[XC"); // Move right X column;
print("\033[XD"); // Move left X column;
print("\033[2J"); // Clear screen