less -> more
[unix-history] / usr / src / usr.bin / window / cmd.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
60de5df9
EW
16 */
17
46e9ea25 18#ifndef lint
5e8b0e60 19static char sccsid[] = "@(#)cmd.c 3.38 (Berkeley) %G%";
46e9ea25
KB
20#endif /* not lint */
21
f6dc361a 22#include "defs.h"
0e64e422 23#include "char.h"
f6dc361a 24
f6dc361a
EW
25docmd()
26{
27 register char c;
28 register struct ww *w;
ffa20db4 29 char out = 0;
f6dc361a 30
2c279448
EW
31 while (!out && !quit) {
32 if ((c = wwgetc()) < 0) {
33 if (terse)
34 wwsetcursor(0, 0);
35 else {
36 wwputs("Command: ", cmdwin);
37 wwcurtowin(cmdwin);
f6dc361a 38 }
2c279448
EW
39 do
40 wwiomux();
41 while ((c = wwgetc()) < 0);
42 }
43 if (!terse)
44 wwputc('\n', cmdwin);
45 switch (c) {
46 default:
47 if (c != escapec)
48 break;
49 case 'h': case 'j': case 'k': case 'l':
50 case ctrl('y'):
51 case ctrl('e'):
52 case ctrl('u'):
53 case ctrl('d'):
54 case ctrl('b'):
55 case ctrl('f'):
56 case ctrl('s'):
57 case ctrl('q'):
58 case ctrl('['):
59 if (selwin == 0) {
60 error("No window.");
61 continue;
62 }
63 }
64 switch (c) {
65 case '1': case '2': case '3': case '4': case '5':
66 case '6': case '7': case '8': case '9':
67 if ((w = window[c - '1']) == 0) {
68 error("%c: No such window.", c);
86845af3 69 break;
2c279448
EW
70 }
71 setselwin(w);
72 if (checkproc(selwin) >= 0)
73 out = 1;
74 break;
75 case '%':
76 if ((w = getwin()) != 0)
77 setselwin(w);
78 break;
79 case ctrl('^'):
80 if (lastselwin != 0) {
81 setselwin(lastselwin);
86845af3 82 if (checkproc(selwin) >= 0)
ffa20db4 83 out = 1;
2c279448
EW
84 } else
85 error("No previous window.");
86 break;
87 case 'c':
88 if ((w = getwin()) != 0)
89 closewin(w);
90 break;
91 case 'w':
92 c_window();
93 break;
94 case 'm':
95 if ((w = getwin()) != 0)
96 c_move(w);
97 break;
98 case 'M':
99 if ((w = getwin()) != 0)
100 movewin(w, w->ww_alt.t, w->ww_alt.l);
101 break;
102 case 's':
103 if ((w = getwin()) != 0)
104 c_size(w);
105 break;
106 case 'S':
107 if ((w = getwin()) != 0)
108 sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
109 break;
110 case ':':
111 c_colon();
112 break;
113 case 'h':
114 (void) wwwrite(selwin, "\b", 1);
115 break;
116 case 'j':
117 (void) wwwrite(selwin, "\n", 1);
118 break;
119 case 'k':
120 (void) wwwrite(selwin, "\033A", 2);
121 break;
122 case 'l':
123 (void) wwwrite(selwin, "\033C", 2);
124 break;
125 case ctrl('e'):
126 wwscroll(selwin, 1);
127 break;
128 case ctrl('y'):
129 wwscroll(selwin, -1);
130 break;
131 case ctrl('d'):
132 wwscroll(selwin, selwin->ww_w.nr / 2);
133 break;
134 case ctrl('u'):
135 wwscroll(selwin, - selwin->ww_w.nr / 2);
136 break;
137 case ctrl('f'):
138 wwscroll(selwin, selwin->ww_w.nr);
139 break;
140 case ctrl('b'):
141 wwscroll(selwin, - selwin->ww_w.nr);
142 break;
143 case ctrl('s'):
144 stopwin(selwin);
145 break;
146 case ctrl('q'):
147 startwin(selwin);
148 break;
149 case ctrl('l'):
150 wwredraw();
151 break;
152 case '?':
153 c_help();
154 break;
155 case ctrl('['):
156 if (checkproc(selwin) >= 0)
157 out = 1;
158 break;
159 case ctrl('z'):
160 wwsuspend();
161 break;
162 case 'q':
163 c_quit();
164 break;
165 /* debugging stuff */
166 case '&':
167 if (debug) {
168 c_debug();
86845af3 169 break;
2c279448
EW
170 }
171 default:
172 if (c == escapec) {
173 if (checkproc(selwin) >= 0) {
174 (void) write(selwin->ww_pty,
175 &escapec, 1);
176 out = 1;
86845af3 177 }
2c279448
EW
178 } else {
179 if (!terse)
180 wwbell();
181 error("Type ? for help.");
74329e4e 182 }
f6dc361a 183 }
101acab4 184 }
ffa20db4
EW
185 if (!quit)
186 setcmd(0);
f6dc361a
EW
187}
188
189struct ww *
190getwin()
191{
192 register int c;
4c8ea7ce 193 struct ww *w = 0;
f6dc361a 194
101acab4 195 if (!terse)
b1189050 196 wwputs("Which window? ", cmdwin);
f2a77fe1 197 wwcurtowin(cmdwin);
8fa6d94c
EW
198 while ((c = wwgetc()) < 0)
199 wwiomux();
bb05dfb5
EW
200 if (debug && c == 'c')
201 w = cmdwin;
202 else if (debug && c == 'f')
203 w = framewin;
720ae37c
EW
204 else if (debug && c == 'b')
205 w = boxwin;
bb05dfb5
EW
206 else if (c >= '1' && c < NWINDOW + '1')
207 w = window[c - '1'];
2422abab
EW
208 else if (c == '+')
209 w = selwin;
210 else if (c == '-')
211 w = lastselwin;
bb05dfb5 212 if (w == 0)
7ecf4dca 213 wwbell();
101acab4 214 if (!terse)
bf3b96e9 215 wwputc('\n', cmdwin);
f6dc361a
EW
216 return w;
217}
218
86845af3
EW
219checkproc(w)
220struct ww *w;
221{
222 if (w->ww_state != WWS_HASPROC) {
223 error("No process in window.");
224 return -1;
225 }
226 return 0;
227}
ffa20db4
EW
228
229setcmd(new)
230char new;
231{
232 if (new && !incmd) {
233 if (!terse)
234 wwadd(cmdwin, &wwhead);
235 if (selwin != 0)
236 wwcursor(selwin, 1);
237 wwcurwin = 0;
238 } else if (!new && incmd) {
239 if (!terse) {
240 wwdelete(cmdwin);
241 reframe();
242 }
243 if (selwin != 0)
244 wwcursor(selwin, 0);
245 wwcurwin = selwin;
246 }
247 incmd = new;
248}
249
250setterse(new)
251char new;
252{
253 if (incmd)
254 if (new && !terse) {
255 wwdelete(cmdwin);
256 reframe();
257 } else if (!new && terse)
258 wwadd(cmdwin, &wwhead);
259 terse = new;
260}
261
262/*
263 * Set the current window.
264 */
265setselwin(w)
266struct ww *w;
267{
268 if (selwin == w)
269 return;
142f32ee
EW
270 if (selwin != 0)
271 lastselwin = selwin;
272 if ((selwin = w) != 0)
273 front(selwin, 1);
ffa20db4 274}