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"
|
70
|
30 #ifdef MULE
|
|
31 #include "device.h"
|
|
32 #include "mule-charset.h"
|
|
33 #endif
|
0
|
34
|
|
35 /* An alist mapping from color names to a cons of (FG-STRING, BG-STRING). */
|
|
36 Lisp_Object Vtty_color_alist;
|
|
37 #if 0 /* This stuff doesn't quite work yet */
|
|
38 Lisp_Object Vtty_dynamic_color_fg;
|
|
39 Lisp_Object Vtty_dynamic_color_bg;
|
|
40 #endif
|
|
41
|
20
|
42 DEFUN ("register-tty-color", Fregister_tty_color, 3, 3, 0, /*
|
0
|
43 Register COLOR as a recognized TTY color.
|
|
44 COLOR should be a string.
|
|
45 Strings FG-STRING and BG-STRING should specify the escape sequences to
|
|
46 set the foreground and background to the given color, respectively.
|
20
|
47 */
|
|
48 (color, fg_string, bg_string))
|
0
|
49 {
|
|
50 CHECK_STRING (color);
|
|
51 CHECK_STRING (fg_string);
|
|
52 CHECK_STRING (bg_string);
|
|
53
|
|
54 color = Fintern (color, Qnil);
|
|
55 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
|
|
56 Vtty_color_alist = Fcons (Fcons (color, Fcons (fg_string, bg_string)),
|
|
57 Vtty_color_alist);
|
|
58
|
|
59 return Qnil;
|
|
60 }
|
|
61
|
20
|
62 DEFUN ("unregister-tty-color", Funregister_tty_color, 1, 1, 0, /*
|
0
|
63 Unregister COLOR as a recognized TTY color.
|
20
|
64 */
|
|
65 (color))
|
0
|
66 {
|
|
67 CHECK_STRING (color);
|
|
68
|
|
69 color = Fintern (color, Qnil);
|
|
70 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
|
|
71 return Qnil;
|
|
72 }
|
|
73
|
20
|
74 DEFUN ("find-tty-color", Ffind_tty_color, 1, 1, 0, /*
|
0
|
75 Look up COLOR in the list of registered TTY colors.
|
|
76 If it is found, return a list (FG-STRING BG-STRING) of the escape
|
|
77 sequences used to set the foreground and background to the color, respectively.
|
|
78 If it is not found, return nil.
|
20
|
79 */
|
|
80 (color))
|
0
|
81 {
|
|
82 Lisp_Object result;
|
|
83
|
|
84 CHECK_STRING (color);
|
|
85
|
|
86 result = Fassq (Fintern (color, Qnil), Vtty_color_alist);
|
|
87 if (!NILP (result))
|
|
88 return list2 (Fcar (Fcdr (result)), Fcdr (Fcdr (result)));
|
|
89 else
|
|
90 return Qnil;
|
|
91 }
|
|
92
|
20
|
93 DEFUN ("tty-color-list", Ftty_color_list, 0, 0, 0, /*
|
0
|
94 Return a list of the registered TTY colors.
|
20
|
95 */
|
|
96 ())
|
0
|
97 {
|
|
98 Lisp_Object result = Qnil;
|
|
99 Lisp_Object rest;
|
|
100
|
|
101 LIST_LOOP (rest, Vtty_color_alist)
|
|
102 {
|
|
103 result = Fcons (Fsymbol_name (XCAR (XCAR (rest))), result);
|
|
104 }
|
|
105
|
|
106 return Fnreverse (result);
|
|
107 }
|
|
108
|
|
109 #if 0
|
|
110
|
|
111 /* This approach is too simplistic. The problem is that the
|
|
112 dynamic color settings apply to *all* text in the default color,
|
|
113 not just the text output after the escape sequence has been given. */
|
|
114
|
20
|
115 DEFUN ("set-tty-dynamic-color-specs", Fset_tty_dynamic_color_specs, 2, 2, 0, /*
|
0
|
116 Set the dynamic color specifications for TTY's.
|
|
117 FG and BG should be either nil or vaguely printf-like strings,
|
|
118 where each occurrence of %s is replaced with the color name and each
|
|
119 occurrence of %% is replaced with a single % character.
|
20
|
120 */
|
|
121 (fg, bg))
|
0
|
122 {
|
|
123 if (!NILP (fg))
|
|
124 CHECK_STRING (fg);
|
|
125 if (!NILP (bg))
|
|
126 CHECK_STRING (bg);
|
|
127
|
|
128 Vtty_dynamic_color_fg = fg;
|
|
129 Vtty_dynamic_color_bg = bg;
|
|
130
|
|
131 return Qnil;
|
|
132 }
|
|
133
|
20
|
134 DEFUN ("tty-dynamic-color-specs", Ftty_dynamic_color_specs, 0, 0, 0, /*
|
0
|
135 Return the dynamic color specifications for TTY's as a list of (FG BG).
|
|
136 See `set-tty-dynamic-color-specs'.
|
20
|
137 */
|
|
138 ())
|
0
|
139 {
|
|
140 return list2 (Vtty_dynamic_color_fg, Vtty_dynamic_color_bg);
|
|
141 }
|
|
142
|
|
143 #endif /* 0 */
|
|
144
|
|
145 static int
|
412
|
146 tty_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name,
|
0
|
147 Lisp_Object device, Error_behavior errb)
|
|
148 {
|
|
149 Lisp_Object result;
|
|
150
|
|
151 name = Fintern (name, Qnil);
|
|
152 result = assq_no_quit (name, Vtty_color_alist);
|
|
153
|
|
154 if (NILP (result))
|
|
155 {
|
|
156 #if 0
|
|
157 if (!STRINGP (Vtty_dynamic_color_fg)
|
|
158 && !STRINGP (Vtty_dynamic_color_bg))
|
|
159 #endif
|
|
160 return 0;
|
|
161 }
|
|
162
|
|
163 /* Don't allocate the data until we're sure that we will succeed. */
|
185
|
164 c->data = xnew (struct tty_color_instance_data);
|
0
|
165 COLOR_INSTANCE_TTY_SYMBOL (c) = name;
|
|
166
|
|
167 return 1;
|
|
168 }
|
|
169
|
|
170 static void
|
424
|
171 tty_mark_color_instance (struct Lisp_Color_Instance *c)
|
0
|
172 {
|
424
|
173 mark_object (COLOR_INSTANCE_TTY_SYMBOL (c));
|
0
|
174 }
|
|
175
|
|
176 static void
|
412
|
177 tty_print_color_instance (struct Lisp_Color_Instance *c,
|
0
|
178 Lisp_Object printcharfun,
|
|
179 int escapeflag)
|
|
180 {
|
|
181 }
|
|
182
|
|
183 static void
|
412
|
184 tty_finalize_color_instance (struct Lisp_Color_Instance *c)
|
0
|
185 {
|
|
186 if (c->data)
|
|
187 xfree (c->data);
|
|
188 }
|
|
189
|
|
190 static int
|
412
|
191 tty_color_instance_equal (struct Lisp_Color_Instance *c1,
|
|
192 struct Lisp_Color_Instance *c2,
|
0
|
193 int depth)
|
|
194 {
|
|
195 return (EQ (COLOR_INSTANCE_TTY_SYMBOL (c1),
|
|
196 COLOR_INSTANCE_TTY_SYMBOL (c2)));
|
|
197 }
|
|
198
|
|
199 static unsigned long
|
412
|
200 tty_color_instance_hash (struct Lisp_Color_Instance *c, int depth)
|
0
|
201 {
|
|
202 return LISP_HASH (COLOR_INSTANCE_TTY_SYMBOL (c));
|
|
203 }
|
|
204
|
|
205 static int
|
|
206 tty_valid_color_name_p (struct device *d, Lisp_Object color)
|
|
207 {
|
|
208 return (!NILP (assoc_no_quit (Fintern (color, Qnil), Vtty_color_alist)));
|
|
209 #if 0
|
|
210 || STRINGP (Vtty_dynamic_color_fg)
|
|
211 || STRINGP (Vtty_dynamic_color_bg)
|
|
212 #endif
|
|
213 }
|
|
214
|
|
215
|
|
216 static int
|
412
|
217 tty_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
|
0
|
218 Lisp_Object device, Error_behavior errb)
|
|
219 {
|
16
|
220 Bufbyte *str = XSTRING_DATA (name);
|
0
|
221 Lisp_Object charset = Qnil;
|
|
222
|
412
|
223 if (strncmp ((CONST char *) str, "normal", 6))
|
0
|
224 return 0;
|
|
225 str += 6;
|
|
226 if (*str)
|
|
227 {
|
70
|
228 #ifdef MULE
|
|
229 if (*str != '/')
|
|
230 return 0;
|
|
231 str++;
|
412
|
232 charset = Ffind_charset (intern ((CONST char *) str));
|
70
|
233 if (NILP (charset))
|
|
234 return 0;
|
|
235 #else
|
0
|
236 return 0;
|
70
|
237 #endif
|
0
|
238 }
|
|
239
|
|
240 /* Don't allocate the data until we're sure that we will succeed. */
|
185
|
241 f->data = xnew (struct tty_font_instance_data);
|
0
|
242 FONT_INSTANCE_TTY_CHARSET (f) = charset;
|
70
|
243 #ifdef MULE
|
|
244 if (CHARSETP (charset))
|
|
245 f->width = XCHARSET_COLUMNS (charset);
|
|
246 else
|
|
247 #endif
|
16
|
248 f->width = 1;
|
0
|
249
|
|
250 f->proportional_p = 0;
|
|
251 f->ascent = f->height = 1;
|
|
252 f->descent = 0;
|
|
253
|
|
254 return 1;
|
|
255 }
|
|
256
|
|
257 static void
|
424
|
258 tty_mark_font_instance (struct Lisp_Font_Instance *f)
|
0
|
259 {
|
424
|
260 mark_object (FONT_INSTANCE_TTY_CHARSET (f));
|
0
|
261 }
|
|
262
|
|
263 static void
|
412
|
264 tty_print_font_instance (struct Lisp_Font_Instance *f,
|
0
|
265 Lisp_Object printcharfun,
|
|
266 int escapeflag)
|
|
267 {
|
|
268 }
|
|
269
|
|
270 static void
|
412
|
271 tty_finalize_font_instance (struct Lisp_Font_Instance *f)
|
0
|
272 {
|
|
273 if (f->data)
|
|
274 xfree (f->data);
|
|
275 }
|
|
276
|
|
277 static Lisp_Object
|
|
278 tty_list_fonts (Lisp_Object pattern, Lisp_Object device)
|
|
279 {
|
|
280 return list1 (build_string ("normal"));
|
|
281 }
|
|
282
|
70
|
283 #ifdef MULE
|
|
284
|
|
285 static int
|
|
286 tty_font_spec_matches_charset (struct device *d, Lisp_Object charset,
|
412
|
287 CONST Bufbyte *nonreloc, Lisp_Object reloc,
|
70
|
288 Bytecount offset, Bytecount length)
|
|
289 {
|
412
|
290 CONST Bufbyte *the_nonreloc = nonreloc;
|
185
|
291
|
70
|
292 if (!the_nonreloc)
|
|
293 the_nonreloc = XSTRING_DATA (reloc);
|
|
294 fixup_internal_substring (nonreloc, reloc, offset, &length);
|
|
295 the_nonreloc += offset;
|
185
|
296
|
70
|
297 if (UNBOUNDP (charset))
|
|
298 return !memchr (the_nonreloc, '/', length);
|
412
|
299 the_nonreloc = (CONST Bufbyte *) memchr (the_nonreloc, '/', length);
|
70
|
300 if (!the_nonreloc)
|
|
301 return 0;
|
|
302 the_nonreloc++;
|
|
303 {
|
412
|
304 struct Lisp_String *s = symbol_name (XSYMBOL (XCHARSET_NAME (charset)));
|
|
305 return !strcmp ((CONST char *) the_nonreloc,
|
|
306 (CONST char *) string_data (s));
|
70
|
307 }
|
|
308 }
|
|
309
|
|
310 /* find a font spec that matches font spec FONT and also matches
|
|
311 (the registry of) CHARSET. */
|
|
312 static Lisp_Object
|
|
313 tty_find_charset_font (Lisp_Object device, Lisp_Object font,
|
|
314 Lisp_Object charset)
|
|
315 {
|
|
316 Bufbyte *fontname = XSTRING_DATA (font);
|
|
317
|
412
|
318 if (strchr ((CONST char *) fontname, '/'))
|
70
|
319 {
|
|
320 if (tty_font_spec_matches_charset (XDEVICE (device), charset, 0,
|
|
321 font, 0, -1))
|
|
322 return font;
|
|
323 return Qnil;
|
|
324 }
|
|
325
|
|
326 if (UNBOUNDP (charset))
|
|
327 return font;
|
|
328
|
|
329 return concat3 (font, build_string ("/"),
|
|
330 Fsymbol_name (XCHARSET_NAME (charset)));
|
|
331 }
|
|
332
|
|
333 #endif /* MULE */
|
|
334
|
0
|
335
|
|
336 /************************************************************************/
|
|
337 /* initialization */
|
|
338 /************************************************************************/
|
|
339
|
|
340 void
|
|
341 syms_of_objects_tty (void)
|
|
342 {
|
20
|
343 DEFSUBR (Fregister_tty_color);
|
|
344 DEFSUBR (Funregister_tty_color);
|
|
345 DEFSUBR (Ffind_tty_color);
|
|
346 DEFSUBR (Ftty_color_list);
|
0
|
347 #if 0
|
20
|
348 DEFSUBR (Fset_tty_dynamic_color_specs);
|
|
349 DEFSUBR (Ftty_dynamic_color_specs);
|
0
|
350 #endif
|
|
351 }
|
|
352
|
|
353 void
|
|
354 console_type_create_objects_tty (void)
|
|
355 {
|
|
356 /* object methods */
|
|
357 CONSOLE_HAS_METHOD (tty, initialize_color_instance);
|
|
358 CONSOLE_HAS_METHOD (tty, mark_color_instance);
|
|
359 CONSOLE_HAS_METHOD (tty, print_color_instance);
|
|
360 CONSOLE_HAS_METHOD (tty, finalize_color_instance);
|
|
361 CONSOLE_HAS_METHOD (tty, color_instance_equal);
|
|
362 CONSOLE_HAS_METHOD (tty, color_instance_hash);
|
|
363 CONSOLE_HAS_METHOD (tty, valid_color_name_p);
|
|
364
|
|
365 CONSOLE_HAS_METHOD (tty, initialize_font_instance);
|
|
366 CONSOLE_HAS_METHOD (tty, mark_font_instance);
|
|
367 CONSOLE_HAS_METHOD (tty, print_font_instance);
|
|
368 CONSOLE_HAS_METHOD (tty, finalize_font_instance);
|
|
369 CONSOLE_HAS_METHOD (tty, list_fonts);
|
70
|
370 #ifdef MULE
|
|
371 CONSOLE_HAS_METHOD (tty, font_spec_matches_charset);
|
|
372 CONSOLE_HAS_METHOD (tty, find_charset_font);
|
|
373 #endif
|
0
|
374 }
|
|
375
|
|
376 void
|
|
377 vars_of_objects_tty (void)
|
|
378 {
|
|
379 staticpro (&Vtty_color_alist);
|
|
380 Vtty_color_alist = Qnil;
|
|
381
|
|
382 #if 0
|
|
383 staticpro (&Vtty_dynamic_color_fg);
|
|
384 Vtty_dynamic_color_fg = Qnil;
|
|
385
|
|
386 staticpro (&Vtty_dynamic_color_bg);
|
|
387 Vtty_dynamic_color_bg = Qnil;
|
|
388 #endif
|
|
389 }
|