Bug 1369182

Summary: Arrow keys dont work inside tmux for putty in Fedora 24
Product: [Fedora] Fedora Reporter: Konstantin Zemlyak <zart>
Component: tmuxAssignee: Sven Lankes <sven>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 26CC: dcantrell, diftraku, jacob.e.keller, m.hatifnatt, mlichvar, praiskup, rosset.filipe, strobert, sven
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: tmux-2.2-4.fc25 tmux-2.5-1.fc26 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-07-27 16:52:34 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
fix for the application keys in tmux
none
updated SRPM package for Fedora 25
none
Fedora 26 SRPM
none
fixed Fedora 26 SRPM none

Description Konstantin Zemlyak 2016-08-22 15:28:20 UTC
Description of problem:
When running tmux with TERM=putty[-256color] left/right arrows do not work inside.

Version-Release number of selected component (if applicable):
tmux-2.2-1.fc24.x86_64

How reproducible:
Always.

Steps to Reproduce:
1. Installed Fedora-Server 24 as a guest.
2. Connected from Windows with Putty 0.67 via ssh.
3. dnf install tmux
4. tmux
5. While typing commands cursor arrow keys up/down work, left/right don't.

Actual results:

$ echo $TERM
putty-256color
$ cat -vT
<pressing up, down, right, left, ^C here>
^[[A^[[B^[[C^[[D^C
$ tmux
$ echo $TERM
screen
$ cat -vT
<pressing up, down, right, left, ^C here>
^[[A^[[B^C
$ exit
$ TERM=xterm-256color tmux
$ echo $TERM
screen
$ cat -vT
<pressing up, down, right, left, ^C here>
^[[A^[[B^[[C^[[D^C
$

Expected results:
Should have seen ^[[A^[[B^[[C^[[D^C output for each cat -vT.

Additional info:
While using xterm-256color helps with tmux somewhat it breaks other funcionality, so can't be considered a fix.

Comparing 'infocmp -1 putty' output between fedora 23 and 24 reveals:

--- 23putty     2016-08-22 13:27:55.285713815 +0000
+++ 24putty     2016-08-22 13:26:31.376164245 +0000
@@ -55,13 +55,15 @@
        indn=\E[%p1%dS,
        initc=\E]P%p1%x%p2%{255}%*%{1000}%/%02x%p3%{255}%*%{1000}%/%02x%p4%{255}%*%{1000}%/%02x,
        is2=\E7\E[r\E[m\E[?7h\E[?1;4;6l\E[4l\E8\E>\E]R,
+       kLFT=\E[D,
+       kRIT=\E[C,
        kb2=\E[G,
        kbs=\177,
        kcbt=\E[Z,
-       kcub1=\E[D,
-       kcud1=\E[B,
-       kcuf1=\E[C,
-       kcuu1=\E[A,
+       kcub1=\EOD,
+       kcud1=\EOB,
+       kcuf1=\EOC,
+       kcuu1=\EOA,
        kdch1=\E[3~,
        kend=\E[4~,
        kf1=\E[11~,
@@ -86,9 +88,11 @@
        kf9=\E[20~,
        khome=\E[1~,
        kich1=\E[2~,
+       kind=\E[B,
        kmous=\E[M,
        knp=\E[6~,
        kpp=\E[5~,
+       kri=\E[A,
        kspd=^Z,
        nel=^M^J,
        oc=\E]R,
@@ -101,6 +105,7 @@
        rmam=\E[?7l,
        rmcup=\E[2J\E[?47l,
        rmir=\E[4l,
+       rmkx=\E[?1l\E>,
        rmpch=\E[10m,
        rmso=\E[27m,
        rmul=\E[24m,
@@ -117,6 +122,7 @@
        smam=\E[?7h,
        smcup=\E[?47h,
        smir=\E[4h,
+       smkx=\E[?1h\E=,
        smpch=\E[11m,
        smso=\E[7m,
        smul=\E[4m,

Seems like there has been some wrong changes to terminfo db in ncurses package.

Comment 1 Miroslav Lichvar 2016-08-23 07:29:01 UTC
Here is upstream discussion that led to this change in the putty terminfo:

https://lists.gnu.org/archive/html/bug-ncurses/2016-01/msg00010.html

Does the problem happen when not in tmux?

Comment 2 Konstantin Zemlyak 2016-08-24 04:20:20 UTC
Interesting. Testing with TERM=putty shows following:

1) 'cat -vT' shows that terminal sends \E[A .. \E[D by default, \E0A .. \E0D when holding shift and/or ctrl.
2) Outside of tmux arrows work fine in vim, nano, mc, bash, zsh, psql.
3) Inside tmux they still work fine in vim, nano, mc, but left/right does not work in bash, zsh and psql.
4) Holding shift and/or control inside tmux makes left/right arrows work.

Using TERM=putty-noapp fixes readline programs inside tmux.

I don't understand why up/down works but left/right doesn't. And can't decide what to blame - updated terminfo in ncurses, GNU readline not using application mode properly or tmux which exhibits weird behavior.

Also zsh deserves seperate bug for broken home/end keys.

Comment 3 Konstantin Zemlyak 2016-08-24 05:10:14 UTC
Upon reading http://git.suckless.org/st/plain/FAQ I've created ~/.inputrc with 'set enable-keypad on' line, and ~/.zshrc with:

    function zle-line-init () { echoti smkx }
    function zle-line-finish () { echoti rmkx }
    zle -N zle-line-init
    zle -N zle-line-finish

This have fixed the original issue, though home/end are still broken in zsh.

Comment 4 Diftraku 2016-11-18 20:55:22 UTC
I personally ended up getting an older version of the terminfo files from Ubuntu 14.04 (ncurses-term 5.9+20140118) and plopped them in-place over the newer ones (Fedora 24, ncurses-term 6.0-6.20160709) and everything works as usual.

I personally feel workarounds are not acceptable solutions and the older version of the PuTTY terminfos shoud be used instead of the newer upstream one for the time being.

Comment 5 Jacob Keller 2017-06-09 15:40:08 UTC
I have this exact problem on Fedora 25 still, the only workarounds are an old terminfo file, or using keypad on, in inputrc. The keypad solution is non-workable as it means that every single server I SSH into must have this setup.

Comment 6 Jacob Keller 2017-06-09 16:48:55 UTC
This is an issue in tmux, and was fixed in tmux 2.4

Comment 7 Jacob Keller 2017-06-09 17:04:52 UTC
Created attachment 1286471 [details]
fix for the application keys in tmux

The attached patch is a cherry-pick onto the 2.2 tag of tmux, which we should be able to backport and include to fix this issue in the tmux-2.2 source for Fedora 25.

Comment 8 Jacob Keller 2017-06-09 17:25:43 UTC
Created attachment 1286472 [details]
updated SRPM package for Fedora 25

I took the liberty of downloading the fedora 25 SRPM for tmux (tmux-2.2-3.fc25.src.rpm) and adding in the patch file that fixes the issue. Hopefully this helps the package owner out.

Comment 10 Fedora Update System 2017-06-10 02:30:37 UTC
tmux-2.2-4.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-094433a33e

Comment 11 Fedora Update System 2017-06-12 06:31:51 UTC
tmux-2.2-4.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-094433a33e

Comment 12 Fedora Update System 2017-07-06 02:20:59 UTC
tmux-2.2-4.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.

Comment 13 Jacob Keller 2017-07-13 18:54:47 UTC
This wasn't fixed upstream until tmux 2.5 so the same fix needs to be backported into the 2.3 package in Fedora 26.

Comment 14 Filipe Rosset 2017-07-13 18:59:59 UTC
I'm planning to update tmux on F26 to latest 2.5 release (already on rawhide).

Since F26 will be supported for at least 13 months I think it's the better approach.

Comment 15 Jacob Keller 2017-07-13 19:06:14 UTC
Created attachment 1297814 [details]
Fedora 26 SRPM

This uses the exact same patch for the Fedora 25 2.2 build.

Comment 16 Jacob Keller 2017-07-13 19:07:22 UTC
That's fine. I rebuilt a 2.3-3 version you can provide now or wait for the 2.5 update. I can easily use this 2.3-3 version locally until an update is provided.

Comment 17 Jacob Keller 2017-07-13 19:13:53 UTC
Created attachment 1297815 [details]
fixed Fedora 26 SRPM

The first attachment forgot to actually apply the patch.

Comment 18 Fedora Update System 2017-07-16 16:03:14 UTC
tmux-2.5-1.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-e9083815d8

Comment 19 Filipe Rosset 2017-07-16 16:05:00 UTC
tmux 2.5 available on Fedora 26, testing needed.

Comment 20 Fedora Update System 2017-07-17 03:25:34 UTC
tmux-2.5-1.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-e9083815d8

Comment 21 Jacob Keller 2017-07-17 23:20:42 UTC
This works for me in Fedora 26

Comment 22 Fedora Update System 2017-07-27 16:52:34 UTC
tmux-2.5-1.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.