Linux 终端:输入反馈消失,不显示换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17682934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux Terminal: typing feedback gone, line breaks not displayed
提问by E.Z.
From time to time I have to run a command-line tool (a Python script) whose output seems to break my terminal.
After the execution is finished, the typing feedback is gone (I can't see what I'm typing), and also line breaks are not displayed. This happens if the terminal is started remotely via Putty
, and also locally when using gnome-terminal
.
有时我不得不运行一个命令行工具(一个 Python 脚本),它的输出似乎破坏了我的终端。执行完成后,打字反馈消失了(我看不到我在打什么),也没有显示换行符。如果终端通过 远程启动Putty
,并且在使用 时也在本地启动,则会发生这种情况gnome-terminal
。
For example, after the problem happens, if I type ENTERpwd
ENTER, I would expect to see:
例如,在问题发生后,如果我输入ENTERpwd
ENTER,我希望看到:
[userA@host006 ~]$
[userA@host006 ~]$ pwd
/home/userA
[userA@host006 ~]$
But actually the output is:
但实际上输出是:
[userA@host006 ~]$ [userA@host006 ~]$ /home/userA
[userA@host006 ~]$
The only way to fix it is to close that terminal and start a new one.
修复它的唯一方法是关闭该终端并启动一个新终端。
Maybe be related: the script output contains some terminal-based formatting (e.g. invert foreground/background to highlight some status messages). If I dump this output to a file I can see things like [07mSome Message Here[0m
.
可能是相关的:脚本输出包含一些基于终端的格式(例如反转前景/背景以突出显示某些状态消息)。如果我将此输出转储到文件中,我可以看到类似[07mSome Message Here[0m
.
Any ideas what I could do to prevent this?
任何想法我可以做些什么来防止这种情况?
采纳答案by Joshua Briefman
Execute the command reset
and your terminal should be restored (reference).
执行命令reset
,你的终端应该被恢复(参考)。
This issue happens generally when dumping binary data to the terminal STDOUT
which when the escape codes received are processed can do anything from change the color of the text, disable echo, even change character set.
这个问题通常发生在将二进制数据转储到终端时STDOUT
,当接收到的转义码被处理时,可以做任何事情,从改变文本的颜色,禁用回显,甚至改变字符集。
The easy way to avoid this is to ensure you do not dump unknown binary data to the terminal, and if you must then convert it to hexadecimal to ensure it doesn't change the terminal settings.
避免这种情况的简单方法是确保您不会将未知的二进制数据转储到终端,如果您必须将其转换为十六进制以确保它不会更改终端设置。
回答by Bas Peeters
To elaborate on Joshua Briefman's answer, executing reset -c
will only reset the control characters responsible for your problem:
为了详细说明Joshua Briefman 的回答,执行reset -c
只会重置导致您的问题的控制字符:
tset
,reset
- terminal initialization
tset
,reset
- 终端初始化
Usage: tset [options] [terminal]
Options:
-c set control characters
-e ch erase character
-I no initialization strings
-i ch interrupt character
-k ch kill character
-m mapping map identifier to type
-Q do not output control key settings
-r display term on stderr
-s output TERM set command
-V print curses-version
-w set window-size
Also note the following form the the command's manual:
另请注意命令手册中的以下内容:
Note, you may have to type
<LF>reset<LF>
(the line-feed character is normally control-J) to get the terminal to work, as carriage-return may no longer work in the abnormal state. Also, the terminal will often not echo the command.
请注意,您可能需要输入
<LF>reset<LF>
(换行符通常是 control-J)使终端工作,因为在异常状态下回车可能不再工作。此外,终端通常不会回显命令。