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