Swordfish90 / cool-retro-term

A good looking terminal emulator which mimics the old cathode display...
22.03k stars 839 forks source link

Ctrl + H is misbehaving. #676

Open theteachr opened 2 years ago

theteachr commented 2 years ago

Ctrl + H is not having the desired effect. I have a key bind set for it in Vim, but it's having the same effect as Backspace. The same key bind in tmux is not functioning either.

theteachr commented 2 years ago

Environment

OS: macOS 15 Terminal Version: 1.1.1

fritzy commented 2 years ago

@theteachr I have this exact same issue.

razziel89 commented 2 years ago

I am experiencing the same issue. Does anyone have an idea how that could be debugged?

Update: I suspect this might have something to do with the keymaps defined in these files:

since they specify some specifc treatment of ctrl-h.

razziel89 commented 2 years ago

I did look around a bit more and managed to find a fix that does not require modifications to cool-retro-term or qmltermwidget. I am writing it down here in case it helps someone. The fix relies on the fact that qmltermwidget allows to define an alternative directory for keytabs via an environment variable (see here). To avoid Ctrl+H behaving like backspace, do the following:

Maybe the above helps someone. FYI @Swordfish90. I haven't yet tried whether it works for the appimage, too, but I would think so. You could, of course, replace /usr/local/share/crt_keytabs/default.keytab by any other directory you want.

The background I could find out in case it is interesting for someone, it was for me:

It seems as if terminals can send two different signals indicating backspace, Ctrl+H (also called ^H or \x08 in hex or \b) or Ctrl+Backspace (also called ^? or \x7f in hex). Different terminals handle things differently. You can find that out by running showkey -a and hitting backspace, end with Ctrl+D, which I did on my machine for a few:

xterm cool-retro-term konsole gnome-terminal
^? ^H ^? ^?

I've read somewhere that xterm used ^H, but the ones I have access to do not seem to do that. It looks like more terminals send ^? than ^H, which means it could maybe make sense to do the same for cool-retro-term :shrug:. I did learn a lot about terminals while looking through the code, maybe this is interesting for someone else, too.

razziel89 commented 2 years ago

Sorry, that was too quick. It seems like the environment variable is overwritten here. One resolution could be to only overwrite the environment variable if is not yet set.

UPDATE: PR suggesting a small workaround is open here.

spudlyo commented 1 year ago

Look for default.keytab on your computer. On my computer it's located at: /usr/lib/aarch64-linux-gnu/qt5/QMLTermWidget/kb-layouts/default.keytab

This file specifies how the backspace key is handled. By default it emits ^H, and when hit Ctrl-backspace it emits ^?. This is important because it also sets your erase key to ^H. You can verify this by doing:

stty -a | grep erase

When your terminal is set this way, vim, or emacs, or tmux is going to treat ^H as the erase key, and not a literal ^H. If you edit the keytab file @razziel89 suggests, this will change. If you can't find the keytab file, or don't feel like editing the keytab file, you can simply do:

stty erase ^?

This will fix ^H so it works, but you'll need to press C-backspace whenever you want to get a backspace in your shell, or you'll just see a ^H on the screen. If you change your keytab file, stty erase will automatically be set to ^?.

jayjwa commented 7 months ago

I had the same issue. It's even more a problem for me because I'm using CRT to login to OpenVMS systems remotely and they don't have a DEL key (it just re-renders the previous line), only Backspace which needs to send ^?. Without changing it, I needed to use ctrl-shift-backspace to erase a character.

My system keeps the keytab at /usr/lib64/qt5/qml/QMLTermWidget/kb-layouts/default.keytab. Setting key Backspace -Control : "\x7f" fixes the problem. Now uxterm, urxvt, and CRT all send (backspace at top, delete key next):

showkey -a                                                

Press any keys - Ctrl-D will terminate this program

^?      127 0177 0x7f
^[[3~    27 0033 0x1b
         91 0133 0x5b
         51 0063 0x33
        126 0176 0x7e
^D        4 0004 0x04

Maybe a small note in the documentation could save people some time.