xref: /csrg-svn/usr.bin/window/cmd2.c (revision 18668)
113979Sedward #ifndef lint
2*18668Sedward static char sccsid[] = "@(#)cmd2.c	3.32 04/22/85";
313979Sedward #endif
413979Sedward 
513979Sedward #include "defs.h"
613979Sedward 
715675Sedward char *help_shortcmd[] = {
8*18668Sedward 	"#       Select window # and return to conversation mode",
9*18668Sedward 	"%#      Select window # but stay in command mode",
10*18668Sedward 	"escape  Return to conversation mode without changing window",
11*18668Sedward 	"^^      Return to conversation mode and change to previous window",
12*18668Sedward 	"c#      Close window #",
13*18668Sedward 	"w       Open a new window",
14*18668Sedward 	"m#      Move window #",
15*18668Sedward 	"M#      Move window # to its previous position",
16*18668Sedward 	"s#      Change the size of window #",
17*18668Sedward 	"S#      Change window # to its previous size",
18*18668Sedward 	"^Y      Scroll up one line",
19*18668Sedward 	"^E      Scroll down one line",
20*18668Sedward 	"^U      Scroll up half a window",
21*18668Sedward 	"^D      Scroll down half a window",
22*18668Sedward 	"^B      Scroll up a full window",
23*18668Sedward 	"^F      Scroll down a full window",
24*18668Sedward 	"h       Move cursor left",
25*18668Sedward 	"j       Move cursor down",
26*18668Sedward 	"k       Move cursor up",
27*18668Sedward 	"l       Move cursor right",
28*18668Sedward 	"^S      Stop output in current window",
29*18668Sedward 	"^Q      Restart output in current window",
30*18668Sedward 	"^L      Redraw screen",
31*18668Sedward 	"^Z      Suspend",
32*18668Sedward 	"q       Quit",
33*18668Sedward 	":       Enter a long command",
3415675Sedward 	0
3515675Sedward };
3615675Sedward char *help_longcmd[] = {
37*18668Sedward 	":alias name string ...  Make `name' an alias for `string ...'",
38*18668Sedward 	":alias                  Show all aliases",
39*18668Sedward 	":close # ...            Close windows",
40*18668Sedward 	":close all              Close all windows",
41*18668Sedward 	":cursor modes           Set the cursor modes",
42*18668Sedward 	":echo # string ...      Print `string ...' in window #",
43*18668Sedward 	":escape c               Set escape character to `c'",
44*18668Sedward 	":foreground # flag      Make # a foreground window, if `flag' is true",
45*18668Sedward 	":label # string         Set label of window # to `string'",
46*18668Sedward 	":list                   List all open windows",
47*18668Sedward 	":nline lines            Set default window buffer size to `lines'",
48*18668Sedward 	":select #               Select window #",
49*18668Sedward 	":shell string ...       Set default shell program to `string ...'",
50*18668Sedward 	":source filename        Execute commands in `filename'",
51*18668Sedward 	":terse flag             Set terse mode",
52*18668Sedward 	":unalias name           Undefine `name' as an alias",
53*18668Sedward 	":unset variable         Deallocate `variable'",
54*18668Sedward 	":variable               List all variables",
5516313Sedward 	":window row col nrow ncol [nline label pty frame shell]",
56*18668Sedward 	"                        Open a window at `row', `col' of size `nrow', `ncol',",
57*18668Sedward 	"                        with `nline' lines in the buffer, and `label'",
58*18668Sedward 	":write # string ...     Write `string ...' to window # as input",
5915675Sedward 	0
6015675Sedward };
6115675Sedward 
6214408Sedward c_help()
6313979Sedward {
6413979Sedward 	register struct ww *w;
6513979Sedward 
6614665Sedward 	if ((w = openiwin(wwnrow - 3, "Help")) == 0) {
6714857Sedward 		error("Can't open help window: %s.", wwerror());
6813979Sedward 		return;
6914027Sedward 	}
7018207Sedward 	wwprintf(w, "The escape character is %c.\n", escapec);
71*18668Sedward 	wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n");
7215856Sedward 	if (help_print(w, "Short commands", help_shortcmd) >= 0)
7315856Sedward 		(void) help_print(w, "Long commands", help_longcmd);
7414408Sedward 	closeiwin(w);
7513979Sedward }
7613979Sedward 
7715675Sedward help_print(w, name, list)
7815675Sedward register struct ww *w;
7915675Sedward char *name;
8015856Sedward register char **list;
8115675Sedward {
8216116Sedward 	wwprintf(w, "%s:\n\n", name);
8315856Sedward 	while (*list)
8415856Sedward 		switch (more(w, 0)) {
8515856Sedward 		case 0:
8616116Sedward 			wwputs(*list++, w);
8716116Sedward 			wwputc('\n', w);
8815856Sedward 			break;
8915856Sedward 		case 1:
9016116Sedward 			wwprintf(w, "%s: (continued)\n\n", name);
9115856Sedward 			break;
9215856Sedward 		case 2:
9315856Sedward 			return -1;
9415675Sedward 		}
9515856Sedward 	return more(w, 1) == 2 ? -1 : 0;
9615675Sedward }
9715675Sedward 
9814408Sedward c_quit()
9914027Sedward {
10016281Sedward 	char oldterse = terse;
10116281Sedward 
10216281Sedward 	setterse(0);
10316116Sedward 	wwputs("Really quit [yn]? ", cmdwin);
10414408Sedward 	wwcurtowin(cmdwin);
10515872Sedward 	while (wwpeekc() < 0)
10615872Sedward 		wwiomux();
10715872Sedward 	if (wwgetc() == 'y') {
10816116Sedward 		wwputs("Yes", cmdwin);
10914027Sedward 		quit++;
11014027Sedward 	} else
11116312Sedward 		wwputc('\n', cmdwin);
11216281Sedward 	setterse(!quit && oldterse);
11314027Sedward }
114