Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backspace does not work with tmux #88

Closed
rbelem opened this issue Dec 28, 2019 · 14 comments
Closed

Backspace does not work with tmux #88

rbelem opened this issue Dec 28, 2019 · 14 comments
Labels
bug Something isn't working

Comments

@rbelem
Copy link

rbelem commented Dec 28, 2019

Describe the bug

The backspace key stops working when using tmux. After exiting tmux it works again.

Environment (please complete the following information):

  • OS: KDE neon 5.17, xorg 7.7
  • Frontend: OpenGL
  • Version: wezterm 20191218-101156-bf35707-49-gfa7a007

Is it a build problem?

No

To Reproduce

Open tmux, type something and try to delete with backspace.

Configuration

None

Expected behavior

Delete the text

Screenshots

None

Session Recording

Issue with input

Additional context

  • tmux: 2.6-3ubuntu0.2
  • bash: set -o vi (vi mode)
@rbelem rbelem added the bug Something isn't working label Dec 28, 2019
@wez
Copy link
Owner

wez commented Dec 28, 2019

What does stty -a output for you, both inside and outside the tmux session?
Can you capture the following from inside the tmux session?

$ echo $TERM
$ tmux info

@rbelem
Copy link
Author

rbelem commented Dec 28, 2019

Delete key is acting as Backspace.

@rbelem
Copy link
Author

rbelem commented Dec 28, 2019

Inside tmux

$ stty -a
speed 38400 baud; rows 34; columns 170; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

Outside tmux

$ stty -a
speed 38400 baud; rows 35; columns 170; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

@rbelem
Copy link
Author

rbelem commented Dec 28, 2019

Inside tmux

