crigler / dtach

A simple program that emulates the detach feature of screen
GNU General Public License v2.0
476 stars 50 forks source link

Weird arrow key behavior when running rtorrent #15

Closed ghost closed 5 years ago

ghost commented 5 years ago

I've been trying to set up a dtach session for rtorrent. dtach -n socket rtorrent; dtach -a socket works perfectly, but wierdly enough, when there's more than 1 second between the first command and the second, the up, down, right and left arrows are remapped to A, B, C and D respectively, and the terminal cursor is actually visible in the bottom left corner of rtorrent (it's normally invisible).

This means that dtach -n socket rtorrent; sleep 1; dtach -a socket isn't buggy, but dtach -n socket rtorrent; sleep 2; dtach -a socket is.

Every other program that I tried didn't get the bug, except vim, which would exit insert mode and throw an "E388: Couldn't find definition" error when any arrow key was pressed, but I'm not sure which key press that would be. I also tried xev, but the arrow key codes looked normal there.

I'm using st with $TERM set to xterm-256color. Also tried urxvt and xterm, and setting TERM to screen-256color. According to vim, $TERM doesn't change inside the dtach session though.
dtach version 0.9 (pacman version) on an up-to-date Arch Linux install.

crigler commented 5 years ago

This sounds like the issue described at http://invisible-island.net/xterm/xterm.faq.html#xterm_arrows which says how some applications do the equivalent of tput smkx and change the keyboard mode.

You may be able to do tput smkx;dtach -a socket;tput rmkx and have the cursor keys work again.

rtorrent is also possibly sending an escape sequence on startup to make the cursor invisible.

ghost commented 5 years ago

That fixed it! Looks like I can also run tput civis to hide the cursor. Thanks for the help.