flozz / nautilus-terminal

A terminal embedded in Nautilus, the GNOME's file browser
GNU General Public License v3.0
323 stars 24 forks source link

Feature/auto clean #55

Closed tkachen closed 3 years ago

tkachen commented 3 years ago

Fix for #16 issue. Two new things here.

  1. Now current user input will be cut from terminal before each directory change.

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.

  1. New 'auto-clean' setting for cleaning terminal after changing directory. It has 2 modes. One cleans like ctrl+l shortcut, which keeps scrollback. And another one using 'clear' command which removes scrollback.
flozz commented 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

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 :)

tkachen commented 3 years ago

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. Screenshot from 2021-04-08 06-57-41

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.

flozz commented 3 years ago

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:

AUTO_CLEAN_CLEAR = 1
AUTO_CLEAR_RESET = 2

(do not hesitate if you have better names)

tkachen commented 3 years ago

Done :D

flozz commented 3 years ago

Thank you :)