[英]how is terminfo delay/padding implemented in TTYs?
I have been looking at terminfo and it has delays, eg $<5>
, in the capability strings. 我一直在查看terminfo,它在功能字符串中有延迟,例如
$<5>
。 I was trying to see through running tput
under strace
how is the delay implemented, ie, whether it is implemented by, say, nanosleep
or by inserting NUL
or other characters. 我试图通过在
strace
下运行tput
来看看延迟是如何实现的,即是否通过nanosleep
或通过插入NUL
或其他字符来实现。 This is the command I have tried to run and trace: 这是我试图运行和跟踪的命令:
TERM=ansi77 strace -o log.txt tput dl1
I chose dl1
on ansi77
because it is defined as dl1=\\E[M$<5*/>
. 我选择
dl1
上ansi77
因为它被定义为dl1=\\E[M$<5*/>
However, all I see in the trace is write of 3 bytes: 但是,我在跟踪中看到的只是写入3个字节:
write(1, "\33[M", 3) = 3
tput
? tput
重现它有什么缺陷吗? Where delays are implemented, it's done by transmitting pad characters, traditionally NUL characters. 在实现延迟的地方,通过传输填充字符(传统的NUL字符)来完成。 The pad character can be changed by a termdata/terminfo setting of the variable pad or pc .
可以通过可变pad或pc的termdata / terminfo设置来改变pad字符。
Pad characters are necessary because the program cannot know when the previously-sent characters have actually been written for it to start a CPU delay. 填充字符是必需的,因为程序无法知道何时实际为其写入了先前发送的字符以启动CPU延迟。 Even if the kernel is done with them after an output flush the characters might still be buffered in the output device UART.
即使在输出刷新之后内核完成了它们,字符仍然可以在输出设备UART中缓冲。
The number of required pad characters is calculated from the baud rate - so it depends on that information being available and accurate. 所需填充字符的数量是根据波特率计算的 - 因此它取决于可用且准确的信息。
The tputs routine in the library implements padding (see man 3 tputs ). 库中的tputs例程实现了填充(参见man 3 tputs )。 I suspect that the command-line tool does too, since it's basically just a wrapper.
我怀疑命令行工具也是如此,因为它基本上只是一个包装器。
Agreeing with @cliffordheath that padding is done by adding padding characters, reference to the available documentation can help. 同意@cliffordheath通过添加填充字符来完成填充,对可用文档的引用可以提供帮助。
Hardware terminals did not cease to exist, they are still supported by ncurses . 硬件终端并没有停止存在,它们仍然受到ncurses的支持 。 Without padding, these old terminals would not work properly (dropping or mangling your output).
没有填充,这些旧的终端将无法正常工作(丢弃或损坏您的输出)。 The
vt100
entry uses padding, that for xterm
does not. vt100
条目使用填充,而xterm
没有。
The terminfo name for the padding character is pad
; 填充字符的terminfo名称是
pad
; pc
is a termcap name (see terminfo(5) ): pc
是termcap名称(参见terminfo(5) ):
pad_char pad pc padding char
(instead of null)
The terminfo manual page has a lengthy paragraph (in Types of Capabilities ) dealing with padding. terminfo手册页有一个冗长的段落(在功能类型中 )处理填充。 There are two types of padding supported in terminfo format ( advisory and mandatory ), distinguished by their format.
terminfo格式支持两种类型的填充( 建议和强制 ),以其格式区分。 termcap supports only the latter (using different syntax of course), and unlike terminfo all of the delays happen at one time (making escape sequences for "flash" generally not work).
termcap仅支持后者(当然使用不同的语法),并且与terminfo不同,所有延迟都是一次发生的(使得“flash”的转义序列通常不起作用)。
The command-line tput
program does more than act as a wrapper for the function tputs
, but it uses that when outputting strings. 命令行
tput
程序做比充当用于功能的包装更tputs
,但是它使用的是输出字符串时。 The command-line program provides for outputting boolean, numeric and of course string capabilities. 命令行程序提供输出布尔值,数字和当然字符串功能。
The library call tputs
has a parameter for the number of affected lines which is taken into account (like baud rate) in computing delays. 库调用
tputs
具有受影响行数的参数,在计算延迟时将其考虑在内(如波特率)。
In OP's question 在OP的问题
dl1=\E[M$<5*/>
specifies a delay proportional to the number of lines affected (marked by the "*"
character). 指定与受影响的行数成比例的延迟(由
"*"
字符标记)。 The number of lines affected for the command-line tput
utility is 1. It calls putp
to do this. 命令行
tput
实用程序受影响的行数为1.它调用putp
来执行此操作。 However, that in turn calls delay_output , and that calls baudrate . 但是,它反过来调用delay_output ,并调用波特率 。 The last function is initialized only when the terminal is initialized.
最后一个功能仅在终端初始化时初始化。 The command-line
tput
does not initialize the terminal, so delays will not work for that . 命令行
tput
不初始化终端,所以延迟将不会为这项工作。 You should see (given the right speed) delays using the library itself. 你应该看到(给定正确的速度)使用库本身的延迟。
ncurses also provides time delays with napms
(milliseconds), which is different from padding. ncurses还提供了
napms
(毫秒)的时间延迟,这与填充不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.