1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Edward Wang at The University of California, Berkeley. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)cmd.c 3.41 (Berkeley) 08/16/92"; 13 #endif /* not lint */ 14 15 #include "defs.h" 16 #include "char.h" 17 18 docmd() 19 { 20 register char c; 21 register struct ww *w; 22 char out = 0; 23 24 while (!out && !quit) { 25 if ((c = wwgetc()) < 0) { 26 if (terse) 27 wwsetcursor(0, 0); 28 else { 29 wwputs("Command: ", cmdwin); 30 wwcurtowin(cmdwin); 31 } 32 do 33 wwiomux(); 34 while ((c = wwgetc()) < 0); 35 } 36 if (!terse) 37 wwputc('\n', cmdwin); 38 switch (c) { 39 default: 40 if (c != escapec) 41 break; 42 case 'h': case 'j': case 'k': case 'l': 43 case 'y': case 'p': 44 case ctrl('y'): 45 case ctrl('e'): 46 case ctrl('u'): 47 case ctrl('d'): 48 case ctrl('b'): 49 case ctrl('f'): 50 case ctrl('s'): 51 case ctrl('q'): 52 case ctrl('['): 53 if (selwin == 0) { 54 error("No window."); 55 continue; 56 } 57 } 58 switch (c) { 59 case '1': case '2': case '3': case '4': case '5': 60 case '6': case '7': case '8': case '9': 61 if ((w = window[c - '1']) == 0) { 62 error("%c: No such window.", c); 63 break; 64 } 65 setselwin(w); 66 if (checkproc(selwin) >= 0) 67 out = 1; 68 break; 69 case '%': 70 if ((w = getwin()) != 0) 71 setselwin(w); 72 break; 73 case ctrl('^'): 74 if (lastselwin != 0) { 75 setselwin(lastselwin); 76 if (checkproc(selwin) >= 0) 77 out = 1; 78 } else 79 error("No previous window."); 80 break; 81 case 'c': 82 if ((w = getwin()) != 0) 83 closewin(w); 84 break; 85 case 'w': 86 c_window(); 87 break; 88 case 'm': 89 if ((w = getwin()) != 0) 90 c_move(w); 91 break; 92 case 'M': 93 if ((w = getwin()) != 0) 94 movewin(w, w->ww_alt.t, w->ww_alt.l); 95 break; 96 case 's': 97 if ((w = getwin()) != 0) 98 c_size(w); 99 break; 100 case 'S': 101 if ((w = getwin()) != 0) 102 sizewin(w, w->ww_alt.nr, w->ww_alt.nc); 103 break; 104 case 'y': 105 c_yank(); 106 break; 107 case 'p': 108 c_put(); 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(); 169 break; 170 } 171 default: 172 if (c == escapec) { 173 if (checkproc(selwin) >= 0) { 174 (void) write(selwin->ww_pty, 175 &escapec, 1); 176 out = 1; 177 } 178 } else { 179 if (!terse) 180 wwbell(); 181 error("Type ? for help."); 182 } 183 } 184 } 185 if (!quit) 186 setcmd(0); 187 } 188 189 struct ww * 190 getwin() 191 { 192 register int c; 193 struct ww *w = 0; 194 195 if (!terse) 196 wwputs("Which window? ", cmdwin); 197 wwcurtowin(cmdwin); 198 while ((c = wwgetc()) < 0) 199 wwiomux(); 200 if (debug && c == 'c') 201 w = cmdwin; 202 else if (debug && c == 'f') 203 w = framewin; 204 else if (debug && c == 'b') 205 w = boxwin; 206 else if (c >= '1' && c < NWINDOW + '1') 207 w = window[c - '1']; 208 else if (c == '+') 209 w = selwin; 210 else if (c == '-') 211 w = lastselwin; 212 if (w == 0) 213 wwbell(); 214 if (!terse) 215 wwputc('\n', cmdwin); 216 return w; 217 } 218 219 checkproc(w) 220 struct ww *w; 221 { 222 if (w->ww_state != WWS_HASPROC) { 223 error("No process in window."); 224 return -1; 225 } 226 return 0; 227 } 228 229 setcmd(new) 230 char 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 250 setterse(new) 251 char 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 */ 265 setselwin(w) 266 struct ww *w; 267 { 268 if (selwin == w) 269 return; 270 if (selwin != 0) 271 lastselwin = selwin; 272 if ((selwin = w) != 0) 273 front(selwin, 1); 274 } 275