lock alias file while rebuilding if flock system call available
[unix-history] / usr / src / usr.bin / window / window.1
CommitLineData
6be9699a
KM
1.\" Copyright (c) 1985 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)window.1 6.1 (Berkeley) %G%
6.\"
7.TH WINDOW 1 ""
8.UC 6
93d5bf32 9.SH NAME
ac024783 10window \- window environment
93d5bf32 11.SH SYNOPSIS
05631f05
EW
12.B window
13[
14.B \-t
15] [
16.B \-f
17] [
18.B \-d
19] [
ac024783
EW
20.B \-e escape-char
21] [
22.B \-c command
05631f05 23]
93d5bf32 24.SH DESCRIPTION
ac024783 25\fIWindow\fP provides a window oriented environment
93d5bf32
EW
26on ordinary CRT terminals.
27.PP
ac024783
EW
28A window is a rectangular portion of the physical terminal
29screen associated with a set of processes. These processes
30communicate with the window in the same way they normally
31interact with a terminal. The window program handles the
32details of redirecting input an output to and from the
33windows. At any one time, only one window can receive
34input from the keyboard, but all windows can simultaneously send output
35to the display.
f85ea165 36.PP
ac024783
EW
37Windows can overlap and are framed as necessary. Each window
38is named by one of the digits ``1'' to ``9''. This one character
39identifier, as well as a user definable label string, are displayed
40with the window on the top edge of its frame. A window can be
41designated to be in the \fIforeground\fP, in which case it will always be
42on top of all normal, non-foreground windows, and can be covered
43only by other foreground windows.
93d5bf32 44.PP
ac024783
EW
45A window need not be completely within the edges of the terminal screen.
46Thus a large window (possibly larger than the screen)
47can be positioned to show only a portion of its full size. In addition,
48both the size and the position of a window can be changed by
49the user at any time.
05631f05 50.PP
ac024783
EW
51Windows are designed to have the appearance of real terminals
52both to the user and to the processes running in them. Each window
53has a cursor and a set of control functions. Most intelligent
54terminal functions such as line and
55character deletion and insertion are supported. Display modes
56such as underlining and reverse video are available if the terminal
57allows them. Also, similar to terminals with multiple pages of memory,
58each window has a text buffer which can be larger than the window.
59Different parts of the buffer can be displayed by scrolling.
60.SH OPTIONS
05631f05
EW
61When \fIwindow\fP starts up, the file \fI.windowrc\fP in the
62user's home directory is checked. If it exists, then the
63commands contained in it are executed (see \fIsource\fP command below).
ac024783 64Otherwise, two equal sized windows are created by default.
05631f05
EW
65.PP
66The command line arguments are
67.TP
ac024783 68.B \-t
05631f05
EW
69Turn on terse mode (see \fIterse\fP command below).
70.TP
ac024783 71.B \-f
05631f05
EW
72Don't perform any startup action.
73.TP
ac024783 74.B \-d
05631f05
EW
75Ignore \fI.windowrc\fP and create the two default
76windows instead.
77.TP
ac024783
EW
78.B \-e escape-char
79Set the escape character to \fIescape-char\fP. \fIEscape-char\fP
80can be a single character, or in the form \fI^X\fP where \fIX\fP
81is any character, meaning control-\fIX\fP.
82.TP
83.B \-c command
84Execute the string \fIcommand\fP as a long command (see below)
85before doing anything else.
86.SH "PROCESS ENVIRONMENT"
87With each newly created window, a shell program is spawned with its
88process environment tailored to that window. Its standard input,
89output, and diagnostic file descriptors are bound to one end of either
90a pseudo-terminal (\fIpty\fP (4)) or a UNIX domain socket
91(\fIsocketpair\fP (4)). If a pseudo-terminal is used, then its special
92characters and modes (see \fIstty\fP (1)) are copied from the physical
93terminal. A \fItermcap\fP (5) entry tailored to this window is created
94and passed as environment (\fIenviron\fP (5)) variable
95\fITERMCAP\fP. The termcap entry contains the window's size and
96characteristics as well as information from the physical terminal,
97such as the existence of underline, reverse video, and other display
98modes, and the codes produced by the terminal's function keys,
99if any. In addition to the termcap entry, a window size structure is
100associated with the pseudo-terminal (and indeed with any terminal). It
101is initialized by \fIwindow\fP at creation time, and updated whenever the
102size of the window changes, using the \fIioctl\fP (2) call
103\fITIOCSWINSZ\fP. In particular, the editor \fIvi\fP (1) uses
104this information to redraw its display.
105.SH OPERATION
05631f05 106.PP
ac024783
EW
107During normal execution, \fIwindow\fP can be in one of two modes:
108conversation mode and command mode. In conversation mode, the
109terminal's real cursor is placed at the cursor position of a particular
110window--called the current window--and input from the keyboard is sent
111to the process in that window. The current window is always
112on top of all other windows, except those in foreground. In addition,
113it is set apart by highlighting its identifier and label in reverse video.
93d5bf32 114.PP
ac024783
EW
115Typing \fIwindow\fP's escape character (normally ^P) in conversation
116mode switches it into command mode. In command mode, the top line of
117the terminal screen becomes the command prompt window, and \fIwindow\fP
118interprets input from the keyboard as commands to manipulate windows.
e4414eae 119.PP
ac024783
EW
120There are two types of commands: short commands are usually one or two
121key strokes; long commands are strings either typed by the user in the
122command window (see the ``:'' command below), or read from a file (see
123\fIsource\fP below).
124.SH "SHORT COMMANDS"
125Below, \fI#\fP represents one of the digits ``1'' to ``9''
126corresponding to the windows 1 to 9. \fI^X\fP means control-\fIX\fP,
127where \fPX\fP is any character. In particular, \fI^^\fP is
128control-^. \fIEscape\fP is the escape key, or \f^[\fP.
129.TP
130.B #
131Select window \fI#\fP as the current window
f85ea165 132and return to conversation mode.
93d5bf32 133.TP
ac024783
EW
134.B %#
135Select window \fI#\fP but stay in command mode.
93d5bf32 136.TP
ac024783
EW
137.B ^^
138Select the previous window and return to conversation
139mode. This is useful for toggling between two windows.
f85ea165 140.TP
93d5bf32
EW
141.B escape
142Return to conversation mode.
143.TP
144.B ^P
145Return to conversation mode and write ^P to the
146current window. Thus, typing two ^P's in conversation
147mode sends one to the current window. If the \fIwindow\fP
148escape is changed to some other character, that
f85ea165 149character takes the place of ^P here.
93d5bf32 150.TP
ac024783
EW
151.B ?
152List a short summary of commands.
153.TP
154.B ^L
155Redraw the screen.
9c9f7aa9 156.TP
f85ea165
EW
157.B q
158Exit \fIwindow\fP. Confirmation is requested.
93d5bf32 159.TP
05631f05
EW
160.B ^Z
161Suspend \fIwindow\fP.
162.TP
93d5bf32 163.B w
ac024783 164Create a new window. The user is prompted for the positions
f85ea165 165of the upper left and lower right corners of the window.
e4414eae
EW
166The cursor is placed on the screen and the keys ``h'', ``j'',
167``k'', and ``l''
168move the cursor left, down, up, and right, respectively.
169The keys ``H'', ``J'', ``K'', and ``L'' move the cursor to the respective
05631f05 170limits of the screen. Typing a number before the movement keys
ac024783 171repeats the movement that number of times. Return enters the cursor position
93d5bf32 172as the upper left corner of the window. The lower right corner
f07b3693 173is entered in the same manner. During this process,
ac024783
EW
174the placement of the new window is indicated by a rectangular
175box drawn on the screen, corresponding to where the new window
176will be framed. Typing escape at any point
f07b3693 177cancels this command.
93d5bf32 178.IP
05631f05 179This window becomes the current window,
ac024783
EW
180and is given the first available ID. The default buffer size
181is used (see \fInline\fP command below).
9c9f7aa9 182.IP
f07b3693 183Only fully visible windows can be created this way.
93d5bf32 184.TP
ac024783
EW
185.B c#
186Close window \fI#\fP. The process in the window is sent
187the hangup signal (see \fIkill\fP (1)). \fICsh\fP (1) should
93d5bf32
EW
188handle this signal correctly and cause no problems.
189.TP
ac024783
EW
190.B m#
191Move window \fI#\fP to another location. A box in the shape
f07b3693
EW
192of the window is drawn on
193the screen to indicate the new position of the window, and the same keys as
ac024783 194those for the \fIw\fP command are used to position the box. The
9c9f7aa9
EW
195window can be moved partially off-screen.
196.TP
ac024783
EW
197.B M#
198Move window \fI#\fP to its previous position.
9c9f7aa9 199.TP
ac024783
EW
200.B s#
201Change the size of window \fI#\fP. The user is prompted
202to enter the new lower right corner of the window. A box
203is drawn to indicate the new window size. The same
204keys used in \fIw\fP and \fIm\fP are used to enter the position.
93d5bf32 205.TP
ac024783
EW
206.B S#
207Change window \fI#\fP to its previous size.
05631f05
EW
208.TP
209.B ^Y
210Scroll the current window up by one line.
211.TP
212.B ^E
213Scroll the current window down by one line.
214.TP
93d5bf32
EW
215.B ^U
216Scroll the current window up by half the window size.
217.TP
218.B ^D
219Scroll the current window down by half the window size.
220.TP
221.B ^B
222Scroll the current window up by the full window size.
223.TP
224.B ^F
225Scroll the current window down by the full window size.
226.TP
227.B h
228Move the cursor of the current window left by one column.
229.TP
230.B j
231Move the cursor of the current window down by one line.
232.TP
233.B k
234Move the cursor of the current window up by one line.
235.TP
236.B l
237Move the cursor of the current window right by one column.
238.TP
ac024783
EW
239.B ^S
240Stop output in the current window.
241.TP
242.B ^Q
243Start output in the current window.
9c9f7aa9 244.TP
f85ea165 245.B :
f07b3693
EW
246Enter a line to be executed as long commands. Normal line
247editing characters (erase character, erase word, erase line) are
248supported.
ac024783
EW
249.SH "LONG COMMANDS"
250Long commands are a sequence of statements
251parsed much like a programming language, with a syntax
252similar to that of C. Numeric and string expressions and variables
253are supported, as well as conditional statements.
9c9f7aa9 254.PP
ac024783
EW
255There are two data types: string and number. A string is a sequence
256of letters or digits beginning with a letter. ``_'' and ``.'' are
257considered letters. Alternately, non-alphanumeric characters can
258be included in strings by quoting them in ``"'' or escaping them
259with ``\\''. In addition, the ``\\'' sequences of C are supported,
260both inside and outside quotes (e.g., ``\\n'' is a new line,
261``\\r'' a carriage return). For example, these are legal strings:
262abcde01234, "&#$^*&#", ab"$#"cd, ab\\$\\#cd, "/usr/ucb/window".
f85ea165 263.PP
ac024783
EW
264A number is an integer value in one of three forms:
265a decimal number, an octal number preceded by ``0'',
266or a hexadecimal number preceded by ``0x'' or ``0X''. The natural
267machine integer size is used (i.e., the signed integer type
268of the C compiler). As in C, a non-zero number represents
269a boolean true.
270.PP
271The character ``#'' begins a comment which terminates at the
272end of the line.
273.PP
274A statement is either a conditional or an expression. Expression
275statements are terminated with a new line or ``;''. To continue
276an expression on the next line, terminate the first line with ``\\''.
277.SH "CONDITIONAL STATEMENT"
278\fIWindow\fP has a single control structure:
279the fully bracketed if statement in the form
280.nf
281 if <expr> then
282 <statement>
283 . . .
284 elsif <expr> then
285 <statement>
286 . . .
287 else
288 <statement>
289 . . .
290 endif
291.fi
292The \fIelse\fP and \fIelsif\fP parts are optional, and the latter can
293be repeated any number of times. \fI<Expr>\fP must be numeric.
294.SH EXPRESSIONS
295Expressions in \fIwindow\fP are similar to those in the
296C language, with most C operators supported on numeric
297operands. In addition, some are overloaded to operate on strings.
298.PP
299When an expression is used as a statement, its value is discarded
300after evaluation. Therefore, only expressions with side
301effects (assignments and function calls) are useful as statements.
302.PP
303Single valued (no arrays) variables are supported, of both
304numeric and string values. Some variables are predefined. They
305are listed below.
306.PP
307The operators in order of increasing precedence:
308.TP
309.B <expr1> = <expr2>
310Assignment. The variable of name \fI<expr1>\fP, which must be string valued,
311is assigned the result of \fI<expr2>\fP. Returns the value of \fI<expr2>\fP.
312.TP
313.B <expr1> ? <expr2> : <expr3>
314Returns the value of \fI<expr2>\fP if \fI<expr1>\fP evaluates true
315(non-zero numeric value); returns the value of \fI<expr3>\fP otherwise. Only
316one of \fI<expr2>\fP and \fI<expr3>\fP is evaluated. \fI<Expr1>\fP must
317be numeric.
318.TP
319.B <expr1> || <expr2>
320Logical or. Numeric values only. Short circuit evaluation is supported
321(i.e., if \fI<expr1>\fP evaluates true, then \fI<expr2>\fP is not evaluated).
322.TP
323.B <expr1> && <expr2>
324Logical and with short circuit evaluation. Numeric values only.
325.TP
326.B <expr1> | <expr2>
327Bitwise or. Numeric values only.
328.TP
329.B <expr1> ^ <expr2>
330Bitwise exclusive or. Numeric values only.
331.TP
332.B <expr1> & <expr2>
333Bitwise and. Numeric values only.
334.TP
335.B <expr1> == <expr2>, <expr1> != <expr2>
336Comparison (equal and not equal, respectively). The boolean
337result (either 1 or 0) of the comparison is returned. The
338operands can be numeric or string valued. One string operand
339forces the other to be converted to a string in necessary.
340.TP
341.B <expr1> < <expr2>, <expr1> > <expr2>, <expr1> <= <expr2>, <expr1> >= <expr2>
342Less than, greater than, less than or equal to,
343greater than or equal to. Both numeric and string values, with
344automatic conversion as above.
345.TP
346.B <expr1> << <expr2>, <expr1> >> <expr2>
347If both operands are numbers, \fI<expr1>\fP is bit
348shifted left (or right) by \fI<expr2>\fP bits. If \fI<expr1>\fP is
349a string, then its first (or last) \fI<expr2>\fP characters are
350returns (if \fI<expr2>\fP is also a string, then its length is used
351in place of its value).
352.TP
353.B <expr1> + <expr2>, <expr1> - <expr2>
354Addition and subtraction on numbers. For ``+'', if one
355argument is a string, then the other is converted to a string,
356and the result is the concatenation of the two strings.
357.TP
358.B <expr1> * <expr2>, <expr1> / <expr2>, <expr1> % <expr2>
359Multiplication, division, modulo. Numbers only.
360.TP
361.B -<expr>, ~<expr>, !<expr>, $<expr>, $?<expr>
362The first three are unary minus, bitwise complement and logical complement
363on numbers only. The operator, ``$'', takes \fI<expr>\fP and returns
364the value of the variable of that name. If \fI<expr>\fP is numeric
365with value \fIn\fP and it appears within an alias macro (see below),
366then it refers to the nth argument of the alias invocation. ``$?''
367tests for the existence of the variable \fI<expr>\fP, and returns 1
368if it exists or 0 otherwise.
369.TP
370.B <expr>(<arglist>)
371Function call. \fI<Expr>\fP must be a string that is the unique
372prefix of the name of a builtin \fIwindow\fP function
373or the full name of a user defined alias macro. In the case of a builtin
374function, \fI<arglist>\fP can be in one of two forms:
375.br
376 <expr1>, <expr2>, . . .
377.br
378 argname1 = <expr1>, argname2 = <expr2>, . . .
379.br
380The two forms can in fact be intermixed, but the result is
381unpredictable. Most arguments can be omitted; default values will
382be supplied for them. The \fIargnames\fP can be unique prefixes
383of the the argument names. The commas separating
384arguments are used only to disambiguate, and can usually be omitted.
385.IP
386Only the first argument form is valid for user defined aliases. Aliases
387are defined using the \fIalias\fP builtin function (see below). Arguments
388are accessed via a variant of the variable mechanism (see ``$'' operator
389above).
390.IP
391Most functions return value, but some are used for side effect
392only and so must be used as statements. When a function or an alias is used
393as a statement, the parenthesis surrounding
394the argument list may be omitted. Aliases return no value.
395.SH "BUILTIN FUNCTIONS"
396The arguments are listed by name in their natural
397order. Optional arguments are in square brackets (``[ ]''). Arguments
398that have no names are in angle brackets (``<>'').
399.TP
400.B alias([<string>], [<string-list>])
401If no argument is given, all currently defined alias macros are
402listed. Otherwise, \fI<string>\fP is defined as an alias,
403with expansion \fI<string-list>\fP. The previous definition of
404\fI<string>\fP, if any, is returned. Default for \fI<string-list>\fP
405is no change.
406.TP
407.B close(<window-list>)
408Close the windows specified in \fI<window-list>\fP. If \fI<window-list>\fP
409is the word \fIall\fP, than all windows are closed. No value is returned.
410.TP
411.B cursormodes([modes])
412Set the window cursor to \fImodes\fP. \fIModes\fP is the bitwise
413or of the mode bits defined as the variables \fIm_ul\fP (underline),
414\fIm_rev\fP (reverse video), \fIm_blk\fP (blinking),
415and \fIm_grp\fP (graphics, terminal dependent). Return
416value is the previous modes. Default is no change.
417For example, cursor($m_rev|$m_blk) sets the window cursors to blinking
418reverse video.
419.TP
420.B echo([window], [<string-list>])
421Write the list of strings, \fI<string-list>\fP, to \fIwindow\fP, separated
422by spaces and terminated with a new line. The strings are only
423displayed in the window, the process in the window are not
424involved (see \fIwrite\fP below). No value is returned. Default
425is the current window.
426.TP
427.B escape([escapec])
428Set the escape character to \fIescape-char\fP. Returns the old
429escape character as a one character string. Default is no
430change. \fPEscapec\fP can be a string of a single character, or
431in the form \fI^X\fP, meaning control-\fIX\fP.
432.TP
433.B foreground([window], [flag])
434Move \fIwindow\fP in or out of foreground. \fIFlag\fP
435can be one of \fIon\fP, \fIoff\fP,
436\fIyes\fP, \fIno\fP, \fItrue\fP, or \fIfalse\fP, with obvious
437meanings, or it can be a numeric expression, in which case
438a non-zero value is true. Returns the old foreground flag
439as a number. Default for \fIwindow\fP is the current window,
440default for \fIflag\fP is no change.
441.TP
442.B label([window], [label])
443Set the label of \fIwindow\fP to \fIlabel\fP. Returns the old
444label as a string. Default for \fIwindow\fP is the current
445window, default for \fIlabel\fP is no change. To turn
446off a label, set it to an empty string ("").
447.TP
448.B list()
449No arguments. List the identifiers and labels of all windows. No
450value is returned.
451.TP
452.B nline([nline])
453Set the default buffer size to \fInline\fP. Initially, it is
45448 lines. Returns the old default buffer size. Default is
455no change. Using a very large buffer can slow the program down
456considerably.
f85ea165 457.TP
ac024783
EW
458.B select([window])
459Make \fIwindow\fP the current window. The previous current window
460is returned. Default is no change.
f85ea165 461.TP
ac024783
EW
462.B shell([<string-list>])
463Set the default window shell program to \fI<string-list>\fP. Returns
464the first string in the old shell setting. Default is no change. Initially,
465the default shell is taken from the environment variable \fISHELL\fP.
430fecd4 466.TP
ac024783
EW
467.B source(filename)
468Read and execute the long commands in \fIfilename\fP. Returns
469-1 if the file cannot be read, 0 otherwise.
f85ea165 470.TP
ac024783
EW
471.B terse([flag])
472Set terse mode to \fIflag\fP. In terse mode, the command window
473stays hidden even in command mode, and errors are reported by
474sounding the terminal's bell. \fIFlag\fP can take on the same
475values as in \fIforeground\fP above. Returns the old terse flag.
476Default is no change.
f85ea165 477.TP
ac024783
EW
478.B unalias(alias)
479Undefine \fIalias\fP. Returns -1 if \fIalias\fP does not exist,
4800 otherwise.
f85ea165 481.TP
ac024783
EW
482.B unset(variable)
483Undefine \fIvariable\fP. Returns -1 if \fIvariable\fP does not exist,
4840 otherwise.
05631f05 485.TP
ac024783
EW
486.B variables()
487No arguments. List all variables. No value is returned.
05631f05 488.TP
ac024783
EW
489.B window([row], [column], [nrow], [ncol], [nline], [frame],
490.B [pty], [mapnl], [shell])
491.br
492Open a window with upper left corner at \fIrow\fP, \fIcolumn\fP
493and size \fInrow\fP, \fIncol\fP. If \fInline\fP is specified,
494then that many lines are allocated for the text buffer. Otherwise,
495the default buffer size is used. Default values for
496\fIrow\fP, \fIcolumn\fP, \fInrow\fP, and \fIncol\fP are, respectively,
497the upper, left-most, lower, or right-most extremes of the
498screen. \fIFrame\fP, \fIpty\fP, and \fImapnl\fP are flag values
499interpreted in the same way as the argument to \fIforeground\fP (see above);
500they mean, respectively, put a frame around this window (default true),
501allocate pseudo-terminal for this window rather than socketpair (default
502true), and map new line characters in this window to carriage return
503and line feed (default true if socketpair is used, false otherwise).
504\fIShell\fP is a list of strings that will be used as the shell
505program to place in the window (default is the program specified
506by \fIshell\fP, see below). The created window's identifier
507is returned as a number.
508.TP
509.B write([window], [<string-list>])
510Send the list of strings, \fI<string-list>\fP, to \fIwindow\fP, separated
511by spaces but not terminated with a new line. The strings are actually
512given to the window as input. No value is returned. Default
513is the current window.
514.SH "PREDEFINED VARIABLES"
515These variables are for information only. Redefining them does
516not affect the internal operation of \fIwindow\fP.
517.TP
518.B baud
519The baud rate as a number between 50 and 38400.
520.TP
521.B modes
522The display modes (reverse video, underline, blinking, graphics)
523supported by the physical terminal. The value of \fImodes\fP is
524the bitwise or of some of the one bit values, \fIm_blk\fP, \fIm_grp\fP,
525\fIm_rev\fP, and \fIm_ul\fP (see below). These values are useful
526in setting the window cursors' modes (see \fIcursormodes\fP above).
527.TP
528.B m_blk
529The blinking mode bit.
530.TP
531.B m_grp
532The graphics mode bit (not very useful).
533.TP
534.B m_rev
535The reverse video mode bit.
536.TP
537.B m_ul
538The underline mode bit.
539.TP
540.B ncol
541The number of columns on the physical screen.
542.TP
543.B nrow
544The number of rows on the physical screen.
545.TP
546.B term
547The terminal type. The standard name, found in the second name
548field of the terminal's \fITERMCAP\fP entry, is used.
93d5bf32
EW
549.SH FILES
550.ta 15
f85ea165
EW
551~/.windowrc startup command file.
552.br
ac024783 553/dev/[pt]ty[pq]? pseudo-terminal devices.
93d5bf32
EW
554.SH DIAGNOSTICS
555Should be self explanatory.
556.SH BUGS