xref: /csrg-svn/usr.bin/window/cmd2.c (revision 62457)
118733Sedward /*
2*62457Sbostic  * Copyright (c) 1983, 1993
3*62457Sbostic  *	The Regents of the University of California.  All rights reserved.
433514Sbostic  *
542954Sbostic  * This code is derived from software contributed to Berkeley by
642954Sbostic  * Edward Wang at The University of California, Berkeley.
742954Sbostic  *
842835Sbostic  * %sccs.include.redist.c%
918733Sedward  */
1018733Sedward 
1133514Sbostic #ifndef lint
12*62457Sbostic static char sccsid[] = "@(#)cmd2.c	8.1 (Berkeley) 06/06/93";
1333514Sbostic #endif /* not lint */
1433514Sbostic 
1513979Sedward #include "defs.h"
1613979Sedward 
1715675Sedward char *help_shortcmd[] = {
1818668Sedward 	"#       Select window # and return to conversation mode",
1918668Sedward 	"%#      Select window # but stay in command mode",
2018668Sedward 	"escape  Return to conversation mode without changing window",
2118668Sedward 	"^^      Return to conversation mode and change to previous window",
2218668Sedward 	"c#      Close window #",
2318668Sedward 	"w       Open a new window",
2418668Sedward 	"m#      Move window #",
2518668Sedward 	"M#      Move window # to its previous position",
2618668Sedward 	"s#      Change the size of window #",
2718668Sedward 	"S#      Change window # to its previous size",
2818668Sedward 	"^Y      Scroll up one line",
2918668Sedward 	"^E      Scroll down one line",
3018668Sedward 	"^U      Scroll up half a window",
3118668Sedward 	"^D      Scroll down half a window",
3218668Sedward 	"^B      Scroll up a full window",
3318668Sedward 	"^F      Scroll down a full window",
3418668Sedward 	"h       Move cursor left",
3518668Sedward 	"j       Move cursor down",
3618668Sedward 	"k       Move cursor up",
3718668Sedward 	"l       Move cursor right",
3857758Sedward 	"y       Yank",
3957758Sedward 	"p       Put",
4018668Sedward 	"^S      Stop output in current window",
4118668Sedward 	"^Q      Restart output in current window",
4218668Sedward 	"^L      Redraw screen",
4318668Sedward 	"^Z      Suspend",
4418668Sedward 	"q       Quit",
4518668Sedward 	":       Enter a long command",
4615675Sedward 	0
4715675Sedward };
4815675Sedward char *help_longcmd[] = {
4918668Sedward 	":alias name string ...  Make `name' an alias for `string ...'",
5018668Sedward 	":alias                  Show all aliases",
5118668Sedward 	":close # ...            Close windows",
5218668Sedward 	":close all              Close all windows",
5318668Sedward 	":cursor modes           Set the cursor modes",
5418668Sedward 	":echo # string ...      Print `string ...' in window #",
5518668Sedward 	":escape c               Set escape character to `c'",
5618668Sedward 	":foreground # flag      Make # a foreground window, if `flag' is true",
5718668Sedward 	":label # string         Set label of window # to `string'",
5818668Sedward 	":list                   List all open windows",
5935330Sedward 	":default_nline lines    Set default window buffer size to `lines'",
6035330Sedward 	":default_shell string ...",
6135330Sedward 	"                        Set default shell to `string ...'",
6235336Sedward 	":default_smooth flag    Set default smooth scroll flag",
6318668Sedward 	":select #               Select window #",
6431140Sedward 	":smooth # flag          Set window # to smooth scroll mode",
6518668Sedward 	":source filename        Execute commands in `filename'",
6618668Sedward 	":terse flag             Set terse mode",
6718668Sedward 	":unalias name           Undefine `name' as an alias",
6818668Sedward 	":unset variable         Deallocate `variable'",
6918668Sedward 	":variable               List all variables",
7031140Sedward 	":window [row col nrow ncol nline label pty frame mapnl keepopen smooth shell]",
7118668Sedward 	"                        Open a window at `row', `col' of size `nrow', `ncol',",
7218668Sedward 	"                        with `nline' lines in the buffer, and `label'",
7318668Sedward 	":write # string ...     Write `string ...' to window # as input",
7415675Sedward 	0
7515675Sedward };
7615675Sedward 
c_help()7714408Sedward c_help()
7813979Sedward {
7913979Sedward 	register struct ww *w;
8013979Sedward 
8114665Sedward 	if ((w = openiwin(wwnrow - 3, "Help")) == 0) {
8214857Sedward 		error("Can't open help window: %s.", wwerror());
8313979Sedward 		return;
8414027Sedward 	}
8518207Sedward 	wwprintf(w, "The escape character is %c.\n", escapec);
8618668Sedward 	wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n");
8715856Sedward 	if (help_print(w, "Short commands", help_shortcmd) >= 0)
8815856Sedward 		(void) help_print(w, "Long commands", help_longcmd);
8914408Sedward 	closeiwin(w);
9013979Sedward }
9113979Sedward 
help_print(w,name,list)9215675Sedward help_print(w, name, list)
9315675Sedward register struct ww *w;
9415675Sedward char *name;
9515856Sedward register char **list;
9615675Sedward {
9716116Sedward 	wwprintf(w, "%s:\n\n", name);
9815856Sedward 	while (*list)
9915856Sedward 		switch (more(w, 0)) {
10015856Sedward 		case 0:
10116116Sedward 			wwputs(*list++, w);
10216116Sedward 			wwputc('\n', w);
10315856Sedward 			break;
10415856Sedward 		case 1:
10516116Sedward 			wwprintf(w, "%s: (continued)\n\n", name);
10615856Sedward 			break;
10715856Sedward 		case 2:
10815856Sedward 			return -1;
10915675Sedward 		}
11015856Sedward 	return more(w, 1) == 2 ? -1 : 0;
11115675Sedward }
11215675Sedward 
c_quit()11314408Sedward c_quit()
11414027Sedward {
11516281Sedward 	char oldterse = terse;
11616281Sedward 
11716281Sedward 	setterse(0);
11816116Sedward 	wwputs("Really quit [yn]? ", cmdwin);
11914408Sedward 	wwcurtowin(cmdwin);
12015872Sedward 	while (wwpeekc() < 0)
12115872Sedward 		wwiomux();
12215872Sedward 	if (wwgetc() == 'y') {
12316116Sedward 		wwputs("Yes", cmdwin);
12414027Sedward 		quit++;
12514027Sedward 	} else
12616312Sedward 		wwputc('\n', cmdwin);
12716281Sedward 	setterse(!quit && oldterse);
12814027Sedward }
129