xref: /dragonfly/usr.bin/window/cmd2.c (revision 0db87cb7)
1 /*	@(#)cmd2.c	8.1 (Berkeley) 6/6/93	*/
2 /*	$NetBSD: cmd2.c,v 1.7 2009/04/14 08:50:06 lukem Exp $	*/
3 
4 /*
5  * Copyright (c) 1983, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Edward Wang at The University of California, Berkeley.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include "defs.h"
37 
38 const char *help_shortcmd[] = {
39 	"#       Select window # and return to conversation mode",
40 	"%#      Select window # but stay in command mode",
41 	"escape  Return to conversation mode without changing window",
42 	"^^      Return to conversation mode and change to previous window",
43 	"c#      Close window #",
44 	"w       Open a new window",
45 	"m#      Move window #",
46 	"M#      Move window # to its previous position",
47 	"s#      Change the size of window #",
48 	"S#      Change window # to its previous size",
49 	"^Y      Scroll up one line",
50 	"^E      Scroll down one line",
51 	"^U      Scroll up half a window",
52 	"^D      Scroll down half a window",
53 	"^B      Scroll up a full window",
54 	"^F      Scroll down a full window",
55 	"h       Move cursor left",
56 	"j       Move cursor down",
57 	"k       Move cursor up",
58 	"l       Move cursor right",
59 	"y       Yank",
60 	"p       Put",
61 	"^S      Stop output in current window",
62 	"^Q      Restart output in current window",
63 	"^L      Redraw screen",
64 	"^Z      Suspend",
65 	"q       Quit",
66 	":       Enter a long command",
67 	0
68 };
69 
70 const char *help_longcmd[] = {
71 	":alias name string ...  Make `name' an alias for `string ...'",
72 	":alias                  Show all aliases",
73 	":close # ...            Close windows",
74 	":close all              Close all windows",
75 	":cursor modes           Set the cursor modes",
76 	":echo # string ...      Print `string ...' in window #",
77 	":escape c               Set escape character to `c'",
78 	":foreground # flag      Make # a foreground window, if `flag' is true",
79 	":label # string         Set label of window # to `string'",
80 	":list                   List all open windows",
81 	":default_nline lines    Set default window buffer size to `lines'",
82 	":default_shell string ...",
83 	"                        Set default shell to `string ...'",
84 	":default_smooth flag    Set default smooth scroll flag",
85 	":select #               Select window #",
86 	":smooth # flag          Set window # to smooth scroll mode",
87 	":source filename        Execute commands in `filename'",
88 	":terse flag             Set terse mode",
89 	":unalias name           Undefine `name' as an alias",
90 	":unset variable         Deallocate `variable'",
91 	":variable               List all variables",
92 	":window [row col nrow ncol nline label pty frame mapnl keepopen smooth shell]",
93 	"                        Open a window at `row', `col' of size `nrow', `ncol',",
94 	"                        with `nline' lines in the buffer, and `label'",
95 	":write # string ...     Write `string ...' to window # as input",
96 	0
97 };
98 
99 int	help_print(struct ww *, const char *, const char **);
100 
101 void
102 c_help(void)
103 {
104 	struct ww *w;
105 
106 	if ((w = openiwin(wwnrow - 3, "Help")) == NULL) {
107 		error("Can't open help window: %s.", wwerror());
108 		return;
109 	}
110 	wwprintf(w, "The escape character is %c.\n", escapec);
111 	wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n");
112 	if (help_print(w, "Short commands", help_shortcmd) >= 0)
113 		(void) help_print(w, "Long commands", help_longcmd);
114 	closeiwin(w);
115 }
116 
117 int
118 help_print(struct ww *w, const char *name, const char **list)
119 {
120 	wwprintf(w, "%s:\n\n", name);
121 	while (*list)
122 		switch (more(w, 0)) {
123 		case 0:
124 			wwputs(*list++, w);
125 			wwputc('\n', w);
126 			break;
127 		case 1:
128 			wwprintf(w, "%s: (continued)\n\n", name);
129 			break;
130 		case 2:
131 			return -1;
132 		}
133 	return more(w, 1) == 2 ? -1 : 0;
134 }
135 
136 void
137 c_quit(void)
138 {
139 	char oldterse = terse;
140 
141 	setterse(0);
142 	wwputs("Really quit [yn]? ", cmdwin);
143 	wwcurtowin(cmdwin);
144 	while (wwpeekc() < 0)
145 		wwiomux();
146 	if (wwgetc() == 'y') {
147 		wwputs("Yes", cmdwin);
148 		quit++;
149 	} else
150 		wwputc('\n', cmdwin);
151 	setterse(!quit && oldterse);
152 }
153