Go to the first, previous, next, last section, table of contents.


Describing the Encoding

A terminal command string that requires parameters contains special character sequences starting with `%' to say how to encode the parameters. These sequences control the actions of tparam and tgoto.

The parameters values passed to tparam or tgoto are considered to form a vector. A pointer into this vector determines the next parameter to be processed. Some of the `%'-sequences encode one parameter and advance the pointer to the next parameter. Other `%'-sequences alter the pointer or alter the parameter values without generating output.

For example, the `cm' string for a standard ANSI terminal is written as `\E[%i%d;%dH'. (`\E' stands for ESC.) `cm' by convention always requires two parameters, the vertical and horizontal goal positions, so this string specifies the encoding of two parameters. Here `%i' increments the two values supplied, and each `%d' encodes one of the values in decimal. If the cursor position values 20,58 are encoded with this string, the result is `\E[21;59H'.

First, here are the `%'-sequences that generate output. Except for `%%', each of them encodes one parameter and advances the pointer to the following parameter.

`%%'
Output a single `%'. This is the only way to represent a literal `%' in a terminal command with parameters. `%%' does not use up a parameter.
`%d'
As in printf, output the next parameter in decimal.
`%2'
Like `%02d' in printf: output the next parameter in decimal, and always use at least two digits.
`%3'
Like `%03d' in printf: output the next parameter in decimal, and always use at least three digits. Note that `%4' and so on are not defined.
`%.'
Output the next parameter as a single character whose ASCII code is the parameter value. Like `%c' in printf.
`%+char'
Add the next parameter to the character char, and output the resulting character. For example, `%+ ' represents 0 as a space, 1 as `!', etc.

The following `%'-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 effects on the parameters. Also, they do not advance the "next parameter" pointer except as explicitly stated. Only `%i', `%r' and `%>' are defined in standard Unix termcap. The others are GNU extensions.

`%i'
Increment the next two parameters. This is used for terminals that expect cursor positions in origin 1. For example, `%i%d,%d' would output two parameters with `1' for 0, `2' for 1, etc.
`%r'
Interchange the next two parameters. This is used for terminals whose cursor positioning command expects the horizontal position first.
`%s'
Skip the next parameter. Do not output anything.
`%b'
Back up one parameter. The last parameter used will become once again the next parameter to be output, and the next output command will use it. Using `%b' more than once, you can back up any number of parameters, and you can refer to each parameter any number of times.
`%>c1c2'
Conditionally increment the next parameter. Here c1 and c2 are characters which stand for their ASCII codes as numbers. If the next parameter is greater than the ASCII code of c1, the ASCII code of c2 is added to it.
`%a op type pos'
Perform arithmetic on the next parameter, do not use it up, and do not output anything. Here op specifies the arithmetic operation, while type and pos together specify the other operand. Spaces are used above to separate the operands for clarity; the spaces don't appear in the data base, where this sequence is exactly five characters long. The character op says what kind of arithmetic operation to perform. It can be any of these characters:
`='
assign a value to the next parameter, ignoring its old value. The new value comes from the other operand.
`+'
add the other operand to the next parameter.
`-'
subtract the other operand from the next parameter.
`*'
multiply the next parameter by the other operand.
`/'
divide the next parameter by the other operand.
The "other operand" may be another parameter's value or a constant; the character type says which. It can be:
`p'
Use another parameter. The character pos says which parameter to use. Subtract 64 from its ASCII code to get the position of the desired parameter relative to this one. Thus, the character `A' as pos means the parameter after the next one; the character `?' means the parameter before the next one.
`c'
Use a constant value. The character pos specifies the value of the constant. The 0200 bit is cleared out, so that 0200 can be used to represent zero.

The following `%'-sequences are special purpose hacks to compensate for the weird designs of obscure terminals. They modify the next parameter or the next two parameters but do not generate output and do not use up any parameters. `%m' is a GNU extension; the others are defined in standard Unix termcap.

`%n'
Exclusive-or the next parameter with 0140, and likewise the parameter after next.
`%m'
Complement all the bits of the next parameter and the parameter after next.
`%B'
Encode the next parameter in BCD. It alters the value of the parameter by adding six times the quotient of the parameter by ten. Here is a C statement that shows how the new value is computed:
parm = (parm / 10) * 16 + parm % 10;
`%D'
Transform the next parameter as needed by Delta Data terminals. This involves subtracting twice the remainder of the parameter by 16.
parm -= 2 * (parm % 16);


Go to the first, previous, next, last section, table of contents.