简体   繁体   English

如何在TTY中实现terminfo延迟/填充?

[英]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*/> . 我选择dl1ansi77因为它被定义为dl1=\\E[M$<5*/> However, all I see in the trace is write of 3 bytes: 但是,我在跟踪中看到的只是写入3个字节:

write(1, "\33[M", 3)                    = 3
  1. So, my question is, how the delay actually implemented? 所以,我的问题是,延迟实际如何实施? Padding characters or simple process/thread sleep? 填充字符或简单的进程/线程睡眠?
  2. Can I observe it in terminal emulator or do I need real hardware terminal to see it? 我可以在终端仿真器中观察它还是需要真正的硬件终端才能看到它?
  3. Is there any flaw in trying to reproduce it with 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 . 可以通过可变padpc的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM