Unexpected terminal behavior after SSH session ends unexpectedly
I am regularly experiencing an unexpected behavior in my terminal, with the following sequence:
- connection to a remote server
- usage of a command/software that will be embedeed in the terminal (text editor, top…)
- session ends unexpectedly
- any mouse interaction injects unexpected characters in the terminal (and it is impossible to select, copy’n’paste, and so on); for example:
- just clicking:
0;129;19M
- selecting:
0;48;37M0;73;38m
So my question is two-fold:
- what is causing this behavior (the root cause)?
- how to circumvent this?
Use ESC [?1000l
to disable mouse events:
printf 'e[?1000l'
The reason you need to do this is because the application enabled mouse events but was unable to disable them in the normal manner ("session ends unexpectedly").
References
- How to get MouseMove and MouseClick in bash on StackOverflow
- XTerm Control Sequences (PDF)