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