xref: /original-bsd/usr.bin/window/cmd2.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  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[] = "@(#)cmd2.c	8.1 (Berkeley) 06/06/93";
13 #endif /* not lint */
14 
15 #include "defs.h"
16 
17 char *help_shortcmd[] = {
18 	"#       Select window # and return to conversation mode",
19 	"%#      Select window # but stay in command mode",
20 	"escape  Return to conversation mode without changing window",
21 	"^^      Return to conversation mode and change to previous window",
22 	"c#      Close window #",
23 	"w       Open a new window",
24 	"m#      Move window #",
25 	"M#      Move window # to its previous position",
26 	"s#      Change the size of window #",
27 	"S#      Change window # to its previous size",
28 	"^Y      Scroll up one line",
29 	"^E      Scroll down one line",
30 	"^U      Scroll up half a window",
31 	"^D      Scroll down half a window",
32 	"^B      Scroll up a full window",
33 	"^F      Scroll down a full window",
34 	"h       Move cursor left",
35 	"j       Move cursor down",
36 	"k       Move cursor up",
37 	"l       Move cursor right",
38 	"y       Yank",
39 	"p       Put",
40 	"^S      Stop output in current window",
41 	"^Q      Restart output in current window",
42 	"^L      Redraw screen",
43 	"^Z      Suspend",
44 	"q       Quit",
45 	":       Enter a long command",
46 	0
47 };
48 char *help_longcmd[] = {
49 	":alias name string ...  Make `name' an alias for `string ...'",
50 	":alias                  Show all aliases",
51 	":close # ...            Close windows",
52 	":close all              Close all windows",
53 	":cursor modes           Set the cursor modes",
54 	":echo # string ...      Print `string ...' in window #",
55 	":escape c               Set escape character to `c'",
56 	":foreground # flag      Make # a foreground window, if `flag' is true",
57 	":label # string         Set label of window # to `string'",
58 	":list                   List all open windows",
59 	":default_nline lines    Set default window buffer size to `lines'",
60 	":default_shell string ...",
61 	"                        Set default shell to `string ...'",
62 	":default_smooth flag    Set default smooth scroll flag",
63 	":select #               Select window #",
64 	":smooth # flag          Set window # to smooth scroll mode",
65 	":source filename        Execute commands in `filename'",
66 	":terse flag             Set terse mode",
67 	":unalias name           Undefine `name' as an alias",
68 	":unset variable         Deallocate `variable'",
69 	":variable               List all variables",
70 	":window [row col nrow ncol nline label pty frame mapnl keepopen smooth shell]",
71 	"                        Open a window at `row', `col' of size `nrow', `ncol',",
72 	"                        with `nline' lines in the buffer, and `label'",
73 	":write # string ...     Write `string ...' to window # as input",
74 	0
75 };
76 
77 c_help()
78 {
79 	register struct ww *w;
80 
81 	if ((w = openiwin(wwnrow - 3, "Help")) == 0) {
82 		error("Can't open help window: %s.", wwerror());
83 		return;
84 	}
85 	wwprintf(w, "The escape character is %c.\n", escapec);
86 	wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n");
87 	if (help_print(w, "Short commands", help_shortcmd) >= 0)
88 		(void) help_print(w, "Long commands", help_longcmd);
89 	closeiwin(w);
90 }
91 
92 help_print(w, name, list)
93 register struct ww *w;
94 char *name;
95 register char **list;
96 {
97 	wwprintf(w, "%s:\n\n", name);
98 	while (*list)
99 		switch (more(w, 0)) {
100 		case 0:
101 			wwputs(*list++, w);
102 			wwputc('\n', w);
103 			break;
104 		case 1:
105 			wwprintf(w, "%s: (continued)\n\n", name);
106 			break;
107 		case 2:
108 			return -1;
109 		}
110 	return more(w, 1) == 2 ? -1 : 0;
111 }
112 
113 c_quit()
114 {
115 	char oldterse = terse;
116 
117 	setterse(0);
118 	wwputs("Really quit [yn]? ", cmdwin);
119 	wwcurtowin(cmdwin);
120 	while (wwpeekc() < 0)
121 		wwiomux();
122 	if (wwgetc() == 'y') {
123 		wwputs("Yes", cmdwin);
124 		quit++;
125 	} else
126 		wwputc('\n', cmdwin);
127 	setterse(!quit && oldterse);
128 }
129