Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

[solved] CLI mail app backspace broken

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
7 posts • Page 1 of 1
Author
Message
jagdpanther
l33t
l33t
Posts: 820
Joined: Sat Nov 22, 2003 2:26 pm

[solved] CLI mail app backspace broken

  • Quote

Post by jagdpanther » Thu May 02, 2024 2:30 am

Inside a terminal window (xterm) backspace normally works as expected. However, when using 'mail' CLI program (from mailx package) both when typing the "Subject:" and the body when I press backspace I receive what looks like a ^H (shift-6 followed by "H") instead of erasing a character. Any idea where I should start looking to fix this? (Also if someone knows some other key combination to simulate a backspace, please let me know.)

For example on each line of the following I made an error (extra character) and pressed backspace. Only on the first line, before 'mail' runs, did backspace work as expected:

Code: Select all

$ mail testuser@localhost
Subject: test messagee^H
This is a test linee^H
.
Cc:
$
Last edited by jagdpanther on Fri May 31, 2024 1:15 am, edited 1 time in total.
Top
myga
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 121
Joined: Mon Jun 12, 2023 2:06 am

  • Quote

Post by myga » Thu May 02, 2024 3:49 am

Just tested it on Mint from Windows Terminal using SSH and it works fine on BASH, SH, & ZSH. I'm suspecting the terminal emulator you are using is the issue.
[Never break the law to save people. Nope, there aint no heroes here. Unless you are 'Satoshi Nakamoto', that's a true anonymous.]
Top
jagdpanther
l33t
l33t
Posts: 820
Joined: Sat Nov 22, 2003 2:26 pm

  • Quote

Post by jagdpanther » Thu May 02, 2024 4:15 am

I'm suspecting the terminal emulator you are using is the issue.
Ok. That is correct. I just dropped down to a console (<ctrl><alt>F2) and there backspace in the mail CLI app works.

So what is wrong with xterm?
Top
Banana
Moderator
Moderator
User avatar
Posts: 2364
Joined: Fri May 21, 2004 12:02 pm
Location: Germany
Contact:
Contact Banana
Website

  • Quote

Post by Banana » Thu May 02, 2024 6:13 am

It is the backarrowKey functionality from https://linux.die.net/man/1/xterm

A good description can be found here: https://superuser.com/questions/993171/ ... ce-sends-h
The key labeled "backspace" is a matter of contention. Technically, it ought to send ^H simply because that is the name of the ASCII control character. Others differ, because their expectations have been affected by the history of this feature (see Why doesn't my delete key work?).

In a discussion where you say you are typing, the usual connotation (lacking clarification) is that you have started a terminal, then run a program within the terminal. For that case, there is a corresponding terminal initialization, e.g., using a shell and program such as stty. This is run on the local machine (where you are typing). MobaXterm provides stty since Version 3.2 (2011-05-30).
or here: https://invisible-island.net/xterm/xter ... term_erase
Forum Guidelines

PFL - Portage file list - find which package a file or command belongs to.
My delta-labs.org snippets do expire
Top
jagdpanther
l33t
l33t
Posts: 820
Joined: Sat Nov 22, 2003 2:26 pm

  • Quote

Post by jagdpanther » Fri May 03, 2024 6:21 pm

Banana: Thank you for the links.

I tried two of the listed solutions without success.

However, I notice that in xterm when running a CLI program (ex: mail) when backspace does not work and I receive a ^H that <ctrl>backspace does work.
Top
mmogilvi
n00b
n00b
Posts: 64
Joined: Fri May 13, 2011 3:13 am

  • Quote

Post by mmogilvi » Fri May 24, 2024 11:03 pm

This is currently happening for any program run in an xterm that uses the tty in its basic "cooked" mode (subject to stty settings). The simplest such program is "cat".

It also happens with programs that might interactively ask for confirmation, such as "emerge -a", "cp -i", etc. You occasionally mistype the confirmation and try to use backspace, and encounter difficulties. These conditions are rare enough you might go weeks before realizing that backspace isn't working properly, which makes tracking down what changed more difficult... Similarly, if a no-echo password prompt fails, you are likely to conclude you lost track of what characters/backspaces you were typing, rather than conclude that backspace isn't actually working. In contrast, some common programs like "bash" and "vim" run the terminal in "raw" mode and (depending on lots of config details) often interpret both ^H and ^? in ways that hide that things are inconsistent elsewhere...

In gentoo, I think it was broken by a recent ncurses update changing the default "kbs" setting in the "xterm" terminfo database. This DB setting typically becomes the default "stty erase" setting:

Code: Select all

$ cat
abc^H^H^C
$ infocmp xterm | grep kbs
        ka3=\EOy, kb2=\EOu, kbeg=\EOE, kbs=^?, kc1=\EOq, kc3=\EOs,
$ stty --all | grep erase
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
$ 
If I run infocmp in an intentionally-old unupdated chroot from 2020, I get "^H" instead of "^?", although I suspect this change is much more recent than 2020.

There seems to be a long-standing disagreement about whether the backspace key should mean "^H" or "^?". But I think it is definitely a gentoo bug when the default setting in the ncurses DB entry and xterm program's default behavior are not consistent with each other in a single install. I think gentoo should fix this inconsistency somehow, but I'm not sure how. There are several possibilities with different nuances... (Maybe someone should file a bug...)

Speculation: Perhaps the terminfo change was an attempt to resolve historically inconsistent "xterm" entries between different OS's? But my searches haven't found anything to indicate there is currently any such effort. In fact, ncurses has long seemed to punt on the issue, to the point where there is apparently a build-time configure option "--with-xterm-kbs" to switch it around (although gentoo's ncurses ebuilds do not seem to use it, and I haven't tried it myself). I was initially concerned that ssh-ing between machines could cause similar issues if the terminfo entries are different, although some testing suggests ssh copies the local "stty erase" setting over to the remote machine by default, which minimizes problems. (There could still be problems if some rare applications trust terminfo over "stty erase"...)

Background:

There are three conceptual settings that ideally should be consistent with each other:
  • Which byte/character does xterm generate and feed to the pseudo-terminal when you press the backspace key?
  • The terminfo "kbs" setting.
  • The stty "erase" setting, which controls which byte/character a "cooked" mode terminal (in kernel) and/or most "raw" mode programs actually treat like a backspace.
Xterm and stty need to be consistent with each other. Most programs don't really care about the terminfo "kbs" setting directly, which allows ssh's copying of the stty setting to usually work even if "kbs" is inconsistent. But occasionally you could encounter programs where "kbs" does matter.

Settings and User Workarounds
  • Use Control-Backspace instead of Backspace, as previously mentioned. (awkward)
  • Use Control-LeftMouse to bring up a menu in xterm, and toggle the "Backarrow Key (BS/DEL)" option, which is called "backarrowKey" or DECBKM in the man page. (temporary)
  • There are at least three X resource properties that xterm uses to control this. See "man xterm" page, especially the sections about "backarrowKeyIsErase", "backarrowKey", "ptyInitialErase", and "ttyMode".
  • The interaction of xterm properties is complicated, but the most promising looks like "backarrowKeyIsErase". If set to true with others left as default, it looks like it makes the sent character and the initial/default stty erase setting match the current terminfo kbs DB entry, so everything is consistent, and will presumably still be consistent (toggled everywhere) even if a later update toggles the DB entry again. I'm not sure why it isn't the default. Maybe because there is apparently a DECBKM control sequence that a program can send to xterm to change the behavior of the backspace key, and "true" disables that sequence? But I don't understand why a program (or the program's user) would ever want to use such a sequence.
  • TLDR maybe-best user workaround: Try putting "xterm*backarrowKeyIsErase: true" in your ~/.Xresources file (and/or maybe .Xdefaults). Not sure if you need to arrange to "xrdb -merge ~/.Xresources" yourself or not, and/or logout/login, but you definitely need to restart your xterms.
  • "stty erase ^H" will also work for this specific case, but could break other cases, like if logged into the Linux console instead of an xterm, or anything else that uses ^?. This command could be placed in .profile or maybe .bashrc, possibly protected by checking various environment variables like "TERM", "SSH_*", "XTERM_*", etc...
  • https://bugs.archlinux.org/task/74379 shows how to replace the "kbs" setting in the terminfo database, but of course that will be lost the next time you emerge ncurses...
  • Maybe experiment with modifying the "--with-xterm-kbs" config option? But that requires customizing the ebuild...
EDIT 2024-05-31: I wrote up https://bugs.gentoo.org/933302 to suggest that the OS defaults ought to be consistent with each other...
Last edited by mmogilvi on Sat Jun 01, 2024 5:57 am, edited 1 time in total.
Top
jagdpanther
l33t
l33t
Posts: 820
Joined: Sat Nov 22, 2003 2:26 pm

  • Quote

Post by jagdpanther » Fri May 31, 2024 1:14 am

mmogilvi:

THANK YOU.

Your suggestion to put the following in my .Xresources file worked:

Code: Select all

xterm*backarrowKeyIsErase: true
(Ok I ran a quick "xrdb -all -remove" followed by "xrdb -merge .Xresources". Then it worked.)

I test with vi (which never had the problem) and then the CLI "mail" application which had the issue. Both work without issue both when running X and in console.
Top
Post Reply

7 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy