From owner-freebsd-questions@freebsd.org Thu May 31 07:36:07 2018 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7C75CFC9DAB for ; Thu, 31 May 2018 07:36:07 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "mout.kundenserver.de", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id EB6F275477 for ; Thu, 31 May 2018 07:36:06 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([92.195.66.222]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPA (Nemesis) id 0M8hmN-1gIbpK43KF-00wHsP; Thu, 31 May 2018 09:11:30 +0200 Date: Thu, 31 May 2018 09:11:29 +0200 From: Polytropon To: =?UTF-8?B?5bSU54GP?= (CUI Hao) Cc: freebsd-questions@freebsd.org Subject: Re: `reset` command makes backspace unusable Message-Id: <20180531091129.c0ff4dbb.freebsd@edvax.de> In-Reply-To: References: Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:sFDdsXCvyDQmynC1rG+2VWITupSJQmcjJLBgEt5olcrWdsmm1XM J3+aEPureXHgu6gbOQVuXCYwM6X+dHuN/PUnPHQIA0r/vuIVMelVoBX89kDzsUPsChjY1O8 MjXLOOfbl9VisfUKuu/YMDLgpXhHE6vm3I9WhNZ/sEG3TxlyeadyRUfABkLmLGeO1KhMLNm 2luy5PiOFLH9jHW+DL/HQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:wCj5xmRUD14=:dEle7+LJCk5qF1Y4H29uzt ljBe64hYANOHLf3h1UB5WPrpfBopSXHtNtKNPw0AvRkNBqES9JtDtQiWVnasB2yTU+ELsBbTs HI8aG0T1wI+3QlTtQLwpfmVO8beyd4yQduksKy3qPDaRiopo+vmQI9i9zpE1FHLaHxCDzwavq qZQ+l/xOPE+p9/CPDBG16e7hsTs0ofDCshAs5dt2XG6LkdLxKIPbDhfbQqawBjyyHtpESIaaO 3xo8S50mfVZWv8FZxUMM07Fl4sb0BHLxCzAdOqcEY1Jn9iIDTXCdAUXw3x6yDvXrti2FpUCsR 95iDbsF9U+05iQe3JwkxLZy/2Jqms7mM1EAJzz/RH67MziDrjJs3YpLO4v7WGtb3G1OJgLQZi fh4SBr6C0By0oEsSUaJ5fFOL9u+jNJMmarhhtxZ393MYoH4A6OS5AGNjeGzg7IesKazkJoIQS KJ0VP5ttpNQzcgI6/Pn1K9M0mKyLMZ3/Egk+2011WrbzFnSlwxK7WhgdEktsAFpBnCDzDkk6m 5KmqcTfwr/e0A/MADokjd6CXBQyJxzJLcMrpE0yDs2iE5toIsnmbHn31gZb999UAic8RiE2PV 6l0ATX0S3xHx2PS9eY9isFdeiWrkBXrU8FgWiy8pLnJPbuFPIF9MA1ERqL4vR5ew6Upp+PnxW uhJbIMJ8mbHlk8IxiNI1NLJqO7iCIYDjR+5OCKv90GXGm+bCC0b1BX6l47sFWVT46WLqQSq8K rSybLnYt5z6PL5UK X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 May 2018 07:36:07 -0000 On Tue, 29 May 2018 17:10:01 +0800, 崔灏 (CUI Hao) wrote: > Hi, new to FreeBSD. On Linux, I often use `reset` command to recover > an broken terminal. On FreeBSD, `reset` seems to render backspace > unusable in some CLI programs. > > Steps to reproduce the problem: > 1. SSH login FreeBSD server from a Linux terminal emulator. TERM is > set to `xterm-256color`. > I tried Konsole / Termite. Both reproducible. > But xterm/uxterm doesn't trigger the problem. > 2. Executing `reset` on FreeBSD. > 3. Then pressing backspace will yields `^?` instead of backward > delete in most CLI programs including bash/vim/cat, but not tcsh and > sh. > > Like this: > wm@wmc:~$ reset > Erase is backspace. > wm@wmc:~$ ^?^?^?^? # typing backspace... This indicates that backspace's ^H has been altered to ^?, which usually is delete, but it only works when the "support chain" does react correctly to this code (the C shell sometimes doesn't, which is why you see the "replacement text" instead of the shell per- forming the correct edit action). > I googled about the problem. `stty erase ^?` after `reset`, or `reset > -e ^?` fix it. But I still wonder why `reset` doesn't work like on > Linux. I do some investigation, here are some of my observations: > > 1. terminal line settings (`stty -a`) > I checked the output of `stty -a`. On Linux terminal (Termite), I saw > `erase = ^?`. For full output, see https://cfp.vim-cn.com/cbff6 Here is some relevant output to compare: % stty -a [...] cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = ; eol2 = ; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W; Note that backspace is called "erase" here, and correctly set to ^H, while there is no mentioning of delete (see further notes). > After SSH login FreeBSD, `stty -a` shows `erase = ^?; erase2 = ^H`, > which seem to be consistent with Linux. See > https://cfp.vim-cn.com/cbff7 This makes the DEL key the backspace key, if I read it correctly. > But after `reset`, the settings changed and becomes `erase = ^H; > erase2 = ^H`. see https://cfp.vim-cn.com/cbff8 Now ^H equals backspace (here: "erase"), which is what should happen when the terminal capabilities are reset according to the database. > 2. termcap > It seems default terminal line settings are determined by termcap db. > I checked `/etc/termcap` and found the entry of `xterm-256color`, > which inherits settings of `xterm-basic` entry. `xterm-basic` sets > `kb=^H`. Yes, that again is "key backspace" with the correct setting. > On Linux, I get the termcap settings by `infocmp -Cr`. Terminal > `xterm-256color` sets `kb=^H`, while `xterm-termite` sets `kb=\177`. Key code 177 (0x7F or 127) is a problematic key code because it sometimes means backspace, sometimes delete. > I tried to override FreeBSD termcap settings in `~/.termcap`: > xterm-256color|xterm alias 3:\ > :Co#256:pa#32767:\ > :kb=\177:\ > :AB=\E[48;5;%dm:AF=\E[38;5;%dm:tc=xterm-new > > Above settings indeed works and `reset` won't alter erase setting. > However, Linux `xterm-256color` termcap does set `kb=^H` like FreeBSD, > but it doesn't cause the problem on Linux. This kind of modification should not be needed. However, you can do certain customization to your C shell's settings (and let's assume for now you're using the C shell as your dialog shell, simply because this is FreeBSD's default). Add the following settings to /etc/csh.cshrc (for global effect) or to ~/.cshrc (for user-local effect): if ($?prompt) then # ... stuff omitted ... bindkey ^? delete-char # delete for console bindkey ^[[3~ delete-char # delete for xterm # ... more stuff ... endif You can also experiment with the "ESC sequence spelling" of the key codes (using "\e" instead of "^["), like this: bindkey "\e[3~" delete-char # delete bindkey "\e[1~" beginning-of-line # home bindkey "\e[4~" end-of-line # end Note that backspace will be reset to ^H which is the correct setting for this key, so there should be no need to add it. You can still _always_ simply press Ctrl+H to check if it does correctly perform the backspace operation on the current line. > Although I have found several workaround to fix backspace problem, may > anyone explain why terminal settings inconsistent on Linux and > FreeBSD? Is this a bug or just some compatibility issues? Are there > other compatibility issues with Linux terminal emulator? This is probably because FreeBSD's console subsystem currently still is in a flow, and Linux is always in a flow, so there is no real agreement about how things should be solved in a cross- compatible way... ;-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...