wsemul_vt100_keys.c revision 1.3.14.2 1 /* $NetBSD: wsemul_vt100_keys.c,v 1.3.14.2 2001/11/14 19:16:26 nathanw Exp $ */
2
3 /*
4 * Copyright (c) 1998
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project
18 * by Matthias Drochner.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_keys.c,v 1.3.14.2 2001/11/14 19:16:26 nathanw Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40
41 #include <dev/wscons/wsdisplayvar.h>
42 #include <dev/wscons/wsksymvar.h>
43 #include <dev/wscons/wsksymdef.h>
44 #include <dev/wscons/wsemul_vt100var.h>
45
46 static char *vt100_fkeys[] = {
47 "\033[11~", /* F1 */
48 "\033[12~",
49 "\033[13~", /* F1-F5 normally don't send codes */
50 "\033[14~",
51 "\033[15~", /* F5 */
52 "\033[17~", /* F6 */
53 "\033[18~",
54 "\033[19~",
55 "\033[20~",
56 "\033[21~",
57 "\033[23~", /* VT100: ESC */
58 "\033[24~", /* VT100: BS */
59 "\033[25~", /* VT100: LF */
60 "\033[26~",
61 "\033[28~", /* help */
62 "\033[29~", /* do */
63 "\033[31~",
64 "\033[32~",
65 "\033[33~",
66 "\033[34~", /* F20 */
67 };
68
69 static char *vt100_pfkeys[] = {
70 "\033OP", /* PF1 */
71 "\033OQ",
72 "\033OR",
73 "\033OS", /* PF4 */
74 };
75
76 static char *vt100_numpad[] = {
77 "\033Op", /* KP 0 */
78 "\033Oq", /* KP 1 */
79 "\033Or", /* KP 2 */
80 "\033Os", /* KP 3 */
81 "\033Ot", /* KP 4 */
82 "\033Ou", /* KP 5 */
83 "\033Ov", /* KP 6 */
84 "\033Ow", /* KP 7 */
85 "\033Ox", /* KP 8 */
86 "\033Oy", /* KP 9 */
87 };
88
89 int
90 wsemul_vt100_translate(void *cookie, keysym_t in, char **out)
91 {
92 struct wsemul_vt100_emuldata *edp = cookie;
93 static char c;
94
95 if (in >= KS_f1 && in <= KS_f20) {
96 *out = vt100_fkeys[in - KS_f1];
97 return (5);
98 }
99 if (in >= KS_F1 && in <= KS_F20) {
100 *out = vt100_fkeys[in - KS_F1];
101 return (5);
102 }
103 if (in >= KS_KP_F1 && in <= KS_KP_F4) {
104 *out = vt100_pfkeys[in - KS_KP_F1];
105 return (3);
106 }
107 if (edp->flags & VTFL_APPLKEYPAD) {
108 if (in >= KS_KP_0 && in <= KS_KP_9) {
109 *out = vt100_numpad[in - KS_KP_0];
110 return (3);
111 }
112 switch (in) {
113 case KS_KP_Tab:
114 *out = "\033OI";
115 return (3);
116 case KS_KP_Enter:
117 *out = "\033OM";
118 return (3);
119 case KS_KP_Multiply:
120 *out = "\033Oj";
121 return (3);
122 case KS_KP_Add:
123 *out = "\033Ok";
124 return (3);
125 case KS_KP_Separator:
126 *out = "\033Ol";
127 return (3);
128 case KS_KP_Subtract:
129 *out = "\033Om";
130 return (3);
131 case KS_KP_Decimal:
132 *out = "\033On";
133 return (3);
134 case KS_KP_Divide:
135 *out = "\033Oo";
136 return (3);
137 }
138 } else {
139 if (!(in & 0x80)) {
140 c = in & 0xff; /* turn into ASCII */
141 *out = &c;
142 return (1);
143 }
144 }
145 switch (in) {
146 case KS_Help:
147 *out = vt100_fkeys[15 - 1];
148 return (5);
149 case KS_Execute: /* "Do" */
150 *out = vt100_fkeys[16 - 1];
151 return (5);
152 case KS_Find:
153 *out = "\033[1~";
154 return (4);
155 case KS_Insert:
156 case KS_KP_Insert:
157 *out = "\033[2~";
158 return (4);
159 case KS_KP_Delete:
160 *out = "\033[3~";
161 return (4);
162 case KS_Select:
163 *out = "\033[4~";
164 return (4);
165 case KS_Prior:
166 case KS_KP_Prior:
167 *out = "\033[5~";
168 return (4);
169 case KS_Next:
170 case KS_KP_Next:
171 *out = "\033[6~";
172 return (4);
173 case KS_Home:
174 case KS_KP_Home:
175 *out = "\033[7~";
176 return (4);
177 case KS_End:
178 case KS_KP_End:
179 *out = "\033[8~";
180 return (4);
181 case KS_Up:
182 case KS_KP_Up:
183 if (edp->flags & VTFL_APPLCURSOR)
184 *out = "\033OA";
185 else
186 *out = "\033[A";
187 return (3);
188 case KS_Down:
189 case KS_KP_Down:
190 if (edp->flags & VTFL_APPLCURSOR)
191 *out = "\033OB";
192 else
193 *out = "\033[B";
194 return (3);
195 case KS_Left:
196 case KS_KP_Left:
197 if (edp->flags & VTFL_APPLCURSOR)
198 *out = "\033OD";
199 else
200 *out = "\033[D";
201 return (3);
202 case KS_Right:
203 case KS_KP_Right:
204 if (edp->flags & VTFL_APPLCURSOR)
205 *out = "\033OC";
206 else
207 *out = "\033[C";
208 return (3);
209 }
210 return (0);
211 }
212