1 /* TTY-specific Lisp objects.
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
3 Copyright (C) 1995, 1996 Ben Wing.
5 This file is part of XEmacs.
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
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
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. */
22 /* Synched up with: Not in FSF. */
27 #include "console-tty.h"
29 #include "objects-tty.h"
32 #include "mule-charset.h"
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;
42 DEFUN ("register-tty-color", Fregister_tty_color, 3, 3, 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.
48 (color, fg_string, bg_string))
51 CHECK_STRING (fg_string);
52 CHECK_STRING (bg_string);
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)),
62 DEFUN ("unregister-tty-color", Funregister_tty_color, 1, 1, 0, /*
63 Unregister COLOR as a recognized TTY color.
69 color = Fintern (color, Qnil);
70 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
74 DEFUN ("find-tty-color", Ffind_tty_color, 1, 1, 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.
86 result = Fassq (Fintern (color, Qnil), Vtty_color_alist);
88 return list2 (Fcar (Fcdr (result)), Fcdr (Fcdr (result)));
93 DEFUN ("tty-color-list", Ftty_color_list, 0, 0, 0, /*
94 Return a list of the registered TTY colors.
98 Lisp_Object result = Qnil;
101 LIST_LOOP (rest, Vtty_color_alist)
103 result = Fcons (Fsymbol_name (XCAR (XCAR (rest))), result);
106 return Fnreverse (result);
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. */
115 DEFUN ("set-tty-dynamic-color-specs", Fset_tty_dynamic_color_specs, 2, 2, 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.
128 Vtty_dynamic_color_fg = fg;
129 Vtty_dynamic_color_bg = bg;
134 DEFUN ("tty-dynamic-color-specs", Ftty_dynamic_color_specs, 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'.
140 return list2 (Vtty_dynamic_color_fg, Vtty_dynamic_color_bg);
146 tty_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name,
147 Lisp_Object device, Error_behavior errb)
151 name = Fintern (name, Qnil);
152 result = assq_no_quit (name, Vtty_color_alist);
157 if (!STRINGP (Vtty_dynamic_color_fg)
158 && !STRINGP (Vtty_dynamic_color_bg))
163 /* Don't allocate the data until we're sure that we will succeed. */
164 c->data = xnew (struct tty_color_instance_data);
165 COLOR_INSTANCE_TTY_SYMBOL (c) = name;
171 tty_mark_color_instance (struct Lisp_Color_Instance *c,
172 void (*markobj) (Lisp_Object))
174 markobj (COLOR_INSTANCE_TTY_SYMBOL (c));
178 tty_print_color_instance (struct Lisp_Color_Instance *c,
179 Lisp_Object printcharfun,
185 tty_finalize_color_instance (struct Lisp_Color_Instance *c)
192 tty_color_instance_equal (struct Lisp_Color_Instance *c1,
193 struct Lisp_Color_Instance *c2,
196 return (EQ (COLOR_INSTANCE_TTY_SYMBOL (c1),
197 COLOR_INSTANCE_TTY_SYMBOL (c2)));
201 tty_color_instance_hash (struct Lisp_Color_Instance *c, int depth)
203 return LISP_HASH (COLOR_INSTANCE_TTY_SYMBOL (c));
207 tty_valid_color_name_p (struct device *d, Lisp_Object color)
209 return (!NILP (assoc_no_quit (Fintern (color, Qnil), Vtty_color_alist)));
211 || STRINGP (Vtty_dynamic_color_fg)
212 || STRINGP (Vtty_dynamic_color_bg)
218 tty_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
219 Lisp_Object device, Error_behavior errb)
221 Bufbyte *str = XSTRING_DATA (name);
222 Lisp_Object charset = Qnil;
224 if (strncmp ((CONST char *) str, "normal", 6))
233 charset = Ffind_charset (intern ((CONST char *) str));
241 /* Don't allocate the data until we're sure that we will succeed. */
242 f->data = xnew (struct tty_font_instance_data);
243 FONT_INSTANCE_TTY_CHARSET (f) = charset;
245 if (CHARSETP (charset))
246 f->width = XCHARSET_COLUMNS (charset);
251 f->proportional_p = 0;
252 f->ascent = f->height = 1;
259 tty_mark_font_instance (struct Lisp_Font_Instance *f,
260 void (*markobj) (Lisp_Object))
262 markobj (FONT_INSTANCE_TTY_CHARSET (f));
266 tty_print_font_instance (struct Lisp_Font_Instance *f,
267 Lisp_Object printcharfun,
273 tty_finalize_font_instance (struct Lisp_Font_Instance *f)
280 tty_list_fonts (Lisp_Object pattern, Lisp_Object device)
282 return list1 (build_string ("normal"));
288 tty_font_spec_matches_charset (struct device *d, Lisp_Object charset,
289 CONST Bufbyte *nonreloc, Lisp_Object reloc,
290 Bytecount offset, Bytecount length)
292 CONST Bufbyte *the_nonreloc = nonreloc;
295 the_nonreloc = XSTRING_DATA (reloc);
296 fixup_internal_substring (nonreloc, reloc, offset, &length);
297 the_nonreloc += offset;
299 if (UNBOUNDP (charset))
300 return !memchr (the_nonreloc, '/', length);
301 the_nonreloc = (CONST Bufbyte *) memchr (the_nonreloc, '/', length);
306 struct Lisp_String *s = symbol_name (XSYMBOL (XCHARSET_NAME (charset)));
307 return !strcmp ((CONST char *) the_nonreloc,
308 (CONST char *) string_data (s));
312 /* find a font spec that matches font spec FONT and also matches
313 (the registry of) CHARSET. */
315 tty_find_charset_font (Lisp_Object device, Lisp_Object font,
318 Bufbyte *fontname = XSTRING_DATA (font);
320 if (strchr ((CONST char *) fontname, '/'))
322 if (tty_font_spec_matches_charset (XDEVICE (device), charset, 0,
328 if (UNBOUNDP (charset))
331 return concat3 (font, build_string ("/"),
332 Fsymbol_name (XCHARSET_NAME (charset)));
338 /************************************************************************/
340 /************************************************************************/
343 syms_of_objects_tty (void)
345 DEFSUBR (Fregister_tty_color);
346 DEFSUBR (Funregister_tty_color);
347 DEFSUBR (Ffind_tty_color);
348 DEFSUBR (Ftty_color_list);
350 DEFSUBR (Fset_tty_dynamic_color_specs);
351 DEFSUBR (Ftty_dynamic_color_specs);
356 console_type_create_objects_tty (void)
359 CONSOLE_HAS_METHOD (tty, initialize_color_instance);
360 CONSOLE_HAS_METHOD (tty, mark_color_instance);
361 CONSOLE_HAS_METHOD (tty, print_color_instance);
362 CONSOLE_HAS_METHOD (tty, finalize_color_instance);
363 CONSOLE_HAS_METHOD (tty, color_instance_equal);
364 CONSOLE_HAS_METHOD (tty, color_instance_hash);
365 CONSOLE_HAS_METHOD (tty, valid_color_name_p);
367 CONSOLE_HAS_METHOD (tty, initialize_font_instance);
368 CONSOLE_HAS_METHOD (tty, mark_font_instance);
369 CONSOLE_HAS_METHOD (tty, print_font_instance);
370 CONSOLE_HAS_METHOD (tty, finalize_font_instance);
371 CONSOLE_HAS_METHOD (tty, list_fonts);
373 CONSOLE_HAS_METHOD (tty, font_spec_matches_charset);
374 CONSOLE_HAS_METHOD (tty, find_charset_font);
379 vars_of_objects_tty (void)
381 staticpro (&Vtty_color_alist);
382 Vtty_color_alist = Qnil;
385 staticpro (&Vtty_dynamic_color_fg);
386 Vtty_dynamic_color_fg = Qnil;
388 staticpro (&Vtty_dynamic_color_bg);
389 Vtty_dynamic_color_bg = Qnil;