In my script, I print backspace symbols in order to implement some UI in console as it's described here.
It works well, but now I want to save the output to my log file (via redirecting stdout). When I read this file using command-line tools such as tail
or less
I get the final 'output view' of my script (i.e. the completed progress bar in this case) and this behavior is preferred for me. But if I open the log file with vim it shows all written symbols to the file with just escaping backslashes as ^H
.
How can I set my vim to display my log file similarly to less
or tail
here?
Here's an example.
1) The python script:
import sys
import time
for i in range(10):
if i: sys.stdout.write(chr(8) * 10)
sys.stdout.write(str(i) * 10)
sys.stdout.flush()
time.sleep(0.5)
sys.stdout.write('\n')
sys.stdout.flush()
2) Running the script: python program.py > out.txt
3) The output of the cat out.txt
:
$ cat out.txt
9999999999
4) Displayed content of my vim out.txt
:
0000000000^H^H^H^H^H^H^H^H^H^H1111111111^H^H^H^H^H^H^H^H^H^H2222222222^H^H^H^H^H^H^H^H^H^H3333333333^H^H^H^H^H^H^H^H^H^H4444444444^H^H^H^H^H^H^H^H^H^H5555555555^H^H^H^H^H^H^H^H^H^H6666666666^H^H^H^H^H^H^H^H^H^H7777777777^H^H^H^H^H^H^H^H^H^H8888888888^H^H^H^H^H^H^H^H^H^H9999999999