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 "character.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 (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 (Lisp_Color_Instance *c)
173 mark_object (COLOR_INSTANCE_TTY_SYMBOL (c));
177 tty_print_color_instance (Lisp_Color_Instance *c,
178 Lisp_Object printcharfun,
184 tty_finalize_color_instance (Lisp_Color_Instance *c)
191 tty_color_instance_equal (Lisp_Color_Instance *c1,
192 Lisp_Color_Instance *c2,
195 return (EQ (COLOR_INSTANCE_TTY_SYMBOL (c1),
196 COLOR_INSTANCE_TTY_SYMBOL (c2)));
200 tty_color_instance_hash (Lisp_Color_Instance *c, int depth)
202 return LISP_HASH (COLOR_INSTANCE_TTY_SYMBOL (c));
206 tty_valid_color_name_p (struct device *d, Lisp_Object color)
208 return (!NILP (assoc_no_quit (Fintern (color, Qnil), Vtty_color_alist)));
210 || STRINGP (Vtty_dynamic_color_fg)
211 || STRINGP (Vtty_dynamic_color_bg)
217 tty_initialize_font_instance (Lisp_Font_Instance *f, Lisp_Object name,
218 Lisp_Object device, Error_behavior errb)
220 Bufbyte *str = XSTRING_DATA (name);
221 Lisp_Object charset = Qnil;
223 if (strncmp ((const char *) str, "normal", 6))
232 charset = Ffind_charset (intern ((const char *) str));
240 /* Don't allocate the data until we're sure that we will succeed. */
241 f->data = xnew (struct tty_font_instance_data);
242 FONT_INSTANCE_TTY_CHARSET (f) = charset;
244 if (CHARSETP (charset))
245 f->width = CHARSET_COLUMNS (XCHARSET (charset));
250 f->proportional_p = 0;
251 f->ascent = f->height = 1;
258 tty_mark_font_instance (Lisp_Font_Instance *f)
260 mark_object (FONT_INSTANCE_TTY_CHARSET (f));
264 tty_print_font_instance (Lisp_Font_Instance *f,
265 Lisp_Object printcharfun,
271 tty_finalize_font_instance (Lisp_Font_Instance *f)
278 tty_list_fonts (Lisp_Object pattern, Lisp_Object device)
280 return list1 (build_string ("normal"));
286 tty_font_spec_matches_charset (struct device *d, Lisp_Object charset,
287 const Bufbyte *nonreloc, Lisp_Object reloc,
288 Bytecount offset, Bytecount length)
290 const Bufbyte *the_nonreloc = nonreloc;
293 the_nonreloc = XSTRING_DATA (reloc);
294 fixup_internal_substring (nonreloc, reloc, offset, &length);
295 the_nonreloc += offset;
297 if (UNBOUNDP (charset))
298 return !memchr (the_nonreloc, '/', length);
299 the_nonreloc = (const Bufbyte *) memchr (the_nonreloc, '/', length);
304 Lisp_String *s = symbol_name (XSYMBOL (XCHARSET_NAME (charset)));
305 return !strcmp ((const char *) the_nonreloc,
306 (const char *) string_data (s));
310 /* find a font spec that matches font spec FONT and also matches
311 (the registry of) CHARSET. */
313 tty_find_charset_font (Lisp_Object device, Lisp_Object font,
316 Bufbyte *fontname = XSTRING_DATA (font);
318 if (strchr ((const char *) fontname, '/'))
320 if (tty_font_spec_matches_charset (XDEVICE (device), charset, 0,
326 if (UNBOUNDP (charset))
329 return concat3 (font, build_string ("/"),
330 Fsymbol_name (XCHARSET_NAME (charset)));
336 /************************************************************************/
338 /************************************************************************/
341 syms_of_objects_tty (void)
343 DEFSUBR (Fregister_tty_color);
344 DEFSUBR (Funregister_tty_color);
345 DEFSUBR (Ffind_tty_color);
346 DEFSUBR (Ftty_color_list);
348 DEFSUBR (Fset_tty_dynamic_color_specs);
349 DEFSUBR (Ftty_dynamic_color_specs);
354 console_type_create_objects_tty (void)
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);
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);
371 CONSOLE_HAS_METHOD (tty, font_spec_matches_charset);
372 CONSOLE_HAS_METHOD (tty, find_charset_font);
377 vars_of_objects_tty (void)
379 staticpro (&Vtty_color_alist);
380 Vtty_color_alist = Qnil;
383 staticpro (&Vtty_dynamic_color_fg);
384 Vtty_dynamic_color_fg = Qnil;
386 staticpro (&Vtty_dynamic_color_bg);
387 Vtty_dynamic_color_bg = Qnil;