现象: 使用mutt查看邮件, 连续查看下一封, 或者按q回退到邮件列表, 屏幕上字符会混乱, 也就是比如看到下一封邮件, 但是有些地方还是上一封的内容字符, 并没有完全重绘(redraw)窗口.
这个问题困扰了很长一段时间, 多次搜索无果, 找不到切入点.
这两天又试了下, 发现在tmux下运行mutt会有这个问题, 否则是正常的. Google “tmux mutt not flush” 搜出这篇回答: Tmux + mutt not redrawing
Set the default terminal for new windows created in this session - the default value of the TERM environment variable. For tmux to work correctly, this must be set to `screen' or a derivative of it.
screen. 另外这里还强调了必须设置screen或它的衍生. 而我设置的是
set -g default-terminal "screen-256color"
if [ -z "$TMUX" ] && [[ "$TERM" =~ "xterm" ]]; then if [ -e /usr/share/terminfo/*/xterm-256color ]; then echo "1" export TERM='xterm-256color' else echo "2" export TERM='xterm-color' fi elif [ -n "$TMUX" ]; then if [ -e /usr/share/terminfo/*/screen-256color ]; then echo "3" export TERM='screen-256color' else echo "4" export TERM='screen' fi fi
$TMUX环境变量, 在使用tmux后, 这个变量是一个路径值
-e /usr/share/terminfo/*/xterm-256color, 在linux下,
*这个其实是terminal type的首字母, 但是mac os下不是这样, 我原先设置的是
-e /usr/share/terminfo/x/xterm-256color, 在mac下不工作.
并且没有完全弄清楚, 可能会有理解错误的地方 )
tty, pty, pts: (
man 4 xxx查看手册)
- A tty is a native terminal device, the backend is either hardware or kernel emulated.
- The TTY is a terminal that doesn’t require X or any program to exist, aka a Real Terminal. So you can use that terminal even when X fails to load. (kernel stuff)
pty, pts, pseudoterminal, 伪终端. 是由普通程序仿真出来, 如screen, ssh等. pty分为ptmx(master)和pts(slave).
- A pty (pseudo terminal device) is a terminal device which is emulated by an other program (example: xterm, screen, or ssh are such programs).
- In practice, pseudo-terminals are used for implementing terminal emulators such as xterm
- A PTS is a a Pseudo Terminal that needs a program to exist. You can launch several PTS in the same TTY. Both behaviors almost the same. (user stuff)
w 可以看到登录情况以及terminal name:
# 这台机器是部署在虚拟机上 # tty1 是我直接在虚拟机终端输入帐号密码登录进去 # pts/0 是通过ssh登录上去 tankywoo ~ % w 18:13:38 up 13 days, 6:08, 2 users, load average: 0.02, 0.04, 0.05 USER TTY LOGIN@ IDLE JCPU PCPU WHAT tankywoo tty1 17:59 14:05 0.36s 0.34s -zsh tankywoo pts/0 17:41 0.00s 0.57s 0.00s w
- What is the difference between a TTY terminal and a PTS graphical terminal in Linux?
- Difference between pts and tty
terminal, console, terminal emulator, terminal multiplexer
terminal emulator, 终端仿真器.
- is a program that emulates a video terminal within some other display architecture.
- provides a standardised character based interface for text mode applications, it emulates the behavior of real or idealised hardware.
这是一份完整的列表List of terminal emulators
terminal multiplexer, 终端复用器.
is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session.
terminal, 其实在日常的技术交流中, 这两个基本是等价的. 所以这里这里要是深究其区别, 并追溯历史原因, 是一件很蛋疼的事情.
- A terminal refers to a wrapper program which runs a shell. Decades ago, this was a physical device consisting of little more than a monitor and keyboard. As unix/linux systems added better multiprocessing and windowing systems, this terminal concept was abstracted into software. Now you have programs such as Gnome Terminal which launches a window in a Gnome windowing environment which will run a shell into which you can enter commands.
- The console is a special sort of terminal. Historically, the console was a single keyboard and monitor plugged into a dedicated serial console port on a computer used for direct communication at a low level with the operating system. Modern linux systems provide virtual consoles. These are accessed through key combinations (e.g.
Ctrl+Alt+F1; the function key numbers different consoles) which are handled at low levels of the linux operating system – this means that there is no special service which needs to be installed and configured to run. Interacting with the console is also done using a shell program.
- What is the difference between a Console, Shell, Terminal, Terminal emulator, Terminal multiplexer, and a Window manager?
- What is the difference between shell, console, and terminal? 比较认可这篇的解释
- What is the difference between Terminal, Console, Shell, and Command Line? 这个帖子的一些回答都值得看看
- What is the exact difference between a ‘terminal’, a ‘shell’, a ‘tty’ and a ‘console’?
- console vs terminal
- terminal一般用于指terminal emulator
其实, 这块还是不纠结, 就当作一回事比较好, 基于历史原因, 曾经的terminal, console现在都software/virtual化了.
$TERM环境变量, 定义terminal type (
man 7 term):
- The environment variable TERM should normally contain the type name of the terminal, console or display-device type you are using. This information is critical for all screen-oriented programs, including your editor and mailer.
- associates the terminal you are using with a list of characteristics given in the terminfo(M) database. The characteristics tell the system how to interpret your terminal’s keys and how to display data on your terminal screen.
- The $TERM variable is for use by applications to take advantage of capabilities of that terminal.
- For example, if a program want’s to display colored text, it must first find out if the terminal you’re using supports colored text, and then if it does, how to do colored text.
- The way this works is that the system keeps a library of known terminals and their capabilities. On most systems this is in /usr/share/terminfo (there’s also termcap, but it’s legacy not used much any more).
toe 可以查看支持的terminal type
/usr/share/terminfo/ 是一个数据库, 存放是支持的terminal功能
infocmp <term type 1> <term type 2> 用于对比两个term的不同
- Which terminal type am I using? 解释的比较详细
- What’s the difference between various $TERM variables?
- Terminal emacs colors only work with TERM=xterm-256color
个人理解, terminal emulator 和 terminal type的关系, 有点类似Linux发行版和系统内核的关系. 比如guake和gnome-terminal这两个terminal emulator都是GNOME终端, terminal type可以是gnome一系的.
iTerm 在 Profiles -> Terminal -> Report Terminal Type 里可以设置终端仿真器的类型.