termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
33.05k stars 3.5k forks source link

Keyboard backspace key sends DEL #212

Open filbo opened 7 years ago

filbo commented 7 years ago

Using Google Keyboard on Android 6. The on-screen symbol is a funky pentagon with 'x', and might actually be an official symbol for 'DEL' in some contexts. Anyway, it is far more convenient for me if it sends ASCII BS 0x08 rather than DEL 0x7f.

This is of course a variable matter between different physical terminals and, these days, emulators. Many emulators have a config setting to choose between (a few will even let you send the Dec VT102 Advanced Mode or Function Mode or whatever it is, complicated ESC [ blahblah sequence, but I'll not ask for that... :)

Please add the setting for 'Backspace key send DEL | BS'. DEL would be the sensible default so as to not break existing users. OR, if the setting already exists, consider this a doc bugreport since I completely failed to find it...

kveroneau commented 5 years ago

I ran into an issue while trying to use efte full-screen editor in Termux, where the editor works properly with either me manually hitting Ctrl-H, or works on my PC in xterm. The editor itself is open source, so someone helped me with creating a patch to have it work with 0x7f as Termux sends. I also agree that having an option to choose what Termux sends over to the programs when the Android backspace key is pressed.

tjapro commented 4 years ago

Hello! I was going to open a new issue, when I saw this one. So, the shortcut CTRL^H always sends to terminal to print a backspace. But it is a bit problematic in this situation: https://savannah.gnu.org/bugs/index.php?56994#comment3 I don't know if this bug affects other programs. Please tell if I need to open a new issue.

filbo commented 4 years ago

@TJProgrammer -- your issue sounds related but isn't really. When you run infocmp | grep kbs and it shows kbs=^H, this tells you that the terminfo entry for your $TERM claims your backspace key sends Ctrl-H (0x08).

In reality, on termux, the backspace key actually sends DEL (0x7F)! So $TERM is somewhat wrong.

My termux shell shows $TERM = xterm-256color. Looking at the definition of xterm-256color on a desktop Linux system, it has kbs=\177 (DEL, 0x7f). So it looks, in fact, like termux ships with a slightly modified terminfo entry which is actually wrong.

None of this relates directly to my issue. Your issue is that nano processes its input in such a way that it receives ^H as curses enum value KEY_BACKSPACE rather than 0x08; and nano isn't able to interpret that correctly. Given that a great number of terminals (and their corresponding terminfo definitions) use ^H as their backspace keys, this is at least partially a bug in nano.

If nano processes its input through the lens of curses, it should allow you to bind not only to ASCII keys but also to curses enum values. That is, you should be able to do something like bind KEY_BACKSPACE help all.

On the other hand, this is fixing it in the wrong place. The right place is in termux's configuration: either it should not set $TERM equal to 'xterm-256color' (but rather to some terminfo entry whose kbs=\177); or its xterm-256color terminfo entry should have kbs=\177.

You can probably fix it yourself by doing something like this (not tested on termux):

$ infocmp xterm-256color > myterm.src $ nano myterm.src ... find kbs definition, change it to \177 ... change the terminal name near the top of the file, e.g.: xterm-256color-del|xterm with 256 colors and backspace key sends DEL ... save edited file $ tic myterm.src $ export TERM=xterm-256color-del

Now when you run nano, your binding to ^H should work since it will no longer be translated by curses to KEY_BACKSPACE.

To complete this fix, you would need to add export TERM=xterm-256color-del to your termux .profile, or some other method of ensuring your $TERM is set to the new terminal type name.

===

The nano bug you pointed to has this statement:

Maybe you can convince Termux to use a different code for the Backspace key by fiddling with the TERM environment variable.

This seems to imply that the author thinks that by changing $TERM (and therefore changing the definition of 'kbs'), you would affect what the terminal keyboard sends when you hit the Backspace key. This is not how it actually works. Terminfo entries are descriptive, not prescriptive: 'kbs' informs software what character is expected to be received when the user hits the Backspace key. It does not instruct the software which operates the keyboard to send that character.

It's true that the particular issue can be fixed by changing $TERM. But this is because the descriptive entry in the termux terminfo entry is wrong, not because changing it changes what the keyboard sends. If, in fact, termux did send ^H, you simply would not be able to have ^H bound to 'help'. ^H would already be in use as Backspace; binding something else to it would prevent you from correcting typing errors.

===

My issue is more or less the inverse. I'm using termux to ssh into a system which strongly prefers ^H to DEL, for the Backspace function. It is an inconvenience to me that the termux keyboard always sends DEL. I would like to be able to configure it to send ^H. Local software inside termux wouldn't be much bothered -- $TERM already claims it's that way, the shell automatically accepts both, and almost all other software is also happy to accept ^H as Backspace. My remote system that I'm ssh'ing into, meanwhile, really doesn't like DEL. I end up having to manually hit Ctrl-H (which, in termux, actually means 'tap the ctrl button on the screen, then h'). It would be far more convenient for me if termux really did send ^H when I tap its on-screen Backspace key.

===

Historically, about half of all physical terminals sent DEL and half sent ^H. Because both were so widespread, almost all modern terminal emulators have a per-profile setting to control what the Backspace key sends. termux lacks this, which is the bug I raised here and has been languishing for nearly 3 years. It causes me daily pain.

filbo commented 4 years ago

@ThomasDickey checking in the field, I find some systems have ^H and some have DEL for xterm-256color's kbs. What is the history of that?

tjapro commented 4 years ago

@ThomasDickey checking in the field, I find some systems have ^H and some have DEL for xterm-256color's kbs. What is the history of that?

I hope this help.

Interesting: according your previous comment I checked the following (and it is according to you):

echo $TERM
xterm-256color

infocmp "$TERM"
#       Reconstructed via infocmp from file: /data/data/com.termux/files/usr/share/terminfo/x/xterm-256color
xterm-256color|xterm with 256 colors,
        am, bce, ccc, km, mc5i, mir, msgr, npc, xenl,
        colors#0x100, cols#80, it#8, lines#24, pairs#0x10000,
        acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
        clear=\E[H\E[2J, cnorm=\E[?12l\E[?25h, cr=\r,
        csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
        cud=\E[%p1%dB, cud1=\n, cuf=\E[%p1%dC, cuf1=\E[C,
        cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
        cvvis=\E[?12;25h, dch=\E[%p1%dP, dch1=\E[P, dim=\E[2m,
        dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K,
        el1=\E[1K, flash=\E[?5h$<100/>\E[?5l, home=\E[H,
        hpa=\E[%i%p1%dG, ht=^I, hts=\EH, ich=\E[%p1%d@,
        il=\E[%p1%dL, il1=\E[L, ind=\n, indn=\E[%p1%dS,
        initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,
        invis=\E[8m, is2=\E[!p\E[?3;4l\E[4l\E>, kDC=\E[3;2~,
        kEND=\E[1;2F, kHOM=\E[1;2H, kIC=\E[2;2~, kLFT=\E[1;2D,
        kNXT=\E[6;2~, kPRV=\E[5;2~, kRIT=\E[1;2C, kb2=\EOE, kbs=^H,
        kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
        kdch1=\E[3~, kend=\EOF, kent=\EOM, kf1=\EOP, kf10=\E[21~,
        kf11=\E[23~, kf12=\E[24~, kf13=\E[1;2P, kf14=\E[1;2Q,
        kf15=\E[1;2R, kf16=\E[1;2S, kf17=\E[15;2~, kf18=\E[17;2~,
        kf19=\E[18;2~, kf2=\EOQ, kf20=\E[19;2~, kf21=\E[20;2~,
        kf22=\E[21;2~, kf23=\E[23;2~, kf24=\E[24;2~,
        kf25=\E[1;5P, kf26=\E[1;5Q, kf27=\E[1;5R, kf28=\E[1;5S,
        kf29=\E[15;5~, kf3=\EOR, kf30=\E[17;5~, kf31=\E[18;5~,
        kf32=\E[19;5~, kf33=\E[20;5~, kf34=\E[21;5~,
        kf35=\E[23;5~, kf36=\E[24;5~, kf37=\E[1;6P, kf38=\E[1;6Q,
        kf39=\E[1;6R, kf4=\EOS, kf40=\E[1;6S, kf41=\E[15;6~,
        kf42=\E[17;6~, kf43=\E[18;6~, kf44=\E[19;6~,
        kf45=\E[20;6~, kf46=\E[21;6~, kf47=\E[23;6~,
        kf48=\E[24;6~, kf49=\E[1;3P, kf5=\E[15~, kf50=\E[1;3Q,
        kf51=\E[1;3R, kf52=\E[1;3S, kf53=\E[15;3~, kf54=\E[17;3~,
        kf55=\E[18;3~, kf56=\E[19;3~, kf57=\E[20;3~,
        kf58=\E[21;3~, kf59=\E[23;3~, kf6=\E[17~, kf60=\E[24;3~,
        kf61=\E[1;4P, kf62=\E[1;4Q, kf63=\E[1;4R, kf7=\E[18~,
        kf8=\E[19~, kf9=\E[20~, khome=\EOH, kich1=\E[2~,
        kind=\E[1;2B, kmous=\E[<, knp=\E[6~, kpp=\E[5~,
        kri=\E[1;2A, mc0=\E[i, mc4=\E[4i, mc5=\E[5i, meml=\El,
        memu=\Em, oc=\E]104\007, op=\E[39;49m, rc=\E8,
        rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, ri=\EM,
        rin=\E[%p1%dT, ritm=\E[23m, rmacs=\E(B, rmam=\E[?7l,
        rmcup=\E[?1049l\E[23;0;0t, rmir=\E[4l, rmkx=\E[?1l\E>,
        rmm=\E[?1034l, rmso=\E[27m, rmul=\E[24m,
        rs1=\Ec\E]104\007, rs2=\E[!p\E[?3;4l\E[4l\E>, sc=\E7,
        setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
        setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
        sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p5%t;2%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
        sgr0=\E(B\E[m, sitm=\E[3m, smacs=\E(0, smam=\E[?7h,
        smcup=\E[?1049h\E[22;0;0t, smir=\E[4h, smkx=\E[?1h\E=,
        smm=\E[?1034h, smso=\E[7m, smul=\E[4
ThomasDickey commented 4 years ago

It's well-known to be system-dependent (Unix and BSDs generally use ^H, while Linux uses ^?. In the sources, that's provided for. infocmp won't show you that.

filbo commented 4 years ago

Ah, yes, infocmp | grep kbs probably isn't a great way to get this. This might be better:

echo $(tput kbs | cat -A)

Anyway, @TJProgrammer's problem can be fixed by changing their active terminfo entry to specify kbs=\177 (thus locally fixing a misconfiguration / bug in termux; changing the active terminfo entry to match the active configuration of the terminal).

My problem needs a slightly deeper termux change -- a way for me to configure the terminal to actually send ^H for the Backspace key (thus, coincidentally, changing the terminal to match the existing terminfo entry).

tjapro commented 4 years ago

Just for debug:

$ echo $(tput kbs | cat -A)
^H