Closed tkachen closed 3 years ago
Hello,
Instead of calling the clear
command or simulating the ctrl+l
key press, you can send ANSI escape sequence to the terminal
clear
is \x1Bc
ctrl+l
is \x1B[2J\x1B[H
Exemple:
terminal.feed(b"\x1Bc")
For the ctrl+e, ctrl+u
I do not know what is the equivalent sequence, if any, but I will take a look :)
To be honest, that escape sequence method is where I started =) I tried to clean terminal by "\x1Bc" and other methods but couldn't get rid of output line with "cd" command.
Only after this I moved to simulating shortcuts and then found ctrl-u + ctrl-y combinations and tried to preserve user input and restore it after navigation.
To be honest, that escape sequence method is where I started =) I tried to clean terminal by "\x1Bc" and other methods but couldn't get rid of output line with "cd" command.
Ok you are right, the sequence is read by vte before the shell has the time to execute the cd
command... So we will keep your solution :)
So the only remarks I have are:
We should allow to disable the ctrl+e ctrl+u
as it could be incompatible with some shell or shell mode (I am thinking to the vi mode of Bash for example (set -o vi
if you want to test))
Please add and use some constants in the code for the "auto clean" option... something like
AUTO_CLEAN_CLEAR = 1
AUTO_CLEAR_RESET = 2
(do not hesitate if you have better names)
Done :D
Thank you :)
Fix for #16 issue. Two new things here.
This will prevent errors after appending ' cd ...' to something already typed in terminal. I'm doing this by triggering 'ctrl-u' shortcut which cuts current user input in some separate buffer.
I tried to restore content after directory change but I have some problem with detecting is there any user input at all. Without this information I can't apply 'ctrl-y' shortcut (which puts content from buffer back to terminal) in all situations. In case when there was no any user input 'ctrl-u' won't clear that buffer. And 'ctrl-y' will fill terminal with something that could be in that buffer before.
But anyway user still can restore it manually by Ctrl-y shortcut.