简体   繁体   中英

how is terminfo delay/padding implemented in TTYs?

I have been looking at terminfo and it has delays, eg $<5> , in the capability strings. 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. 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*/> . However, all I see in the trace is write of 3 bytes:

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 ?

Where delays are implemented, it's done by transmitting pad characters, traditionally NUL characters. The pad character can be changed by a termdata/terminfo setting of the variable pad or pc .

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. Even if the kernel is done with them after an output flush the characters might still be buffered in the output device 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 ). 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.

Hardware terminals did not cease to exist, they are still supported by 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.

The terminfo name for the padding character is pad ; pc is a termcap name (see 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. There are two types of padding supported in terminfo format ( advisory and mandatory ), distinguished by their format. 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).

The command-line tput program does more than act as a wrapper for the function tputs , but it uses that when outputting strings. 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.

In OP's question

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. However, that in turn calls delay_output , and that calls baudrate . 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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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