Is there a way to have reset command reset input settings without clearing the screen?

I have a problem with an application, dosemu2 in -dumb -td -kt mode, which messes with my MATE terminal window. (Either directly in the MATE terminal window, or with GNU screen between them.) After I terminate the application using a signal (killall -v dosemu.bin) or by crashing it, the bash shell that’s left running in this window will receive lots of text data as the MATE terminal window receives mouse cursor movement data.

I found that I can restore the normal working of the shell by running the reset command, and sometimes also by running only tset. However, tset is hit or miss in that it sometimes clears the screen and also sometimes doesn’t reset the mouse input spam. reset always resets the mouse input, but it also always clears the screen which I would like to avoid. reset -I does not clear the screen but also does not fix the mouse input problem.

Is there a way to have what reset does in terms of disabling the mouse input, but without clearing the visible screen area?

I previously wrote about this in the dosemu2 discussions, here: https://github.com/dosemu2/dosemu2/discussions/2061

Here’s an image showing the mouse data entered as text at the end:

Terminal window receiving mouse movement data as text after terminating dosemu2.

Asked By: ecm

||

The reset command is a shortcut to tput reset. The documentation for this command says,

reset […] the terminal’s reset strings will be output if present
(rs1, rs2, rs3, rf). If the reset strings are not present, but initialization strings are, the initialization strings will be output. Otherwise, reset acts identically to init.

So, to find out what sequences the reset command actually sends to the terminal to switch it out of the various modes it might be in, we need to look at the settings for rs1, rs2, rs3, and rf.

At this point, instead of reset, you could try tput rs1, and tput rs2, and tput rs3, and tput rf to see which one – if any – resolves the issue without clearing the screen.

However, continuing on with the dive. In man terminfo the documentation simply writes,

reset_1string        rs1        r1         reset string
reset_2string        rs2        r2         reset string
reset_3string        rs3        r3         reset string
reset_file           rf         rf         name of reset file

This means we need to revert to the terminfo database directly

infocmp | grep -Po 'w+=[^,]*' | grep -E '^(rs[123]|rf)='

For me this returns two entries,

rs1=Ec
rs2=E[!pE[?3;4lE[4lE>

These can be read directly with E representing Escape, and rewritten as printf sequences:

printf 'ec'
printf 'e[!p'; printf 'e[?3;4l'; printf 'e[4l'; printf 'e>'

Finding out what the escape sequences actually mean is probably beyond the scope of this answer but here are some

ESC c          # Reset and clear screen
ESC [!p
ESC [?e;4l
ESC [4l
ESC >

And finally, it’s been noted that there is a recent commit on dosemu itself to perform the necessary resets:

# disable xterm mouse tracking
printf '33[?1006l33[?1003l33[?1002l33[?1000l33[?9l'
# disable xterm cursor keys
printf '33[?1l'

i.e.

ESC [?1006l ESC [?1003l ESC [?1002l ESC [?1001l ESC ?9l
ESC [?1l
Answered By: roaima
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.