📄 termcap.texi
字号:
Keep in mind that on many terminals the correct padding for insert/deleteline or for scrolling is cursor-position dependent. If you get problemsfrom scrolling a large region of the screen but not from scrolling a smallpart (just a few lines moving), it may mean that fixed padding should bereplaced with position-dependent padding.@node Describe Padding, Output Padding, Not Enough, Padding@subsection Specifying Padding in a Terminal DescriptionIn the terminal description, the amount of padding required by each displaycommand is recorded as a sequence of digits at the front of the command.These digits specify the padding time in milliseconds (msec). They can befollowed optionally by a decimal point and one more digit, which is anumber of tenths of msec.Sometimes the padding needed by a command depends on the cursor position.For example, the time taken by an ``insert line'' command is usuallyproportional to the number of lines that need to be moved down or cleared.An asterisk (@samp{*}) following the padding time says that the timeshould be multiplied by the number of screen lines affected by the command.@example:al=1.3*\E[L:@end example@noindentis used to describe the ``insert line'' command for a certain terminal.The padding required is 1.3 msec per line affected. The command itself is@samp{@key{ESC} [ L}.The padding time specified in this way tells @code{tputs} how many padcharacters to output. @xref{Output Padding}.Two special capability values affect padding for all commands. These arethe @samp{pc} and @samp{pb}. The variable @samp{pc} specifies thecharacter to pad with, and @samp{pb} the speed below which no padding isneeded. The defaults for these variables, a null character and 0,are correct for most terminals. @xref{Pad Specs}.@node Output Padding, , Describe Padding, Padding@subsection Performing Padding with @code{tputs}@cindex line speed@findex tputsUse the termcap function @code{tputs} to output a string containing anoptional padding spec of the form described above (@pxref{DescribePadding}). The function @code{tputs} strips off and decodes the paddingspec, outputs the rest of the string, and then outputs the appropriatepadding. Here is its declaration in ANSI C:@examplechar PC;short ospeed;int tputs (char *@var{string}, int @var{nlines}, int (*@var{outfun}) ());@end exampleHere @var{string} is the string (including padding spec) to be output;@var{nlines} is the number of lines affected by the operation, which isused to multiply the amount of padding if the padding spec ends with a@samp{*}. Finally, @var{outfun} is a function (such as @code{fputchar})that is called to output each character. When actually called,@var{outfun} should expect one argument, a character.@vindex ospeed@vindex PCThe operation of @code{tputs} is controlled by two global variables,@code{ospeed} and @code{PC}. The value of @code{ospeed} is supposed to bethe terminal output speed, encoded as in the @code{ioctl} system call whichgets the speed information. This is needed to compute the number ofpadding characters. The value of @code{PC} is the character used forpadding.You are responsible for storing suitable values into these variables beforeusing @code{tputs}. The value stored into the @code{PC} variable should betaken from the @samp{pc} capability in the terminal description (@pxref{PadSpecs}). Store zero in @code{PC} if there is no @samp{pc}capability.@refillThe argument @var{nlines} requires some thought. Normally, it should bethe number of lines whose contents will be cleared or moved by the command.For cursor motion commands, or commands that do editing within one line,use the value 1. For most commands that affect multiple lines, such as@samp{al} (insert a line) and @samp{cd} (clear from the cursor to the endof the screen), @var{nlines} should be the screen height minus the currentvertical position (origin 0). For multiple insert and scroll commands suchas @samp{AL} (insert multiple lines), that same value for @var{nlines} iscorrect; the number of lines being inserted is @i{not} correct.@refillIf a ``scroll window'' feature is used to reduce the number of linesaffected by a command, the value of @var{nlines} should take this intoaccount. This is because the delay time required depends on how much workthe terminal has to do, and the scroll window feature reduces the work.@xref{Scrolling}.Commands such as @samp{ic} and @samp{dc} (insert or delete characters) areproblematical because the padding needed by these commands is proportionalto the number of characters affected, which is the number of columns fromthe cursor to the end of the line. It would be nice to have a way tospecify such a dependence, and there is no need for dependence on verticalposition in these commands, so it is an obvious idea to say that for thesecommands @var{nlines} should really be the number of columns affected.However, the definition of termcap clearly says that @var{nlines} is alwaysthe number of lines affected, even in this case, where it is always 1. Itis not easy to change this rule now, because too many programs and terminaldescriptions have been written to follow it.Because @var{nlines} is always 1 for the @samp{ic} and @samp{dc} strings,there is no reason for them to use @samp{*}, but some of them do. Theseshould be corrected by deleting the @samp{*}. If, some day, such entrieshave disappeared, it may be possible to change to a more useful conventionfor the @var{nlines} argument for these operations without breaking anyprograms.@node Parameters, , Padding, Library@section Filling In Parameters@cindex parametersSome terminal control strings require numeric @dfn{parameters}. Forexample, when you move the cursor, you need to say what horizontal andvertical positions to move it to. The value of the terminal's @samp{cm}capability, which says how to move the cursor, cannot simply be a string ofcharacters; it must say how to express the cursor position numbers andwhere to put them within the command.The specifications of termcap include conventions as to which string-valuedcapabilities require parameters, how many parameters, and what theparameters mean; for example, it defines the @samp{cm} string to taketwo parameters, the vertical and horizontal positions, with 0,0 being theupper left corner. These conventions are described where the individualcommands are documented.Termcap also defines a language used within the capability definition forspecifying how and where to encode the parameters for output. This languageuses character sequences starting with @samp{%}. (This is the same idea as@code{printf}, but the details are different.) The language for parameterencoding is described in this section.A program that is doing display output calls the functions @code{tparam} or@code{tgoto} to encode parameters according to the specifications. Thesefunctions produce a string containing the actual commands to be output (aswell a padding spec which must be processed with @code{tputs};@pxref{Padding}).@menu* Encode Parameters:: The language for encoding parameters.* Using Parameters:: Outputting a string command with parameters.@end menu@node Encode Parameters, Using Parameters, , Parameters@subsection Describing the Encoding@cindex %A terminal command string that requires parameters contains specialcharacter sequences starting with @samp{%} to say how to encode theparameters. These sequences control the actions of @code{tparam} and@code{tgoto}.The parameters values passed to @code{tparam} or @code{tgoto} areconsidered to form a vector. A pointer into this vector determinesthe next parameter to be processed. Some of the @samp{%}-sequencesencode one parameter and advance the pointer to the next parameter.Other @samp{%}-sequences alter the pointer or alter the parametervalues without generating output.For example, the @samp{cm} string for a standard ANSI terminal is writtenas @samp{\E[%i%d;%dH}. (@samp{\E} stands for @key{ESC}.) @samp{cm} byconvention always requires two parameters, the vertical and horizontal goalpositions, so this string specifies the encoding of two parameters. Here@samp{%i} increments the two values supplied, and each @samp{%d} encodesone of the values in decimal. If the cursor position values 20,58 areencoded with this string, the result is @samp{\E[21;59H}.First, here are the @samp{%}-sequences that generate output. Except for@samp{%%}, each of them encodes one parameter and advances the pointerto the following parameter.@table @samp@item %%Output a single @samp{%}. This is the only way to represent a literal@samp{%} in a terminal command with parameters. @samp{%%} does notuse up a parameter.@item %dAs in @code{printf}, output the next parameter in decimal.@item %2Like @samp{%02d} in @code{printf}: output the next parameter indecimal, and always use at least two digits.@item %3Like @samp{%03d} in @code{printf}: output the next parameter indecimal, and always use at least three digits. Note that @samp{%4}and so on are @emph{not} defined.@item %.Output the next parameter as a single character whose ASCII code isthe parameter value. Like @samp{%c} in @code{printf}.@item %+@var{char}Add the next parameter to the character @var{char}, and output theresulting character. For example, @samp{%+ } represents 0 as a space,1 as @samp{!}, etc.@end tableThe following @samp{%}-sequences specify alteration of the parameters(their values, or their order) rather than encoding a parameter for output.They generate no output; they are used only for their side effectson the parameters. Also, they do not advance the ``next parameter'' pointerexcept as explicitly stated. Only @samp{%i}, @samp{%r} and @samp{%>} aredefined in standard Unix termcap. The others are GNU extensions.@refill@table @samp@item %iIncrement the next two parameters. This is used for terminals thatexpect cursor positions in origin 1. For example, @samp{%i%d,%d} wouldoutput two parameters with @samp{1} for 0, @samp{2} for 1, etc.@item %rInterchange the next two parameters. This is used for terminals whosecursor positioning command expects the horizontal position first.@item %sSkip the next parameter. Do not output anything.@item %bBack up one parameter. The last parameter used will become once againthe next parameter to be output, and the next output command will useit. Using @samp{%b} more than once, you can back up any number ofparameters, and you can refer to each parameter any number of times.@item %>@var{c1}@var{c2}Conditionally increment the next parameter. Here @var{c1} and@var{c2} are characters which stand for their ASCII codes as numbers.If the next parameter is greater than the ASCII code of @var{c1}, theASCII code of @var{c2} is added to it.@refill@item %a @var{op} @var{type} @var{pos}Perform arithmetic on the next parameter, do not use it up, and do notoutput anything. Here @var{op} specifies the arithmetic operation,while @var{type} and @var{pos} together specify the other operand.Spaces are used above to separate the operands for clarity; the spacesdon't appear in the data base, where this sequence is exactly fivecharacters long.The character @var{op} says what kind of arithmetic operation toperform. It can be any of these characters:@table @samp@item =assign a value to the next parameter, ignoring its old value.The new value comes from the other operand.@item +add the other operand to the next parameter.@item -subtract the other operand from the next parameter.@item *multiply the next parameter by the other operand.@item /divide the next parameter by the other operand.@end tableThe ``other operand'' may be another parameter's value or a constant;the character @var{type} says which. It can be:@table @samp@item pUse another parameter. The character @var{pos} says whichparameter to use. Subtract 64 from its ASCII code to get theposition of the desired parameter relative to this one. Thus,the character @samp{A} as @var{pos} means the parameter after thenext one; the character @samp{?} means the parameter before thenext one.@item cUse a constant value. The character @var{pos} specifies thevalue of the constant. The 0200 bit is cleared out, so that 0200can be used to represent zero.@end table@end tableThe following @samp{%}-sequences are special purpose hacks to compensatefor the weird designs of obscure terminals. They modify the next parameteror the next two parameters but do not generate output and do not use up anyparameters. @samp{%m} is a GNU extension; the others are defined instandard Unix termcap.@table @samp@item %nExclusive-or the next parameter with 0140, and likewise the parameterafter next.@item %mComplement all the bits of the next parameter and the parameter after next.@item %BEncode the next parameter in BCD. It alters the value of theparameter by adding six times the quotient of the parameter by ten.Here is a C statement that shows how the new value is computed:@example@var{parm} = (@var{parm} / 10) * 16 + @var{parm} % 10;@end example@item %DTransform the next parameter as needed by Delta Data terminals.This involves subtracting twice the remainder of the parameter by 16.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -