date and time created 83/11/22 12:48:04 by edward
[unix-history] / usr / src / usr.bin / window / cmd.c
CommitLineData
f6dc361a 1#ifndef lint
57fc9db6 2static char *sccsid = "@(#)cmd.c 3.14 83/11/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;
f176f953
EW
70 case 'M':
71 if ((w = getwin()) != 0)
72 movewin(w, w->ww_altpos.r,
73 w->ww_altpos.c);
74 break;
86845af3
EW
75 case 'S':
76 c_show();
77 break;
78 case 'L':
79 c_list();
80 break;
81 case ':':
82 c_colon();
83 break;
84 case 'h':
85 (void) wwwrite(selwin, "\b", 1);
86 break;
87 case 'j':
88 (void) wwwrite(selwin, "\n", 1);
89 break;
90 case 'k':
91 (void) wwwrite(selwin, "\033A", 2);
92 break;
93 case 'l':
94 (void) wwwrite(selwin, "\033C", 2);
95 break;
96 case CTRL(e):
97 wwscroll(selwin, 1);
98 break;
99 case CTRL(y):
100 wwscroll(selwin, -1);
101 break;
102 case CTRL(d):
103 wwscroll(selwin, selwin->ww_w.nr / 2);
104 break;
105 case CTRL(u):
106 wwscroll(selwin, - selwin->ww_w.nr / 2);
107 break;
108 case CTRL(f):
109 wwscroll(selwin, selwin->ww_w.nr);
110 break;
111 case CTRL(b):
112 wwscroll(selwin, - selwin->ww_w.nr);
113 break;
114 case CTRL(s):
115 (void) write(selwin->ww_pty,
116 &wwwintty.ww_tchars.t_stopc, 1);
117 break;
118 case CTRL(q):
119 (void) write(selwin->ww_pty,
120 &wwwintty.ww_tchars.t_startc, 1);
121 break;
122 case CTRL(l):
123 wwredraw();
124 break;
125 case '?':
126 c_help();
127 break;
128 case CTRL([):
129 if (checkproc(selwin) >= 0)
130 incmd = 0;
131 break;
132 case CTRL(z):
133 wwsuspend();
134 break;
135 case 'q':
136 c_quit();
137 break;
138 /* undocumented commands */
139 case 's':
140 c_stat();
141 break;
57fc9db6 142#ifndef O_4_1A
86845af3
EW
143 case 't':
144 c_time(RUSAGE_SELF);
145 break;
146 case 'T':
147 c_time(RUSAGE_CHILDREN);
148 break;
57fc9db6 149#endif
f176f953
EW
150 /* debugging stuff */
151 case '&':
152 if (debug) {
153 c_debug();
154 break;
155 }
86845af3 156 default:
86845af3
EW
157 if (c == escapec) {
158 if (checkproc(selwin) >= 0) {
159 (void) write(selwin->ww_pty,
160 &escapec, 1);
161 incmd = 0;
162 }
163 } else {
164 if (!terse)
165 wwbell();
166 error("Type ? for help.");
167 }
74329e4e 168 }
f6dc361a 169 }
86845af3
EW
170 if (!incmd || quit)
171 break;
172 if (terse)
173 wwsetcursor(0, 0);
174 else {
bb05dfb5 175 (void) wwputs("Command: ", cmdwin);
86845af3
EW
176 wwcurtowin(cmdwin);
177 }
178 while (bpeekc() < 0)
179 bread();
101acab4 180 }
bb05dfb5 181 if (!quit) {
bb05dfb5
EW
182 if (!terse) {
183 wwdelete(cmdwin);
184 reframe();
185 }
73218728 186 wwcursor(selwin, 0);
86845af3 187 }
f6dc361a
EW
188}
189
190struct ww *
191getwin()
192{
193 register int c;
4c8ea7ce 194 struct ww *w = 0;
f6dc361a 195
101acab4 196 if (!terse)
bb05dfb5 197 (void) wwputs("Which window? ", cmdwin);
f2a77fe1 198 wwcurtowin(cmdwin);
b4be6cd6 199 while ((c = bgetc()) < 0)
f6dc361a 200 bread();
bb05dfb5
EW
201 if (debug && c == 'c')
202 w = cmdwin;
203 else if (debug && c == 'f')
204 w = framewin;
720ae37c
EW
205 else if (debug && c == 'b')
206 w = boxwin;
bb05dfb5
EW
207 else if (c >= '1' && c < NWINDOW + '1')
208 w = window[c - '1'];
209 if (w == 0)
210 wwbell();
101acab4 211 if (!terse)
bb05dfb5 212 (void) wwputs("\r\n", cmdwin);
f6dc361a
EW
213 return w;
214}
215
86845af3
EW
216checkproc(w)
217struct ww *w;
218{
219 if (w->ww_state != WWS_HASPROC) {
220 error("No process in window.");
221 return -1;
222 }
223 return 0;
224}
225
f6dc361a 226setselwin(w)
fe24a747
EW
227struct ww *w;
228{
229 if ((selwin = w) != 0)
230 front(w);
231}
232
27b31336
EW
233/*
234 * This is all heuristic.
f176f953
EW
235 * wwvisible() doesn't work for tinted windows.
236 * and wwmoveup() doesn't work for transparent windows
237 * (completely or partially).
27b31336
EW
238 * But anything to make it faster.
239 */
fe24a747 240front(w)
f6dc361a
EW
241register struct ww *w;
242{
fe24a747 243 char moved = 0;
4c8ea7ce 244
27b31336 245 if (wwvisible(w))
fe24a747 246 moved = 1;
27b31336
EW
247 else
248 while (w->ww_back != framewin) {
249 wwmoveup(w);
250 moved = 1;
251 }
fe24a747
EW
252 if (moved)
253 reframe();
254}
255
256reframe()
257{
258 register struct ww *w;
259
260 wwunframe(framewin);
261 for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back)
262 if (w->ww_hasframe) {
263 wwframe(w, framewin);
264 labelwin(w);
265 }
f6dc361a
EW
266}
267
4c8ea7ce 268labelwin(w)
f6dc361a
EW
269register struct ww *w;
270{
bb05dfb5
EW
271 int mode = w == selwin ? WWM_REV : 0;
272
273 if (w->ww_id >= 0) {
274 char buf[2];
f6dc361a 275
bb05dfb5
EW
276 buf[0] = w->ww_id + '1';
277 buf[1] = 0;
03e75950 278 wwlabel(w, framewin, 1, buf, mode);
bb05dfb5
EW
279 }
280 if (w->ww_label) {
281 int col;
282
283 if (w->ww_center) {
284 col = (w->ww_w.nc - strlen(w->ww_label)) / 2;
285 col = MAX(3, col);
286 } else
287 col = 3;
03e75950 288 wwlabel(w, framewin, col, w->ww_label, mode);
bb05dfb5 289 }
f6dc361a 290}