2 Color setup for S_Lang screen library
4 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 2007, 2008, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
9 Andrew Borodin <aborodin@vmail.ru>, 2009
10 Egmont Koblinger <egmont@gmail.com>, 2010
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** \file color-slang.c
29 * \brief Source: S-Lang-specific color setup
37 #include <sys/types.h> /* size_t */
39 #include "lib/global.h"
41 #include "tty-slang.h"
42 #include "color.h" /* variables */
43 #include "color-internal.h"
45 /*** global variables ****************************************************************************/
47 /*** file scope macro definitions ****************************************************************/
49 /*** file scope type declarations ****************************************************************/
51 /*** file scope variables ************************************************************************/
53 /*** file scope functions ************************************************************************/
54 /* --------------------------------------------------------------------------------------------- */
57 has_colors (gboolean disable
, gboolean force
)
59 mc_tty_color_disable
= disable
;
61 if (force
|| (getenv ("COLORTERM") != NULL
))
62 SLtt_Use_Ansi_Colors
= 1;
64 if (!mc_tty_color_disable
)
66 const char *terminal
= getenv ("TERM");
67 const size_t len
= strlen (terminal
);
69 char *cts
= mc_global
.tty
.color_terminal_string
;
73 /* check mc_global.tty.color_terminal_string */
76 while (*cts
== ' ' || *cts
== '\t')
81 while (*cts
!= '\0' && *cts
!= ',')
87 if ((i
!= 0) && (i
== len
) && (strncmp (s
, terminal
, i
) == 0))
88 SLtt_Use_Ansi_Colors
= 1;
94 return SLtt_Use_Ansi_Colors
;
97 /* --------------------------------------------------------------------------------------------- */
100 mc_tty_color_pair_init_special (tty_color_pair_t
* mc_color_pair
,
101 const char *fg1
, const char *bg1
,
102 const char *fg2
, const char *bg2
, SLtt_Char_Type mask
)
104 if (SLtt_Use_Ansi_Colors
!= 0)
106 if (!mc_tty_color_disable
)
108 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg1
, (char *) bg1
);
112 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg2
, (char *) bg2
);
117 SLtt_set_mono (mc_color_pair
->pair_index
, NULL
, mask
);
121 /* --------------------------------------------------------------------------------------------- */
122 /*** public functions ****************************************************************************/
123 /* --------------------------------------------------------------------------------------------- */
126 tty_color_init_lib (gboolean disable
, gboolean force
)
128 /* FIXME: if S-Lang is used, has_colors() must be called regardless
129 of whether we are interested in its result */
130 if (has_colors (disable
, force
) && !disable
)
136 /* --------------------------------------------------------------------------------------------- */
139 tty_color_deinit_lib (void)
143 /* --------------------------------------------------------------------------------------------- */
146 tty_color_try_alloc_pair_lib (tty_color_pair_t
* mc_color_pair
)
149 if (mc_color_pair
->ifg
<= (int) SPEC_A_REVERSE
)
151 switch (mc_color_pair
->ifg
)
154 mc_tty_color_pair_init_special (mc_color_pair
,
155 "black", "white", "black", "lightgray", SLTT_REV_MASK
);
158 mc_tty_color_pair_init_special (mc_color_pair
,
159 "white", "black", "white", "black", SLTT_BOLD_MASK
);
161 case SPEC_A_BOLD_REVERSE
:
163 mc_tty_color_pair_init_special (mc_color_pair
,
165 "white", "white", SLTT_BOLD_MASK
| SLTT_REV_MASK
);
167 case SPEC_A_UNDERLINE
:
168 mc_tty_color_pair_init_special (mc_color_pair
,
169 "white", "black", "white", "black", SLTT_ULINE_MASK
);
175 fg
= tty_color_get_name_by_index (mc_color_pair
->ifg
);
176 bg
= tty_color_get_name_by_index (mc_color_pair
->ibg
);
177 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg
, (char *) bg
);
178 SLtt_add_color_attribute (mc_color_pair
->pair_index
, mc_color_pair
->attr
);
182 /* --------------------------------------------------------------------------------------------- */
185 tty_setcolor (int color
)
187 SLsmg_set_color (color
);
190 /* --------------------------------------------------------------------------------------------- */
192 * Set colorpair by index, don't interpret S-Lang "emulated attributes"
196 tty_lowlevel_setcolor (int color
)
198 SLsmg_set_color (color
& 0x7F);
201 /* --------------------------------------------------------------------------------------------- */
204 tty_set_normal_attrs (void)
206 SLsmg_normal_video ();
209 /* --------------------------------------------------------------------------------------------- */
212 tty_use_256colors (void)
214 return (SLtt_Use_Ansi_Colors
&& SLtt_tgetnum ((char *) "Co") == 256);
217 /* --------------------------------------------------------------------------------------------- */