Bash 一个模糊不清的例子:记录在案的VT100';软包装&x27;逃逸序列?
当通过SSH(终端类型设置为vt100)连接到远程BASH会话时,当光标指向第80列时,控制台命令行将软换行 我试图发现的是,此时发送的Bash 一个模糊不清的例子:记录在案的VT100';软包装&x27;逃逸序列?,bash,console,word-wrap,ansi-escape,vt100,Bash,Console,Word Wrap,Ansi Escape,Vt100,当通过SSH(终端类型设置为vt100)连接到远程BASH会话时,当光标指向第80列时,控制台命令行将软换行 我试图发现的是,此时发送的序列是否记录在任何地方 例如,发送以下字符串 std::string str = "0123456789" // 1 "0123456789" "0123456789" // 3 "0123456789"
序列是否记录在任何地方
例如,发送以下字符串
std::string str = "0123456789" // 1
"0123456789"
"0123456789" // 3
"0123456789"
"0123456789" // 5
"012345678 9"
"0123456789_" // 7
"0123456789"
"0";
从主机(Linux Mint)返回以下响应
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789_01234567890
观察到的行为并不是bash的一部分;相反,它是readline
库行为的一部分。如果只是使用echo
(bash内置)输出足够的文本以强制自动换行,则不会发生这种情况,如果bash生成的错误消息比控制台更宽,也不会发生这种情况。(例如,尝试使用参数超过80个字符的命令
,该参数与任何现有文件都不对应。)
因此,它不是官方的“软包装序列”,也不是任何标准的一部分。相反,这是一个务实的解决方案,解决了许多与控制台显示管理相关的恼人问题之一
换行的终端实现存在歧义:
xenl
:eat新线故障
选项2实际上有两个可能的子变量。在实际由VT-100(和xterm)实现的一种情况下,光标在行的末尾处于异常状态;实际上,它离屏幕只有一个字符的位置,因此您仍然可以在同一行中对光标进行退格。其他历史终端“吃”了换行符,但无论如何都将光标定位在下一行的开头,这样就不可能退格。(除非终端具有bw
功能。)
这就给需要精确跟踪光标位置的程序带来了问题,即使对于回音输入这样的简单应用程序也是如此。(显然,回显输入的最简单方法是让终端自己回显输入,但这样就无法实现额外的控制字符,如制表符完成。)假设用户输入的文本一直到右边距,然后键入退格字符以删除最后键入的字符。通常,您可以通过输出cub1
(向左移动1)代码和el
(清除到行尾)来实现退格删除。(如果删除是在中间行,但原理是相同的。)
但是,如果光标可能位于下一行的开头,这将不起作用。如果您知道光标位于下一行的开头,则可以在执行el
之前先向上移动,然后向右移动,但如果光标仍在同一行上,则无法执行此操作
从历史上看,被认为是“正确的”是强制光标返回到下一行。(以下引用自ncurses
发行版中的文件terminfo.src
。我不知道是谁写的,也不知道是什么时候写的):
(xn
是xenl
的缩写)
笔记
git
存储库当前视图中display.c
的第1326行。在将来的版本中,它可能位于不同的行号,因此提供的链接将无法工作。如果您注意到它已更改,请随时更正链接
将线包装作为一种特殊情况有不止一个原因(这似乎是一个不合适的术语):
- xterm FAQ是讨论vt100换行的众多地方之一
- vim和vim都注意不要使用光标寻址来避免换行,因为这会干扰sele
01234567890123456789012345678901234567890123456789012345678<WS><WS><CR>90123456789_01234567890
# Note that the <xenl> glitch in vt100 is not quite the same as on the Concept, # since the cursor is left in a different position while in the # weird state (concept at beginning of next line, vt100 at end # of this line) so all versions of vi before 3.7 don't handle # <xenl> right on vt100. The correct way to handle <xenl> is when # you output the char in column 80, immediately output CR LF # and then assume you are in column 1 of the next line. If <xenl> # is on, am should be on too.
/* If we're at the right edge of a terminal that supports xn, we're ready to wrap around, so do so. This fixes problems with knowing the exact cursor position and cut-and-paste with certain terminal emulators. In this calculation, TEMP is the physical screen position of the cursor. */
# # -------------------------------- # # dec: DEC (DIGITAL EQUIPMENT CORPORATION) # # Manufacturer: DEC (DIGITAL EQUIPTMENT CORP.) # Class: II # # Info: # Note that xenl glitch in vt100 is not quite the same as concept, # since the cursor is left in a different position while in the # weird state (concept at beginning of next line, vt100 at end # of this line) so all versions of vi before 3.7 don't handle # xenl right on vt100. The correct way to handle xenl is when # you output the char in column 80, immediately output CR LF # and then assume you are in column 1 of the next line. If xenl # is on, am should be on too. # # I assume you have smooth scroll off or are at a slow enough baud # rate that it doesn't matter (1200? or less). Also this assumes # that you set auto-nl to "on", if you set it off use vt100-nam # below. # # The padding requirements listed here are guesses. It is strongly # recommended that xon/xoff be enabled, as this is assumed here. # # The vt100 uses rs2 and rf rather than is2/tbc/hts because the # tab settings are in non-volatile memory and don't need to be # reset upon login. Also setting the number of columns glitches # the screen annoyingly. You can type "reset" to get them set. # # smkx and rmkx, given below, were removed. # smkx=\E[?1h\E=, rmkx=\E[?1l\E>, # Somtimes smkx and rmkx are included. This will put the auxilliary keypad in # dec application mode, which is not appropriate for SCO applications. vt100|vt100-am|dec vt100 (w/advanced video),