aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2002-01-14 13:45:36 +0000
committerEli Zaretskii2002-01-14 13:45:36 +0000
commitace282979b07417322cc9f85426a13944ae27631 (patch)
treef963e9708e82592dd024373b5be43c30d5d3d9bf /src
parentae0bec0b42e8af2188b0b00d700ca2a8dfcb327f (diff)
downloademacs-ace282979b07417322cc9f85426a13944ae27631.tar.gz
emacs-ace282979b07417322cc9f85426a13944ae27631.zip
(tty_default_color_capabilities, tty_setup_colors)
(set_tty_color_mode): New functions. (term_init): Call tty_default_color_capabilities. (Qtty_color_mode_alist): New variable. (syms_of_term): Intern and staticpro it.
Diffstat (limited to 'src')
-rw-r--r--src/term.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/term.c b/src/term.c
index 2f3830f329b..93644c837de 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1983,7 +1983,138 @@ DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
1983 return TN_max_colors > 0 ? Qt : Qnil; 1983 return TN_max_colors > 0 ? Qt : Qnil;
1984} 1984}
1985 1985
1986#ifndef WINDOWSNT
1986 1987
1988/* Save or restore the default color-related capabilities of this
1989 terminal. */
1990static void
1991tty_default_color_capabilities (save)
1992 int save;
1993{
1994 static char
1995 *default_orig_pair, *default_set_foreground, *default_set_background;
1996 static int default_max_colors, default_max_pairs, default_no_color_video;
1997
1998 if (save)
1999 {
2000 if (default_orig_pair)
2001 xfree (default_orig_pair);
2002 default_orig_pair = TS_orig_pair ? xstrdup (TS_orig_pair) : NULL;
2003
2004 if (default_set_foreground)
2005 xfree (default_set_foreground);
2006 default_set_foreground = TS_set_foreground ? xstrdup (TS_set_foreground)
2007 : NULL;
2008
2009 if (default_set_background)
2010 xfree (default_set_background);
2011 default_set_background = TS_set_background ? xstrdup (TS_set_background)
2012 : NULL;
2013
2014 default_max_colors = TN_max_colors;
2015 default_max_pairs = TN_max_pairs;
2016 default_no_color_video = TN_no_color_video;
2017 }
2018 else
2019 {
2020 TS_orig_pair = default_orig_pair;
2021 TS_set_foreground = default_set_foreground;
2022 TS_set_background = default_set_background;
2023 TN_max_colors = default_max_colors;
2024 TN_max_pairs = default_max_pairs;
2025 TN_no_color_video = default_no_color_video;
2026 }
2027}
2028
2029/* Setup one of the standard tty color schemes according to MODE.
2030 MODE's value is generally the number of colors which we want to
2031 support; zero means set up for the default capabilities, the ones
2032 we saw at term_init time; -1 means turn off color support. */
2033void
2034tty_setup_colors (mode)
2035 int mode;
2036{
2037 switch (mode)
2038 {
2039 case -1: /* no colors at all */
2040 TN_max_colors = 0;
2041 TN_max_pairs = 0;
2042 TN_no_color_video = 0;
2043 TS_set_foreground = TS_set_background = TS_orig_pair = NULL;
2044 break;
2045 case 0: /* default colors, if any */
2046 default:
2047 tty_default_color_capabilities (0);
2048 break;
2049 case 8: /* 8 standard ANSI colors */
2050 TS_orig_pair = "\033[0m";
2051#ifdef TERMINFO
2052 TS_set_foreground = "\033[3%p1%dm";
2053 TS_set_background = "\033[4%p1%dm";
2054#else
2055 TS_set_foreground = "\033[3%dm";
2056 TS_set_background = "\033[4%dm";
2057#endif
2058 TN_max_colors = 8;
2059 TN_max_pairs = 64;
2060 TN_no_color_video = 0;
2061 break;
2062 }
2063}
2064
2065void
2066set_tty_color_mode (f, val)
2067 struct frame *f;
2068 Lisp_Object val;
2069{
2070 Lisp_Object color_mode_spec, current_mode_spec, tem;
2071 Lisp_Object color_mode, current_mode;
2072 int mode, old_mode;
2073 extern Lisp_Object Qtty_color_mode;
2074 Lisp_Object tty_color_mode_alist;
2075
2076 tty_color_mode_alist = Fintern_soft (build_string ("tty-color-mode-alist"),
2077 Qnil);
2078
2079 if (NATNUMP (val))
2080 color_mode = val;
2081 else
2082 {
2083 if (NILP (tty_color_mode_alist))
2084 color_mode_spec = Qnil;
2085 else
2086 color_mode_spec = Fassq (val, XSYMBOL (tty_color_mode_alist)->value);
2087 current_mode_spec = assq_no_quit (Qtty_color_mode, f->param_alist);
2088
2089 if (CONSP (color_mode_spec))
2090 color_mode = XCDR (color_mode_spec);
2091 else
2092 color_mode = Qnil;
2093 }
2094 if (CONSP (current_mode_spec))
2095 current_mode = XCDR (current_mode_spec);
2096 else
2097 current_mode = Qnil;
2098 if (NATNUMP (color_mode))
2099 mode = XINT (color_mode);
2100 else
2101 mode = 0; /* meaning default */
2102 if (NATNUMP (current_mode))
2103 old_mode = XINT (current_mode);
2104 else
2105 old_mode = 0;
2106
2107 if (mode != old_mode)
2108 {
2109 tty_setup_colors (mode);
2110 /* This recomputes all the faces given the new color
2111 definitions. */
2112 call0 (intern ("tty-set-up-initial-frame-faces"));
2113 redraw_frame (f);
2114 }
2115}
2116
2117#endif /* !WINDOWSNT */
1987 2118
1988 2119
1989/*********************************************************************** 2120/***********************************************************************
@@ -2172,6 +2303,8 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2172 TN_no_color_video = 0; 2303 TN_no_color_video = 0;
2173 } 2304 }
2174 2305
2306 tty_default_color_capabilities (1);
2307
2175 MagicWrap = tgetflag ("xn"); 2308 MagicWrap = tgetflag ("xn");
2176 /* Since we make MagicWrap terminals look like AutoWrap, we need to have 2309 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2177 the former flag imply the latter. */ 2310 the former flag imply the latter. */