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