d9918389d55ee24a139805f7feb07ca6cf970412
[platform/upstream/bash.git] / lib / termcap / grot / termcap.texi
1 \input texinfo  @c -*-texinfo-*-
2 @setfilename termcap
3 @settitle The Termcap Library
4 @smallbook
5
6 @ifinfo
7 This file documents the termcap library of the GNU system.
8
9 Copyright (C) 1988 Free Software Foundation, Inc.
10
11 Permission is granted to make and distribute verbatim copies of
12 this manual provided the copyright notice and this permission notice
13 are preserved on all copies.
14
15 @ignore
16 Permission is granted to process this file through TeX and print the
17 results, provided the printed document carries copying permission
18 notice identical to this one except for the removal of this paragraph
19 (this paragraph not being relevant to the printed manual).
20
21 @end ignore
22 Permission is granted to copy and distribute modified versions of this
23 manual under the conditions for verbatim copying, provided that the entire
24 resulting derived work is distributed under the terms of a permission
25 notice identical to this one.
26
27 Permission is granted to copy and distribute translations of this manual
28 into another language, under the above conditions for modified versions,
29 except that this permission notice may be stated in a translation approved
30 by the Foundation.
31 @end ifinfo
32
33 @setchapternewpage odd
34
35 @c @shorttitlepage The Termcap Manual
36
37 @titlepage
38 @ignore
39 @sp 6
40 @center @titlefont{Termcap}
41 @sp 1
42 @center The Termcap Library and Data Base
43 @sp 4
44 @center Second Edition
45 @sp 1
46 @center December 1992
47 @sp 5
48 @center Richard M. Stallman
49 @sp 1
50 @center Free Software Foundation
51 @end ignore
52
53 @c Real title page
54 @title The Termcap Manual
55 @subtitle The Termcap Library and Data Base
56 @subtitle Second Edition
57 @subtitle December 1992
58 @author Richard M. Stallman
59 @page
60 @vskip 0pt plus 1filll
61 Copyright @copyright{} 1988 Free Software Foundation, Inc.
62
63 Published by the Free Software Foundation
64 (675 Mass Ave, Cambridge MA 02139).
65 Printed copies are available for $10 each.
66
67 Permission is granted to make and distribute verbatim copies of
68 this manual provided the copyright notice and this permission notice
69 are preserved on all copies.
70
71 Permission is granted to copy and distribute modified versions of this
72 manual under the conditions for verbatim copying, provided that the entire
73 resulting derived work is distributed under the terms of a permission
74 notice identical to this one.
75
76 Permission is granted to copy and distribute translations of this manual
77 into another language, under the above conditions for modified versions,
78 except that this permission notice may be stated in a translation approved
79 by the Foundation.
80 @sp 2
81 Cover art by Etienne Suvasa.
82 @end titlepage
83 @page
84
85 @synindex vr fn
86
87 @node Top, Introduction, (dir), (dir)
88
89 @menu
90 * Introduction::  What is termcap?  Why this manual?
91 * Library::     The termcap library functions.
92 * Data Base::   What terminal descriptions in @file{/etc/termcap} look like.
93 * Capabilities::  Definitions of the individual terminal capabilities:
94                  how to write them in descriptions, and how to use
95                  their values to do display updating.
96 * Summary::     Brief table of capability names and their meanings.
97 * Var Index::   Index of C functions and variables.
98 * Cap Index::   Index of termcap capabilities.
99 * Index::       Concept index.
100
101  --- The Detailed Node Listing ---
102
103 The Termcap Library
104
105 * Preparation::  Preparing to use the termcap library.
106 * Find::        Finding the description of the terminal being used.
107 * Interrogate::  Interrogating the description for particular capabilities.
108 * Initialize::  Initialization for output using termcap.
109 * Padding::     Outputting padding.
110 * Parameters::  Encoding parameters such as cursor positions.
111
112 Padding
113
114 * Why Pad::     Explanation of padding.
115 * Not Enough::  When there is not enough padding.
116 * Describe Padding::  The data base says how much padding a terminal needs.
117 * Output Padding::    Using @code{tputs} to output the needed padding.
118
119 Filling In Parameters
120
121 * Encode Parameters::  The language for encoding parameters.
122 * Using Parameters::   Outputting a string command with parameters.
123
124 Sending Display Commands with Parameters
125
126 * tparam::      The general case, for GNU termcap only.
127 * tgoto::       The special case of cursor motion.
128
129 The Format of the Data Base
130
131 * Format::      Overall format of a terminal description.
132 * Capability Format::  Format of capabilities within a description.
133 * Naming::      Naming conventions for terminal types.
134 * Inheriting::  Inheriting part of a description from
135 a related terminal type.
136 * Changing::    When changes in the data base take effect.
137
138 Definitions of the Terminal Capabilities
139
140 * Basic::       Basic characteristics.
141 * Screen Size::  Screen size, and what happens when it changes.
142 * Cursor Motion::  Various ways to move the cursor.
143 * Wrapping::    What happens if you write a character in the last column.
144 * Scrolling::   Pushing text up and down on the screen.
145 * Windows::     Limiting the part of the window that output affects.
146 * Clearing::    Erasing one or many lines.
147 * Insdel Line::  Making new blank lines in mid-screen; deleting lines.
148 * Insdel Char::  Inserting and deleting characters within a line.
149 * Standout::    Highlighting some of the text.
150 * Underlining::  Underlining some of the text.
151 * Cursor Visibility::  Making the cursor more or less easy to spot.
152 * Bell::        Attracts user's attention; not localized on the screen.
153 * Keypad::      Recognizing when function keys or arrows are typed.
154 * Meta Key::    @key{META} acts like an extra shift key.
155 * Initialization::  Commands used to initialize or reset the terminal.
156 * Pad Specs::   Info for the kernel on how much padding is needed.
157 * Status Line::  A status line displays ``background'' information.
158 * Half-Line::   Moving by half-lines, for superscripts and subscripts.
159 * Printer::     Controlling auxiliary printers of display terminals.
160 @end menu
161
162 @node Introduction, Library, Top, Top
163 @unnumbered Introduction
164
165 @cindex termcap
166 @dfn{Termcap} is a library and data base that enables programs to use
167 display terminals in a terminal-independent manner.  It originated in
168 Berkeley Unix.
169
170 The termcap data base describes the capabilities of hundreds of different
171 display terminals in great detail.  Some examples of the information
172 recorded for a terminal could include how many columns wide it is, what
173 string to send to move the cursor to an arbitrary position (including how
174 to encode the row and column numbers), how to scroll the screen up one or
175 several lines, and how much padding is needed for such a scrolling
176 operation.
177
178 The termcap library is provided for easy access this data base in programs
179 that want to do terminal-independent character-based display output.
180
181 This manual describes the GNU version of the termcap library, which has
182 some extensions over the Unix version.  All the extensions are identified
183 as such, so this manual also tells you how to use the Unix termcap.
184
185 The GNU version of the termcap library is available free as source code,
186 for use in free programs, and runs on Unix and VMS systems (at least).  You
187 can find it in the GNU Emacs distribution in the files @file{termcap.c} and
188 @file{tparam.c}.
189
190 This manual was written for the GNU project, whose goal is to develop a
191 complete free operating system upward-compatible with Unix for user
192 programs.  The project is approximately two thirds complete.  For more
193 information on the GNU project, including the GNU Emacs editor and the
194 mostly-portable optimizing C compiler, send one dollar to
195
196 @display
197 Free Software Foundation
198 675 Mass Ave
199 Cambridge, MA 02139
200 @end display
201
202 @node Library, Data Base, Introduction, Top
203 @chapter The Termcap Library
204
205 The termcap library is the application programmer's interface to the
206 termcap data base.  It contains functions for the following purposes:
207
208 @itemize @bullet
209 @item
210 Finding the description of the user's terminal type (@code{tgetent}).
211
212 @item
213 Interrogating the description for information on various topics
214 (@code{tgetnum}, @code{tgetflag}, @code{tgetstr}).
215
216 @item
217 Computing and performing padding (@code{tputs}).
218
219 @item
220 Encoding numeric parameters such as cursor positions into the
221 terminal-specific form required for display commands (@code{tparam},
222 @code{tgoto}).
223 @end itemize
224
225 @menu
226 * Preparation::  Preparing to use the termcap library.
227 * Find::        Finding the description of the terminal being used.
228 * Interrogate::  Interrogating the description for particular capabilities.
229 * Initialize::  Initialization for output using termcap.
230 * Padding::     Outputting padding.
231 * Parameters::  Encoding parameters such as cursor positions.
232 @end menu
233
234 @node Preparation, Find,  , Library
235 @section Preparing to Use the Termcap Library
236
237 To use the termcap library in a program, you need two kinds of preparation:
238
239 @itemize @bullet
240 @item
241 The compiler needs declarations of the functions and variables in the
242 library.
243
244 On GNU systems, it suffices to include the header file
245 @file{termcap.h} in each source file that uses these functions and
246 variables.@refill
247
248 On Unix systems, there is often no such header file.  Then you must
249 explictly declare the variables as external.  You can do likewise for
250 the functions, or let them be implicitly declared and cast their
251 values from type @code{int} to the appropriate type.
252
253 We illustrate the declarations of the individual termcap library
254 functions with ANSI C prototypes because they show how to pass the
255 arguments.  If you are not using the GNU C compiler, you probably
256 cannot use function prototypes, so omit the argument types and names
257 from your declarations.
258
259 @item
260 The linker needs to search the library.  Usually either
261 @samp{-ltermcap} or @samp{-ltermlib} as an argument when linking will
262 do this.@refill
263 @end itemize
264
265 @node Find, Interrogate, Preparation, Library
266 @section Finding a Terminal Description: @code{tgetent}
267
268 @findex tgetent
269 An application program that is going to use termcap must first look up the
270 description of the terminal type in use.  This is done by calling
271 @code{tgetent}, whose declaration in ANSI Standard C looks like:
272
273 @example
274 int tgetent (char *@var{buffer}, char *@var{termtype});
275 @end example
276
277 @noindent
278 This function finds the description and remembers it internally so that
279 you can interrogate it about specific terminal capabilities
280 (@pxref{Interrogate}).
281
282 The argument @var{termtype} is a string which is the name for the type of
283 terminal to look up.  Usually you would obtain this from the environment
284 variable @code{TERM} using @code{getenv ("TERM")}.
285
286 If you are using the GNU version of termcap, you can alternatively ask
287 @code{tgetent} to allocate enough space.  Pass a null pointer for
288 @var{buffer}, and @code{tgetent} itself allocates the storage using
289 @code{malloc}.  In this case the returned value on success is the address
290 of the storage, cast to @code{int}.  But normally there is no need for you
291 to look at the address.  Do not free the storage yourself.@refill
292
293 With the Unix version of termcap, you must allocate space for the
294 description yourself and pass the address of the space as the argument
295 @var{buffer}.  There is no way you can tell how much space is needed, so
296 the convention is to allocate a buffer 2048 characters long and assume that
297 is enough.  (Formerly the convention was to allocate 1024 characters and
298 assume that was enough.  But one day, for one kind of terminal, that was
299 not enough.)
300
301 No matter how the space to store the description has been obtained,
302 termcap records its address internally for use when you later interrogate
303 the description with @code{tgetnum}, @code{tgetstr} or @code{tgetflag}.  If
304 the buffer was allocated by termcap, it will be freed by termcap too if you
305 call @code{tgetent} again.  If the buffer was provided by you, you must
306 make sure that its contents remain unchanged for as long as you still plan
307 to interrogate the description.@refill
308
309 The return value of @code{tgetent} is @minus{}1 if there is some difficulty
310 accessing the data base of terminal types, 0 if the data base is accessible
311 but the specified type is not defined in it, and some other value
312 otherwise.
313
314 Here is how you might use the function @code{tgetent}:
315
316 @smallexample
317 #ifdef unix
318 static char term_buffer[2048];
319 #else
320 #define term_buffer 0
321 #endif
322
323 init_terminal_data ()
324 @{
325   char *termtype = getenv ("TERM");
326   int success;
327
328   if (termtype == 0)
329     fatal ("Specify a terminal type with `setenv TERM <yourtype>'.\n");
330
331   success = tgetent (term_buffer, termtype);
332   if (success < 0)
333     fatal ("Could not access the termcap data base.\n");
334   if (success == 0)
335     fatal ("Terminal type `%s' is not defined.\n", termtype);
336 @}
337 @end smallexample
338
339 @noindent
340 Here we assume the function @code{fatal} prints an error message and exits.
341
342 If the environment variable @code{TERMCAP} is defined, its value is used to
343 override the terminal type data base.  The function @code{tgetent} checks
344 the value of @code{TERMCAP} automatically.  If the value starts with
345 @samp{/} then it is taken as a file name to use as the data base file,
346 instead of @file{/etc/termcap} which is the standard data base.  If the
347 value does not start with @samp{/} then it is itself used as the terminal
348 description, provided that the terminal type @var{termtype} is among the
349 types it claims to apply to.  @xref{Data Base}, for information on the
350 format of a terminal description.@refill
351
352 @node Interrogate, Initialize, Find, Library
353 @section Interrogating the Terminal Description
354
355 Each piece of information recorded in a terminal description is called a
356 @dfn{capability}.  Each defined terminal capability has a two-letter code
357 name and a specific meaning.  For example, the number of columns is named
358 @samp{co}.  @xref{Capabilities}, for definitions of all the standard
359 capability names.
360
361 Once you have found the proper terminal description with @code{tgetent}
362 (@pxref{Find}), your application program must @dfn{interrogate} it for
363 various terminal capabilities.  You must specify the two-letter code of
364 the capability whose value you seek.
365
366 Capability values can be numeric, boolean (capability is either present or
367 absent) or strings.  Any particular capability always has the same value
368 type; for example, @samp{co} always has a numeric value, while @samp{am}
369 (automatic wrap at margin) is always a flag, and @samp{cm} (cursor motion
370 command) always has a string value.  The documentation of each capability
371 says which type of value it has.@refill
372
373 There are three functions to use to get the value of a capability,
374 depending on the type of value the capability has.  Here are their
375 declarations in ANSI C:
376
377 @findex tgetnum
378 @findex tgetflag
379 @findex tgetstr
380 @example
381 int tgetnum (char *@var{name});
382 int tgetflag (char *@var{name});
383 char *tgetstr (char *@var{name}, char **@var{area});
384 @end example
385
386 @table @code
387 @item tgetnum
388 Use @code{tgetnum} to get a capability value that is numeric.  The
389 argument @var{name} is the two-letter code name of the capability.  If
390 the capability is present, @code{tgetnum} returns the numeric value
391 (which is nonnegative).  If the capability is not mentioned in the
392 terminal description, @code{tgetnum} returns @minus{}1.
393
394 @item tgetflag
395 Use @code{tgetflag} to get a boolean value.  If the capability
396 @var{name} is present in the terminal description, @code{tgetflag}
397 returns 1; otherwise, it returns 0.
398
399 @item tgetstr
400 Use @code{tgetstr} to get a string value.  It returns a pointer to a
401 string which is the capability value, or a null pointer if the
402 capability is not present in the terminal description.
403
404 There are two ways @code{tgetstr} can find space to store the string value:
405
406 @itemize @bullet
407 @item
408 You can ask @code{tgetstr} to allocate the space.  Pass a null
409 pointer for the argument @var{area}, and @code{tgetstr} will use
410 @code{malloc} to allocate storage big enough for the value.
411 Termcap will never free this storage or refer to it again; you
412 should free it when you are finished with it.
413
414 This method is more robust, since there is no need to guess how
415 much space is needed.  But it is supported only by the GNU
416 termcap library.
417
418 @item
419 You can provide the space.  Provide for the argument @var{area} the
420 address of a pointer variable of type @code{char *}.  Before calling
421 @code{tgetstr}, initialize the variable to point at available space.
422 Then @code{tgetstr} will store the string value in that space and will
423 increment the pointer variable to point after the space that has been
424 used.  You can use the same pointer variable for many calls to
425 @code{tgetstr}.
426
427 There is no way to determine how much space is needed for a single
428 string, and no way for you to prevent or handle overflow of the area
429 you have provided.  However, you can be sure that the total size of
430 all the string values you will obtain from the terminal description is
431 no greater than the size of the description (unless you get the same
432 capability twice).  You can determine that size with @code{strlen} on
433 the buffer you provided to @code{tgetent}.  See below for an example.
434
435 Providing the space yourself is the only method supported by the Unix
436 version of termcap.
437 @end itemize
438 @end table
439
440 Note that you do not have to specify a terminal type or terminal
441 description for the interrogation functions.  They automatically use the
442 description found by the most recent call to @code{tgetent}.
443
444 Here is an example of interrogating a terminal description for various
445 capabilities, with conditionals to select between the Unix and GNU methods
446 of providing buffer space.
447
448 @example
449 char *tgetstr ();
450
451 char *cl_string, *cm_string;
452 int height;
453 int width;
454 int auto_wrap;
455
456 char PC;   /* For tputs.  */
457 char *BC;  /* For tgoto.  */
458 char *UP;
459
460 interrogate_terminal ()
461 @{
462 #ifdef UNIX
463   /* Here we assume that an explicit term_buffer
464      was provided to tgetent.  */
465   char *buffer
466     = (char *) malloc (strlen (term_buffer));
467 #define BUFFADDR &buffer
468 #else
469 #define BUFFADDR 0
470 #endif
471
472   char *temp;
473
474   /* Extract information we will use.  */
475   cl_string = tgetstr ("cl", BUFFADDR);
476   cm_string = tgetstr ("cm", BUFFADDR);
477   auto_wrap = tgetflag ("am");
478   height = tgetnum ("li");
479   width = tgetnum ("co");
480
481   /* Extract information that termcap functions use.  */
482   temp = tgetstr ("pc", BUFFADDR);
483   PC = temp ? *temp : 0;
484   BC = tgetstr ("le", BUFFADDR);
485   UP = tgetstr ("up", BUFFADDR);
486 @}
487 @end example
488
489 @noindent
490 @xref{Padding}, for information on the variable @code{PC}.  @xref{Using
491 Parameters}, for information on @code{UP} and @code{BC}.
492
493 @node Initialize, Padding, Interrogate, Library
494 @section Initialization for Use of Termcap
495 @cindex terminal flags (kernel)
496
497 Before starting to output commands to a terminal using termcap,
498 an application program should do two things:
499
500 @itemize @bullet
501 @item
502 Initialize various global variables which termcap library output
503 functions refer to.  These include @code{PC} and @code{ospeed} for
504 padding (@pxref{Output Padding}) and @code{UP} and @code{BC} for
505 cursor motion (@pxref{tgoto}).@refill
506
507 @item
508 Tell the kernel to turn off alteration and padding of horizontal-tab
509 characters sent to the terminal.
510 @end itemize
511
512 To turn off output processing in Berkeley Unix you would use @code{ioctl}
513 with code @code{TIOCLSET} to set the bit named @code{LLITOUT}, and clear
514 the bits @code{ANYDELAY} using @code{TIOCSETN}.  In POSIX or System V, you
515 must clear the bit named @code{OPOST}.  Refer to the system documentation
516 for details.@refill
517
518 If you do not set the terminal flags properly, some older terminals will
519 not work.  This is because their commands may contain the characters that
520 normally signify newline, carriage return and horizontal tab---characters
521 which the kernel thinks it ought to modify before output.
522
523 When you change the kernel's terminal flags, you must arrange to restore
524 them to their normal state when your program exits.  This implies that the
525 program must catch fatal signals such as @code{SIGQUIT} and @code{SIGINT}
526 and restore the old terminal flags before actually terminating.
527
528 Modern terminals' commands do not use these special characters, so if you
529 do not care about problems with old terminals, you can leave the kernel's
530 terminal flags unaltered.
531
532 @node Padding, Parameters, Initialize, Library
533 @section Padding
534 @cindex padding
535
536 @dfn{Padding} means outputting null characters following a terminal display
537 command that takes a long time to execute.  The terminal description says
538 which commands require padding and how much; the function @code{tputs},
539 described below, outputs a terminal command while extracting from it the
540 padding information, and then outputs the padding that is necessary.
541
542 @menu
543 * Why Pad::     Explanation of padding.
544 * Not Enough::  When there is not enough padding.
545 * Describe Padding::  The data base says how much padding a terminal needs.
546 * Output Padding::  Using @code{tputs} to output the needed padding.
547 @end menu
548
549 @node Why Pad, Not Enough,  , Padding
550 @subsection Why Pad, and How
551
552 Most types of terminal have commands that take longer to execute than they
553 do to send over a high-speed line.  For example, clearing the screen may
554 take 20msec once the entire command is received.  During that time, on a
555 9600 bps line, the terminal could receive about 20 additional output
556 characters while still busy clearing the screen.  Every terminal has a
557 certain amount of buffering capacity to remember output characters that
558 cannot be processed yet, but too many slow commands in a row can cause the
559 buffer to fill up.  Then any additional output that cannot be processed
560 immediately will be lost.
561
562 To avoid this problem, we normally follow each display command with enough
563 useless charaters (usually null characters) to fill up the time that the
564 display command needs to execute.  This does the job if the terminal throws
565 away null characters without using up space in the buffer (which most
566 terminals do).  If enough padding is used, no output can ever be lost.  The
567 right amount of padding avoids loss of output without slowing down
568 operation, since the time used to transmit padding is time that nothing
569 else could be done.
570
571 The number of padding characters needed for an operation depends on the
572 line speed.  In fact, it is proportional to the line speed.  A 9600 baud
573 line transmits about one character per msec, so the clear screen command in
574 the example above would need about 20 characters of padding.  At 1200 baud,
575 however, only about 3 characters of padding are needed to fill up 20msec.
576
577 @node Not Enough, Describe Padding, Why Pad, Padding
578 @subsection When There Is Not Enough Padding
579
580 There are several common manifestations of insufficient padding.
581
582 @itemize @bullet
583 @item
584 Emacs displays @samp{I-search: ^Q-} at the bottom of the screen.
585
586 This means that the terminal thought its buffer was getting full of
587 display commands, so it tried to tell the computer to stop sending
588 any.
589
590 @item
591 The screen is garbled intermittently, or the details of garbling vary
592 when you repeat the action.  (A garbled screen could be due to a
593 command which is simply incorrect, or to user option in the terminal
594 which doesn't match the assumptions of the terminal description, but
595 this usually leads to reproducible failure.)
596
597 This means that the buffer did get full, and some commands were lost.
598 Many changeable factors can change which ones are lost.
599
600 @item
601 Screen is garbled at high output speeds but not at low speeds.
602 Padding problems nearly always go away at low speeds, usually even at
603 1200 baud.
604
605 This means that a high enough speed permits commands to arrive faster
606 than they can be executed.
607 @end itemize
608
609 Although any obscure command on an obscure terminal might lack padding,
610 in practice problems arise most often from the clearing commands
611 @samp{cl} and @samp{cd} (@pxref{Clearing}), the scrolling commands
612 @samp{sf} and @samp{sr} (@pxref{Scrolling}), and the line insert/delete
613 commands @samp{al} and @samp{dl} (@pxref{Insdel Line}).
614
615 Occasionally the terminal description fails to define @samp{sf} and some
616 programs will use @samp{do} instead, so you may get a problem with
617 @samp{do}.  If so, first define @samp{sf} just like @samp{do}, then
618 add some padding to @samp{sf}.
619
620 The best strategy is to add a lot of padding at first, perhaps 200 msec.
621 This is much more than enough; in fact, it should cause a visible slowdown.
622 (If you don't see a slowdown, the change has not taken effect;
623 @pxref{Changing}.)  If this makes the problem go away, you have found the
624 right place to add padding; now reduce the amount until the problem comes
625 back, then increase it again.  If the problem remains, either it is in some
626 other capability or it is not a matter of padding at all.
627
628 Keep in mind that on many terminals the correct padding for insert/delete
629 line or for scrolling is cursor-position dependent.  If you get problems
630 from scrolling a large region of the screen but not from scrolling a small
631 part (just a few lines moving), it may mean that fixed padding should be
632 replaced with position-dependent padding.
633
634 @node Describe Padding, Output Padding, Not Enough, Padding
635 @subsection Specifying Padding in a Terminal Description
636
637 In the terminal description, the amount of padding required by each display
638 command is recorded as a sequence of digits at the front of the command.
639 These digits specify the padding time in milliseconds (msec).  They can be
640 followed optionally by a decimal point and one more digit, which is a
641 number of tenths of msec.
642
643 Sometimes the padding needed by a command depends on the cursor position.
644 For example, the time taken by an ``insert line'' command is usually
645 proportional to the number of lines that need to be moved down or cleared.
646 An asterisk (@samp{*}) following the padding time says that the time
647 should be multiplied by the number of screen lines affected by the command.
648
649 @example
650 :al=1.3*\E[L:
651 @end example
652
653 @noindent
654 is used to describe the ``insert line'' command for a certain terminal.
655 The padding required is 1.3 msec per line affected.  The command itself is
656 @samp{@key{ESC} [ L}.
657
658 The padding time specified in this way tells @code{tputs} how many pad
659 characters to output.  @xref{Output Padding}.
660
661 Two special capability values affect padding for all commands.  These are
662 the @samp{pc} and @samp{pb}.  The variable @samp{pc} specifies the
663 character to pad with, and @samp{pb} the speed below which no padding is
664 needed.  The defaults for these variables, a null character and 0,
665 are correct for most terminals.  @xref{Pad Specs}.
666
667 @node Output Padding,  , Describe Padding, Padding
668 @subsection Performing Padding with @code{tputs}
669 @cindex line speed
670
671 @findex tputs
672 Use the termcap function @code{tputs} to output a string containing an
673 optional padding spec of the form described above (@pxref{Describe
674 Padding}).  The function @code{tputs} strips off and decodes the padding
675 spec, outputs the rest of the string, and then outputs the appropriate
676 padding.  Here is its declaration in ANSI C:
677
678 @example
679 char PC;
680 short ospeed;
681
682 int tputs (char *@var{string}, int @var{nlines}, int (*@var{outfun}) ());
683 @end example
684
685 Here @var{string} is the string (including padding spec) to be output;
686 @var{nlines} is the number of lines affected by the operation, which is
687 used to multiply the amount of padding if the padding spec ends with a
688 @samp{*}.  Finally, @var{outfun} is a function (such as @code{fputchar})
689 that is called to output each character.  When actually called,
690 @var{outfun} should expect one argument, a character.
691
692 @vindex ospeed
693 @vindex PC
694 The operation of @code{tputs} is controlled by two global variables,
695 @code{ospeed} and @code{PC}.  The value of @code{ospeed} is supposed to be
696 the terminal output speed, encoded as in the @code{ioctl} system call which
697 gets the speed information.  This is needed to compute the number of
698 padding characters.  The value of @code{PC} is the character used for
699 padding.
700
701 You are responsible for storing suitable values into these variables before
702 using @code{tputs}.  The value stored into the @code{PC} variable should be
703 taken from the @samp{pc} capability in the terminal description (@pxref{Pad
704 Specs}).  Store zero in @code{PC} if there is no @samp{pc}
705 capability.@refill
706
707 The argument @var{nlines} requires some thought.  Normally, it should be
708 the number of lines whose contents will be cleared or moved by the command.
709 For cursor motion commands, or commands that do editing within one line,
710 use the value 1.  For most commands that affect multiple lines, such as
711 @samp{al} (insert a line) and @samp{cd} (clear from the cursor to the end
712 of the screen), @var{nlines} should be the screen height minus the current
713 vertical position (origin 0).  For multiple insert and scroll commands such
714 as @samp{AL} (insert multiple lines), that same value for @var{nlines} is
715 correct; the number of lines being inserted is @i{not} correct.@refill
716
717 If a ``scroll window'' feature is used to reduce the number of lines
718 affected by a command, the value of @var{nlines} should take this into
719 account.  This is because the delay time required depends on how much work
720 the terminal has to do, and the scroll window feature reduces the work.
721 @xref{Scrolling}.
722
723 Commands such as @samp{ic} and @samp{dc} (insert or delete characters) are
724 problematical because the padding needed by these commands is proportional
725 to the number of characters affected, which is the number of columns from
726 the cursor to the end of the line.  It would be nice to have a way to
727 specify such a dependence, and there is no need for dependence on vertical
728 position in these commands, so it is an obvious idea to say that for these
729 commands @var{nlines} should really be the number of columns affected.
730 However, the definition of termcap clearly says that @var{nlines} is always
731 the number of lines affected, even in this case, where it is always 1.  It
732 is not easy to change this rule now, because too many programs and terminal
733 descriptions have been written to follow it.
734
735 Because @var{nlines} is always 1 for the @samp{ic} and @samp{dc} strings,
736 there is no reason for them to use @samp{*}, but some of them do.  These
737 should be corrected by deleting the @samp{*}.  If, some day, such entries
738 have disappeared, it may be possible to change to a more useful convention
739 for the @var{nlines} argument for these operations without breaking any
740 programs.
741
742 @node Parameters,  , Padding, Library
743 @section Filling In Parameters
744 @cindex parameters
745
746 Some terminal control strings require numeric @dfn{parameters}.  For
747 example, when you move the cursor, you need to say what horizontal and
748 vertical positions to move it to.  The value of the terminal's @samp{cm}
749 capability, which says how to move the cursor, cannot simply be a string of
750 characters; it must say how to express the cursor position numbers and
751 where to put them within the command.
752
753 The specifications of termcap include conventions as to which string-valued
754 capabilities require parameters, how many parameters, and what the
755 parameters mean; for example, it defines the @samp{cm} string to take
756 two parameters, the vertical and horizontal positions, with 0,0 being the
757 upper left corner.  These conventions are described where the individual
758 commands are documented.
759
760 Termcap also defines a language used within the capability definition for
761 specifying how and where to encode the parameters for output.  This language
762 uses character sequences starting with @samp{%}.  (This is the same idea as
763 @code{printf}, but the details are different.)  The language for parameter
764 encoding is described in this section.
765
766 A program that is doing display output calls the functions @code{tparam} or
767 @code{tgoto} to encode parameters according to the specifications.  These
768 functions produce a string containing the actual commands to be output (as
769 well a padding spec which must be processed with @code{tputs};
770 @pxref{Padding}).
771
772 @menu
773 * Encode Parameters::  The language for encoding parameters.
774 * Using Parameters::  Outputting a string command with parameters.
775 @end menu
776
777 @node Encode Parameters, Using Parameters,  , Parameters
778 @subsection Describing the Encoding
779 @cindex %
780
781 A terminal command string that requires parameters contains special
782 character sequences starting with @samp{%} to say how to encode the
783 parameters.  These sequences control the actions of @code{tparam} and
784 @code{tgoto}.
785
786 The parameters values passed to @code{tparam} or @code{tgoto} are
787 considered to form a vector.  A pointer into this vector determines
788 the next parameter to be processed.  Some of the @samp{%}-sequences
789 encode one parameter and advance the pointer to the next parameter.
790 Other @samp{%}-sequences alter the pointer or alter the parameter
791 values without generating output.
792
793 For example, the @samp{cm} string for a standard ANSI terminal is written
794 as @samp{\E[%i%d;%dH}.  (@samp{\E} stands for @key{ESC}.)  @samp{cm} by
795 convention always requires two parameters, the vertical and horizontal goal
796 positions, so this string specifies the encoding of two parameters.  Here
797 @samp{%i} increments the two values supplied, and each @samp{%d} encodes
798 one of the values in decimal.  If the cursor position values 20,58 are
799 encoded with this string, the result is @samp{\E[21;59H}.
800
801 First, here are the @samp{%}-sequences that generate output.  Except for
802 @samp{%%}, each of them encodes one parameter and advances the pointer
803 to the following parameter.
804
805 @table @samp
806 @item %%
807 Output a single @samp{%}.  This is the only way to represent a literal
808 @samp{%} in a terminal command with parameters.  @samp{%%} does not
809 use up a parameter.
810
811 @item %d
812 As in @code{printf}, output the next parameter in decimal.
813
814 @item %2
815 Like @samp{%02d} in @code{printf}: output the next parameter in
816 decimal, and always use at least two digits.
817
818 @item %3
819 Like @samp{%03d} in @code{printf}: output the next parameter in
820 decimal, and always use at least three digits.  Note that @samp{%4}
821 and so on are @emph{not} defined.
822
823 @item %.
824 Output the next parameter as a single character whose ASCII code is
825 the parameter value.  Like @samp{%c} in @code{printf}.
826
827 @item %+@var{char}
828 Add the next parameter to the character @var{char}, and output the
829 resulting character.  For example, @samp{%+ } represents 0 as a space,
830 1 as @samp{!}, etc.
831 @end table
832
833 The following @samp{%}-sequences specify alteration of the parameters
834 (their values, or their order) rather than encoding a parameter for output.
835 They generate no output; they are used only for their side effects
836 on the parameters.  Also, they do not advance the ``next parameter'' pointer
837 except as explicitly stated.  Only @samp{%i}, @samp{%r} and @samp{%>} are
838 defined in standard Unix termcap.  The others are GNU extensions.@refill
839
840 @table @samp
841 @item %i
842 Increment the next two parameters.  This is used for terminals that
843 expect cursor positions in origin 1.  For example, @samp{%i%d,%d} would
844 output two parameters with @samp{1} for 0, @samp{2} for 1, etc.
845
846 @item %r
847 Interchange the next two parameters.  This is used for terminals whose
848 cursor positioning command expects the horizontal position first.
849
850 @item %s
851 Skip the next parameter.  Do not output anything.
852
853 @item %b
854 Back up one parameter.  The last parameter used will become once again
855 the next parameter to be output, and the next output command will use
856 it.  Using @samp{%b} more than once, you can back up any number of
857 parameters, and you can refer to each parameter any number of times.
858
859 @item %>@var{c1}@var{c2}
860 Conditionally increment the next parameter.  Here @var{c1} and
861 @var{c2} are characters which stand for their ASCII codes as numbers.
862 If the next parameter is greater than the ASCII code of @var{c1}, the
863 ASCII code of @var{c2} is added to it.@refill
864
865 @item %a @var{op} @var{type} @var{pos}
866 Perform arithmetic on the next parameter, do not use it up, and do not
867 output anything.  Here @var{op} specifies the arithmetic operation,
868 while @var{type} and @var{pos} together specify the other operand.
869
870 Spaces are used above to separate the operands for clarity; the spaces
871 don't appear in the data base, where this sequence is exactly five
872 characters long.
873
874 The character @var{op} says what kind of arithmetic operation to
875 perform.  It can be any of these characters:
876
877 @table @samp
878 @item =
879 assign a value to the next parameter, ignoring its old value.
880 The new value comes from the other operand.
881
882 @item +
883 add the other operand to the next parameter.
884
885 @item -
886 subtract the other operand from the next parameter.
887
888 @item *
889 multiply the next parameter by the other operand.
890
891 @item /
892 divide the next parameter by the other operand.
893 @end table
894
895 The ``other operand'' may be another parameter's value or a constant;
896 the character @var{type} says which.  It can be:
897
898 @table @samp
899 @item p
900 Use another parameter.  The character @var{pos} says which
901 parameter to use.  Subtract 64 from its ASCII code to get the
902 position of the desired parameter relative to this one.  Thus,
903 the character @samp{A} as @var{pos} means the parameter after the
904 next one; the character @samp{?} means the parameter before the
905 next one.
906
907 @item c
908 Use a constant value.  The character @var{pos} specifies the
909 value of the constant.  The 0200 bit is cleared out, so that 0200
910 can be used to represent zero.
911 @end table
912 @end table
913
914 The following @samp{%}-sequences are special purpose hacks to compensate
915 for the weird designs of obscure terminals.  They modify the next parameter
916 or the next two parameters but do not generate output and do not use up any
917 parameters.  @samp{%m} is a GNU extension; the others are defined in
918 standard Unix termcap.
919
920 @table @samp
921 @item %n
922 Exclusive-or the next parameter with 0140, and likewise the parameter
923 after next.
924
925 @item %m
926 Complement all the bits of the next parameter and the parameter after next.
927
928 @item %B
929 Encode the next parameter in BCD.  It alters the value of the
930 parameter by adding six times the quotient of the parameter by ten.
931 Here is a C statement that shows how the new value is computed:
932
933 @example
934 @var{parm} = (@var{parm} / 10) * 16 + @var{parm} % 10;
935 @end example
936
937 @item %D
938 Transform the next parameter as needed by Delta Data terminals.
939 This involves subtracting twice the remainder of the parameter by 16.
940
941 @example
942 @var{parm} -= 2 * (@var{parm} % 16);
943 @end example
944 @end table
945
946 @node Using Parameters,  , Encode Parameters, Parameters
947 @subsection Sending Display Commands with Parameters
948
949 The termcap library functions @code{tparam} and @code{tgoto} serve as the
950 analog of @code{printf} for terminal string parameters.  The newer function
951 @code{tparam} is a GNU extension, more general but missing from Unix
952 termcap.  The original parameter-encoding function is @code{tgoto}, which
953 is preferable for cursor motion.
954
955 @menu
956 * tparam::      The general case, for GNU termcap only.
957 * tgoto::       The special case of cursor motion.
958 @end menu
959
960 @node tparam, tgoto,  , Using Parameters
961 @subsubsection @code{tparam}
962
963 @findex tparam
964 The function @code{tparam} can encode display commands with any number of
965 parameters and allows you to specify the buffer space.  It is the preferred
966 function for encoding parameters for all but the @samp{cm} capability.  Its
967 ANSI C declaration is as follows:
968
969 @smallexample
970 char *tparam (char *@var{ctlstring}, char *@var{buffer}, int @var{size}, int @var{parm1},...)
971 @end smallexample
972
973 The arguments are a control string @var{ctlstring} (the value of a terminal
974 capability, presumably), an output buffer @var{buffer} and @var{size}, and
975 any number of integer parameters to be encoded.  The effect of
976 @code{tparam} is to copy the control string into the buffer, encoding
977 parameters according to the @samp{%} sequences in the control string.
978
979 You describe the output buffer by its address, @var{buffer}, and its size
980 in bytes, @var{size}.  If the buffer is not big enough for the data to be
981 stored in it, @code{tparam} calls @code{malloc} to get a larger buffer.  In
982 either case, @code{tparam} returns the address of the buffer it ultimately
983 uses.  If the value equals @var{buffer}, your original buffer was used.
984 Otherwise, a new buffer was allocated, and you must free it after you are
985 done with printing the results.  If you pass zero for @var{size} and
986 @var{buffer}, @code{tparam} always allocates the space with @code{malloc}.
987
988 All capabilities that require parameters also have the ability to specify
989 padding, so you should use @code{tputs} to output the string produced by
990 @code{tparam}.  @xref{Padding}.  Here is an example.
991
992 @example
993 @{
994 char *buf;
995 char buffer[40];
996
997 buf = tparam (command, buffer, 40, parm);
998 tputs (buf, 1, fputchar);
999 if (buf != buffer)
1000 free (buf);
1001 @}
1002 @end example
1003
1004 If a parameter whose value is zero is encoded with @samp{%.}-style
1005 encoding, the result is a null character, which will confuse @code{tputs}.
1006 This would be a serious problem, but luckily @samp{%.} encoding is used
1007 only by a few old models of terminal, and only for the @samp{cm}
1008 capability.  To solve the problem, use @code{tgoto} rather than
1009 @code{tparam} to encode the @samp{cm} capability.@refill
1010
1011 @node tgoto,  , tparam, Using Parameters
1012 @subsubsection @code{tgoto}
1013
1014 @findex tgoto
1015 The special case of cursor motion is handled by @code{tgoto}.  There
1016 are two reasons why you might choose to use @code{tgoto}:
1017
1018 @itemize @bullet
1019 @item
1020 For Unix compatibility, because Unix termcap does not have @code{tparam}.
1021
1022 @item
1023 For the @samp{cm} capability, since @code{tgoto} has a special feature
1024 to avoid problems with null characters, tabs and newlines on certain old
1025 terminal types that use @samp{%.} encoding for that capability.
1026 @end itemize
1027
1028 Here is how @code{tgoto} might be declared in ANSI C:
1029
1030 @example
1031 char *tgoto (char *@var{cstring}, int @var{hpos}, int @var{vpos})
1032 @end example
1033
1034 There are three arguments, the terminal description's @samp{cm} string and
1035 the two cursor position numbers; @code{tgoto} computes the parametrized
1036 string in an internal static buffer and returns the address of that buffer.
1037 The next time you use @code{tgoto} the same buffer will be reused.
1038
1039 @vindex UP
1040 @vindex BC
1041 Parameters encoded with @samp{%.} encoding can generate null characters,
1042 tabs or newlines.  These might cause trouble: the null character because
1043 @code{tputs} would think that was the end of the string, the tab because
1044 the kernel or other software might expand it into spaces, and the newline
1045 becaue the kernel might add a carriage-return, or padding characters
1046 normally used for a newline.  To prevent such problems, @code{tgoto} is
1047 careful to avoid these characters.  Here is how this works: if the target
1048 cursor position value is such as to cause a problem (that is to say, zero,
1049 nine or ten), @code{tgoto} increments it by one, then compensates by
1050 appending a string to move the cursor back or up one position.
1051
1052 The compensation strings to use for moving back or up are found in global
1053 variables named @code{BC} and @code{UP}.  These are actual external C
1054 variables with upper case names; they are declared @code{char *}.  It is up
1055 to you to store suitable values in them, normally obtained from the
1056 @samp{le} and @samp{up} terminal capabilities in the terminal description
1057 with @code{tgetstr}.  Alternatively, if these two variables are both zero,
1058 the feature of avoiding nulls, tabs and newlines is turned off.
1059
1060 It is safe to use @code{tgoto} for commands other than @samp{cm} only if
1061 you have stored zero in @code{BC} and @code{UP}.
1062
1063 Note that @code{tgoto} reverses the order of its operands: the horizontal
1064 position comes before the vertical position in the arguments to
1065 @code{tgoto}, even though the vertical position comes before the horizontal
1066 in the parameters of the @samp{cm} string.  If you use @code{tgoto} with a
1067 command such as @samp{AL} that takes one parameter, you must pass the
1068 parameter to @code{tgoto} as the ``vertical position''.@refill
1069
1070 @node Data Base, Capabilities, Library, Top
1071 @chapter The Format of the Data Base
1072
1073 The termcap data base of terminal descriptions is stored in the file
1074 @file{/etc/termcap}.  It contains terminal descriptions, blank lines, and
1075 comments.
1076
1077 A terminal description starts with one or more names for the terminal type.
1078 The information in the description is a series of @dfn{capability names}
1079 and values.  The capability names have standard meanings
1080 (@pxref{Capabilities}) and their values describe the terminal.
1081
1082 @menu
1083 * Format::      Overall format of a terminal description.
1084 * Capability Format::  Format of capabilities within a description.
1085 * Naming::      Naming conventions for terminal types.
1086 * Inheriting::  Inheriting part of a description from
1087 a related terminal type.
1088 * Changing::    When changes in the data base take effect.
1089 @end menu
1090
1091 @node Format, Capability Format,  , Data Base
1092 @section Terminal Description Format
1093 @cindex description format
1094
1095 Aside from comments (lines starting with @samp{#}, which are ignored), each
1096 nonblank line in the termcap data base is a terminal description.
1097 A terminal description is nominally a single line, but it can be split
1098 into multiple lines by inserting the two characters @samp{\ newline}.
1099 This sequence is ignored wherever it appears in a description.
1100
1101 The preferred way to split the description is between capabilities: insert
1102 the four characters @samp{: \ newline tab} immediately before any colon.
1103 This allows each sub-line to start with some indentation.  This works
1104 because, after the @samp{\ newline} are ignored, the result is @samp{: tab
1105 :}; the first colon ends the preceding capability and the second colon
1106 starts the next capability.  If you split with @samp{\ newline} alone, you
1107 may not add any indentation after them.
1108
1109 Here is a real example of a terminal description:
1110
1111 @example
1112 dw|vt52|DEC vt52:\
1113         :cr=^M:do=^J:nl=^J:bl=^G:\
1114         :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:\
1115         :cm=\EY%+ %+ :co#80:li#24:\
1116         :nd=\EC:ta=^I:pt:sr=\EI:up=\EA:\
1117         :ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:
1118 @end example
1119
1120 Each terminal description begins with several names for the terminal type.
1121 The names are separated by @samp{|} characters, and a colon ends the last
1122 name.  The first name should be two characters long; it exists only for the
1123 sake of very old Unix systems and is never used in modern systems.  The
1124 last name should be a fully verbose name such as ``DEC vt52'' or ``Ann
1125 Arbor Ambassador with 48 lines''.  The other names should include whatever
1126 the user ought to be able to specify to get this terminal type, such as
1127 @samp{vt52} or @samp{aaa-48}.  @xref{Naming}, for information on how to
1128 choose terminal type names.
1129
1130 After the terminal type names come the terminal capabilities, separated by
1131 colons and with a colon after the last one.  Each capability has a
1132 two-letter name, such as @samp{cm} for ``cursor motion string'' or @samp{li}
1133 for ``number of display lines''.
1134
1135 @node Capability Format, Naming, Format, Data Base
1136 @section Writing the Capabilities
1137
1138 There are three kinds of capabilities: flags, numbers, and strings.  Each
1139 kind has its own way of being written in the description.  Each defined
1140 capability has by convention a particular kind of value; for example,
1141 @samp{li} always has a numeric value and @samp{cm} always a string value.
1142
1143 A flag capability is thought of as having a boolean value: the value is
1144 true if the capability is present, false if not.  When the capability is
1145 present, just write its name between two colons.
1146
1147 A numeric capability has a value which is a nonnegative number.  Write the
1148 capability name, a @samp{#}, and the number, between two colons.  For
1149 example, @samp{@dots{}:li#48:@dots{}} is how you specify the @samp{li}
1150 capability for 48 lines.@refill
1151
1152 A string-valued capability has a value which is a sequence of characters.
1153 Usually these are the characters used to perform some display operation.
1154 Write the capability name, a @samp{=}, and the characters of the value,
1155 between two colons.  For example, @samp{@dots{}:cm=\E[%i%d;%dH:@dots{}} is
1156 how the cursor motion command for a standard ANSI terminal would be
1157 specified.@refill
1158
1159 Special characters in the string value can be expressed using
1160 @samp{\}-escape sequences as in C; in addition, @samp{\E} stands for
1161 @key{ESC}.  @samp{^} is also a kind of escape character; @samp{^} followed
1162 by @var{char} stands for the control-equivalent of @var{char}.  Thus,
1163 @samp{^a} stands for the character control-a, just like @samp{\001}.
1164 @samp{\} and @samp{^} themselves can be represented as @samp{\\} and
1165 @samp{\^}.@refill
1166
1167 To include a colon in the string, you must write @samp{\072}.  You might
1168 ask, ``Why can't @samp{\:} be used to represent a colon?''  The reason is
1169 that the interrogation functions do not count slashes while looking for a
1170 capability.  Even if @samp{:ce=ab\:cd:} were interpreted as giving the
1171 @samp{ce} capability the value @samp{ab:cd}, it would also appear to define
1172 @samp{cd} as a flag.
1173
1174 The string value will often contain digits at the front to specify padding
1175 (@pxref{Padding}) and/or @samp{%}-sequences within to specify how to encode
1176 parameters (@pxref{Parameters}).  Although these things are not to be
1177 output literally to the terminal, they are considered part of the value of
1178 the capability.  They are special only when the string value is processed
1179 by @code{tputs}, @code{tparam} or @code{tgoto}.  By contrast, @samp{\} and
1180 @samp{^} are considered part of the syntax for specifying the characters
1181 in the string.
1182
1183 Let's look at the VT52 example again:
1184
1185 @example
1186 dw|vt52|DEC vt52:\
1187         :cr=^M:do=^J:nl=^J:bl=^G:\
1188         :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:\
1189         :cm=\EY%+ %+ :co#80:li#24:\     
1190         :nd=\EC:ta=^I:pt:sr=\EI:up=\EA:\
1191         :ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:
1192 @end example
1193
1194 Here we see the numeric-valued capabilities @samp{co} and @samp{li}, the
1195 flags @samp{bs} and @samp{pt}, and many string-valued capabilities.  Most
1196 of the strings start with @key{ESC} represented as @samp{\E}.  The rest
1197 contain control characters represented using @samp{^}.  The meanings of the
1198 individual capabilities are defined elsewhere (@pxref{Capabilities}).
1199
1200 @node Naming, Inheriting, Capability Format, Data Base
1201 @section Terminal Type Name Conventions
1202 @cindex names of terminal types
1203
1204 There are conventions for choosing names of terminal types.  For one thing,
1205 all letters should be in lower case.  The terminal type for a terminal in
1206 its most usual or most fundamental mode of operation should not have a
1207 hyphen in it.
1208
1209 If the same terminal has other modes of operation which require
1210 different terminal descriptions, these variant descriptions are given
1211 names made by adding suffixes with hyphens.  Such alternate descriptions
1212 are used for two reasons:
1213
1214 @itemize @bullet
1215 @item
1216 When the terminal has a switch that changes its behavior.  Since the
1217 computer cannot tell how the switch is set, the user must tell the
1218 computer by choosing the appropriate terminal type name.
1219
1220 @cindex wrapping
1221 For example, the VT-100 has a setup flag that controls whether the
1222 cursor wraps at the right margin.  If this flag is set to ``wrap'',
1223 you must use the terminal type @samp{vt100-am}.  Otherwise you must
1224 use @samp{vt100-nam}.  Plain @samp{vt100} is defined as a synonym for
1225 either @samp{vt100-am} or @samp{vt100-nam} depending on the
1226 preferences of the local site.@refill
1227
1228 The standard suffix @samp{-am} stands for ``automatic margins''.
1229
1230 @item
1231 To give the user a choice in how to use the terminal.  This is done
1232 when the terminal has a switch that the computer normally controls.
1233
1234 @cindex screen size
1235 For example, the Ann Arbor Ambassador can be configured with many
1236 screen sizes ranging from 20 to 60 lines.  Fewer lines make bigger
1237 characters but more lines let you see more of what you are editing.
1238 As a result, users have different preferences.  Therefore, termcap
1239 provides terminal types for many screen sizes.  If you choose type
1240 @samp{aaa-30}, the terminal will be configured to use 30 lines; if you
1241 choose @samp{aaa-48}, 48 lines will be used, and so on.
1242 @end itemize
1243
1244 Here is a list of standard suffixes and their conventional meanings:
1245
1246 @table @samp
1247 @item -w
1248 Short for ``wide''.  This is a mode that gives the terminal more
1249 columns than usual.  This is normally a user option.
1250
1251 @item -am
1252 ``Automatic margins''.  This is an alternate description for use when
1253 the terminal's margin-wrap switch is on; it contains the @samp{am}
1254 flag.  The implication is that normally the switch is off and the
1255 usual description for the terminal says that the switch is off.
1256
1257 @item -nam
1258 ``No automatic margins''.  The opposite of @samp{-am}, this names an
1259 alternative description which lacks the @samp{am} flag.  This implies
1260 that the terminal is normally operated with the margin-wrap switch
1261 turned on, and the normal description of the terminal says so.
1262
1263 @item -na
1264 ``No arrows''.  This terminal description initializes the terminal to
1265 keep its arrow keys in local mode.  This is a user option.
1266
1267 @item -rv
1268 ``Reverse video''.  This terminal description causes text output for
1269 normal video to appear as reverse, and text output for reverse video
1270 to come out as normal.  Often this description differs from the usual
1271 one by interchanging the two strings which turn reverse video on and
1272 off.@refill
1273
1274 This is a user option; you can choose either the ``reverse video''
1275 variant terminal type or the normal terminal type, and termcap will
1276 obey.
1277
1278 @item -s
1279 ``Status''.  Says to enable use of a status line which ordinary output
1280 does not touch (@pxref{Status Line}).
1281
1282 Some terminals have a special line that is used only as a status line.
1283 For these terminals, there is no need for an @samp{-s} variant; the
1284 status line commands should be defined by default.  On other
1285 terminals, enabling a status line means removing one screen line from
1286 ordinary use and reducing the effective screen height.  For these
1287 terminals, the user can choose the @samp{-s} variant type to request
1288 use of a status line.
1289
1290 @item -@var{nlines}
1291 Says to operate with @var{nlines} lines on the screen, for terminals
1292 such as the Ambassador which provide this as an option.  Normally this
1293 is a user option; by choosing the terminal type, you control how many
1294 lines termcap will use.
1295
1296 @item -@var{npages}p
1297 Says that the terminal has @var{npages} pages worth of screen memory,
1298 for terminals where this is a hardware option.
1299
1300 @item -unk
1301 Says that description is not for direct use, but only for reference in
1302 @samp{tc} capabilities.  Such a description is a kind of subroutine,
1303 because it describes the common characteristics of several variant
1304 descriptions that would use other suffixes in place of @samp{-unk}.
1305 @end table
1306
1307 @node Inheriting, Changing, Naming, Data Base
1308 @section Inheriting from Related Descriptions
1309
1310 @cindex inheritance
1311 When two terminal descriptions are similar, their identical parts do not
1312 need to be given twice.  Instead, one of the two can be defined in terms of
1313 the other, using the @samp{tc} capability.  We say that one description
1314 @dfn{refers to} the other, or @dfn{inherits from} the other.
1315
1316 The @samp{tc} capability must be the last one in the terminal description,
1317 and its value is a string which is the name of another terminal type which
1318 is referred to.  For example,
1319
1320 @example
1321 N9|aaa|ambassador|aaa-30|ann arbor ambassador/30 lines:\
1322         :ti=\E[2J\E[30;0;0;30p:\
1323         :te=\E[60;0;0;30p\E[30;1H\E[J:\
1324         :li#30:tc=aaa-unk:
1325 @end example
1326
1327 @noindent
1328 defines the terminal type @samp{aaa-30} (also known as plain @samp{aaa}) in
1329 terms of @samp{aaa-unk}, which defines everything about the Ambassador that
1330 is independent of screen height.  The types @samp{aaa-36}, @samp{aaa-48}
1331 and so on for other screen heights are likewise defined to inherit from
1332 @samp{aaa-unk}.
1333
1334 The capabilities overridden by @samp{aaa-30} include @samp{li}, which says
1335 how many lines there are, and @samp{ti} and @samp{te}, which configure the
1336 terminal to use that many lines.
1337
1338 The effective terminal description for type @samp{aaa} consists of the text
1339 shown above followed by the text of the description of @samp{aaa-unk}.  The
1340 @samp{tc} capability is handled automatically by @code{tgetent}, which
1341 finds the description thus referenced and combines the two descriptions
1342 (@pxref{Find}).  Therefore, only the implementor of the terminal
1343 descriptions needs to think about using @samp{tc}.  Users and application
1344 programmers do not need to be concerned with it.
1345
1346 Since the reference terminal description is used last, capabilities
1347 specified in the referring description override any specifications of the
1348 same capabilities in the reference description.
1349
1350 The referring description can cancel out a capability without specifying
1351 any new value for it by means of a special trick.  Write the capability in
1352 the referring description, with the character @samp{@@} after the capability
1353 name, as follows:
1354
1355 @smallexample
1356 NZ|aaa-30-nam|ann arbor ambassador/30 lines/no automatic-margins:\
1357         :am@@:tc=aaa-30:
1358 @end smallexample
1359
1360 @node Changing,  , Inheriting, Data Base
1361 @section When Changes in the Data Base Take Effect
1362
1363 Each application program must read the terminal description from the
1364 data base, so a change in the data base is effective for all jobs started
1365 after the change is made.
1366
1367 The change will usually have no effect on a job that have been in existence
1368 since before the change. The program probably read the terminal description
1369 once, when it was started, and is continuing to use what it read then.
1370 If the program does not have a feature for reexamining the data base, then
1371 you will need to run it again (probably killing the old job).
1372
1373 If the description in use is coming from the @code{TERMCAP} environment
1374 variable, then the data base file is effectively overridden, and changes in
1375 it will have no effect until you change the @code{TERMCAP} variable as
1376 well.  For example, some users' @file{.login} files automatically copy the
1377 terminal description into @code{TERMCAP} to speed startup of applications.
1378 If you have done this, you will need to change the @code{TERMCAP} variable
1379 to make the changed data base take effect.
1380
1381 @node Capabilities, Summary, Data Base, Top
1382 @chapter Definitions of the Terminal Capabilities
1383
1384 This section is divided into many subsections, each for one aspect of
1385 use of display terminals.  For writing a display program, you usually need
1386 only check the subsections for the operations you want to use.  For writing
1387 a terminal description, you must read each subsection and fill in the
1388 capabilities described there.
1389
1390 String capabilities that are display commands may require numeric
1391 parameters (@pxref{Parameters}).  Most such capabilities do not use
1392 parameters.  When a capability requires parameters, this is explicitly
1393 stated at the beginning of its definition.  In simple cases, the first or
1394 second sentence of the definition mentions all the parameters, in the order
1395 they should be given, using a name
1396 @iftex
1397 in italics
1398 @end iftex
1399 @ifinfo
1400 in upper case
1401 @end ifinfo
1402 for each one.  For example, the @samp{rp} capability is a command that
1403 requires two parameters; its definition begins as follows:
1404
1405 @quotation
1406 String of commands to output a graphic character @var{c}, repeated @var{n}
1407 times.
1408 @end quotation
1409
1410 In complex cases or when there are many parameters, they are described
1411 explicitly.
1412
1413 When a capability is described as obsolete, this means that programs should
1414 not be written to look for it, but terminal descriptions should still be
1415 written to provide it.
1416
1417 When a capability is described as very obsolete, this means that it should
1418 be omitted from terminal descriptions as well.
1419
1420 @menu
1421 * Basic::       Basic characteristics.
1422 * Screen Size::  Screen size, and what happens when it changes.
1423 * Cursor Motion::  Various ways to move the cursor.
1424 * Wrapping::    What happens if you write a character in the last column.
1425 * Scrolling::   Pushing text up and down on the screen.
1426 * Windows::     Limiting the part of the window that output affects.
1427 * Clearing::    Erasing one or many lines.
1428 * Insdel Line::  Making new blank lines in mid-screen; deleting lines.
1429 * Insdel Char::  Inserting and deleting characters within a line.
1430 * Standout::    Highlighting some of the text.
1431 * Underlining::  Underlining some of the text.
1432 * Cursor Visibility::  Making the cursor more or less easy to spot.
1433 * Bell::        Attracts user's attention; not localized on the screen.
1434 * Keypad::      Recognizing when function keys or arrows are typed.
1435 * Meta Key::    @key{META} acts like an extra shift key.
1436 * Initialization::  Commands used to initialize or reset the terminal.
1437 * Pad Specs::   Info for the kernel on how much padding is needed.
1438 * Status Line::  A status line displays ``background'' information.
1439 * Half-Line::   Moving by half-lines, for superscripts and subscripts.
1440 * Printer::     Controlling auxiliary printers of display terminals.
1441 @end menu
1442
1443 @node Basic, Screen Size,  , Capabilities
1444 @section Basic Characteristics
1445
1446 This section documents the capabilities that describe the basic and
1447 nature of the terminal, and also those that are relevant to the output
1448 of graphic characters.
1449
1450 @table @samp
1451 @item os
1452 @kindex os
1453 @cindex overstrike
1454 Flag whose presence means that the terminal can overstrike.  This
1455 means that outputting a graphic character does not erase whatever was
1456 present in the same character position before.  The terminals that can
1457 overstrike include printing terminals, storage tubes (all obsolete
1458 nowadays), and many bit-map displays.
1459
1460 @item eo
1461 @kindex eo
1462 Flag whose presence means that outputting a space erases a character
1463 position even if the terminal supports overstriking.  If this flag is
1464 not present and overstriking is supported, output of a space has no
1465 effect except to move the cursor.
1466
1467 (On terminals that do not support overstriking, you can always assume
1468 that outputting a space at a position erases whatever character was
1469 previously displayed there.)
1470
1471 @item gn
1472 @kindex gn
1473 @cindex generic terminal type
1474 Flag whose presence means that this terminal type is a generic type
1475 which does not really describe any particular terminal.  Generic types
1476 are intended for use as the default type assigned when the user
1477 connects to the system, with the intention that the user should
1478 specify what type he really has.  One example of a generic type
1479 is the type @samp{network}.
1480
1481 Since the generic type cannot say how to do anything interesting with
1482 the terminal, termcap-using programs will always find that the
1483 terminal is too weak to be supported if the user has failed to specify
1484 a real terminal type in place of the generic one.  The @samp{gn} flag
1485 directs these programs to use a different error message: ``You have
1486 not specified your real terminal type'', rather than ``Your terminal
1487 is not powerful enough to be used''.
1488
1489 @item hc
1490 @kindex hc
1491 Flag whose presence means this is a hardcopy terminal.
1492
1493 @item rp
1494 @kindex rp
1495 @cindex repeat output
1496 String of commands to output a graphic character @var{c}, repeated @var{n}
1497 times.  The first parameter value is the ASCII code for the desired
1498 character, and the second parameter is the number of times to repeat the
1499 character.  Often this command requires padding proportional to the 
1500 number of times the character is repeated.  This effect can be had by
1501 using parameter arithmetic with @samp{%}-sequences to compute the
1502 amount of padding, then generating the result as a number at the front
1503 of the string so that @code{tputs} will treat it as padding.
1504
1505 @item hz
1506 @kindex hz
1507 Flag whose presence means that the ASCII character @samp{~} cannot be
1508 output on this terminal because it is used for display commands.
1509
1510 Programs handle this flag by checking all text to be output and
1511 replacing each @samp{~} with some other character(s).  If this is not
1512 done, the screen will be thoroughly garbled.
1513
1514 The old Hazeltine terminals that required such treatment are probably
1515 very rare today, so you might as well not bother to support this flag.
1516
1517 @item CC
1518 @kindex CC
1519 @cindex command character
1520 String whose presence means the terminal has a settable command
1521 character.  The value of the string is the default command character
1522 (which is usually @key{ESC}).
1523
1524 All the strings of commands in the terminal description should be
1525 written to use the default command character.  If you are writing an
1526 application program that changes the command character, use the
1527 @samp{CC} capability to figure out how to translate all the display
1528 commands to work with the new command character.
1529
1530 Most programs have no reason to look at the @samp{CC} capability.
1531
1532 @item xb
1533 @kindex xb
1534 @cindex Superbee
1535 Flag whose presence identifies Superbee terminals which are unable to
1536 transmit the characters @key{ESC} and @kbd{Control-C}.  Programs which
1537 support this flag are supposed to check the input for the code sequences
1538 sent by the @key{F1} and @key{F2} keys, and pretend that @key{ESC}
1539 or @kbd{Control-C} (respectively) had been read.  But this flag is
1540 obsolete, and not worth supporting.
1541 @end table
1542
1543 @node Screen Size, Cursor Motion, Basic, Capabilities
1544 @section Screen Size
1545 @cindex screen size
1546
1547 A terminal description has two capabilities, @samp{co} and @samp{li},
1548 that describe the screen size in columns and lines.  But there is more
1549 to the question of screen size than this.
1550
1551 On some operating systems the ``screen'' is really a window and the
1552 effective width can vary.  On some of these systems, @code{tgetnum}
1553 uses the actual width of the window to decide what value to return for
1554 the @samp{co} capability, overriding what is actually written in the
1555 terminal description.  On other systems, it is up to the application
1556 program to check the actual window width using a system call.  For
1557 example, on BSD 4.3 systems, the system call @code{ioctl} with code
1558 @code{TIOCGWINSZ} will tell you the current screen size.
1559
1560 On all window systems, termcap is powerless to advise the application
1561 program if the user resizes the window.  Application programs must
1562 deal with this possibility in a system-dependent fashion.  On some
1563 systems the C shell handles part of the problem by detecting changes
1564 in window size and setting the @code{TERMCAP} environment variable
1565 appropriately.  This takes care of application programs that are
1566 started subsequently.  It does not help application programs already
1567 running.
1568
1569 On some systems, including BSD 4.3, all programs using a terminal get
1570 a signal named @code{SIGWINCH} whenever the screen size changes.
1571 Programs that use termcap should handle this signal by using
1572 @code{ioctl TIOCGWINSZ} to learn the new screen size.
1573
1574 @table @samp
1575 @item co
1576 @kindex co
1577 @cindex screen size
1578 Numeric value, the width of the screen in character positions.  Even
1579 hardcopy terminals normally have a @samp{co} capability.
1580
1581 @item li
1582 @kindex li
1583 Numeric value, the height of the screen in lines.
1584 @end table
1585
1586 @node Cursor Motion, Wrapping, Screen Size, Capabilities
1587 @section Cursor Motion
1588 @cindex cursor motion
1589
1590 Termcap assumes that the terminal has a @dfn{cursor}, a spot on the screen
1591 where a visible mark is displayed, and that most display commands take
1592 effect at the position of the cursor.  It follows that moving the cursor
1593 to a specified location is very important.
1594
1595 There are many terminal capabilities for different cursor motion
1596 operations.  A terminal description should define as many as possible, but
1597 most programs do not need to use most of them.  One capability, @samp{cm},
1598 moves the cursor to an arbitrary place on the screen; this by itself is
1599 sufficient for any application as long as there is no need to support
1600 hardcopy terminals or certain old, weak displays that have only relative
1601 motion commands.  Use of other cursor motion capabilities is an
1602 optimization, enabling the program to output fewer characters in some
1603 common cases.
1604
1605 If you plan to use the relative cursor motion commands in an application
1606 program, you must know what the starting cursor position is.  To do this,
1607 you must keep track of the cursor position and update the records each
1608 time anything is output to the terminal, including graphic characters.
1609 In addition, it is necessary to know whether the terminal wraps after
1610 writing in the rightmost column.  @xref{Wrapping}.
1611
1612 One other motion capability needs special mention: @samp{nw} moves the
1613 cursor to the beginning of the following line, perhaps clearing all the
1614 starting line after the cursor, or perhaps not clearing at all.  This
1615 capability is a least common denominator that is probably supported even by
1616 terminals that cannot do most other things such as @samp{cm} or @samp{do}.
1617 Even hardcopy terminals can support @samp{nw}.
1618
1619 @table @asis
1620 @item @samp{cm}
1621 @kindex cm
1622 String of commands to position the cursor at line @var{l}, column @var{c}.
1623 Both parameters are origin-zero, and are defined relative to the
1624 screen, not relative to display memory.
1625
1626 All display terminals except a few very obsolete ones support @samp{cm},
1627 so it is acceptable for an application program to refuse to operate on
1628 terminals lacking @samp{cm}.
1629
1630 @item @samp{ho}
1631 @kindex ho
1632 @cindex home position
1633 String of commands to move the cursor to the upper left corner of the
1634 screen (this position is called the @dfn{home position}).  In
1635 terminals where the upper left corner of the screen is not the same as
1636 the beginning of display memory, this command must go to the upper
1637 left corner of the screen, not the beginning of display memory.
1638
1639 Every display terminal supports this capability, and many application
1640 programs refuse to operate if the @samp{ho} capability is missing.
1641
1642 @item @samp{ll}
1643 @kindex ll
1644 String of commands to move the cursor to the lower left corner of the
1645 screen.  On some terminals, moving up from home position does this,
1646 but programs should never assume that will work.  Just output the
1647 @samp{ll} string (if it is provided); if moving to home position and
1648 then moving up is the best way to get there, the @samp{ll} command
1649 will do that.
1650
1651 @item @samp{cr}
1652 @kindex cr
1653 String of commands to move the cursor to the beginning of the line it
1654 is on.  If this capability is not specified, many programs assume
1655 they can use the ASCII carriage return character for this.
1656
1657 @item @samp{le}
1658 @kindex le
1659 String of commands to move the cursor left one column.  Unless the
1660 @samp{bw} flag capability is specified, the effect is undefined if the
1661 cursor is at the left margin; do not use this command there.  If
1662 @samp{bw} is present, this command may be used at the left margin, and
1663 it wraps the cursor to the last column of the preceding line.
1664
1665 @item @samp{nd}
1666 @kindex nd
1667 String of commands to move the cursor right one column.  The effect is
1668 undefined if the cursor is at the right margin; do not use this
1669 command there, not even if @samp{am} is present.
1670
1671 @item @samp{up}
1672 @kindex up
1673 String of commands to move the cursor vertically up one line.  The
1674 effect of sending this string when on the top line is undefined;
1675 programs should never use it that way.
1676
1677 @item @samp{do}
1678 @kindex do
1679 String of commands to move the cursor vertically down one line.  The
1680 effect of sending this string when on the bottom line is undefined;
1681 programs should never use it that way.
1682
1683 Some programs do use @samp{do} to scroll up one line if used at the
1684 bottom line, if @samp{sf} is not defined but @samp{sr} is.  This is
1685 only to compensate for certain old, incorrect terminal descriptions.
1686 (In principle this might actually lead to incorrect behavior on other
1687 terminals, but that seems to happen rarely if ever.)  But the proper
1688 solution is that the terminal description should define @samp{sf} as
1689 well as @samp{do} if the command is suitable for scrolling.
1690
1691 The original idea was that this string would not contain a newline
1692 character and therefore could be used without disabling the kernel's
1693 usual habit of converting of newline into a carriage-return newline
1694 sequence.  But many terminal descriptions do use newline in the
1695 @samp{do} string, so this is not possible; a program which sends the
1696 @samp{do} string must disable output conversion in the kernel
1697 (@pxref{Initialize}).
1698
1699 @item @samp{bw}
1700 @kindex bw
1701 Flag whose presence says that @samp{le} may be used in column zero
1702 to move to the last column of the preceding line.  If this flag
1703 is not present, @samp{le} should not be used in column zero.
1704
1705 @item @samp{nw}
1706 @kindex nw
1707 String of commands to move the cursor to start of next line, possibly
1708 clearing rest of line (following the cursor) before moving.
1709
1710 @item @samp{DO}, @samp{UP}, @samp{LE}, @samp{RI}
1711 @kindex DO
1712 @kindex LE
1713 @kindex RI
1714 @kindex UP
1715 Strings of commands to move the cursor @var{n} lines down vertically,
1716 up vertically, or @var{n} columns left or right.  Do not attempt to
1717 move past any edge of the screen with these commands; the effect of
1718 trying that is undefined.  Only a few terminal descriptions provide
1719 these commands, and most programs do not use them.
1720
1721 @item @samp{CM}
1722 @kindex CM
1723 String of commands to position the cursor at line @var{l}, column
1724 @var{c}, relative to display memory.  Both parameters are origin-zero.
1725 This capability is present only in terminals where there is a
1726 difference between screen-relative and memory-relative addressing, and
1727 not even in all such terminals.
1728
1729 @item @samp{ch}
1730 @kindex ch
1731 String of commands to position the cursor at column @var{c} in the
1732 same line it is on.  This is a special case of @samp{cm} in which the
1733 vertical position is not changed.  The @samp{ch} capability is
1734 provided only when it is faster to output than @samp{cm} would be in
1735 this special case.  Programs should not assume most display terminals
1736 have @samp{ch}.
1737
1738 @item @samp{cv}
1739 @kindex cv
1740 String of commands to position the cursor at line @var{l} in the same
1741 column.  This is a special case of @samp{cm} in which the horizontal
1742 position is not changed.  The @samp{cv} capability is provided only
1743 when it is faster to output than @samp{cm} would be in this special
1744 case.  Programs should not assume most display terminals have
1745 @samp{cv}.
1746
1747 @item @samp{sc}
1748 @kindex sc
1749 String of commands to make the terminal save the current cursor
1750 position.  Only the last saved position can be used.  If this
1751 capability is present, @samp{rc} should be provided also.  Most
1752 terminals have neither.
1753
1754 @item @samp{rc}
1755 @kindex rc
1756 String of commands to make the terminal restore the last saved cursor
1757 position.  If this capability is present, @samp{sc} should be provided
1758 also.  Most terminals have neither.
1759
1760 @item @samp{ff}
1761 @kindex ff
1762 String of commands to advance to the next page, for a hardcopy
1763 terminal.
1764
1765 @item @samp{ta}
1766 @kindex ta
1767 String of commands to move the cursor right to the next hardware tab
1768 stop column.  Missing if the terminal does not have any kind of
1769 hardware tabs.  Do not send this command if the kernel's terminal
1770 modes say that the kernel is expanding tabs into spaces.
1771
1772 @item @samp{bt}
1773 @kindex bt
1774 String of commands to move the cursor left to the previous hardware
1775 tab stop column.  Missing if the terminal has no such ability; many
1776 terminals do not.  Do not send this command if the kernel's terminal
1777 modes say that the kernel is expanding tabs into spaces.
1778 @end table
1779
1780 The following obsolete capabilities should be included in terminal
1781 descriptions when appropriate, but should not be looked at by new programs.
1782
1783 @table @samp
1784 @item nc
1785 @kindex nc
1786 Flag whose presence means the terminal does not support the ASCII
1787 carriage return character as @samp{cr}.  This flag is needed because
1788 old programs assume, when the @samp{cr} capability is missing, that
1789 ASCII carriage return can be used for the purpose.  We use @samp{nc}
1790 to tell the old programs that carriage return may not be used.
1791
1792 New programs should not assume any default for @samp{cr}, so they need
1793 not look at @samp{nc}.  However, descriptions should contain @samp{nc}
1794 whenever they do not contain @samp{cr}.
1795
1796 @item xt
1797 @kindex xt
1798 Flag whose presence means that the ASCII tab character may not be used
1799 for cursor motion.  This flag exists because old programs assume, when
1800 the @samp{ta} capability is missing, that ASCII tab can be used for
1801 the purpose.  We use @samp{xt} to tell the old programs not to use tab.
1802
1803 New programs should not assume any default for @samp{ta}, so they need
1804 not look at @samp{xt} in connection with cursor motion.  Note that
1805 @samp{xt} also has implications for standout mode (@pxref{Standout}).
1806 It is obsolete in regard to cursor motion but not in regard to
1807 standout.
1808
1809 In fact, @samp{xt} means that the terminal is a Teleray 1061.
1810
1811 @item bc
1812 @kindex bc
1813 Very obsolete alternative name for the @samp{le} capability.
1814
1815 @item bs
1816 @kindex bs
1817 Flag whose presence means that the ASCII character backspace may be
1818 used to move the cursor left.  Obsolete; look at @samp{le} instead.
1819
1820 @item nl
1821 @kindex nl
1822 Obsolete capability which is a string that can either be used to move
1823 the cursor down or to scroll.  The same string must scroll when used
1824 on the bottom line and move the cursor when used on any other line.
1825 New programs should use @samp{do} or @samp{sf}, and ignore @samp{nl}.
1826
1827 If there is no @samp{nl} capability, some old programs assume they can
1828 use the newline character for this purpose.  These programs follow a
1829 bad practice, but because they exist, it is still desirable to define
1830 the @samp{nl} capability in a terminal description if the best way to
1831 move down is @emph{not} a newline.
1832 @end table
1833
1834 @node Wrapping, Scrolling, Cursor Motion, Capabilities
1835 @section Wrapping
1836 @cindex wrapping
1837
1838 @dfn{Wrapping} means moving the cursor from the right margin to the left
1839 margin of the following line.  Some terminals wrap automatically when a
1840 graphic character is output in the last column, while others do not.  Most
1841 application programs that use termcap need to know whether the terminal
1842 wraps.  There are two special flag capabilities to describe what the
1843 terminal does when a graphic character is output in the last column.
1844
1845 @table @samp
1846 @item am
1847 @kindex am
1848 Flag whose presence means that writing a character in the last column
1849 causes the cursor to wrap to the beginning of the next line.
1850
1851 If @samp{am} is not present, writing in the last column leaves the
1852 cursor at the place where the character was written.
1853
1854 Writing in the last column of the last line should be avoided on
1855 terminals with @samp{am}, as it may or may not cause scrolling to
1856 occur (@pxref{Scrolling}).  Scrolling is surely not what you would
1857 intend.
1858
1859 If your program needs to check the @samp{am} flag, then it also needs
1860 to check the @samp{xn} flag which indicates that wrapping happens in a
1861 strange way.  Many common terminals have the @samp{xn} flag.
1862
1863 @item xn
1864 @kindex xn
1865 Flag whose presence means that the cursor wraps in a strange way.  At
1866 least two distinct kinds of strange behavior are known; the termcap
1867 data base does not contain anything to distinguish the two.
1868
1869 On Concept-100 terminals, output in the last column wraps the cursor
1870 almost like an ordinary @samp{am} terminal.  But if the next thing
1871 output is a newline, it is ignored.
1872
1873 DEC VT-100 terminals (when the wrap switch is on) do a different
1874 strange thing: the cursor wraps only if the next thing output is
1875 another graphic character.  In fact, the wrap occurs when the
1876 following graphic character is received by the terminal, before the
1877 character is placed on the screen.
1878
1879 On both of these terminals, after writing in the last column a
1880 following graphic character will be displayed in the first column of
1881 the following line.  But the effect of relative cursor motion
1882 characters such as newline or backspace at such a time depends on the
1883 terminal.  The effect of erase or scrolling commands also depends on
1884 the terminal.  You can't assume anything about what they will do on a
1885 terminal that has @samp{xn}.  So, to be safe, you should never do
1886 these things at such a time on such a terminal.
1887
1888 To be sure of reliable results on a terminal which has the @samp{xn}
1889 flag, output a @samp{cm} absolute positioning command after writing in
1890 the last column.  Another safe thing to do is to output carriage-return
1891 newline, which will leave the cursor at the beginning of the following
1892 line.
1893 @end table
1894
1895 @node Scrolling, Windows, Wrapping, Capabilities
1896 @section Scrolling
1897 @cindex scrolling
1898
1899 @dfn{Scrolling} means moving the contents of the screen up or down one or
1900 more lines.  Moving the contents up is @dfn{forward scrolling}; moving them
1901 down is @dfn{reverse scrolling}.
1902
1903 Scrolling happens after each line of output during ordinary output on most
1904 display terminals.  But in an application program that uses termcap for
1905 random-access output, scrolling happens only when explicitly requested with
1906 the commands in this section.
1907
1908 Some terminals have a @dfn{scroll region} feature.  This lets you limit
1909 the effect of scrolling to a specified range of lines.  Lines outside the
1910 range are unaffected when scrolling happens.  The scroll region feature
1911 is available if either @samp{cs} or @samp{cS} is present.
1912
1913 @table @samp
1914 @item sf
1915 @kindex sf
1916 String of commands to scroll the screen one line up, assuming it is
1917 output with the cursor at the beginning of the bottom line.
1918
1919 @item sr
1920 @kindex sr
1921 String of commands to scroll the screen one line down, assuming it is
1922 output with the cursor at the beginning of the top line.
1923
1924 @item do
1925 A few programs will try to use @samp{do} to do the work of @samp{sf}.
1926 This is not really correct---it is an attempt to compensate for the
1927 absence of a @samp{sf} command in some old terminal descriptions.
1928
1929 Since these terminal descriptions do define @samp{sr}, perhaps at one
1930 time the definition of @samp{do} was different and it could be used
1931 for scrolling as well.  But it isn't desirable to combine these two
1932 functions in one capability, since scrolling often requires more
1933 padding than simply moving the cursor down.  Defining @samp{sf} and
1934 @samp{do} separately allows you to specify the padding properly.
1935 Also, all sources agree that @samp{do} should not be relied on to do
1936 scrolling.
1937
1938 So the best approach is to add @samp{sf} capabilities to the
1939 descriptions of these terminals, copying the definition of @samp{do}
1940 if that does scroll.
1941
1942 @item SF
1943 @kindex SF
1944 String of commands to scroll the screen @var{n} lines up, assuming it
1945 is output with the cursor at the beginning of the bottom line.
1946
1947 @item SR
1948 @kindex SR
1949 String of commands to scroll the screen @var{n} lines down, assuming it
1950 is output with the cursor at the beginning of the top line.
1951
1952 @item cs
1953 @kindex cs
1954 String of commands to set the scroll region.  This command takes two
1955 parameters, @var{start} and @var{end}, which are the line numbers
1956 (origin-zero) of the first line to include in the scroll region and of
1957 the last line to include in it.  When a scroll region is set,
1958 scrolling is limited to the specified range of lines; lines outside
1959 the range are not affected by scroll commands.
1960
1961 Do not try to move the cursor outside the scroll region.  The region
1962 remains set until explicitly removed.  To remove the scroll region,
1963 use another @samp{cs} command specifying the full height of the
1964 screen.
1965
1966 The cursor position is undefined after the @samp{cs} command is set,
1967 so position the cursor with @samp{cm} immediately afterward.
1968
1969 @item cS
1970 @kindex cS
1971 String of commands to set the scroll region using parameters in
1972 different form.  The effect is the same as if @samp{cs} were used.
1973 Four parameters are required:
1974
1975 @enumerate
1976 @item
1977 Total number of lines on the screen.
1978 @item
1979 Number of lines above desired scroll region.
1980 @item
1981 Number of lines below (outside of) desired scroll region.
1982 @item
1983 Total number of lines on the screen, the same as the first parameter.
1984 @end enumerate
1985
1986 This capability is a GNU extension that was invented to allow the Ann
1987 Arbor Ambassador's scroll-region command to be described; it could
1988 also be done by putting non-Unix @samp{%}-sequences into a @samp{cs}
1989 string, but that would have confused Unix programs that used the
1990 @samp{cs} capability with the Unix termcap.  Currently only GNU Emacs
1991 uses the @samp{cS} capability.
1992
1993 @item ns
1994 @kindex ns
1995 Flag which means that the terminal does not normally scroll for
1996 ordinary sequential output.  For modern terminals, this means that
1997 outputting a newline in ordinary sequential output with the cursor on
1998 the bottom line wraps to the top line.  For some obsolete terminals,
1999 other things may happen.
2000
2001 The terminal may be able to scroll even if it does not normally do so.
2002 If the @samp{sf} capability is provided, it can be used for scrolling
2003 regardless of @samp{ns}.
2004
2005 @item da
2006 @kindex da
2007 Flag whose presence means that lines scrolled up off the top of the
2008 screen may come back if scrolling down is done subsequently.
2009
2010 The @samp{da} and @samp{db} flags do not, strictly speaking, affect
2011 how to scroll.  But programs that scroll usually need to clear the
2012 lines scrolled onto the screen, if these flags are present.
2013
2014 @item db
2015 @kindex db
2016 Flag whose presence means that lines scrolled down off the bottom of
2017 the screen may come back if scrolling up is done subsequently.
2018
2019 @item lm
2020 @kindex lm
2021 Numeric value, the number of lines of display memory that the terminal
2022 has.  A value of zero means that the terminal has more display memory
2023 than can fit on the screen, but no fixed number of lines.  (The number
2024 of lines may depend on the amount of text in each line.)
2025 @end table
2026
2027 Any terminal description that defines @samp{SF} should also define @samp{sf};
2028 likewise for @samp{SR} and @samp{sr}.  However, many terminals can only
2029 scroll by one line at a time, so it is common to find @samp{sf} and not
2030 @samp{SF}, or @samp{sr} without @samp{SR}.@refill
2031
2032 Therefore, all programs that use the scrolling facilities should be
2033 prepared to work with @samp{sf} in the case that @samp{SF} is absent, and
2034 likewise with @samp{sr}.  On the other hand, an application program that
2035 uses only @samp{sf} and not @samp{SF} is acceptable, though slow on some
2036 terminals.@refill
2037
2038 When outputting a scroll command with @code{tputs}, the @var{nlines}
2039 argument should be the total number of lines in the portion of the screen
2040 being scrolled.  Very often these commands require padding proportional to
2041 this number of lines.  @xref{Padding}.
2042
2043 @node Windows, Clearing, Scrolling, Capabilities
2044 @section Windows
2045 @cindex window
2046
2047 A @dfn{window}, in termcap, is a rectangular portion of the screen to which
2048 all display operations are restricted.  Wrapping, clearing, scrolling,
2049 insertion and deletion all operate as if the specified window were all the
2050 screen there was.
2051
2052 @table @samp
2053 @item wi
2054 @kindex wi
2055 String of commands to set the terminal output screen window.
2056 This string requires four parameters, all origin-zero:
2057 @enumerate
2058 @item
2059 The first line to include in the window.
2060 @item
2061 The last line to include in the window.
2062 @item
2063 The first column to include in the window.
2064 @item
2065 The last column to include in the window.
2066 @end enumerate
2067 @end table
2068
2069 Most terminals do not support windows.
2070
2071 @node Clearing, Insdel Line, Windows, Capabilities
2072 @section Clearing Parts of the Screen
2073 @cindex erasing
2074 @cindex clearing the screen
2075
2076 There are several terminal capabilities for clearing parts of the screen
2077 to blank.  All display terminals support the @samp{cl} string, and most
2078 display terminals support all of these capabilities.
2079
2080 @table @samp
2081 @item cl
2082 @kindex cl
2083 String of commands to clear the entire screen and position the cursor
2084 at the upper left corner.
2085
2086 @item cd
2087 @kindex cd
2088 String of commands to clear the line the cursor is on, and all the
2089 lines below it, down to the bottom of the screen.  This command string
2090 should be used only with the cursor in column zero; their effect is
2091 undefined if the cursor is elsewhere.
2092
2093 @item ce
2094 @kindex ce
2095 String of commands to clear from the cursor to the end of the current
2096 line.
2097
2098 @item ec
2099 @kindex ec
2100 String of commands to clear @var{n} characters, starting with the
2101 character that the cursor is on.  This command string is expected to
2102 leave the cursor position unchanged.  The parameter @var{n} should never
2103 be large enough to reach past the right margin; the effect of such a
2104 large parameter would be undefined.
2105 @end table
2106
2107 Clear to end of line (@samp{ce}) is extremely important in programs that
2108 maintain an updating display.  Nearly all display terminals support this
2109 operation, so it is acceptable for a an application program to refuse to
2110 work if @samp{ce} is not present.  However, if you do not want this
2111 limitation, you can accomplish clearing to end of line by outputting spaces
2112 until you reach the right margin.  In order to do this, you must know the
2113 current horizontal position.  Also, this technique assumes that writing a
2114 space will erase.  But this happens to be true on all the display terminals
2115 that fail to support @samp{ce}.
2116
2117 @node Insdel Line, Insdel Char, Clearing, Capabilities
2118 @section Insert/Delete Line
2119
2120 @cindex insert line
2121 @cindex delete line
2122 @dfn{Inserting a line} means creating a blank line in the middle
2123 of the screen, and pushing the existing lines of text apart.  In fact,
2124 the lines above the insertion point do not change, while the lines below
2125 move down, and one is normally lost at the bottom of the screen.
2126
2127 @dfn{Deleting a line} means causing the line to disappear from the screen,
2128 closing up the gap by moving the lines below it upward.  A new line
2129 appears at the bottom of the screen.  Usually this line is blank, but
2130 on terminals with the @samp{db} flag it may be a line previously moved
2131 off the screen bottom by scrolling or line insertion.
2132
2133 Insertion and deletion of lines is useful in programs that maintain an
2134 updating display some parts of which may get longer or shorter.  They are
2135 also useful in editors for scrolling parts of the screen, and for
2136 redisplaying after lines of text are killed or inserted.
2137
2138 Many terminals provide commands to insert or delete a single line at the
2139 cursor position.  Some provide the ability to insert or delete several
2140 lines with one command, using the number of lines to insert or delete as a
2141 parameter.  Always move the cursor to column zero before using any of
2142 these commands.
2143
2144 @table @samp
2145 @item al
2146 @kindex al
2147 String of commands to insert a blank line before the line the cursor
2148 is on.  The existing line, and all lines below it, are moved down.
2149 The last line in the screen (or in the scroll region, if one is set)
2150 disappears and in most circumstances is discarded.  It may not be
2151 discarded if the @samp{db} is present (@pxref{Scrolling}).
2152
2153 The cursor must be at the left margin before this command is used.
2154 This command does not move the cursor.
2155
2156 @item dl
2157 @kindex dl
2158 String of commands to delete the line the cursor is on.  The following
2159 lines move up, and a blank line appears at the bottom of the screen
2160 (or bottom of the scroll region).  If the terminal has the @samp{db}
2161 flag, a nonblank line previously pushed off the screen bottom may
2162 reappear at the bottom.
2163
2164 The cursor must be at the left margin before this command is used.
2165 This command does not move the cursor.
2166
2167 @item AL
2168 @kindex AL
2169 String of commands to insert @var{n} blank lines before the line that
2170 the cursor is on.  It is like @samp{al} repeated @var{n} times, except
2171 that it is as fast as one @samp{al}.
2172
2173 @item DL
2174 @kindex DL
2175 String of commands to delete @var{n} lines starting with the line that
2176 the cursor is on.  It is like @samp{dl} repeated @var{n} times, except
2177 that it is as fast as one @samp{dl}.
2178 @end table
2179
2180 Any terminal description that defines @samp{AL} should also define
2181 @samp{al}; likewise for @samp{DL} and @samp{dl}.  However, many terminals
2182 can only insert or delete one line at a time, so it is common to find
2183 @samp{al} and not @samp{AL}, or @samp{dl} without @samp{DL}.@refill
2184
2185 Therefore, all programs that use the insert and delete facilities should be
2186 prepared to work with @samp{al} in the case that @samp{AL} is absent, and
2187 likewise with @samp{dl}.  On the other hand, it is acceptable to write
2188 an application that uses only @samp{al} and @samp{dl} and does not look
2189 for @samp{AL} or @samp{DL} at all.@refill
2190
2191 If a terminal does not support line insertion and deletion directly,
2192 but does support a scroll region, the effect of insertion and deletion
2193 can be obtained with scrolling.  However, it is up to the individual
2194 user program to check for this possibility and use the scrolling
2195 commands to get the desired result.  It is fairly important to implement
2196 this alternate strategy, since it is the only way to get the effect of
2197 line insertion and deletion on the popular VT100 terminal.
2198
2199 Insertion and deletion of lines is affected by the scroll region on
2200 terminals that have a settable scroll region.  This is useful when it is
2201 desirable to move any few consecutive lines up or down by a few lines.
2202 @xref{Scrolling}.
2203
2204 The line pushed off the bottom of the screen is not lost if the terminal
2205 has the @samp{db} flag capability; instead, it is pushed into display
2206 memory that does not appear on the screen.  This is the same thing that
2207 happens when scrolling pushes a line off the bottom of the screen.
2208 Either reverse scrolling or deletion of a line can bring the apparently
2209 lost line back onto the bottom of the screen.  If the terminal has the
2210 scroll region feature as well as @samp{db}, the pushed-out line really
2211 is lost if a scroll region is in effect.
2212
2213 When outputting an insert or delete command with @code{tputs}, the
2214 @var{nlines} argument should be the total number of lines from the cursor
2215 to the bottom of the screen (or scroll region).  Very often these commands
2216 require padding proportional to this number of lines.  @xref{Padding}.
2217
2218 For @samp{AL} and @samp{DL} the @var{nlines} argument should @emph{not}
2219 depend on the number of lines inserted or deleted; only the total number of
2220 lines affected.  This is because it is just as fast to insert two or
2221 @var{n} lines with @samp{AL} as to insert one line with @samp{al}.
2222
2223 @node Insdel Char, Standout, Insdel Line, Capabilities
2224 @section Insert/Delete Character
2225 @cindex insert character
2226 @cindex delete character
2227
2228 @dfn{Inserting a character} means creating a blank space in the middle of a
2229 line, and pushing the rest of the line rightward.  The character in the
2230 rightmost column is lost.
2231
2232 @dfn{Deleting a character} means causing the character to disappear from
2233 the screen, closing up the gap by moving the rest of the line leftward.  A
2234 blank space appears in the rightmost column.
2235
2236 Insertion and deletion of characters is useful in programs that maintain an
2237 updating display some parts of which may get longer or shorter.  It is also
2238 useful in editors for redisplaying the results of editing within a line.
2239
2240 Many terminals provide commands to insert or delete a single character at
2241 the cursor position.  Some provide the ability to insert or delete several
2242 characters with one command, using the number of characters to insert or
2243 delete as a parameter.
2244
2245 @cindex insert mode
2246 Many terminals provide an insert mode in which outputting a graphic
2247 character has the added effect of inserting a position for that character.
2248 A special command string is used to enter insert mode and another is used
2249 to exit it.  The reason for designing a terminal with an insert mode rather
2250 than an insert command is that inserting character positions is usually
2251 followed by writing characters into them.  With insert mode, this is as
2252 fast as simply writing the characters, except for the fixed overhead of
2253 entering and leaving insert mode.  However, when the line speed is great
2254 enough, padding may be required for the graphic characters output in insert
2255 mode.
2256
2257 Some terminals require you to enter insert mode and then output a special
2258 command for each position to be inserted.  Or they may require special
2259 commands to be output before or after each graphic character to be
2260 inserted.
2261
2262 @cindex delete mode
2263 Deletion of characters is usually accomplished by a straightforward command
2264 to delete one or several positions; but on some terminals, it is necessary
2265 to enter a special delete mode before using the delete command, and leave
2266 delete mode afterward.  Sometimes delete mode and insert mode are the same
2267 mode.
2268
2269 Some terminals make a distinction between character positions in which a
2270 space character has been output and positions which have been cleared.  On
2271 these terminals, the effect of insert or delete character runs to the first
2272 cleared position rather than to the end of the line.  In fact, the effect
2273 may run to more than one line if there is no cleared position to stop the
2274 shift on the first line.  These terminals are identified by the @samp{in}
2275 flag capability.
2276
2277 On terminals with the @samp{in} flag, the technique of skipping over
2278 characters that you know were cleared, and then outputting text later on in
2279 the same line, causes later insert and delete character operations on that
2280 line to do nonstandard things.  A program that has any chance of doing this
2281 must check for the @samp{in} flag and must be careful to write explicit
2282 space characters into the intermediate columns when @samp{in} is present.
2283
2284 A plethora of terminal capabilities are needed to describe all of this
2285 complexity.  Here is a list of them all.  Following the list, we present
2286 an algorithm for programs to use to take proper account of all of these
2287 capabilities.
2288
2289 @table @samp
2290 @item im
2291 @kindex im
2292 String of commands to enter insert mode.
2293
2294 If the terminal has no special insert mode, but it can insert
2295 characters with a special command, @samp{im} should be defined with a
2296 null value, because the @samp{vi} editor assumes that insertion of a
2297 character is impossible if @samp{im} is not provided.
2298
2299 New programs should not act like @samp{vi}.  They should pay attention
2300 to @samp{im} only if it is defined.
2301
2302 @item ei
2303 @kindex ei
2304 String of commands to leave insert mode.  This capability must be
2305 present if @samp{im} is.
2306
2307 On a few old terminals the same string is used to enter and exit
2308 insert mode.  This string turns insert mode on if it was off, and off
2309 it it was on.  You can tell these terminals because the @samp{ei}
2310 string equals the @samp{im} string.  If you want to support these
2311 terminals, you must always remember accurately whether insert mode is
2312 in effect.  However, these terminals are obsolete, and it is
2313 reasonable to refuse to support them.  On all modern terminals, you
2314 can safely output @samp{ei} at any time to ensure that insert mode is
2315 turned off.
2316
2317 @item ic
2318 @kindex ic
2319 String of commands to insert one character position at the cursor.
2320 The cursor does not move.
2321
2322 If outputting a graphic character while in insert mode is sufficient
2323 to insert the character, then the @samp{ic} capability should be
2324 defined with a null value.
2325
2326 If your terminal offers a choice of ways to insert---either use insert
2327 mode or use a special command---then define @samp{im} and do not define
2328 @samp{ic}, since this gives the most efficient operation when several
2329 characters are to be inserted.  @emph{Do not} define both strings, for
2330 that means that @emph{both} must be used each time insertion is done.
2331
2332 @item ip
2333 @kindex ip
2334 String of commands to output following an inserted graphic character
2335 in insert mode.  Often it is used just for a padding spec, when padding
2336 is needed after an inserted character (@pxref{Padding}).
2337
2338 @item IC
2339 @kindex IC
2340 String of commands to insert @var{n} character positions at and after
2341 the cursor.  It has the same effect as repeating the @samp{ic} string
2342 and a space, @var{n} times.
2343
2344 If @samp{IC} is provided, application programs may use it without first
2345 entering insert mode.
2346
2347 @item mi
2348 @kindex mi
2349 Flag whose presence means it is safe to move the cursor while in insert
2350 mode and assume the terminal remains in insert mode.
2351
2352 @item in
2353 @kindex in
2354 Flag whose presence means that the terminal distinguishes between
2355 character positions in which space characters have been output and
2356 positions which have been cleared.
2357 @end table
2358
2359 An application program can assume that the terminal can do character
2360 insertion if @emph{any one of} the capabilities @samp{IC}, @samp{im},
2361 @samp{ic} or @samp{ip} is provided.
2362
2363 To insert @var{n} blank character positions, move the cursor to the place
2364 to insert them and follow this algorithm:
2365
2366 @enumerate
2367 @item
2368 If an @samp{IC} string is provided, output it with parameter @var{n}
2369 and you are finished.  Otherwise (or if you don't want to bother to
2370 look for an @samp{IC} string) follow the remaining steps.
2371
2372 @item
2373 Output the @samp{im} string, if there is one, unless the terminal is
2374 already in insert mode.
2375
2376 @item
2377 Repeat steps 4 through 6, @var{n} times.
2378
2379 @item
2380 Output the @samp{ic} string if any.
2381
2382 @item
2383 Output a space.
2384
2385 @item
2386 Output the @samp{ip} string if any.
2387
2388 @item
2389 Output the @samp{ei} string, eventually, to exit insert mode.  There
2390 is no need to do this right away.  If the @samp{mi} flag is present,
2391 you can move the cursor and the cursor will remain in insert mode;
2392 then you can do more insertion elsewhere without reentering insert
2393 mode.
2394 @end enumerate
2395
2396 To insert @var{n} graphic characters, position the cursor and follow this
2397 algorithm:
2398
2399 @enumerate
2400 @item
2401 If an @samp{IC} string is provided, output it with parameter @var{n},
2402 then output the graphic characters, and you are finished.  Otherwise
2403 (or if you don't want to bother to look for an @samp{IC} string)
2404 follow the remaining steps.
2405
2406 @item
2407 Output the @samp{im} string, if there is one, unless the terminal is
2408 already in insert mode.
2409
2410 @item
2411 For each character to be output, repeat steps 4 through 6.
2412
2413 @item
2414 Output the @samp{ic} string if any.
2415
2416 @item
2417 Output the next graphic character.
2418
2419 @item
2420 Output the @samp{ip} string if any.
2421
2422 @item
2423 Output the @samp{ei} string, eventually, to exit insert mode.  There
2424 is no need to do this right away.  If the @samp{mi} flag is present,
2425 you can move the cursor and the cursor will remain in insert mode;
2426 then you can do more insertion elsewhere without reentering insert
2427 mode.
2428 @end enumerate
2429
2430 Note that this is not the same as the original Unix termcap specifications
2431 in one respect: it assumes that the @samp{IC} string can be used without
2432 entering insert mode.  This is true as far as I know, and it allows you be
2433 able to avoid entering and leaving insert mode, and also to be able to
2434 avoid the inserted-character padding after the characters that go into the
2435 inserted positions.
2436
2437 Deletion of characters is less complicated; deleting one column is done by
2438 outputting the @samp{dc} string.  However, there may be a delete mode that
2439 must be entered with @samp{dm} in order to make @samp{dc} work.
2440
2441 @table @samp
2442 @item dc
2443 @kindex dc
2444 String of commands to delete one character position at the cursor.  If
2445 @samp{dc} is not present, the terminal cannot delete characters.
2446
2447 @item DC
2448 @kindex DC
2449 String of commands to delete @var{n} characters starting at the cursor.
2450 It has the same effect as repeating the @samp{dc} string @var{n} times.
2451 Any terminal description that has @samp{DC} also has @samp{dc}.
2452
2453 @item dm
2454 @kindex dm
2455 String of commands to enter delete mode.  If not present, there is no
2456 delete mode, and @samp{dc} can be used at any time (assuming there is
2457 a @samp{dc}).
2458
2459 @item ed
2460 @kindex ed
2461 String of commands to exit delete mode.  This must be present if
2462 @samp{dm} is.
2463 @end table
2464
2465 To delete @var{n} character positions, position the cursor and follow these
2466 steps:
2467
2468 @enumerate
2469 @item
2470 If the @samp{DC} string is present, output it with parameter @var{n}
2471 and you are finished.  Otherwise, follow the remaining steps.
2472
2473 @item
2474 Output the @samp{dm} string, unless you know the terminal is already
2475 in delete mode.
2476
2477 @item
2478 Output the @samp{dc} string @var{n} times.
2479
2480 @item
2481 Output the @samp{ed} string eventually.  If the flag capability
2482 @samp{mi} is present, you can move the cursor and do more deletion
2483 without leaving and reentering delete mode.
2484 @end enumerate
2485
2486 As with the @samp{IC} string, we have departed from the original termcap
2487 specifications by assuming that @samp{DC} works without entering delete
2488 mode even though @samp{dc} would not.
2489
2490 If the @samp{dm} and @samp{im} capabilities are both present and have the
2491 same value, it means that the terminal has one mode for both insertion and
2492 deletion.  It is useful for a program to know this, because then it can do
2493 insertions after deletions, or vice versa, without leaving insert/delete
2494 mode and reentering it.
2495
2496 @node Standout, Underlining, Insdel Char, Capabilities
2497 @section Standout and Appearance Modes
2498 @cindex appearance modes
2499 @cindex standout
2500 @cindex magic cookie
2501
2502 @dfn{Appearance modes} are modifications to the ways characters are
2503 displayed.  Typical appearance modes include reverse video, dim, bright,
2504 blinking, underlined, invisible, and alternate character set.  Each kind of
2505 terminal supports various among these, or perhaps none.
2506
2507 For each type of terminal, one appearance mode or combination of them that
2508 looks good for highlighted text is chosen as the @dfn{standout mode}.  The
2509 capabilities @samp{so} and @samp{se} say how to enter and leave standout
2510 mode.  Programs that use appearance modes only to highlight some text
2511 generally use the standout mode so that they can work on as many terminals
2512 as possible.  Use of specific appearance modes other than ``underlined''
2513 and ``alternate character set'' is rare.
2514
2515 Terminals that implement appearance modes fall into two general classes as
2516 to how they do it.
2517
2518 In some terminals, the presence or absence of any appearance mode is
2519 recorded separately for each character position.  In these terminals, each
2520 graphic character written is given the appearance modes current at the time
2521 it is written, and keeps those modes until it is erased or overwritten.
2522 There are special commands to turn the appearance modes on or off for
2523 characters to be written in the future.
2524
2525 In other terminals, the change of appearance modes is represented by a
2526 marker that belongs to a certain screen position but affects all following
2527 screen positions until the next marker.  These markers are traditionally
2528 called @dfn{magic cookies}.
2529
2530 The same capabilities (@samp{so}, @samp{se}, @samp{mb} and so on) for
2531 turning appearance modes on and off are used for both magic-cookie
2532 terminals and per-character terminals.  On magic cookie terminals, these
2533 give the commands to write the magic cookies.  On per-character terminals,
2534 they change the current modes that affect future output and erasure.  Some
2535 simple applications can use these commands without knowing whether or not
2536 they work by means of cookies.
2537
2538 However, a program that maintains and updates a display needs to know
2539 whether the terminal uses magic cookies, and exactly what their effect is.
2540 This information comes from the @samp{sg} capability.
2541
2542 The @samp{sg} capability is a numeric capability whose presence indicates
2543 that the terminal uses magic cookies for appearance modes.  Its value is
2544 the number of character positions that a magic cookie occupies.  Usually
2545 the cookie occupies one or more character positions on the screen, and these
2546 character positions are displayed as blank, but in some terminals the
2547 cookie has zero width.
2548
2549 The @samp{sg} capability describes both the magic cookie to turn standout
2550 on and the cookie to turn it off.  This makes the assumption that both
2551 kinds of cookie have the same width on the screen.  If that is not true,
2552 the narrower cookie must be ``widened'' with spaces until it has the same
2553 width as the other.
2554
2555 On some magic cookie terminals, each line always starts with normal
2556 display; in other words, the scope of a magic cookie never extends over
2557 more than one line.  But on other terminals, one magic cookie affects all
2558 the lines below it unless explicitly canceled.  Termcap does not define any
2559 way to distinguish these two ways magic cookies can work.  To be safe, it
2560 is best to put a cookie at the beginning of each line.
2561
2562 On some per-character terminals, standout mode or other appearance modes
2563 may be canceled by moving the cursor.  On others, moving the cursor has no
2564 effect on the state of the appearance modes.  The latter class of terminals
2565 are given the flag capability @samp{ms} (``can move in standout'').  All
2566 programs that might have occasion to move the cursor while appearance modes
2567 are turned on must check for this flag; if it is not present, they should
2568 reset appearance modes to normal before doing cursor motion.
2569
2570 A program that has turned on only standout mode should use @samp{se} to
2571 reset the standout mode to normal.  A program that has turned on only
2572 alternate character set mode should use @samp{ae} to return it to normal.
2573 If it is possible that any other appearance modes are turned on, use the
2574 @samp{me} capability to return them to normal.
2575
2576 Note that the commands to turn on one appearance mode, including @samp{so}
2577 and @samp{mb} @dots{} @samp{mr}, if used while some other appearance modes
2578 are turned on, may combine the two modes on some terminals but may turn off
2579 the mode previously enabled on other terminals.  This is because some
2580 terminals do not have a command to set or clear one appearance mode without
2581 changing the others.  Programs should not attempt to use appearance modes
2582 in combination except with @samp{sa}, and when switching from one single
2583 mode to another should always turn off the previously enabled mode and then
2584 turn on the new desired mode.
2585
2586 On some old terminals, the @samp{so} and @samp{se} commands may be the same
2587 command, which has the effect of turning standout on if it is off, or off
2588 it is on.  It is therefore risky for a program to output extra @samp{se}
2589 commands for good measure.  Fortunately, all these terminals are obsolete.
2590
2591 Programs that update displays in which standout-text may be replaced with
2592 non-standout text must check for the @samp{xs} flag.  In a per-character
2593 terminal, this flag says that the only way to remove standout once written is
2594 to clear that portion of the line with the @samp{ce} string or something
2595 even more powerful (@pxref{Clearing}); just writing new characters at those
2596 screen positions will not change the modes in effect there.  In a magic
2597 cookie terminal, @samp{xs} says that the only way to remove a cookie is to
2598 clear a portion of the line that includes the cookie; writing a different
2599 cookie at the same position does not work.
2600
2601 Such programs must also check for the @samp{xt} flag, which means that the
2602 terminal is a Teleray 1061.  On this terminal it is impossible to position
2603 the cursor at the front of a magic cookie, so the only two ways to remove a
2604 cookie are (1) to delete the line it is on or (2) to position the cursor at
2605 least one character before it (possibly on a previous line) and output the
2606 @samp{se} string, which on these terminals finds and removes the next
2607 @samp{so} magic cookie on the screen.  (It may also be possible to remove a
2608 cookie which is not at the beginning of a line by clearing that line.)  The
2609 @samp{xt} capability also has implications for the use of tab characters,
2610 but in that regard it is obsolete (@xref{Cursor Motion}).
2611
2612 @table @samp
2613 @item so
2614 @kindex so
2615 String of commands to enter standout mode.
2616
2617 @item se
2618 @kindex se
2619 String of commands to leave standout mode.
2620
2621 @item sg
2622 @kindex sg
2623 Numeric capability, the width on the screen of the magic cookie.  This
2624 capability is absent in terminals that record appearance modes
2625 character by character.
2626
2627 @item ms
2628 @kindex ms
2629 Flag whose presence means that it is safe to move the cursor while the
2630 appearance modes are not in the normal state.  If this flag is absent,
2631 programs should always reset the appearance modes to normal before
2632 moving the cursor.
2633
2634 @item xs
2635 @kindex xs
2636 Flag whose presence means that the only way to reset appearance modes
2637 already on the screen is to clear to end of line.  On a per-character
2638 terminal, you must clear the area where the modes are set.  On a magic
2639 cookie terminal, you must clear an area containing the cookie.
2640 See the discussion above.
2641
2642 @item xt
2643 @kindex xt
2644 Flag whose presence means that the cursor cannot be positioned right
2645 in front of a magic cookie, and that @samp{se} is a command to delete
2646 the next magic cookie following the cursor.  See discussion above.
2647
2648 @item mb
2649 @kindex mb
2650 String of commands to enter blinking mode.
2651
2652 @item md
2653 @kindex md
2654 String of commands to enter double-bright mode.
2655
2656 @item mh
2657 @kindex mh
2658 String of commands to enter half-bright mode.
2659
2660 @item mk
2661 @kindex mk
2662 String of commands to enter invisible mode.
2663
2664 @item mp
2665 @kindex mp
2666 String of commands to enter protected mode.
2667
2668 @item mr
2669 @kindex mr
2670 String of commands to enter reverse-video mode.
2671
2672 @item me
2673 @kindex me
2674 String of commands to turn off all appearance modes, including
2675 standout mode and underline mode.  On some terminals it also turns off
2676 alternate character set mode; on others, it may not.  This capability
2677 must be present if any of @samp{mb} @dots{} @samp{mr} is present.
2678
2679 @item as
2680 @kindex as
2681 String of commands to turn on alternate character set mode.  This mode
2682 assigns some or all graphic characters an alternate picture on the
2683 screen.  There is no standard as to what the alternate pictures look
2684 like.
2685
2686 @item ae
2687 @kindex ae
2688 String of commands to turn off alternate character set mode.
2689
2690 @item sa
2691 @kindex sa
2692 String of commands to turn on an arbitrary combination of appearance
2693 modes.  It accepts 9 parameters, each of which controls a particular
2694 kind of appearance mode.  A parameter should be 1 to turn its appearance
2695 mode on, or zero to turn that mode off.  Most terminals do not support
2696 the @samp{sa} capability, even among those that do have various
2697 appearance modes.
2698
2699 The nine parameters are, in order, @var{standout}, @var{underline},
2700 @var{reverse}, @var{blink}, @var{half-bright}, @var{double-bright},
2701 @var{blank}, @var{protect}, @var{alt char set}.
2702 @end table
2703
2704 @node Underlining, Cursor Visibility, Standout, Capabilities
2705 @section Underlining
2706 @cindex underlining
2707
2708 Underlining on most terminals is a kind of appearance mode, much like
2709 standout mode.  Therefore, it may be implemented using magic cookies or as
2710 a flag in the terminal whose current state affects each character that is
2711 output.  @xref{Standout}, for a full explanation.
2712
2713 The @samp{ug} capability is a numeric capability whose presence indicates
2714 that the terminal uses magic cookies for underlining.  Its value is the
2715 number of character positions that a magic cookie for underlining occupies;
2716 it is used for underlining just as @samp{sg} is used for standout.  Aside
2717 from the simplest applications, it is impossible to use underlining
2718 correctly without paying attention to the value of @samp{ug}.
2719
2720 @table @samp
2721 @item us
2722 @kindex us
2723 String of commands to turn on underline mode or to output a magic cookie
2724 to start underlining.
2725
2726 @item ue
2727 @kindex ue
2728 String of commands to turn off underline mode or to output a magic
2729 cookie to stop underlining.
2730
2731 @item ug
2732 @kindex ug
2733 Width of magic cookie that represents a change of underline mode;
2734 or missing, if the terminal does not use a magic cookie for this.
2735
2736 @item ms
2737 @kindex ms
2738 Flag whose presence means that it is safe to move the cursor while the
2739 appearance modes are not in the normal state.  Underlining is an
2740 appearance mode.  If this flag is absent, programs should always turn
2741 off underlining before moving the cursor.
2742 @end table
2743
2744 There are two other, older ways of doing underlining: there can be a
2745 command to underline a single character, or the output of @samp{_}, the
2746 ASCII underscore character, as an overstrike could cause a character to be
2747 underlined.  New programs need not bother to handle these capabilities
2748 unless the author cares strongly about the obscure terminals which support
2749 them.  However, terminal descriptions should provide these capabilities
2750 when appropriate.
2751
2752 @table @samp
2753 @item uc
2754 @kindex uc
2755 String of commands to underline the character under the cursor, and
2756 move the cursor right.
2757
2758 @item ul
2759 @kindex ul
2760 Flag whose presence means that the terminal can underline by
2761 overstriking an underscore character (@samp{_}); some terminals can do
2762 this even though they do not support overstriking in general.  An
2763 implication of this flag is that when outputting new text to overwrite
2764 old text, underscore characters must be treated specially lest they
2765 underline the old text instead.
2766 @end table
2767
2768 @node Cursor Visibility, Bell, Underlining, Capabilities
2769 @section Cursor Visibility
2770 @cindex visibility
2771
2772 Some terminals have the ability to make the cursor invisible, or to enhance
2773 it.  Enhancing the cursor is often done by programs that plan to use the
2774 cursor to indicate to the user a position of interest that may be anywhere
2775 on the screen---for example, the Emacs editor enhances the cursor on entry.
2776 Such programs should always restore the cursor to normal on exit.
2777
2778 @table @samp
2779 @item vs
2780 @kindex vs
2781 String of commands to enhance the cursor.
2782
2783 @item vi
2784 @kindex vi
2785 String of commands to make the cursor invisible.
2786
2787 @item ve
2788 @kindex ve
2789 String of commands to return the cursor to normal.
2790 @end table
2791
2792 If you define either @samp{vs} or @samp{vi}, you must also define @samp{ve}.
2793
2794 @node Bell, Keypad, Cursor Visibility, Capabilities
2795 @section Bell
2796 @cindex bell
2797 @cindex visible bell
2798
2799 Here we describe commands to make the terminal ask for the user to pay
2800 attention to it.
2801
2802 @table @samp
2803 @item bl
2804 @kindex bl
2805 String of commands to cause the terminal to make an audible sound.  If
2806 this capability is absent, the terminal has no way to make a suitable
2807 sound.
2808
2809 @item vb
2810 @kindex vb
2811 String of commands to cause the screen to flash to attract attention
2812 (``visible bell'').  If this capability is absent, the terminal has no
2813 way to do such a thing.
2814 @end table
2815
2816 @node Keypad, Meta Key, Bell, Capabilities
2817 @section Keypad and Function Keys
2818
2819 Many terminals have arrow and function keys that transmit specific
2820 character sequences to the computer.  Since the precise sequences used
2821 depend on the terminal, termcap defines capabilities used to say what the
2822 sequences are.  Unlike most termcap string-valued capabilities, these are
2823 not strings of commands to be sent to the terminal, rather strings that
2824 are received from the terminal.
2825
2826 Programs that expect to use keypad keys should check, initially, for a
2827 @samp{ks} capability and send it, to make the keypad actually transmit.
2828 Such programs should also send the @samp{ke} string when exiting.
2829
2830 @table @asis
2831 @item @samp{ks}
2832 @kindex ka@dots{}ku
2833 String of commands to make the function keys transmit.  If this
2834 capability is not provided, but the others in this section are,
2835 programs may assume that the function keys always transmit.
2836
2837 @item @samp{ke}
2838 String of commands to make the function keys work locally.  This
2839 capability is provided only if @samp{ks} is.
2840
2841 @item @samp{kl}
2842 String of input characters sent by typing the left-arrow key.  If this
2843 capability is missing, you cannot expect the terminal to have a
2844 left-arrow key that transmits anything to the computer.
2845
2846 @item @samp{kr}
2847 String of input characters sent by typing the right-arrow key.
2848
2849 @item @samp{ku}
2850 String of input characters sent by typing the up-arrow key.
2851
2852 @item @samp{kd}
2853 String of input characters sent by typing the down-arrow key.
2854
2855 @item @samp{kh}
2856 String of input characters sent by typing the ``home-position'' key.
2857
2858 @item @samp{K1} @dots{} @samp{K5}
2859 @kindex K1@dots{}K5
2860 Strings of input characters sent by the five other keys in a 3-by-3
2861 array that includes the arrow keys, if the keyboard has such a 3-by-3
2862 array.  Note that one of these keys may be the ``home-position'' key,
2863 in which case one of these capabilities will have the same value as
2864 the @samp{kh} key.
2865
2866 @item @samp{k0}
2867 String of input characters sent by function key 10 (or 0, if the terminal
2868 has one labeled 0).
2869
2870 @item @samp{k1} @dots{} @samp{k9}
2871 @kindex k1@dots{}k9
2872 Strings of input characters sent by function keys 1 through 9,
2873 provided for those function keys that exist.
2874
2875 @item @samp{kn}
2876 Number: the number of numbered function keys, if there are more than
2877 10.
2878
2879 @item @samp{l0} @dots{} @samp{l9}
2880 @kindex l0@dots{}l9
2881 Strings which are the labels appearing on the keyboard on the keys
2882 described by the capabilities @samp{k0} @dots{} @samp{l9}.  These
2883 capabilities should be left undefined if the labels are @samp{f0} or
2884 @samp{f10} and @samp{f1} @dots{} @samp{f9}.@refill
2885
2886 @item @samp{kH}
2887 @kindex kA@dots{}kT
2888 String of input characters sent by the ``home down'' key, if there is
2889 one.
2890
2891 @item @samp{kb}
2892 String of input characters sent by the ``backspace'' key, if there is
2893 one.
2894
2895 @item @samp{ka}
2896 String of input characters sent by the ``clear all tabs'' key, if there
2897 is one.
2898
2899 @item @samp{kt}
2900 String of input characters sent by the ``clear tab stop this column''
2901 key, if there is one.
2902
2903 @item @samp{kC}
2904 String of input characters sent by the ``clear screen'' key, if there is
2905 one.
2906
2907 @item @samp{kD}
2908 String of input characters sent by the ``delete character'' key, if
2909 there is one.
2910
2911 @item @samp{kL}
2912 String of input characters sent by the ``delete line'' key, if there is
2913 one.
2914
2915 @item @samp{kM}
2916 String of input characters sent by the ``exit insert mode'' key, if
2917 there is one.
2918
2919 @item @samp{kE}
2920 String of input characters sent by the ``clear to end of line'' key, if
2921 there is one.
2922
2923 @item @samp{kS}
2924 String of input characters sent by the ``clear to end of screen'' key,
2925 if there is one.
2926
2927 @item @samp{kI}
2928 String of input characters sent by the ``insert character'' or ``enter
2929 insert mode'' key, if there is one.
2930
2931 @item @samp{kA}
2932 String of input characters sent by the ``insert line'' key, if there is
2933 one.
2934
2935 @item @samp{kN}
2936 String of input characters sent by the ``next page'' key, if there is
2937 one.
2938
2939 @item @samp{kP}
2940 String of input characters sent by the ``previous page'' key, if there is
2941 one.
2942
2943 @item @samp{kF}
2944 String of input characters sent by the ``scroll forward'' key, if there
2945 is one.
2946
2947 @item @samp{kR}
2948 String of input characters sent by the ``scroll reverse'' key, if there
2949 is one.
2950
2951 @item @samp{kT}
2952 String of input characters sent by the ``set tab stop in this column''
2953 key, if there is one.
2954
2955 @item @samp{ko}
2956 String listing the other function keys the terminal has.  This is a
2957 very obsolete way of describing the same information found in the
2958 @samp{kH} @dots{} @samp{kT} keys.  The string contains a list of
2959 two-character termcap capability names, separated by commas.  The
2960 meaning is that for each capability name listed, the terminal has a
2961 key which sends the string which is the value of that capability.  For
2962 example, the value @samp{:ko=cl,ll,sf,sr:} says that the terminal has
2963 four function keys which mean ``clear screen'', ``home down'',
2964 ``scroll forward'' and ``scroll reverse''.@refill
2965 @end table
2966
2967 @node Meta Key, Initialization, Keypad, Capabilities
2968 @section Meta Key
2969
2970 @cindex meta key
2971 A Meta key is a key on the keyboard that modifies each character you type
2972 by controlling the 0200 bit.  This bit is on if and only if the Meta key is
2973 held down when the character is typed.  Characters typed using the Meta key
2974 are called Meta characters.  Emacs uses Meta characters as editing
2975 commands.
2976
2977 @table @samp
2978 @item km
2979 @kindex km
2980 Flag whose presence means that the terminal has a Meta key.
2981
2982 @item mm
2983 @kindex mm
2984 String of commands to enable the functioning of the Meta key.
2985
2986 @item mo
2987 @kindex mo
2988 String of commands to disable the functioning of the Meta key.
2989 @end table
2990
2991 If the terminal has @samp{km} but does not have @samp{mm} and @samp{mo}, it
2992 means that the Meta key always functions.  If it has @samp{mm} and
2993 @samp{mo}, it means that the Meta key can be turned on or off.  Send the
2994 @samp{mm} string to turn it on, and the @samp{mo} string to turn it off.
2995 I do not know why one would ever not want it to be on.
2996
2997 @node Initialization, Pad Specs, Meta Key, Capabilities
2998 @section Initialization
2999 @cindex reset
3000 @cindex initialization
3001 @cindex tab stops
3002
3003 @table @samp
3004 @item ti
3005 @kindex ti
3006 String of commands to put the terminal into whatever special modes are
3007 needed or appropriate for programs that move the cursor
3008 nonsequentially around the screen.  Programs that use termcap to do
3009 full-screen display should output this string when they start up.
3010
3011 @item te
3012 @kindex te
3013 String of commands to undo what is done by the @samp{ti} string.
3014 Programs that output the @samp{ti} string on entry should output this
3015 string when they exit.
3016
3017 @item is
3018 @kindex is
3019 String of commands to initialize the terminal for each login session.
3020
3021 @item if
3022 @kindex if
3023 String which is the name of a file containing the string of commands
3024 to initialize the terminal for each session of use.  Normally @samp{is}
3025 and @samp{if} are not both used.
3026
3027 @item i1
3028 @itemx i3
3029 @kindex i1
3030 @kindex i3
3031 Two more strings of commands to initialize the terminal for each login
3032 session.  The @samp{i1} string (if defined) is output before @samp{is}
3033 or @samp{if}, and the @samp{i3} string (if defined) is output after.
3034
3035 The reason for having three separate initialization strings is to make
3036 it easier to define a group of related terminal types with slightly
3037 different initializations.  Define two or three of the strings in the
3038 basic type; then the other types can override one or two of the
3039 strings.
3040
3041 @item rs
3042 @kindex rs
3043 String of commands to reset the terminal from any strange mode it may
3044 be in.  Normally this includes the @samp{is} string (or other commands
3045 with the same effects) and more.  What would go in the @samp{rs}
3046 string but not in the @samp{is} string are annoying or slow commands
3047 to bring the terminal back from strange modes that nobody would
3048 normally use.
3049
3050 @item it
3051 @kindex it
3052 Numeric value, the initial spacing between hardware tab stop columns
3053 when the terminal is powered up.  Programs to initialize the terminal
3054 can use this to decide whether there is a need to set the tab stops.
3055 If the initial width is 8, well and good; if it is not 8, then the
3056 tab stops should be set; if they cannot be set, the kernel is told
3057 to convert tabs to spaces, and other programs will observe this and do
3058 likewise.
3059
3060 @item ct
3061 @kindex ct
3062 String of commands to clear all tab stops.
3063
3064 @item st
3065 @kindex st
3066 String of commands to set tab stop at current cursor column on all
3067 lines.
3068 @end table
3069
3070 @node Pad Specs, Status Line, Initialization, Capabilities
3071 @section Padding Capabilities
3072 @cindex padding
3073
3074 There are two terminal capabilities that exist just to explain the proper
3075 way to obey the padding specifications in all the command string
3076 capabilities.  One, @samp{pc}, must be obeyed by all termcap-using
3077 programs.
3078
3079 @table @samp
3080 @item pb
3081 @kindex pb
3082 Numeric value, the lowest baud rate at which padding is actually
3083 needed.  Programs may check this and refrain from doing any padding at
3084 lower speeds.
3085
3086 @item pc
3087 @kindex pc
3088 String of commands for padding.  The first character of this string is
3089 to be used as the pad character, instead of using null characters for
3090 padding.  If @samp{pc} is not provided, use null characters.  Every
3091 program that uses termcap must look up this capability and use it to
3092 set the variable @code{PC} that is used by @code{tputs}.
3093 @xref{Padding}.
3094 @end table
3095
3096 Some termcap capabilities exist just to specify the amount of padding that
3097 the kernel should give to cursor motion commands used in ordinary
3098 sequential output.
3099
3100 @table @samp
3101 @item dC
3102 @kindex dC
3103 Numeric value, the number of msec of padding needed for the
3104 carriage-return character.
3105
3106 @item dN
3107 @kindex dN
3108 Numeric value, the number of msec of padding needed for the newline
3109 (linefeed) character.
3110
3111 @item dB
3112 @kindex dB
3113 Numeric value, the number of msec of padding needed for the backspace
3114 character.
3115
3116 @item dF
3117 @kindex dF
3118 Numeric value, the number of msec of padding needed for the formfeed
3119 character.
3120
3121 @item dT
3122 @kindex dT
3123 Numeric value, the number of msec of padding needed for the tab
3124 character.
3125 @end table
3126
3127 In some systems, the kernel uses the above capabilities; in other systems,
3128 the kernel uses the paddings specified in the string capabilities
3129 @samp{cr}, @samp{sf}, @samp{le}, @samp{ff} and @samp{ta}.  Descriptions of
3130 terminals which require such padding should contain the @samp{dC} @dots{}
3131 @samp{dT} capabilities and also specify the appropriate padding in the
3132 corresponding string capabilities.  Since no modern terminals require
3133 padding for ordinary sequential output, you probably won't need to do
3134 either of these things.
3135
3136 @node Status Line, Half-Line, Pad Specs, Capabilities
3137 @section Status Line
3138
3139 @cindex status line
3140 A @dfn{status line} is a line on the terminal that is not used for ordinary
3141 display output but instead used for a special message.  The intended use is
3142 for a continuously updated description of what the user's program is doing,
3143 and that is where the name ``status line'' comes from, but in fact it could
3144 be used for anything.  The distinguishing characteristic of a status line
3145 is that ordinary output to the terminal does not affect it; it changes only
3146 if the special status line commands of this section are used.
3147
3148 @table @samp
3149 @item hs
3150 @kindex hs
3151 Flag whose presence means that the terminal has a status line.  If a
3152 terminal description specifies that there is a status line, it must
3153 provide the @samp{ts} and @samp{fs} capabilities.
3154
3155 @item ts
3156 @kindex ts
3157 String of commands to move the terminal cursor into the status line.
3158 Usually these commands must specifically record the old cursor
3159 position for the sake of the @samp{fs} string.
3160
3161 @item fs
3162 @kindex fs
3163 String of commands to move the cursor back from the status line to its
3164 previous position (outside the status line).
3165
3166 @item es
3167 @kindex es
3168 Flag whose presence means that other display commands work while
3169 writing the status line.  In other words, one can clear parts of it,
3170 insert or delete characters, move the cursor within it using @samp{ch}
3171 if there is a @samp{ch} capability, enter and leave standout mode, and
3172 so on.
3173
3174 @item ds
3175 @kindex ds
3176 String of commands to disable the display of the status line.  This
3177 may be absent, if there is no way to disable the status line display.
3178
3179 @item ws
3180 @kindex ws
3181 Numeric value, the width of the status line.  If this capability is
3182 absent in a terminal that has a status line, it means the status line
3183 is the same width as the other lines.
3184
3185 Note that the value of @samp{ws} is sometimes as small as 8.
3186 @end table
3187
3188 @node Half-Line, Printer, Status Line, Capabilities
3189 @section Half-Line Motion
3190
3191 Some terminals have commands for moving the cursor vertically by half-lines,
3192 useful for outputting subscripts and superscripts.  Mostly it is hardcopy
3193 terminals that have such features.
3194
3195 @table @samp
3196 @item hu
3197 @kindex hu
3198 String of commands to move the cursor up half a line.  If the terminal
3199 is a display, it is your responsibility to avoid moving up past the
3200 top line; however, most likely the terminal that supports this is a
3201 hardcopy terminal and there is nothing to be concerned about.
3202
3203 @item hd
3204 @kindex hd
3205 String of commands to move the cursor down half a line.  If the
3206 terminal is a display, it is your responsibility to avoid moving down
3207 past the bottom line, etc.
3208 @end table
3209
3210 @node Printer,  , Half-Line, Capabilities
3211 @section Controlling Printers Attached to Terminals
3212 @cindex printer
3213
3214 Some terminals have attached hardcopy printer ports.  They may be able to
3215 copy the screen contents to the printer; they may also be able to redirect
3216 output to the printer.  Termcap does not have anything to tell the program
3217 whether the redirected output appears also on the screen; it does on some
3218 terminals but not all.
3219
3220 @table @samp
3221 @item ps
3222 @kindex ps
3223 String of commands to cause the contents of the screen to be printed.
3224 If it is absent, the screen contents cannot be printed.
3225
3226 @item po
3227 @kindex po
3228 String of commands to redirect further output to the printer.
3229
3230 @item pf
3231 @kindex pf
3232 String of commands to terminate redirection of output to the printer.
3233 This capability must be present in the description if @samp{po} is.
3234
3235 @item pO
3236 @kindex pO
3237 String of commands to redirect output to the printer for next @var{n}
3238 characters of output, regardless of what they are.  Redirection will
3239 end automatically after @var{n} characters of further output.  Until
3240 then, nothing that is output can end redirection, not even the
3241 @samp{pf} string if there is one.  The number @var{n} should not be
3242 more than 255.
3243
3244 One use of this capability is to send non-text byte sequences (such as
3245 bit-maps) to the printer.
3246 @end table
3247
3248 Most terminals with printers do not support all of @samp{ps}, @samp{po} and
3249 @samp{pO}; any one or two of them may be supported.  To make a program that
3250 can send output to all kinds of printers, it is necessary to check for all
3251 three of these capabilities, choose the most convenient of the ones that
3252 are provided, and use it in its own appropriate fashion.
3253
3254 @node Summary, Var Index, Capabilities, Top
3255 @chapter Summary of Capability Names
3256
3257 Here are all the terminal capability names in alphabetical order
3258 with a brief description of each.  For cross references to their definitions,
3259 see the index of capability names (@pxref{Cap Index}).
3260
3261 @table @samp
3262 @item ae
3263 String to turn off alternate character set mode.
3264 @item al
3265 String to insert a blank line before the cursor.
3266 @item AL
3267 String to insert @var{n} blank lines before the cursor.
3268 @item am
3269 Flag: output to last column wraps cursor to next line.
3270 @item as
3271 String to turn on alternate character set mode.like.
3272 @item bc
3273 Very obsolete alternative name for the @samp{le} capability.
3274 @item bl
3275 String to sound the bell.
3276 @item bs
3277 Obsolete flag: ASCII backspace may be used for leftward motion.
3278 @item bt
3279 String to move the cursor left to the previous hardware tab stop column.
3280 @item bw
3281 Flag: @samp{le} at left margin wraps to end of previous line.
3282 @item CC
3283 String to change terminal's command character.
3284 @item cd
3285 String to clear the line the cursor is on, and following lines.
3286 @item ce
3287 String to clear from the cursor to the end of the line.
3288 @item ch
3289 String to position the cursor at column @var{c} in the same line.
3290 @item cl
3291 String to clear the entire screen and put cursor at upper left corner.
3292 @item cm
3293 String to position the cursor at line @var{l}, column @var{c}.
3294 @item CM
3295 String to position the cursor at line @var{l}, column
3296 @var{c}, relative to display memory.
3297 @item co
3298 Number: width of the screen.
3299 @item cr
3300 String to move cursor sideways to left margin.
3301 @item cs
3302 String to set the scroll region.
3303 @item cS
3304 Alternate form of string to set the scroll region.
3305 @item ct
3306 String to clear all tab stops.
3307 @item cv
3308 String to position the cursor at line @var{l} in the same column.
3309 @item da
3310 Flag: data scrolled off top of screen may be scrolled back.
3311 @item db
3312 Flag: data scrolled off bottom of screen may be scrolled back.
3313 @item dB
3314 Obsolete number: msec of padding needed for the backspace character.
3315 @item dc
3316 String to delete one character position at the cursor.
3317 @item dC
3318 Obsolete number: msec of padding needed for the carriage-return character.
3319 @item DC
3320 String to delete @var{n} characters starting at the cursor.
3321 @item dF
3322 Obsolete number: msec of padding needed for the formfeed character.
3323 @item dl
3324 String to delete the line the cursor is on.
3325 @item DL
3326 String to delete @var{n} lines starting with the cursor's line.
3327 @item dm
3328 String to enter delete mode.
3329 @item dN
3330 Obsolete number: msec of padding needed for the newline character.
3331 @item do
3332 String to move the cursor vertically down one line.
3333 @item DO
3334 String to move cursor vertically down @var{n} lines.
3335 @item ds
3336 String to disable the display of the status line.
3337 @item dT
3338 Obsolete number: msec of padding needed for the tab character.
3339 @item ec
3340 String of commands to clear @var{n} characters at cursor.
3341 @item ed
3342 String to exit delete mode.
3343 @item ei
3344 String to leave insert mode.
3345 @item eo
3346 Flag: output of a space can erase an overstrike.
3347 @item es
3348 Flag: other display commands work while writing the status line.
3349 @item ff
3350 String to advance to the next page, for a hardcopy terminal.
3351 @item fs
3352 String to move the cursor back from the status line to its
3353 previous position (outside the status line).
3354 @item gn
3355 Flag: this terminal type is generic, not real.
3356 @item hc
3357 Flag: hardcopy terminal.
3358 @item hd
3359 String to move the cursor down half a line.
3360 @item ho
3361 String to position cursor at upper left corner.
3362 @item hs
3363 Flag: the terminal has a status line.
3364 @item hu
3365 String to move the cursor up half a line.
3366 @item hz
3367 Flag: terminal cannot accept @samp{~} as output.
3368 @item i1
3369 String to initialize the terminal for each login session.
3370 @item i3
3371 String to initialize the terminal for each login session.
3372 @item ic
3373 String to insert one character position at the cursor.
3374 @item IC
3375 String to insert @var{n} character positions at the cursor.
3376 @item if
3377 String naming a file of commands to initialize the terminal.
3378 @item im
3379 String to enter insert mode.
3380 @item in
3381 Flag: outputting a space is different from moving over empty positions.
3382 @item ip
3383 String to output following an inserted character in insert mode.
3384 @item is
3385 String to initialize the terminal for each login session.
3386 @item it
3387 Number: initial spacing between hardware tab stop columns.
3388 @item k0
3389 String of input sent by function key 0 or 10.
3390 @item k1 @dots{} k9
3391 Strings of input sent by function keys 1 through 9.
3392 @item K1 @dots{} K5
3393 Strings sent by the five other keys in 3-by-3 array with arrows.
3394 @item ka
3395 String of input sent by the ``clear all tabs'' key.
3396 @item kA
3397 String of input sent by the ``insert line'' key.
3398 @item kb
3399 String of input sent by the ``backspace'' key.
3400 @item kC
3401 String of input sent by the ``clear screen'' key.
3402 @item kd
3403 String of input sent by typing the down-arrow key.
3404 @item kD
3405 String of input sent by the ``delete character'' key.
3406 @item ke
3407 String to make the function keys work locally.
3408 @item kE
3409 String of input sent by the ``clear to end of line'' key.
3410 @item kF
3411 String of input sent by the ``scroll forward'' key.
3412 @item kh
3413 String of input sent by typing the ``home-position'' key.
3414 @item kH
3415 String of input sent by the ``home down'' key.
3416 @item kI
3417 String of input sent by the ``insert character'' or ``enter
3418 insert mode'' key.
3419 @item kl
3420 String of input sent by typing the left-arrow key.
3421 @item kL
3422 String of input sent by the ``delete line'' key.
3423 @item km
3424 Flag: the terminal has a Meta key.
3425 @item kM
3426 String of input sent by the ``exit insert mode'' key.
3427 @item kn
3428 Numeric value, the number of numbered function keys.
3429 @item kN
3430 String of input sent by the ``next page'' key.
3431 @item ko
3432 Very obsolete string listing the terminal's named function keys.
3433 @item kP
3434 String of input sent by the ``previous page'' key.
3435 @item kr
3436 String of input sent by typing the right-arrow key.
3437 @item kR
3438 String of input sent by the ``scroll reverse'' key.
3439 @item ks
3440 String to make the function keys transmit.
3441 @item kS
3442 String of input sent by the ``clear to end of screen'' key.
3443 @item kt
3444 String of input sent by the ``clear tab stop this column'' key.
3445 @item kT
3446 String of input sent by the ``set tab stop in this column'' key.
3447 @item ku
3448 String of input sent by typing the up-arrow key.
3449 @item l0
3450 String on keyboard labelling function key 0 or 10.
3451 @item l1 @dots{} l9
3452 Strings on keyboard labelling function keys 1 through 9.
3453 @item le
3454 String to move the cursor left one column.
3455 @item LE
3456 String to move cursor left @var{n} columns.
3457 @item li
3458 Number: height of the screen.
3459 @item ll
3460 String to position cursor at lower left corner.
3461 @item lm
3462 Number: lines of display memory.
3463 @item mb
3464 String to enter blinking mode.
3465 @item md
3466 String to enter double-bright mode.
3467 @item me
3468 String to turn off all appearance modes
3469 @item mh
3470 String to enter half-bright mode.
3471 @item mi
3472 Flag: cursor motion in insert mode is safe.
3473 @item mk
3474 String to enter invisible mode.
3475 @item mm
3476 String to enable the functioning of the Meta key.
3477 @item mo
3478 String to disable the functioning of the Meta key.
3479 @item mp
3480 String to enter protected mode.
3481 @item mr
3482 String to enter reverse-video mode.
3483 @item ms
3484 Flag: cursor motion in standout mode is safe.
3485 @item nc
3486 Obsolete flag: do not use ASCII carriage-return on this terminal.
3487 @item nd
3488 String to move the cursor right one column.
3489 @item nl
3490 Obsolete alternative name for the @samp{do} and @samp{sf} capabilities.
3491 @item ns
3492 Flag: the terminal does not normally scroll for sequential output.
3493 @item nw
3494 String to move to start of next line, possibly clearing rest of old line.
3495 @item os
3496 Flag: terminal can overstrike.
3497 @item pb
3498 Number: the lowest baud rate at which padding is actually needed.
3499 @item pc
3500 String containing character for padding.
3501 @item pf
3502 String to terminate redirection of output to the printer.
3503 @item po
3504 String to redirect further output to the printer.
3505 @item pO
3506 String to redirect @var{n} characters ofoutput to the printer.
3507 @item ps
3508 String to print the screen on the attached printer.
3509 @item rc
3510 String to move to last saved cursor position.
3511 @item RI
3512 String to move cursor right @var{n} columns.
3513 @item rp
3514 String to output character @var{c} repeated @var{n} times.
3515 @item rs
3516 String to reset the terminal from any strange modes.
3517 @item sa
3518 String to turn on an arbitrary combination of appearance modes.
3519 @item sc
3520 String to save the current cursor position.
3521 @item se
3522 String to leave standout mode.
3523 @item sf
3524 String to scroll the screen one line up.
3525 @item SF
3526 String to scroll the screen @var{n} lines up.
3527 @item sg
3528 Number: width of magic standout cookie.  Absent if magic cookies are
3529 not used.
3530 @item so
3531 String to enter standout mode.
3532 @item sr
3533 String to scroll the screen one line down.
3534 @item SR
3535 String to scroll the screen @var{n} line down.
3536 @item st
3537 String to set tab stop at current cursor column on all lines.
3538 programs.
3539 @item ta
3540 String to move the cursor right to the next hardware tab stop column.
3541 @item te
3542 String to return terminal to settings for sequential output.
3543 @item ti
3544 String to initialize terminal for random cursor motion.
3545 @item ts
3546 String to move the terminal cursor into the status line.
3547 @item uc
3548 String to underline one character and move cursor right.
3549 @item ue
3550 String to turn off underline mode
3551 @item ug
3552 Number: width of underlining magic cookie.  Absent if underlining
3553 doesn't use magic cookies.
3554 @item ul
3555 Flag: underline by overstriking with an underscore.
3556 @item up
3557 String to move the cursor vertically up one line.
3558 @item UP
3559 String to move cursor vertically up @var{n} lines.
3560 @item us
3561 String to turn on underline mode
3562 @item vb
3563 String to make the screen flash.
3564 @item ve
3565 String to return the cursor to normal.
3566 @item vi
3567 String to make the cursor invisible.
3568 @item vs
3569 String to enhance the cursor.
3570 @item wi
3571 String to set the terminal output screen window.
3572 @item ws
3573 Number: the width of the status line.
3574 @item xb
3575 Flag: superbee terminal.
3576 @item xn
3577 Flag: cursor wraps in a strange way.
3578 @item xs
3579 Flag: clearing a line is the only way to clear the appearance modes of
3580 positions in that line (or, only way to remove magic cookies on that
3581 line).
3582 @item xt
3583 Flag: Teleray 1061; several strange characteristics.
3584 @end table
3585
3586 @node Var Index, Cap Index, Summary, Top
3587 @unnumbered Variable and Function Index
3588
3589 @printindex fn
3590
3591 @node Cap Index, Index, Var Index, Top
3592 @unnumbered Capability Index
3593
3594 @printindex ky
3595
3596 @node Index,  , Cap Index, Top
3597 @unnumbered Concept Index
3598
3599 @printindex cp
3600
3601 @contents
3602 @bye
3603