1.\" $NetBSD: tset.1,v 1.11 2002/02/08 01:36:36 ross Exp $ 2.\" 3.\" Copyright (c) 1985, 1990, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)tset.1 8.1 (Berkeley) 6/9/93 35.\" 36.Dd June 9, 1993 37.Dt TSET 1 38.Os 39.Sh NAME 40.Nm tset , 41.Nm reset 42.Nd terminal initialization 43.Sh SYNOPSIS 44.Nm 45.Op Fl EIQrSs 46.Op Fl 47.Op Fl e Ar ch 48.Op Fl i Ar ch 49.Op Fl k Ar ch 50.Op Fl m Ar mapping 51.Op Ar terminal 52.br 53.Nm reset 54.Op Fl EIQrSs 55.Op Fl 56.Op Fl e Ar ch 57.Op Fl i Ar ch 58.Op Fl k Ar ch 59.Op Fl m Ar mapping 60.Op Ar terminal 61.Sh DESCRIPTION 62.Nm 63initializes terminals. 64.Nm 65first determines the type of terminal that you are using. 66This determination is done as follows, using the first terminal type found. 67.sp 68.Bl -bullet -compact -offset indent 69.It 70The 71.Ar terminal 72argument specified on the command line. 73.It 74The value of the 75.Ev TERM 76environmental variable. 77.It 78The terminal type associated with the standard error output device in the 79.Pa /etc/ttys 80file. 81.It 82The default terminal type, 83.Dq unknown . 84.El 85.Pp 86If the terminal type was not specified on the command-line, the 87.Fl m 88option mappings are then applied (see below for more information). 89Then, if the terminal type begins with a question mark (``?''), the user is 90prompted for confirmation of the terminal type. 91An empty response confirms the type, or, another type can be entered to 92specify a new type. 93Once the terminal type has been determined, the termcap entry for the terminal 94is retrieved. 95If no termcap entry is found for the type, the user is prompted for another 96terminal type. 97.Pp 98Once the termcap entry is retrieved, the window size, backspace, interrupt 99and line kill characters (among many other things) are set and the terminal 100and tab initialization strings are sent to the standard error output. 101Finally, if the erase, interrupt and line kill characters have changed, 102or are not set to their default values, their values are displayed to the 103standard error output. 104.Pp 105When invoked as 106.Nm reset , 107.Nm 108sets cooked and echo modes, turns off cbreak and raw modes, turns on 109newline translation and resets any unset special characters to their 110default values before doing the terminal initialization described above. 111This is useful after a program dies leaving a terminal in a abnormal state. 112Note, you may have to type 113.Dq Li \*[Lt]LF\*[Gt]reset\*[Lt]LF\*[Gt] 114(the line-feed character is normally control-J) to get the terminal 115to work, as carriage-return may no longer work in the abnormal state. 116Also, the terminal will often not echo the command. 117.Pp 118The options are as follows: 119.Bl -tag -width flag 120.It Fl 121The terminal type is displayed to the standard output, and the terminal is 122not initialized in any way. 123.It Fl e 124Set the erase character to 125.Ar ch . 126.It Fl E 127Emit the extended termcap entry. By default the termcap entry is 128truncated to 1024 bytes, this flag specifies the untruncated termcap 129entry is to be output. Using this flag may cause problems with some 130shells. 131.It Fl I 132Do not send the terminal or tab initialization strings to the terminal. 133.It Fl i 134Set the interrupt character to 135.Ar ch . 136.It Fl k 137Set the line kill character to 138.Ar ch . 139.It Fl m 140Specify a mapping from a port type to a terminal. 141See below for more information. 142.It Fl Q 143Don't display any values for the erase, interrupt and line kill characters. 144.It Fl r 145Print the terminal type to the standard error output. 146.It Fl S 147Print the terminal type and the termcap entry to the standard output. 148See the section below on setting the environment for details. 149.It Fl s 150Print the sequence of shell commands to initialize the environment variables 151.Ev TERM 152and 153.Ev TERMCAP 154to the standard output. 155See the section below on setting the environment for details. 156.El 157.Pp 158The arguments for the 159.Fl e , 160.Fl i 161and 162.Fl k 163options may either be entered as actual characters or by using the 164.Dq hat 165notation, i.e. control-h may be specified as 166.Dq Li ^H 167or 168.Dq Li ^h . 169.Sh SETTING THE ENVIRONMENT 170It is often desirable to enter the terminal type and information about 171the terminal's capabilities into the shell's environment. 172This is done using the 173.Fl S 174and 175.Fl s 176options. 177.Pp 178When the 179.Fl S 180option is specified, the terminal type and the termcap entry are written 181to the standard output, separated by a space and without a terminating 182newline. 183This can be assigned to an array by 184.Xr csh 1 185and 186.Xr ksh 1 187users and then used like any other shell array. 188.Pp 189When the 190.Fl s 191option is specified, the commands to enter the information into the 192shell's environment are written to the standard output. 193If the 194.Ev SHELL 195environmental variable ends in 196.Dq csh , 197the commands are for the 198.Xr csh 1 , 199otherwise, they are for 200.Xr sh 1 . 201Note, the 202.Xr csh 1 203commands 204.Ic set 205and 206.Ic unset 207the shell variable 208.Dq noglob , 209leaving it unset. 210The following line in the 211.Pa .login 212or 213.Pa .profile 214files will initialize the environment correctly: 215.Bd -literal -offset indent 216eval \`tset -s options ... \` 217.Ed 218.Pp 219To demonstrate a simple use of the 220.Fl S 221option, the following lines in the 222.Pa .login 223file have an equivalent effect: 224.Bd -literal -offset indent 225set noglob 226set term=(`tset -S options ...`) 227setenv TERM $term[1] 228setenv TERMCAP "$term[2]" 229unset term 230unset noglob 231.Ed 232.Sh TERMINAL TYPE MAPPING 233When the terminal is not hardwired into the system (or the current system 234information is incorrect) the terminal type derived from the 235.Pa /etc/ttys 236file or the 237.Ev TERM 238environmental variable is often something generic like 239.Dq network , 240.Dq dialup , 241or 242.Dq unknown . 243When 244.Nm 245is used in a startup script 246.Pf ( Pa .profile 247for 248.Xr sh 1 249users or 250.Pa .login 251for 252.Xr csh 1 253users) it is often desirable to provide information about the type of 254terminal used on such ports. 255The purpose of the 256.Fl m 257option is to 258.Dq map 259from some set of conditions to a terminal type, that is, to 260tell 261.Nm 262``If I'm on this port at a particular speed, guess that I'm on that 263kind of terminal''. 264.Pp 265The argument to the 266.Fl m 267option consists of an optional port type, an optional operator, an optional 268baud rate specification, an optional colon (``:'') character and a terminal 269type. 270The port type is a string (delimited by either the operator or the colon 271character). 272The operator may be any combination of: 273.Dq Li \&\*[Gt] , 274.Dq Li \&\*[Lt] , 275.Dq Li \&@ , 276and 277.Dq Li \&! ; 278.Dq Li \&\*[Gt] 279means greater than, 280.Dq Li \&\*[Lt] 281means less than, 282.Dq Li \&@ 283means equal to 284and 285.Dq Li \&! 286inverts the sense of the test. 287The baud rate is specified as a number and is compared with the speed 288of the standard error output (which should be the control terminal). 289The terminal type is a string. 290.Pp 291If the terminal type is not specified on the command line, the 292.Fl m 293mappings are applied to the terminal type. 294If the port type and baud rate match the mapping, the terminal type specified 295in the mapping replaces the current type. 296If more than one mapping is specified, the first applicable mapping is used. 297.Pp 298For example, consider the following mapping: 299.Dq Li dialup\*[Gt]9600:vt100 . 300The port type is 301.Dq Li dialup , 302the operator is 303.Dq Li \*[Gt] , 304the baud rate specification is 305.Dq Li 9600 , 306and the terminal type is 307.Dq Li vt100 . 308The result of this mapping is to specify that if the terminal type is 309.Dq Li dialup , 310and the baud rate is greater than 9600 baud, a terminal type of 311.Dq Li vt100 312will be used. 313.Pp 314If no port type is specified, the terminal type will match any port type, 315for example, 316.Dq Li -m dialup:vt100 -m :?xterm 317will cause any dialup port, regardless of baud rate, to match the terminal 318type 319.Dq Li vt100 , 320and any non-dialup port type to match the terminal type 321.Dq Li ?xterm . 322Note, because of the leading question mark, the user will be 323queried on a default port as to whether they are actually using an 324.Ar xterm 325terminal. 326.Pp 327No whitespace characters are permitted in the 328.Fl m 329option argument. 330Also, to avoid problems with metacharacters, it is suggested that the entire 331.Fl m 332option argument be placed within single quote characters, and that 333.Xr csh 1 334users insert a backslash character (``\e'') before any exclamation 335marks (``!''). 336.Sh ENVIRONMENT 337The 338.Nm 339command utilizes the 340.Ev SHELL 341and 342.Ev TERM 343environment variables. 344.Sh FILES 345.Bl -tag -width /usr/share/misc/termcap -compact 346.It Pa /etc/ttys 347system port name to terminal type mapping database 348.It Pa /usr/share/misc/termcap 349terminal capability database 350.El 351.Sh SEE ALSO 352.Xr csh 1 , 353.Xr sh 1 , 354.Xr stty 1 , 355.Xr tty 4 , 356.Xr termcap 5 , 357.Xr ttys 5 , 358.Xr environ 7 359.Sh HISTORY 360The 361.Nm 362command appeared in 363.Bx 3.0 . 364.Sh COMPATIBILITY 365The 366.Fl A , 367.Fl E , 368.Fl h , 369.Fl u 370and 371.Fl v 372options have been deleted from the 373.Nm 374utility. 375None of them were documented in 376.Bx 4.3 377and all are of limited utility at 378best. 379The 380.Fl a , 381.Fl d 382and 383.Fl p 384options are similarly not documented or useful, but were retained as they 385appear to be in widespread use. 386It is strongly recommended that any usage of these three options be 387changed to use the 388.Fl m 389option instead. 390The 391.Fl n 392option remains, but has no effect. 393It is still permissible to specify the 394.Fl e , 395.Fl i 396and 397.Fl k 398options without arguments, although it is strongly recommended that such 399usage be fixed to explicitly specify the character. 400.Pp 401Executing 402.Nm 403as 404.Nm reset 405no longer implies the 406.Fl Q 407option. 408Also, the interaction between the 409.Fl 410option and the 411.Ar terminal 412argument in some historic implementations of 413.Nm 414has been removed. 415.Pp 416Finally, the 417.Nm 418implementation has been completely redone (as part of the addition to the 419system of a 420.St -p1003.1-88 421compliant terminal interface) and will no longer compile on systems with 422older terminal interfaces. 423