0
|
1 /* TTY-specific Lisp objects.
|
|
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1995, 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 #include <config.h>
|
|
25 #include "lisp.h"
|
|
26
|
|
27 #include "console-tty.h"
|
|
28 #include "insdel.h"
|
|
29 #include "objects-tty.h"
|
|
30
|
|
31 /* An alist mapping from color names to a cons of (FG-STRING, BG-STRING). */
|
|
32 Lisp_Object Vtty_color_alist;
|
|
33 #if 0 /* This stuff doesn't quite work yet */
|
|
34 Lisp_Object Vtty_dynamic_color_fg;
|
|
35 Lisp_Object Vtty_dynamic_color_bg;
|
|
36 #endif
|
|
37
|
20
|
38 DEFUN ("register-tty-color", Fregister_tty_color, 3, 3, 0, /*
|
0
|
39 Register COLOR as a recognized TTY color.
|
|
40 COLOR should be a string.
|
|
41 Strings FG-STRING and BG-STRING should specify the escape sequences to
|
|
42 set the foreground and background to the given color, respectively.
|
20
|
43 */
|
|
44 (color, fg_string, bg_string))
|
0
|
45 {
|
|
46 CHECK_STRING (color);
|
|
47 CHECK_STRING (fg_string);
|
|
48 CHECK_STRING (bg_string);
|
|
49
|
|
50 color = Fintern (color, Qnil);
|
|
51 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
|
|
52 Vtty_color_alist = Fcons (Fcons (color, Fcons (fg_string, bg_string)),
|
|
53 Vtty_color_alist);
|
|
54
|
|
55 return Qnil;
|
|
56 }
|
|
57
|
20
|
58 DEFUN ("unregister-tty-color", Funregister_tty_color, 1, 1, 0, /*
|
0
|
59 Unregister COLOR as a recognized TTY color.
|
20
|
60 */
|
|
61 (color))
|
0
|
62 {
|
|
63 CHECK_STRING (color);
|
|
64
|
|
65 color = Fintern (color, Qnil);
|
|
66 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
|
|
67 return Qnil;
|
|
68 }
|
|
69
|
20
|
70 DEFUN ("find-tty-color", Ffind_tty_color, 1, 1, 0, /*
|
0
|
71 Look up COLOR in the list of registered TTY colors.
|
|
72 If it is found, return a list (FG-STRING BG-STRING) of the escape
|
|
73 sequences used to set the foreground and background to the color, respectively.
|
|
74 If it is not found, return nil.
|
20
|
75 */
|
|
76 (color))
|
0
|
77 {
|
|
78 Lisp_Object result;
|
|
79
|
|
80 CHECK_STRING (color);
|
|
81
|
|
82 result = Fassq (Fintern (color, Qnil), Vtty_color_alist);
|
|
83 if (!NILP (result))
|
|
84 return list2 (Fcar (Fcdr (result)), Fcdr (Fcdr (result)));
|
|
85 else
|
|
86 return Qnil;
|
|
87 }
|
|
88
|
20
|
89 DEFUN ("tty-color-list", Ftty_color_list, 0, 0, 0, /*
|
0
|
90 Return a list of the registered TTY colors.
|
20
|
91 */
|
|
92 ())
|
0
|
93 {
|
|
94 Lisp_Object result = Qnil;
|
|
95 Lisp_Object rest;
|
|
96
|
|
97 LIST_LOOP (rest, Vtty_color_alist)
|
|
98 {
|
|
99 result = Fcons (Fsymbol_name (XCAR (XCAR (rest))), result);
|
|
100 }
|
|
101
|
|
102 return Fnreverse (result);
|
|
103 }
|
|
104
|
|
105 #if 0
|
|
106
|
|
107 /* This approach is too simplistic. The problem is that the
|
|
108 dynamic color settings apply to *all* text in the default color,
|
|
109 not just the text output after the escape sequence has been given. */
|
|
110
|
20
|
111 DEFUN ("set-tty-dynamic-color-specs", Fset_tty_dynamic_color_specs, 2, 2, 0, /*
|
0
|
112 Set the dynamic color specifications for TTY's.
|
|
113 FG and BG should be either nil or vaguely printf-like strings,
|
|
114 where each occurrence of %s is replaced with the color name and each
|
|
115 occurrence of %% is replaced with a single % character.
|
20
|
116 */
|
|
117 (fg, bg))
|
0
|
118 {
|
|
119 if (!NILP (fg))
|
|
120 CHECK_STRING (fg);
|
|
121 if (!NILP (bg))
|
|
122 CHECK_STRING (bg);
|
|
123
|
|
124 Vtty_dynamic_color_fg = fg;
|
|
125 Vtty_dynamic_color_bg = bg;
|
|
126
|
|
127 return Qnil;
|
|
128 }
|
|
129
|
20
|
130 DEFUN ("tty-dynamic-color-specs", Ftty_dynamic_color_specs, 0, 0, 0, /*
|
0
|
131 Return the dynamic color specifications for TTY's as a list of (FG BG).
|
|
132 See `set-tty-dynamic-color-specs'.
|
20
|
133 */
|
|
134 ())
|
0
|
135 {
|
|
136 return list2 (Vtty_dynamic_color_fg, Vtty_dynamic_color_bg);
|
|
137 }
|
|
138
|
|
139 #endif /* 0 */
|
|
140
|
|
141 static int
|
|
142 tty_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name,
|
|
143 Lisp_Object device, Error_behavior errb)
|
|
144 {
|
|
145 Lisp_Object result;
|
|
146
|
|
147 name = Fintern (name, Qnil);
|
|
148 result = assq_no_quit (name, Vtty_color_alist);
|
|
149
|
|
150 if (NILP (result))
|
|
151 {
|
|
152 #if 0
|
|
153 if (!STRINGP (Vtty_dynamic_color_fg)
|
|
154 && !STRINGP (Vtty_dynamic_color_bg))
|
|
155 #endif
|
|
156 return 0;
|
|
157 }
|
|
158
|
|
159 /* Don't allocate the data until we're sure that we will succeed. */
|
|
160 c->data = malloc_type (struct tty_color_instance_data);
|
|
161 COLOR_INSTANCE_TTY_SYMBOL (c) = name;
|
|
162
|
|
163 return 1;
|
|
164 }
|
|
165
|
|
166 static void
|
|
167 tty_mark_color_instance (struct Lisp_Color_Instance *c,
|
|
168 void (*markobj) (Lisp_Object))
|
|
169 {
|
|
170 ((markobj) (COLOR_INSTANCE_TTY_SYMBOL (c)));
|
|
171 }
|
|
172
|
|
173 static void
|
|
174 tty_print_color_instance (struct Lisp_Color_Instance *c,
|
|
175 Lisp_Object printcharfun,
|
|
176 int escapeflag)
|
|
177 {
|
|
178 }
|
|
179
|
|
180 static void
|
|
181 tty_finalize_color_instance (struct Lisp_Color_Instance *c)
|
|
182 {
|
|
183 if (c->data)
|
|
184 xfree (c->data);
|
|
185 }
|
|
186
|
|
187 static int
|
|
188 tty_color_instance_equal (struct Lisp_Color_Instance *c1,
|
|
189 struct Lisp_Color_Instance *c2,
|
|
190 int depth)
|
|
191 {
|
|
192 return (EQ (COLOR_INSTANCE_TTY_SYMBOL (c1),
|
|
193 COLOR_INSTANCE_TTY_SYMBOL (c2)));
|
|
194 }
|
|
195
|
|
196 static unsigned long
|
|
197 tty_color_instance_hash (struct Lisp_Color_Instance *c, int depth)
|
|
198 {
|
|
199 return LISP_HASH (COLOR_INSTANCE_TTY_SYMBOL (c));
|
|
200 }
|
|
201
|
|
202 static int
|
|
203 tty_valid_color_name_p (struct device *d, Lisp_Object color)
|
|
204 {
|
|
205 return (!NILP (assoc_no_quit (Fintern (color, Qnil), Vtty_color_alist)));
|
|
206 #if 0
|
|
207 || STRINGP (Vtty_dynamic_color_fg)
|
|
208 || STRINGP (Vtty_dynamic_color_bg)
|
|
209 #endif
|
|
210 }
|
|
211
|
|
212
|
|
213 static int
|
|
214 tty_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
|
|
215 Lisp_Object device, Error_behavior errb)
|
|
216 {
|
16
|
217 Bufbyte *str = XSTRING_DATA (name);
|
0
|
218 Lisp_Object charset = Qnil;
|
|
219
|
|
220 if (strncmp ((CONST char *) str, "normal", 6))
|
|
221 return 0;
|
|
222 str += 6;
|
|
223 if (*str)
|
|
224 {
|
|
225 return 0;
|
|
226 }
|
|
227
|
|
228 /* Don't allocate the data until we're sure that we will succeed. */
|
|
229 f->data = malloc_type (struct tty_font_instance_data);
|
|
230 FONT_INSTANCE_TTY_CHARSET (f) = charset;
|
16
|
231 f->width = 1;
|
0
|
232
|
|
233 f->proportional_p = 0;
|
|
234 f->ascent = f->height = 1;
|
|
235 f->descent = 0;
|
|
236
|
|
237 return 1;
|
|
238 }
|
|
239
|
|
240 static void
|
|
241 tty_mark_font_instance (struct Lisp_Font_Instance *f,
|
|
242 void (*markobj) (Lisp_Object))
|
|
243 {
|
|
244 ((markobj) (FONT_INSTANCE_TTY_CHARSET (f)));
|
|
245 }
|
|
246
|
|
247 static void
|
|
248 tty_print_font_instance (struct Lisp_Font_Instance *f,
|
|
249 Lisp_Object printcharfun,
|
|
250 int escapeflag)
|
|
251 {
|
|
252 }
|
|
253
|
|
254 static void
|
|
255 tty_finalize_font_instance (struct Lisp_Font_Instance *f)
|
|
256 {
|
|
257 if (f->data)
|
|
258 xfree (f->data);
|
|
259 }
|
|
260
|
|
261 static Lisp_Object
|
|
262 tty_list_fonts (Lisp_Object pattern, Lisp_Object device)
|
|
263 {
|
|
264 return list1 (build_string ("normal"));
|
|
265 }
|
|
266
|
|
267
|
|
268 /************************************************************************/
|
|
269 /* initialization */
|
|
270 /************************************************************************/
|
|
271
|
|
272 void
|
|
273 syms_of_objects_tty (void)
|
|
274 {
|
20
|
275 DEFSUBR (Fregister_tty_color);
|
|
276 DEFSUBR (Funregister_tty_color);
|
|
277 DEFSUBR (Ffind_tty_color);
|
|
278 DEFSUBR (Ftty_color_list);
|
0
|
279 #if 0
|
20
|
280 DEFSUBR (Fset_tty_dynamic_color_specs);
|
|
281 DEFSUBR (Ftty_dynamic_color_specs);
|
0
|
282 #endif
|
|
283 }
|
|
284
|
|
285 void
|
|
286 console_type_create_objects_tty (void)
|
|
287 {
|
|
288 /* object methods */
|
|
289 CONSOLE_HAS_METHOD (tty, initialize_color_instance);
|
|
290 CONSOLE_HAS_METHOD (tty, mark_color_instance);
|
|
291 CONSOLE_HAS_METHOD (tty, print_color_instance);
|
|
292 CONSOLE_HAS_METHOD (tty, finalize_color_instance);
|
|
293 CONSOLE_HAS_METHOD (tty, color_instance_equal);
|
|
294 CONSOLE_HAS_METHOD (tty, color_instance_hash);
|
|
295 CONSOLE_HAS_METHOD (tty, valid_color_name_p);
|
|
296
|
|
297 CONSOLE_HAS_METHOD (tty, initialize_font_instance);
|
|
298 CONSOLE_HAS_METHOD (tty, mark_font_instance);
|
|
299 CONSOLE_HAS_METHOD (tty, print_font_instance);
|
|
300 CONSOLE_HAS_METHOD (tty, finalize_font_instance);
|
|
301 CONSOLE_HAS_METHOD (tty, list_fonts);
|
|
302 }
|
|
303
|
|
304 void
|
|
305 vars_of_objects_tty (void)
|
|
306 {
|
|
307 staticpro (&Vtty_color_alist);
|
|
308 Vtty_color_alist = Qnil;
|
|
309
|
|
310 #if 0
|
|
311 staticpro (&Vtty_dynamic_color_fg);
|
|
312 Vtty_dynamic_color_fg = Qnil;
|
|
313
|
|
314 staticpro (&Vtty_dynamic_color_bg);
|
|
315 Vtty_dynamic_color_bg = Qnil;
|
|
316 #endif
|
|
317 }
|