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