1 /* Color setup for S_Lang screen library
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 Andrew Borodin <aborodin@vmail.ru>, 2009
7 Egmont Koblinger <egmont@gmail.com>, 2010
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 /** \file color-slang.c
24 * \brief Source: S-Lang-specific color setup
32 #include <sys/types.h> /* size_t */
34 #include "lib/global.h"
36 #include "tty-slang.h"
37 #include "color.h" /* variables */
38 #include "color-internal.h"
40 /*** global variables ****************************************************************************/
42 /*** file scope macro definitions ****************************************************************/
44 /*** file scope type declarations ****************************************************************/
46 /*** file scope variables ************************************************************************/
48 /*** file scope functions ************************************************************************/
49 /* --------------------------------------------------------------------------------------------- */
52 has_colors (gboolean disable
, gboolean force
)
54 mc_tty_color_disable
= disable
;
56 if (force
|| (getenv ("COLORTERM") != NULL
))
57 SLtt_Use_Ansi_Colors
= 1;
59 if (!mc_tty_color_disable
)
61 const char *terminal
= getenv ("TERM");
62 const size_t len
= strlen (terminal
);
64 char *cts
= mc_global
.tty
.color_terminal_string
;
68 /* check mc_global.tty.color_terminal_string */
71 while (*cts
== ' ' || *cts
== '\t')
76 while (*cts
!= '\0' && *cts
!= ',')
82 if ((i
!= 0) && (i
== len
) && (strncmp (s
, terminal
, i
) == 0))
83 SLtt_Use_Ansi_Colors
= 1;
89 return SLtt_Use_Ansi_Colors
;
92 /* --------------------------------------------------------------------------------------------- */
95 mc_tty_color_pair_init_special (tty_color_pair_t
* mc_color_pair
,
96 const char *fg1
, const char *bg1
,
97 const char *fg2
, const char *bg2
, SLtt_Char_Type mask
)
99 if (SLtt_Use_Ansi_Colors
!= 0)
101 if (!mc_tty_color_disable
)
103 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg1
, (char *) bg1
);
107 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg2
, (char *) bg2
);
112 SLtt_set_mono (mc_color_pair
->pair_index
, NULL
, mask
);
116 /* --------------------------------------------------------------------------------------------- */
117 /*** public functions ****************************************************************************/
118 /* --------------------------------------------------------------------------------------------- */
121 tty_color_init_lib (gboolean disable
, gboolean force
)
123 /* FIXME: if S-Lang is used, has_colors() must be called regardless
124 of whether we are interested in its result */
125 if (has_colors (disable
, force
) && !disable
)
131 /* --------------------------------------------------------------------------------------------- */
134 tty_color_deinit_lib (void)
138 /* --------------------------------------------------------------------------------------------- */
141 tty_color_try_alloc_pair_lib (tty_color_pair_t
* mc_color_pair
)
144 if (mc_color_pair
->ifg
<= (int) SPEC_A_REVERSE
)
146 switch (mc_color_pair
->ifg
)
149 mc_tty_color_pair_init_special (mc_color_pair
,
150 "black", "white", "black", "lightgray", SLTT_REV_MASK
);
153 mc_tty_color_pair_init_special (mc_color_pair
,
154 "white", "black", "white", "black", SLTT_BOLD_MASK
);
156 case SPEC_A_BOLD_REVERSE
:
158 mc_tty_color_pair_init_special (mc_color_pair
,
160 "white", "white", SLTT_BOLD_MASK
| SLTT_REV_MASK
);
162 case SPEC_A_UNDERLINE
:
163 mc_tty_color_pair_init_special (mc_color_pair
,
164 "white", "black", "white", "black", SLTT_ULINE_MASK
);
170 fg
= tty_color_get_name_by_index (mc_color_pair
->ifg
);
171 bg
= tty_color_get_name_by_index (mc_color_pair
->ibg
);
172 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg
, (char *) bg
);
173 SLtt_add_color_attribute (mc_color_pair
->pair_index
, mc_color_pair
->attr
);
177 /* --------------------------------------------------------------------------------------------- */
180 tty_setcolor (int color
)
182 SLsmg_set_color (color
);
185 /* --------------------------------------------------------------------------------------------- */
187 * Set colorpair by index, don't interpret S-Lang "emulated attributes"
191 tty_lowlevel_setcolor (int color
)
193 SLsmg_set_color (color
& 0x7F);
196 /* --------------------------------------------------------------------------------------------- */
199 tty_set_normal_attrs (void)
201 SLsmg_normal_video ();
204 /* --------------------------------------------------------------------------------------------- */
207 tty_use_256colors (void)
209 return (SLtt_Use_Ansi_Colors
&& SLtt_tgetnum ((char *) "Co") == 256);
212 /* --------------------------------------------------------------------------------------------- */