1.\" $NetBSD: tset.1,v 1.22 2017/07/03 21:34:22 wiz 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 April 5, 2012 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 terminfo 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 <LF>reset<LF> 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 162When the 163.Fl s 164option is specified, the commands to enter the information into the 165shell's environment are written to the standard output. 166If the 167.Ev SHELL 168environmental variable ends in 169.Dq csh , 170the commands are for the 171.Xr csh 1 , 172otherwise, they are for 173.Xr sh 1 . 174Note, the 175.Xr csh 1 176commands 177.Ic set 178and 179.Ic unset 180the shell variable 181.Dq noglob , 182leaving it unset. 183The following line in the 184.Pa .login 185or 186.Pa .profile 187files will initialize the environment correctly: 188.Bd -literal -offset indent 189eval \`tset -s options ... \` 190.Ed 191.Pp 192To demonstrate a simple use of the 193.Fl S 194option, the following lines in the 195.Pa .login 196file have an equivalent effect: 197.Bd -literal -offset indent 198set noglob 199set term=(`tset -S options ...`) 200setenv TERM $term[1] 201unset term 202unset noglob 203.Ed 204.Sh TERMINAL TYPE MAPPING 205When the terminal is not hardwired into the system (or the current system 206information is incorrect) the terminal type derived from the 207.Pa /etc/ttys 208file or the 209.Ev TERM 210environmental variable is often something generic like 211.Dq network , 212.Dq dialup , 213or 214.Dq unknown . 215When 216.Nm 217is used in a startup script 218.Pf ( Pa .profile 219for 220.Xr sh 1 221users or 222.Pa .login 223for 224.Xr csh 1 225users) it is often desirable to provide information about the type of 226terminal used on such ports. 227The purpose of the 228.Fl m 229option is to 230.Dq map 231from some set of conditions to a terminal type, that is, to 232tell 233.Nm 234``If I'm on this port at a particular speed, guess that I'm on that 235kind of terminal''. 236.Pp 237The argument to the 238.Fl m 239option consists of an optional port type, an optional operator, an optional 240baud rate specification, an optional colon (``:'') character and a terminal 241type. 242The port type is a string (delimited by either the operator or the colon 243character). 244The operator may be any combination of: 245.Dq Li \&> , 246.Dq Li \&< , 247.Dq Li \&@ , 248and 249.Dq Li \&! ; 250.Dq Li \&> 251means greater than, 252.Dq Li \&< 253means less than, 254.Dq Li \&@ 255means equal to 256and 257.Dq Li \&! 258inverts the sense of the test. 259The baud rate is specified as a number and is compared with the speed 260of the standard error output (which should be the control terminal). 261The terminal type is a string. 262.Pp 263If the terminal type is not specified on the command line, the 264.Fl m 265mappings are applied to the terminal type. 266If the port type and baud rate match the mapping, the terminal type specified 267in the mapping replaces the current type. 268If more than one mapping is specified, the first applicable mapping is used. 269.Pp 270For example, consider the following mapping: 271.Dq Li dialup>9600:vt100 . 272The port type is 273.Dq Li dialup , 274the operator is 275.Dq Li > , 276the baud rate specification is 277.Dq Li 9600 , 278and the terminal type is 279.Dq Li vt100 . 280The result of this mapping is to specify that if the terminal type is 281.Dq Li dialup , 282and the baud rate is greater than 9600 baud, a terminal type of 283.Dq Li vt100 284will be used. 285.Pp 286If no port type is specified, the terminal type will match any port type, 287for example, 288.Dq Li -m dialup:vt100 -m :?xterm 289will cause any dialup port, regardless of baud rate, to match the terminal 290type 291.Dq Li vt100 , 292and any non-dialup port type to match the terminal type 293.Dq Li ?xterm . 294Note, because of the leading question mark, the user will be 295queried on a default port as to whether they are actually using an 296.Ar xterm 297terminal. 298.Pp 299No whitespace characters are permitted in the 300.Fl m 301option argument. 302Also, to avoid problems with metacharacters, it is suggested that the entire 303.Fl m 304option argument be placed within single quote characters, and that 305.Xr csh 1 306users insert a backslash character (``\e'') before any exclamation 307marks (``!''). 308.Sh ENVIRONMENT 309The 310.Nm 311command uses the 312.Ev SHELL 313and 314.Ev TERM 315environment variables. 316.Sh FILES 317.Bl -tag -width /usr/share/misc/terminfo -compact 318.It Pa /etc/ttys 319system port name to terminal type mapping database 320.It Pa /usr/share/misc/terminfo 321terminal capability database 322.El 323.Sh COMPATIBILITY 324The 325.Fl A , 326.Fl E , 327.Fl h , 328.Fl u 329and 330.Fl v 331options have been deleted from the 332.Nm 333utility. 334None of them were documented in 335.Bx 4.3 336and all are of limited utility at 337best. 338The 339.Fl a , 340.Fl d 341and 342.Fl p 343options are similarly not documented or useful, but were retained as they 344appear to be in widespread use. 345It is strongly recommended that any usage of these three options be 346changed to use the 347.Fl m 348option instead. 349The 350.Fl n 351option remains, but has no effect. 352It is still permissible to specify the 353.Fl e , 354.Fl i 355and 356.Fl k 357options without arguments, although it is strongly recommended that such 358usage be fixed to explicitly specify the character. 359.Pp 360Executing 361.Nm 362as 363.Nm reset 364no longer implies the 365.Fl Q 366option. 367Also, the interaction between the 368.Fl 369option and the 370.Ar terminal 371argument in some historic implementations of 372.Nm 373has been removed. 374.Pp 375The 376.Fl E 377and 378.Fl S 379options have been removed as they only make sense for termcap and 380.Nm 381now uses terminfo. 382As such, the 383.Ev TERMCAP 384entry has been removed from 385.Fl s . 386.Pp 387Finally, the 388.Nm 389implementation has been completely redone (as part of the addition to the 390system of a 391.St -p1003.1-88 392compliant terminal interface) and will no longer compile on systems with 393older terminal interfaces. 394.Sh SEE ALSO 395.Xr csh 1 , 396.Xr sh 1 , 397.Xr stty 1 , 398.Xr tty 4 , 399.Xr terminfo 5 , 400.Xr ttys 5 , 401.Xr environ 7 402.Sh HISTORY 403The 404.Nm reset 405and 406.Nm tset 407commands appeared in 408.Bx 1 . 409