GNU Screen weird characters on click

6,507

Solution 1

Something that runs inside GNU screen decided it was running in an xterm (or similar) instead and enabled Application Mouse mode. (Or something you run in that terminal before you attached to GNU screen, possibly even before ssh, which did not properly reset itself.) This is often the case if $TERM is not “screen” but e.g. “xterm” or “screen.xterm”. The latter is seen on Debian systems (and derivates) that have ncurses-term installed; try purging that package (on host and raspi).

Otherwise, reset (as was already said) or printf \\x033c may help temporarily. Or, of course, the proper escape sequences to tell your terminal emulator to disable mouse mode.

Solution 2

reset has its place, but clears your screen. If you are running xterm or anything compatible, the shortest, least intrusive thing to use would be

printf '\033[?9l'

That is not explicitly stated in the Mouse Tracking section of XTerm Control Sequences, but xterm allows you to reset (disable) mouse mode by turning off any of the possible modes that might be turned on. Those are documented as named constants:

 #define SET_X10_MOUSE               9
 #define SET_VT200_MOUSE             1000
 #define SET_VT200_HIGHLIGHT_MOUSE   1001
 #define SET_BTN_EVENT_MOUSE         1002
 #define SET_ANY_EVENT_MOUSE         1003

and 9 is the shortest.

Mouse-mode is turned on by many applications. If one exits without turning it off, that produces the odd characters which you saw. ncurses applications turn mouse-mode off in endwin, which all well-behaved curses application call. Other applications may not use (n)curses, or may forget to call endwin.

ncurses applications check if xterm-mouse mode is available by testing for the kmous capability (which is part of the screen terminal description). That has been the standard way to test for the feature since 1999, so it is unlikely that an application turned mouse mode on accidentally. Rather, it indicates an application that forgot to do its job.

There is, by the way, no screen.xterm entry in Debian's ncurses-term package (keeping it is more helpful than removing it). Here is a list of all of the screen-related entries in that package. Most are used for fixing discrepancies in screen behavior for various terminals:

/usr/share/terminfo/s/screen.konsole
/usr/share/terminfo/s/screen-16color-bce
/usr/share/terminfo/s/screen-16color
/usr/share/terminfo/s/screen3
/usr/share/terminfo/s/screen.mrxvt
/usr/share/terminfo/s/screen-bce.Eterm
/usr/share/terminfo/s/screen-bce.gnome
/usr/share/terminfo/s/screen.xterm-xfree86
/usr/share/terminfo/s/screen-bce.konsole
/usr/share/terminfo/s/screen-bce.mlterm
/usr/share/terminfo/s/screen-256color-s
/usr/share/terminfo/s/screen-bce.mrxvt
/usr/share/terminfo/s/screen-bce.rxvt
/usr/share/terminfo/s/screen.linux
/usr/share/terminfo/s/screen.vte
/usr/share/terminfo/s/screen-bce.xterm-new
/usr/share/terminfo/s/screen.teraterm
/usr/share/terminfo/s/screen-16color-bce-s
/usr/share/terminfo/s/screen.xterm-r6
/usr/share/terminfo/s/screen+fkeys
/usr/share/terminfo/s/screen-256color-bce-s
/usr/share/terminfo/s/screen.mlterm
/usr/share/terminfo/s/screen-16color-s
/usr/share/terminfo/s/screen-bce.linux
/usr/share/terminfo/s/screen.gnome
/usr/share/terminfo/s/screen.rxvt
/usr/share/terminfo/s/screen2
/usr/share/terminfo/s/screen.Eterm
/usr/share/terminfo/s/screen.xterm-new
Share:
6,507

Related videos on Youtube

Noé Malzieu
Author by

Noé Malzieu

Updated on September 18, 2022

Comments

  • Noé Malzieu
    Noé Malzieu over 1 year

    I have a small problem in GNU screen. A GNU screen session runs on my RaspberryPi. Now sometimes, when I join it, if I click in the terminal (I'm using terminator on Fedora) I see weird characters written. These characters depend on the coordinates of my mouse… Seems like a wrong decoding of the click event sent to GNU Screen. These characters include things like

    kM#kM -  Z3#Z3  -  q-#q-
    

    etc…

    I first thought it was a problem with my tty so I went and opened a new GNU Screen session on my RaspberryPi: no problem at all.
    I did a stty -a on both session and saw there were difference. I then did a stty -g > ~/stty-good-settings on the good session and loaded it on the bad one with stty `cat ~/stty-good-settings` (I compared the values after that, the settings were successfully loaded) but I still have the problem in one of the screen sessions and not the other!

    I'm not sure what's happening, if this is due to my TERM value (same in both), my tty settings, my terminal…

    • peterph
      peterph almost 11 years
      I see this with tmux from time to time too. At some point the terminal multiplexers seem to go banana and decode the inputs incorrectly (xterm might also have something to say here). reset usually fixes this for me.
    • Noé Malzieu
      Noé Malzieu almost 11 years
      Indeed, reset works in screen too! Thanks for the fix, however, I'd love some insight as to why...
    • peterph
      peterph almost 11 years
      Me too... :) I suspect it to be some kind of bad interaction between the terminal multiplexers and the containing terminal.
    • Noé Malzieu
      Noé Malzieu almost 11 years
      I see.. You can answer the question, I'll validate this answer!
  • AlikElzin-kilaka
    AlikElzin-kilaka almost 5 years
    reset did the trick. Thanks.