date and time created 83/09/13 15:00:22 by edward
[unix-history] / usr / src / usr.bin / window / cmd.c
CommitLineData
f6dc361a 1#ifndef lint
27b31336 2static char *sccsid = "@(#)cmd.c 3.11 83/09/02";
f6dc361a
EW
3#endif
4
5#include "defs.h"
6
f6dc361a
EW
7docmd()
8{
9 register char c;
10 register struct ww *w;
f6dc361a 11
74329e4e 12 if (!terse)
bb05dfb5 13 wwadd(cmdwin, &wwhead);
c417b691 14 if (selwin != 0)
73218728 15 wwcursor(selwin, 1);
86845af3
EW
16 for (;;) {
17 while ((c = bgetc()) >= 0) {
18 if (!terse)
19 (void) wwputs("\r\n", cmdwin);
20 switch (c) {
21 default:
22 if (c == escapec)
23 goto foo;
f6dc361a 24 break;
86845af3
EW
25 case 'h': case 'j': case 'k': case 'l':
26 case CTRL(y):
27 case CTRL(e):
28 case CTRL(u):
29 case CTRL(d):
30 case CTRL(b):
31 case CTRL(f):
32 case CTRL(s):
33 case CTRL(q):
34 case CTRL([):
35 foo:
36 if (selwin == 0) {
37 error("No window.");
38 continue;
39 }
f6dc361a 40 }
86845af3
EW
41 switch (c) {
42 case '1': case '2': case '3': case '4': case '5':
43 case '6': case '7': case '8': case '9':
44 if ((w = window[c - '1']) == 0) {
45 wwbell();
46 break;
47 }
4c8ea7ce 48 setselwin(w);
86845af3
EW
49 if (checkproc(selwin) >= 0)
50 incmd = 0;
51 break;
52 case '%':
53 if ((w = getwin()) != 0)
54 setselwin(w);
55 break;
56 case 'c':
57 if ((w = getwin()) != 0)
58 c_close(w);
59 break;
60 case 'C':
61 c_close((struct ww *)0);
62 break;
63 case 'w':
64 c_window();
65 break;
66 case 'm':
67 if ((w = getwin()) != 0)
68 c_move(w);
69 break;
70 case 'S':
71 c_show();
72 break;
73 case 'L':
74 c_list();
75 break;
76 case ':':
77 c_colon();
78 break;
79 case 'h':
80 (void) wwwrite(selwin, "\b", 1);
81 break;
82 case 'j':
83 (void) wwwrite(selwin, "\n", 1);
84 break;
85 case 'k':
86 (void) wwwrite(selwin, "\033A", 2);
87 break;
88 case 'l':
89 (void) wwwrite(selwin, "\033C", 2);
90 break;
91 case CTRL(e):
92 wwscroll(selwin, 1);
93 break;
94 case CTRL(y):
95 wwscroll(selwin, -1);
96 break;
97 case CTRL(d):
98 wwscroll(selwin, selwin->ww_w.nr / 2);
99 break;
100 case CTRL(u):
101 wwscroll(selwin, - selwin->ww_w.nr / 2);
102 break;
103 case CTRL(f):
104 wwscroll(selwin, selwin->ww_w.nr);
105 break;
106 case CTRL(b):
107 wwscroll(selwin, - selwin->ww_w.nr);
108 break;
109 case CTRL(s):
110 (void) write(selwin->ww_pty,
111 &wwwintty.ww_tchars.t_stopc, 1);
112 break;
113 case CTRL(q):
114 (void) write(selwin->ww_pty,
115 &wwwintty.ww_tchars.t_startc, 1);
116 break;
117 case CTRL(l):
118 wwredraw();
119 break;
120 case '?':
121 c_help();
122 break;
123 case CTRL([):
124 if (checkproc(selwin) >= 0)
125 incmd = 0;
126 break;
127 case CTRL(z):
128 wwsuspend();
129 break;
130 case 'q':
131 c_quit();
132 break;
133 /* undocumented commands */
134 case 's':
135 c_stat();
136 break;
137 case 't':
138 c_time(RUSAGE_SELF);
139 break;
140 case 'T':
141 c_time(RUSAGE_CHILDREN);
142 break;
143 /* debugging commands */
144 case 'M':
145 if (!debug)
146 goto badcmd;
147 wwdumpsmap();
148 break;
149 case 'V':
150 if (!debug)
151 goto badcmd;
152 if ((w = getwin()) != 0)
153 wwdumpnvis(w);
154 break;
155 case 'D':
156 if (!debug)
157 goto badcmd;
158 if ((w = getwin()) != 0)
159 wwdumpcov(w);
160 break;
161 case 'W':
162 if (!debug)
163 goto badcmd;
164 if ((w = getwin()) != 0)
165 wwdumpwin(w);
166 break;
167 default:
168 badcmd:
169 if (c == escapec) {
170 if (checkproc(selwin) >= 0) {
171 (void) write(selwin->ww_pty,
172 &escapec, 1);
173 incmd = 0;
174 }
175 } else {
176 if (!terse)
177 wwbell();
178 error("Type ? for help.");
179 }
74329e4e 180 }
f6dc361a 181 }
86845af3
EW
182 if (!incmd || quit)
183 break;
184 if (terse)
185 wwsetcursor(0, 0);
186 else {
bb05dfb5 187 (void) wwputs("Command: ", cmdwin);
86845af3
EW
188 wwcurtowin(cmdwin);
189 }
190 while (bpeekc() < 0)
191 bread();
101acab4 192 }
bb05dfb5 193 if (!quit) {
bb05dfb5
EW
194 if (!terse) {
195 wwdelete(cmdwin);
196 reframe();
197 }
73218728 198 wwcursor(selwin, 0);
86845af3 199 }
f6dc361a
EW
200}
201
202struct ww *
203getwin()
204{
205 register int c;
4c8ea7ce 206 struct ww *w = 0;
f6dc361a 207
101acab4 208 if (!terse)
bb05dfb5
EW
209 (void) wwputs("Which window? ", cmdwin);
210 wwsetcursor(wwcurrow(cmdwin), wwcurcol(cmdwin));
b4be6cd6 211 while ((c = bgetc()) < 0)
f6dc361a 212 bread();
bb05dfb5
EW
213 if (debug && c == 'c')
214 w = cmdwin;
215 else if (debug && c == 'f')
216 w = framewin;
720ae37c
EW
217 else if (debug && c == 'b')
218 w = boxwin;
bb05dfb5
EW
219 else if (c >= '1' && c < NWINDOW + '1')
220 w = window[c - '1'];
221 if (w == 0)
222 wwbell();
101acab4 223 if (!terse)
bb05dfb5 224 (void) wwputs("\r\n", cmdwin);
f6dc361a
EW
225 return w;
226}
227
86845af3
EW
228checkproc(w)
229struct ww *w;
230{
231 if (w->ww_state != WWS_HASPROC) {
232 error("No process in window.");
233 return -1;
234 }
235 return 0;
236}
237
f6dc361a 238setselwin(w)
fe24a747
EW
239struct ww *w;
240{
241 if ((selwin = w) != 0)
242 front(w);
243}
244
27b31336
EW
245/*
246 * This is all heuristic.
247 * wwvisible() doesn't work for partially tinted windows.
248 * and wwmoveup() doesn't work for transparent (completely or in part) windows.
249 * But anything to make it faster.
250 */
fe24a747 251front(w)
f6dc361a
EW
252register struct ww *w;
253{
fe24a747 254 char moved = 0;
4c8ea7ce 255
27b31336 256 if (wwvisible(w))
fe24a747 257 moved = 1;
27b31336
EW
258 else
259 while (w->ww_back != framewin) {
260 wwmoveup(w);
261 moved = 1;
262 }
fe24a747
EW
263 if (moved)
264 reframe();
265}
266
267reframe()
268{
269 register struct ww *w;
270
271 wwunframe(framewin);
272 for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back)
273 if (w->ww_hasframe) {
274 wwframe(w, framewin);
275 labelwin(w);
276 }
f6dc361a
EW
277}
278
4c8ea7ce 279labelwin(w)
f6dc361a
EW
280register struct ww *w;
281{
bb05dfb5
EW
282 int mode = w == selwin ? WWM_REV : 0;
283
284 if (w->ww_id >= 0) {
285 char buf[2];
f6dc361a 286
bb05dfb5
EW
287 buf[0] = w->ww_id + '1';
288 buf[1] = 0;
03e75950 289 wwlabel(w, framewin, 1, buf, mode);
bb05dfb5
EW
290 }
291 if (w->ww_label) {
292 int col;
293
294 if (w->ww_center) {
295 col = (w->ww_w.nc - strlen(w->ww_label)) / 2;
296 col = MAX(3, col);
297 } else
298 col = 3;
03e75950 299 wwlabel(w, framewin, col, w->ww_label, mode);
bb05dfb5 300 }
f6dc361a 301}