static char sccsid
[] = "@(#)win.c 3.16 %G%";
* Copyright (c) 1983 Regents of the University of California,
* All rights reserved. Redistribution permitted subject to
* the terms of the Berkeley Software License Agreement.
* Higher level routines for dealing with windows.
* There are two types of windows: user window, and information window.
* User windows are the ones with a pty and shell. Information windows
* are for displaying error messages, and other information.
* The windows are doubly linked in overlapping order and divided into
* two groups: foreground and normal. Information
* windows are always foreground. User windows can be either.
* Addwin() adds a window to the list at the top of one of the two groups.
* Deletewin() deletes a window. Front() moves a window to the front
* of its group. Wwopen(), wwadd(), and wwdelete() should never be called
openwin(id
, row
, col
, nrow
, ncol
, nline
, label
, haspty
, hasframe
, shf
, sh
)
if (id
< 0 && (id
= findid()) < 0)
if (row
+ nrow
<= 0 || row
> wwnrow
- 1
|| col
+ ncol
<= 0 || col
> wwncol
- 1) {
error("Illegal window position.");
w
= wwopen(haspty
? WWO_PTY
: WWO_SOCKET
, nrow
, ncol
, row
, col
, nline
);
error("Can't open window: %s.", wwerror());
w
->ww_hasframe
= hasframe
;
if (label
!= 0 && setlabel(w
, label
) < 0)
error("No memory for label.");
* We have to do this little maneuver to make sure
* addwin() puts w at the top, so we don't waste an
* insert and delete operation.
setselwin((struct ww
*)0);
if (wwspawn(w
, shf
, sh
) < 0) {
error("Can't execute %s: %s.", shf
, wwerror());
for (i
= 0; i
< NWINDOW
&& window
[i
] != 0; i
++)
error("Too many windows.");
if (w
->ww_id
>= 0 && w
->ww_id
< NWINDOW
)
* Open an information (display) window.
if ((w
= wwopen(0, nrow
, wwncol
, 2, 0, 0)) == 0)
(void) setlabel(w
, label
);
* Close an information window.
* Move the window to the top of its group.
* Don't do it if already fully visible.
* Wwvisible() doesn't work for tinted windows.
* But anything to make it faster.
* Always reframe() if doreframe is true.
if (w
->ww_back
!= (isfg(w
) ? framewin
: fgwin
) && !wwvisible(w
)) {
* Add a window at the top of normal windows or foreground windows.
* For normal windows, we put it behind the current window.
wwadd(w
, selwin
!= 0 && selwin
!= w
&& !isfg(selwin
)
for (w
= wwhead
.ww_back
; w
!= &wwhead
; w
= w
->ww_back
)
int mode
= w
== selwin
? WWM_REV
: 0;
wwlabel(w
, framewin
, 1, buf
, mode
);
col
= (w
->ww_w
.nc
- strlen(w
->ww_label
)) / 2;
wwlabel(w
, framewin
, col
, w
->ww_label
, mode
);
if (w
->ww_pty
>= 0 && w
->ww_ispty
)
(void) ioctl(w
->ww_pty
, TIOCSTOP
, (char *)0);
if (w
->ww_pty
>= 0 && w
->ww_ispty
)
(void) ioctl(w
->ww_pty
, TIOCSTART
, (char *)0);
struct ww
*back
= w
->ww_back
;
w
->ww_alt
.nr
= w
->ww_w
.nr
;
w
->ww_alt
.nc
= w
->ww_w
.nc
;
if (wwsize(w
, nrow
, ncol
) < 0)
error("Can't resize window: %s.", wwerror());
(void) waitnl1(w
, "[Type any key to continue]");
if (!always
&& w
->ww_cur
.r
< w
->ww_w
.b
- 2)
c
= waitnl1(w
, "[Type escape to abort, any other key to continue]");
return c
== ctrl([) ? 2 : 1;
wwprintf(w
, "\033Y%c%c\033sA%s\033rA ",
w
->ww_w
.nr
- 1 + ' ', ' ', prompt
); /* print on last line */