Commit | Line | Data |
---|---|---|
b6b63f20 | 1 | #ifndef lint |
b1189050 | 2 | static char *sccsid = "@(#)win.c 3.3 84/03/03"; |
b6b63f20 EW |
3 | #endif |
4 | ||
5 | #include "defs.h" | |
6 | ||
7 | /* | |
8 | * Routines for opening and closing windows | |
9 | */ | |
10 | ||
11 | /* | |
12 | * Open a user window. | |
13 | */ | |
14 | struct ww * | |
15 | openwin(id, row, col, nrow, ncol, nline, label) | |
16 | char *label; | |
17 | { | |
18 | register struct ww *w; | |
19 | ||
20 | if (id < 0 && (id = findid()) < 0) | |
21 | return 0; | |
22 | if (row + nrow <= 0 || row > wwnrow - 1 | |
23 | || col + ncol <= 0 || col > wwncol - 1) { | |
24 | error("Illegal window position."); | |
25 | return 0; | |
26 | } | |
27 | if ((w = wwopen(WWO_PTY, nrow, ncol, row, col, nline)) == 0) { | |
28 | error("%s.", wwerror()); | |
29 | return 0; | |
30 | } | |
31 | w->ww_id = id; | |
32 | window[id] = w; | |
33 | w->ww_hasframe = 1; | |
34 | w->ww_altpos.r = 1; | |
35 | w->ww_altpos.c = 0; | |
36 | if (label != 0 && setlabel(w, label) < 0) | |
37 | error("No memory for label."); | |
38 | wwcursor(w, 1); | |
39 | wwadd(w, framewin); | |
40 | selwin = w; | |
41 | reframe(); | |
42 | wwupdate(); | |
43 | wwflush(); | |
44 | if (wwspawn(w, shell, shellname, (char *)0) < 0) { | |
45 | c_close(w); | |
46 | error("%s: %s.", shell, wwerror()); | |
47 | return 0; | |
48 | } | |
49 | return w; | |
50 | } | |
51 | ||
52 | findid() | |
53 | { | |
54 | register i; | |
55 | ||
56 | for (i = 0; i < NWINDOW && window[i] != 0; i++) | |
57 | ; | |
58 | if (i >= NWINDOW) { | |
59 | error("Too many windows."); | |
60 | return -1; | |
61 | } | |
62 | return i; | |
63 | } | |
64 | ||
65 | /* | |
66 | * Close a user window. | |
67 | */ | |
68 | closewin(w) | |
69 | register struct ww *w; | |
70 | { | |
71 | if (w == selwin) | |
72 | selwin = 0; | |
73 | if (w == lastselwin) | |
74 | lastselwin = 0; | |
75 | if (w->ww_id >= 0 && w->ww_id < NWINDOW) | |
76 | window[w->ww_id] = 0; | |
77 | if (w->ww_label) | |
78 | str_free(w->ww_label); | |
79 | wwdelete(w); | |
80 | wwclose(w); | |
81 | } | |
82 | ||
83 | /* | |
84 | * Open an information (display) window. | |
85 | */ | |
86 | struct ww * | |
87 | openiwin(nrow, label) | |
88 | char *label; | |
89 | { | |
90 | register struct ww *w; | |
91 | ||
92 | if ((w = wwopen(0, nrow, wwncol, 2, 0, 0)) == 0) | |
93 | return 0; | |
94 | w->ww_mapnl = 1; | |
95 | w->ww_hasframe = 1; | |
b1189050 | 96 | w->ww_nointr = 1; |
b6b63f20 EW |
97 | w->ww_id = -1; |
98 | w->ww_center = 1; | |
99 | (void) setlabel(w, label); | |
100 | wwadd(w, framewin); | |
101 | reframe(); | |
b1189050 | 102 | wwupdate(); |
b6b63f20 EW |
103 | return w; |
104 | } | |
105 | ||
106 | /* | |
107 | * Close an information window. | |
108 | */ | |
109 | closeiwin(w) | |
110 | struct ww *w; | |
111 | { | |
112 | closewin(w); | |
113 | reframe(); | |
114 | } | |
115 | ||
116 | waitnl(w) | |
117 | struct ww *w; | |
118 | { | |
119 | (void) waitnl1(w, "[Type any key to continue]"); | |
120 | } | |
121 | ||
b1189050 | 122 | more(w, always) |
b6b63f20 | 123 | register struct ww *w; |
b1189050 | 124 | char always; |
b6b63f20 EW |
125 | { |
126 | int c; | |
127 | ||
b1189050 | 128 | if (!always && w->ww_cur.r < w->ww_w.b - 2) |
b6b63f20 EW |
129 | return 0; |
130 | c = waitnl1(w, "[Type escape to abort, any other key to continue]"); | |
b1189050 | 131 | wwputs("\033E", w); |
b6b63f20 EW |
132 | return c == CTRL([) ? 2 : 1; |
133 | } | |
134 | ||
135 | waitnl1(w, prompt) | |
136 | register struct ww *w; | |
137 | char *prompt; | |
138 | { | |
139 | front(w, 0); | |
b1189050 | 140 | wwprintf(w, "\033Y%c%c\033p%s\033q ", |
b6b63f20 EW |
141 | w->ww_w.nr - 1 + ' ', ' ', prompt); /* print on last line */ |
142 | wwcurtowin(w); | |
8fa6d94c EW |
143 | while (wwpeekc() < 0) |
144 | wwiomux(); | |
145 | return wwgetc(); | |
b6b63f20 | 146 | } |