szermatt / mistty

Shell/Comint alternative with a fully functional terminal for Emacs 29.1 and later.
GNU General Public License v3.0
92 stars 5 forks source link

Is there a way to make the _clear_ command work? #20

Closed simurgh9 closed 2 weeks ago

simurgh9 commented 3 weeks ago

I often end up running clear by the force of habit and it messes up the buffer. Is there a way to make this command run as intended, i.e., clear the buffer/terminal?

szermatt commented 3 weeks ago

clear should not mess up the buffer. When it works as it should, clear just opens a new prompt because, while it clears the terminal, the MisTTY buffer displays keeps a log of previous terminal states, so you just don't see anything. So you get something like the following in the buffer:

$ clear
$ 

At least that's what happen in my tests. I'd like to look into why it doesn't work that way for you. What does it mean that it messes up the buffer? Could you give an example? What's the value of the TERM env variable? What shell are you running? Which version? Which version of Emacs and MisTTY are you using?

Maybe when MisTTY detects a clear or reset command, it should call (recenter-top-bottom 0) (or 1 for multi-line prompts) so that only the prompt is visible - but the history remains in the buffer. I could definitely add something like that, but first it's important for clear to not mess things up.

In the meantime, in case you type clear by mistake in a MisTTY buffer, you could add the following to your .bashrc or the equivalent for your shell if you don't use bash:

if [ ! -z "$INSIDE_EMACS" ]; then 
  alias clear="echo disabled for now"; 
fi
simurgh9 commented 2 weeks ago

Here is some info,

Here is how it looks,

sc

Btw the vterm people also be doing some special to handle a clear. I am running zsh and echo $TERM yields eterm-color.

szermatt commented 2 weeks ago

I can reproduce the problem and I'm working on a fix. The issue seems specific to clear on zsh; reset works. The screen grab was very useful in understanding what's going on. Thank you!

simurgh9 commented 2 weeks ago

BTW since we are doing this. It would also not be a bad idea if when exit is ran, the mistty window is also quit.

szermatt commented 2 weeks ago

BTW since we are doing this. It would also not be a bad idea if when exit is ran, the mistty window is also quit.

Yes, it might be a good idea to add some hooks to allow tracking the process state. I'll add that separately from this issue.

szermatt commented 2 weeks ago

With the latest commits, "clear" should work, even on zsh, and empty the window. Please give it a try and let me know if something's not working for you.

The changes are also available on melpa, starting from 20240902.959.

szermatt commented 1 week ago

BTW since we are doing this. It would also not be a bad idea if when exit is ran, the mistty window is also quit.

This can now be turned on as described on: https://mistty.readthedocs.io/en/latest/extensions.html#mistty-after-process-end-hook