$ echo $TERM
screen-256color
$ tmux info
Terminal 0: xterm-256color [references=1, flags=0x1]:
   0: AX: (flag) true
   1: acsc: (string) ``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~
   2: bce: (flag) true
   3: bel: (string) \007
   4: blink: (string) \033[5m
   5: bold: (string) \033[1m
   6: civis: (string) \033[?25l
   7: clear: (string) \033[H\033[2J
   8: cnorm: (string) \033[?12l\033[?25h
   9: colors: (number) 256
  10: Cr: (string) \033]112\007
  11: Cs: (string) \033]12;%p1%s\007
  12: csr: (string) \033[%i%p1%d;%p2%dr
  13: cub: (string) \033[%p1%dD
  14: cub1: (string) \010
  15: cud: (string) \033[%p1%dB
  16: cud1: (string) \012
  17: cuf: (string) \033[%p1%dC
  18: cuf1: (string) \033[C
  19: cup: (string) \033[%i%p1%d;%p2%dH
  20: cuu: (string) \033[%p1%dA
  21: cuu1: (string) \033[A
  22: cvvis: (string) \033[?12;25h
  23: dch: (string) \033[%p1%dP
  24: dch1: (string) \033[P
  25: dim: (string) \033[2m
  26: dl: (string) \033[%p1%dM
  27: dl1: (string) \033[M
  28: E3: (string) \033[3J
  29: ech: (string) \033[%p1%dX
  30: ed: (string) \033[J
  31: el: (string) \033[K
  32: el1: (string) \033[1K
  33: enacs: [missing]
  34: fsl: (string) \007
  35: home: (string) \033[H
  36: hpa: (string) \033[%i%p1%dG
  37: ich: (string) \033[%p1%d@
  38: ich1: [missing]
  39: il: (string) \033[%p1%dL
  40: il1: (string) \033[L
  41: indn: (string) \033[%p1%dS
  42: invis: (string) \033[8m
  43: kcbt: (string) \033[Z
  44: kcub1: (string) \033OD
  45: kcud1: (string) \033OB
  46: kcuf1: (string) \033OC
  47: kcuu1: (string) \033OA
  48: kDC: (string) \033[3;2~
  49: kDC3: (string) \033[3;3~
  50: kDC4: (string) \033[3;4~
  51: kDC5: (string) \033[3;5~
  52: kDC6: (string) \033[3;6~
  53: kDC7: (string) \033[3;7~
  54: kdch1: (string) \033[3~
  55: kDN: (string) \033[1;2B
  56: kDN3: (string) \033[1;3B
  57: kDN4: (string) \033[1;4B
  58: kDN5: (string) \033[1;5B
  59: kDN6: (string) \033[1;6B
  60: kDN7: (string) \033[1;7B
  61: kend: (string) \033OF
  62: kEND: (string) \033[1;2F
  63: kEND3: (string) \033[1;3F
  64: kEND4: (string) \033[1;4F
  65: kEND5: (string) \033[1;5F
  66: kEND6: (string) \033[1;6F
  67: kEND7: (string) \033[1;7F
  68: kf1: (string) \033OP
  69: kf10: (string) \033[21~
  70: kf11: (string) \033[23~
  71: kf12: (string) \033[24~
  72: kf13: (string) \033[1;2P
  73: kf14: (string) \033[1;2Q
  74: kf15: (string) \033[1;2R
  75: kf16: (string) \033[1;2S
  76: kf17: (string) \033[15;2~
  77: kf18: (string) \033[17;2~
  78: kf19: (string) \033[18;2~
  79: kf2: (string) \033OQ
  80: kf20: (string) \033[19;2~
  81: kf21: (string) \033[20;2~
  82: kf22: (string) \033[21;2~
  83: kf23: (string) \033[23;2~
  84: kf24: (string) \033[24;2~
  85: kf25: (string) \033[1;5P
  86: kf26: (string) \033[1;5Q
  87: kf27: (string) \033[1;5R
  88: kf28: (string) \033[1;5S
  89: kf29: (string) \033[15;5~
  90: kf3: (string) \033OR
  91: kf30: (string) \033[17;5~
  92: kf31: (string) \033[18;5~
  93: kf32: (string) \033[19;5~
  94: kf33: (string) \033[20;5~
  95: kf34: (string) \033[21;5~
  96: kf35: (string) \033[23;5~
  97: kf36: (string) \033[24;5~
  98: kf37: (string) \033[1;6P
  99: kf38: (string) \033[1;6Q
 100: kf39: (string) \033[1;6R
 101: kf4: (string) \033OS
 102: kf40: (string) \033[1;6S
 103: kf41: (string) \033[15;6~
 104: kf42: (string) \033[17;6~
 105: kf43: (string) \033[18;6~
 106: kf44: (string) \033[19;6~
 107: kf45: (string) \033[20;6~
 108: kf46: (string) \033[21;6~
 109: kf47: (string) \033[23;6~
 110: kf48: (string) \033[24;6~
 111: kf49: (string) \033[1;3P
 112: kf5: (string) \033[15~
 113: kf50: (string) \033[1;3Q
 114: kf51: (string) \033[1;3R
 115: kf52: (string) \033[1;3S
 116: kf53: (string) \033[15;3~
 117: kf54: (string) \033[17;3~
 118: kf55: (string) \033[18;3~
 119: kf56: (string) \033[19;3~
 120: kf57: (string) \033[20;3~
 121: kf58: (string) \033[21;3~
 122: kf59: (string) \033[23;3~
 123: kf6: (string) \033[17~
 124: kf60: (string) \033[24;3~
 125: kf61: (string) \033[1;4P
 126: kf62: (string) \033[1;4Q
 127: kf63: (string) \033[1;4R
 128: kf7: (string) \033[18~
 129: kf8: (string) \033[19~
 130: kf9: (string) \033[20~
 131: kHOM: (string) \033[1;2H
 132: kHOM3: (string) \033[1;3H
 133: kHOM4: (string) \033[1;4H
 134: kHOM5: (string) \033[1;5H
 135: kHOM6: (string) \033[1;6H
 136: kHOM7: (string) \033[1;7H
 137: khome: (string) \033OH
 138: kIC: (string) \033[2;2~
 139: kIC3: (string) \033[2;3~
 140: kIC4: (string) \033[2;4~
 141: kIC5: (string) \033[2;5~
 142: kIC6: (string) \033[2;6~
 143: kIC7: (string) \033[2;7~
 144: kich1: (string) \033[2~
 145: kind: (string) \033[1;2B
 146: kLFT: (string) \033[1;2D
 147: kLFT3: (string) \033[1;3D
 148: kLFT4: (string) \033[1;4D
 149: kLFT5: (string) \033[1;5D
 150: kLFT6: (string) \033[1;6D
 151: kLFT7: (string) \033[1;7D
 152: kmous: (string) \033[M
 153: knp: (string) \033[6~
 154: kNXT: (string) \033[6;2~
 155: kNXT3: (string) \033[6;3~
 156: kNXT4: (string) \033[6;4~
 157: kNXT5: (string) \033[6;5~
 158: kNXT6: (string) \033[6;6~
 159: kNXT7: (string) \033[6;7~
 160: kpp: (string) \033[5~
 161: kPRV: (string) \033[5;2~
 162: kPRV3: (string) \033[5;3~
 163: kPRV4: (string) \033[5;4~
 164: kPRV5: (string) \033[5;5~
 165: kPRV6: (string) \033[5;6~
 166: kPRV7: (string) \033[5;7~
 167: kri: (string) \033[1;2A
 168: kRIT: (string) \033[1;2C
 169: kRIT3: (string) \033[1;3C
 170: kRIT4: (string) \033[1;4C
 171: kRIT5: (string) \033[1;5C
 172: kRIT6: (string) \033[1;6C
 173: kRIT7: (string) \033[1;7C
 174: kUP: (string) \033[1;2A
 175: kUP3: (string) \033[1;3A
 176: kUP4: (string) \033[1;4A
 177: kUP5: (string) \033[1;5A
 178: kUP6: (string) \033[1;6A
 179: kUP7: (string) \033[1;7A
 180: Ms: (string) \033]52;%p1%s;%p2%s\007
 181: op: (string) \033[39;49m
 182: rev: (string) \033[7m
 183: ri: (string) \033M
 184: rmacs: (string) \033(B
 185: rmcup: [missing]
 186: rmkx: (string) \033[?1l\033>
 187: Se: (string) \033[2 q
 188: setab: (string) \033[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m
 189: setaf: (string) \033[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m
 190: setrgbb: [missing]
 191: setrgbf: [missing]
 192: sgr0: (string) \033(B\033[m
 193: sitm: (string) \033[3m
 194: smacs: (string) \033(0
 195: smcup: [missing]
 196: smkx: (string) \033[?1h\033=
 197: smso: (string) \033[7m
 198: smul: (string) \033[4m
 199: smxx: (string) \033[9m
 200: Ss: (string) \033[%p1%d q
 201: Tc: [missing]
 202: tsl: (string) \033]0;
 203: U8: [missing]
 204: vpa: (string) \033[%i%p1%dd
 205: xenl: (flag) true
 206: XT: (flag) true

@wez
Copy link
Owner

wez commented Dec 29, 2019

Delete key is acting as Backspace.

Hmm, you might try adding this option to your wezterm.toml config file:

swap_backspace_and_delete = true

More information about this option here:
https://github.com/wez/wezterm/blob/master/src/config/mod.rs#L410-L415

@rbelem
Copy link
Author

rbelem commented Dec 29, 2019

With that option the delete stops working.

@wez
Copy link
Owner

wez commented Dec 29, 2019

I've been trying to reproduce this locally but without luck. I suspect that there is some other local configuration that is impacting things, but it's not clear at which layer. Since this seems to only be an issue inside tmux, it might be something to do with its configuration. Would you mind sharing your tmux configuration file?

What I usually do to sanity check this sort of input issue is to run od -c; that will print out escaped readable versions of the input data. For example, this is what I see when I press my backspace key:

$ od -c
^H

Could you try that both outside and inside your tmux session?

@nicm
Copy link

nicm commented Dec 30, 2019

tmux works out what to expect for backspace by looking at VERASE. From your stty output, it looks like you have ^? - if the terminal actually sends ^H, tmux will not correctly recognise backspace.

tmux will always send ^? for backspace to applications inside, if you want ^H you will need to build tmux from master and change the backspace option (I do not recommend using ^H however).

tmux will expect \033[3~ for delete because that is what is in kdch1 for xterm-256color, if the terminal sends something different you may need a different TERM (or to modify it with the terminal-overrides option).

@wez
Copy link
Owner

wez commented Dec 30, 2019

Thanks @nicm; that's helpful!

I still can't reproduce this locally, so I'm wondering whether @rbelem has a keyboard that has Backspace/Delete swapped. If so, then that swap_backspace_and_delete option would be the right thing to use with wezterm, except that wezterm doesn't actually emit \033[3~ for delete right now. I can fix that easily enough.

wez added a commit that referenced this issue Dec 30, 2019
Previously we would try to pass through the Backspace and Delete
code points without interference, but that behavior wasn't quite
right.

With this commit our behavior is now:

- At the window layer: Classify a `Backspace` key press as logically
  `BS` and a `Delete` key press as logically `DEL` unless the
  `swap_backspace_and_delete` is true (macOS is true by default), in
  which case `Backspace` is mapped to `Delete` and vice versa.

- At the terminal input layer: A `Backspace` input from the Window sends
  the `DEL` sequence to the pty as that matches the default `VERASE` stty
  configuration.  A `Delete` input from the Window emits `\033[3~`,
  which matches up to the `TERMINFO` for `xterm-256color` which we
  claim to be compatible with, and is our default `$TERM` value.

The net result of this is that `Backspace` will now start to emit `^?`
which should match folks stty verase.   Heads up to @fanzeyi!

I've tested this only on a linux system so far and will follow up on
a macOS system a little later today.

Refs: #88
Refs: #63
@rbelem
Copy link
Author

rbelem commented Dec 30, 2019

@wez my keyboard is a regular keyboard type. The bug behavior is reproducible only with wezterm+tmux+bash. In the same session when I use wezterm+tmux+neovim in insert mode it works as expected, but it doesn't when using wezterm+tmux+neovim in command mode.

@wez
Copy link
Owner

wez commented Dec 30, 2019

@rbelem: could you test with the latest nightly build and see if things are better?

@rbelem
Copy link
Author

rbelem commented Dec 30, 2019

I just built the HEAD and it is working \o/
Ah! and disabled swap_backspace_and_delete = true

@rbelem rbelem closed this as completed Dec 30, 2019
wez added a commit that referenced this issue Dec 30, 2019
With the changes in Refs: #88
we don't need to swap them by default on macos any more.
@rbelem
Copy link
Author

rbelem commented Dec 30, 2019

HEAD is working and release 20191229-193639-e7aa2f3 is not.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants