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