support graphics if setup by somebody else.
[unix-history] / usr / src / usr.bin / window / cmd.c
CommitLineData
f6dc361a 1#ifndef lint
f176f953 2static char *sccsid = "@(#)cmd.c 3.13 83/09/15";
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;
142 case 't':
143 c_time(RUSAGE_SELF);
144 break;
145 case 'T':
146 c_time(RUSAGE_CHILDREN);
147 break;
f176f953
EW
148 /* debugging stuff */
149 case '&':
150 if (debug) {
151 c_debug();
152 break;
153 }
86845af3 154 default:
86845af3
EW
155 if (c == escapec) {
156 if (checkproc(selwin) >= 0) {
157 (void) write(selwin->ww_pty,
158 &escapec, 1);
159 incmd = 0;
160 }
161 } else {
162 if (!terse)
163 wwbell();
164 error("Type ? for help.");
165 }
74329e4e 166 }
f6dc361a 167 }
86845af3
EW
168 if (!incmd || quit)
169 break;
170 if (terse)
171 wwsetcursor(0, 0);
172 else {
bb05dfb5 173 (void) wwputs("Command: ", cmdwin);
86845af3
EW
174 wwcurtowin(cmdwin);
175 }
176 while (bpeekc() < 0)
177 bread();
101acab4 178 }
bb05dfb5 179 if (!quit) {
bb05dfb5
EW
180 if (!terse) {
181 wwdelete(cmdwin);
182 reframe();
183 }
73218728 184 wwcursor(selwin, 0);
86845af3 185 }
f6dc361a
EW
186}
187
188struct ww *
189getwin()
190{
191 register int c;
4c8ea7ce 192 struct ww *w = 0;
f6dc361a 193
101acab4 194 if (!terse)
bb05dfb5 195 (void) wwputs("Which window? ", cmdwin);
f2a77fe1 196 wwcurtowin(cmdwin);
b4be6cd6 197 while ((c = bgetc()) < 0)
f6dc361a 198 bread();
bb05dfb5
EW
199 if (debug && c == 'c')
200 w = cmdwin;
201 else if (debug && c == 'f')
202 w = framewin;
720ae37c
EW
203 else if (debug && c == 'b')
204 w = boxwin;
bb05dfb5
EW
205 else if (c >= '1' && c < NWINDOW + '1')
206 w = window[c - '1'];
207 if (w == 0)
208 wwbell();
101acab4 209 if (!terse)
bb05dfb5 210 (void) wwputs("\r\n", cmdwin);
f6dc361a
EW
211 return w;
212}
213
86845af3
EW
214checkproc(w)
215struct ww *w;
216{
217 if (w->ww_state != WWS_HASPROC) {
218 error("No process in window.");
219 return -1;
220 }
221 return 0;
222}
223
f6dc361a 224setselwin(w)
fe24a747
EW
225struct ww *w;
226{
227 if ((selwin = w) != 0)
228 front(w);
229}
230
27b31336
EW
231/*
232 * This is all heuristic.
f176f953
EW
233 * wwvisible() doesn't work for tinted windows.
234 * and wwmoveup() doesn't work for transparent windows
235 * (completely or partially).
27b31336
EW
236 * But anything to make it faster.
237 */
fe24a747 238front(w)
f6dc361a
EW
239register struct ww *w;
240{
fe24a747 241 char moved = 0;
4c8ea7ce 242
27b31336 243 if (wwvisible(w))
fe24a747 244 moved = 1;
27b31336
EW
245 else
246 while (w->ww_back != framewin) {
247 wwmoveup(w);
248 moved = 1;
249 }
fe24a747
EW
250 if (moved)
251 reframe();
252}
253
254reframe()
255{
256 register struct ww *w;
257
258 wwunframe(framewin);
259 for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back)
260 if (w->ww_hasframe) {
261 wwframe(w, framewin);
262 labelwin(w);
263 }
f6dc361a
EW
264}
265
4c8ea7ce 266labelwin(w)
f6dc361a
EW
267register struct ww *w;
268{
bb05dfb5
EW
269 int mode = w == selwin ? WWM_REV : 0;
270
271 if (w->ww_id >= 0) {
272 char buf[2];
f6dc361a 273
bb05dfb5
EW
274 buf[0] = w->ww_id + '1';
275 buf[1] = 0;
03e75950 276 wwlabel(w, framewin, 1, buf, mode);
bb05dfb5
EW
277 }
278 if (w->ww_label) {
279 int col;
280
281 if (w->ww_center) {
282 col = (w->ww_w.nc - strlen(w->ww_label)) / 2;
283 col = MAX(3, col);
284 } else
285 col = 3;
03e75950 286 wwlabel(w, framewin, col, w->ww_label, mode);
bb05dfb5 287 }
f6dc361a 288}