xref: /csrg-svn/usr.bin/window/cmd2.c (revision 16313)
113979Sedward #ifndef lint
2*16313Sedward static	char *sccsid = "@(#)cmd2.c	3.29 84/04/08";
313979Sedward #endif
413979Sedward 
513979Sedward #include "defs.h"
613979Sedward 
715675Sedward char *help_shortcmd[] = {
815675Sedward 	"{1-9}   Select window {1-9} and return to conversation mode.",
915675Sedward 	"%{1-9}  Select window {1-9} but stay in command mode.",
1016301Sedward 	"escape  Return to conversation mode without changing window.",
1116301Sedward 	"^^      Return to conversation mode and change to previous window.",
1215675Sedward 	"c{1-9}  Close window {1-9}.",
1315675Sedward 	"w       Open a new window.",
1415675Sedward 	"m{1-9}  Move window {1-9}.",
1515675Sedward 	"M{1-9}  Move window {1-9} to previous position.",
1615675Sedward 	"{^Y^E}  Scroll {up, down} one line",
1715675Sedward 	"{^U^D}  Scroll {up, down} half a window.",
1815675Sedward 	"{^B^F}  Scroll {up, down} a full window.",
1915675Sedward 	"{hjkl}  Move cursor {left, down, up, right}.",
2015675Sedward 	"^L      Redraw screen.",
2115675Sedward 	"^Z      Suspend.",
2215675Sedward 	"q       Quit.",
2315675Sedward 	0
2415675Sedward };
2515675Sedward char *help_longcmd[] = {
2615675Sedward 	":%{1-9}               Select window {1-9}.",
2716301Sedward 	":close {1-9} . . .    Close windows.",
2816301Sedward 	":close all            Close all windows.",
2915675Sedward 	":cursor modes         Set the cursor modes.",
3015675Sedward 	":escape C             Set escape character to C.",
3116301Sedward 	":foreground {1-9} [off]",
3216301Sedward 	"                      Make {1-9} a foreground window.",
3315675Sedward 	":label {1-9} string   Label window {1-9}.",
3416301Sedward 	":list                 List all windows.",
3516301Sedward 	":nline lines          Set the default number of lines",
3616301Sedward 	"                      in window text buffers.",
37*16313Sedward 	":shell string         Set default shell program to ``string.''",
38*16313Sedward 	":source filename      Execute commands in ``filename.''",
3915675Sedward 	":terse [off]          Turn on (or off) terse mode.",
4015845Sedward 	":unset variable       Deallocate ``variable''.",
4116301Sedward 	":variable             List all variables.",
42*16313Sedward 	":window row col nrow ncol [nline label pty frame shell]",
4315675Sedward 	"                      Open a window at ``row'', ``col''",
4415675Sedward 	"                      of size ``nrow'', ``ncol'',",
4515675Sedward 	"                      with ``nline'', and ``label''.",
4616301Sedward 	":write {1-9} string . . .",
4716301Sedward 	"                      Write strings to window {1-9}.",
4815675Sedward 	0
4915675Sedward };
5015675Sedward 
5114408Sedward c_help()
5213979Sedward {
5313979Sedward 	register struct ww *w;
5413979Sedward 
5514665Sedward 	if ((w = openiwin(wwnrow - 3, "Help")) == 0) {
5614857Sedward 		error("Can't open help window: %s.", wwerror());
5713979Sedward 		return;
5814027Sedward 	}
5916309Sedward 	wwprintf(w, "The escape character is %c, which gets you into command mode.\n\n",
6016309Sedward 		escapec);
6115856Sedward 	if (help_print(w, "Short commands", help_shortcmd) >= 0)
6215856Sedward 		(void) help_print(w, "Long commands", help_longcmd);
6314408Sedward 	closeiwin(w);
6413979Sedward }
6513979Sedward 
6615675Sedward help_print(w, name, list)
6715675Sedward register struct ww *w;
6815675Sedward char *name;
6915856Sedward register char **list;
7015675Sedward {
7116116Sedward 	wwprintf(w, "%s:\n\n", name);
7215856Sedward 	while (*list)
7315856Sedward 		switch (more(w, 0)) {
7415856Sedward 		case 0:
7516116Sedward 			wwputs(*list++, w);
7616116Sedward 			wwputc('\n', w);
7715856Sedward 			break;
7815856Sedward 		case 1:
7916116Sedward 			wwprintf(w, "%s: (continued)\n\n", name);
8015856Sedward 			break;
8115856Sedward 		case 2:
8215856Sedward 			return -1;
8315675Sedward 		}
8415856Sedward 	return more(w, 1) == 2 ? -1 : 0;
8515675Sedward }
8615675Sedward 
8714408Sedward c_quit()
8814027Sedward {
8916281Sedward 	char oldterse = terse;
9016281Sedward 
9116281Sedward 	setterse(0);
9216116Sedward 	wwputs("Really quit [yn]? ", cmdwin);
9314408Sedward 	wwcurtowin(cmdwin);
9415872Sedward 	while (wwpeekc() < 0)
9515872Sedward 		wwiomux();
9615872Sedward 	if (wwgetc() == 'y') {
9716116Sedward 		wwputs("Yes", cmdwin);
9814027Sedward 		quit++;
9914027Sedward 	} else
10016312Sedward 		wwputc('\n', cmdwin);
10116281Sedward 	setterse(!quit && oldterse);
10214027Sedward }
103