Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 May 2018 17:10:01 +0800
From:      =?UTF-8?B?5bSU54GPIChDVUkgSGFvKQ==?= <cuihao.leo@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   `reset` command makes backspace unusable
Message-ID:  <CAJm2p=Kk_LhZ6atTA9P4bjv1tN9mXZpo-3orE1hjogTo0WhECg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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...

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 =3D ^?`. For full output, see https://cfp.vim-cn.com/cbff6

After SSH login FreeBSD, `stty -a` shows `erase =3D ^?; erase2 =3D ^H`,
which seem to be consistent with Linux. See
https://cfp.vim-cn.com/cbff7

But after `reset`, the settings changed and becomes `erase =3D ^H;
erase2 =3D ^H`. see https://cfp.vim-cn.com/cbff8

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=3D^H`.
On Linux, I get the termcap settings by `infocmp -Cr`. Terminal
`xterm-256color` sets `kb=3D^H`, while `xterm-termite` sets `kb=3D\177`.

I tried to override FreeBSD termcap settings in `~/.termcap`:
xterm-256color|xterm alias 3:\
        :Co#256:pa#32767:\
        :kb=3D\177:\
        :AB=3D\E[48;5;%dm:AF=3D\E[38;5;%dm:tc=3Dxterm-new

Above settings indeed works and `reset` won't alter erase setting.
However, Linux `xterm-256color` termcap does set `kb=3D^H` like FreeBSD,
but it doesn't cause the problem on Linux.

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?

--=20
=E5=B4=94=E7=81=8F / CUI Hao
Homepage: i-yu.me
Twitter: @cuihaoleo



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJm2p=Kk_LhZ6atTA9P4bjv1tN9mXZpo-3orE1hjogTo0WhECg>