1 /* Color setup for S_Lang screen library
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007, 2008, 2009 Free Software Foundation, Inc.
6 Andrew Borodin <aborodin@vmail.ru>, 2009.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 /** \file color-slang.c
23 * \brief Source: S-Lang-specific color setup
31 #include <sys/types.h> /* size_t */
33 #include "lib/global.h"
35 #include "tty-slang.h"
36 #include "color.h" /* variables */
37 #include "color-internal.h"
39 #include "src/setup.h" /* color_terminal_string */
41 /*** global variables ****************************************************************************/
43 /*** file scope macro definitions ****************************************************************/
45 /*** file scope type declarations ****************************************************************/
47 /*** file scope variables ************************************************************************/
49 /*** file scope functions ************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
53 has_colors (gboolean disable
, gboolean force
)
55 mc_tty_color_disable
= disable
;
57 if (force
|| (getenv ("COLORTERM") != NULL
))
58 SLtt_Use_Ansi_Colors
= 1;
60 if (!mc_tty_color_disable
)
62 const char *terminal
= getenv ("TERM");
63 const size_t len
= strlen (terminal
);
65 char *cts
= color_terminal_string
;
69 /* check color_terminal_string */
72 while (*cts
== ' ' || *cts
== '\t')
77 while (*cts
!= '\0' && *cts
!= ',')
83 if ((i
!= 0) && (i
== len
) && (strncmp (s
, terminal
, i
) == 0))
84 SLtt_Use_Ansi_Colors
= 1;
90 return SLtt_Use_Ansi_Colors
;
93 /* --------------------------------------------------------------------------------------------- */
96 mc_tty_color_pair_init_special (tty_color_pair_t
* mc_color_pair
,
97 const char *fg1
, const char *bg1
,
98 const char *fg2
, const char *bg2
, SLtt_Char_Type mask
)
100 if (SLtt_Use_Ansi_Colors
!= 0)
102 if (!mc_tty_color_disable
)
104 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg1
, (char *) bg1
);
108 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg2
, (char *) bg2
);
113 SLtt_set_mono (mc_color_pair
->pair_index
, NULL
, mask
);
117 /* --------------------------------------------------------------------------------------------- */
118 /*** public functions ****************************************************************************/
119 /* --------------------------------------------------------------------------------------------- */
122 tty_color_init_lib (gboolean disable
, gboolean force
)
124 /* FIXME: if S-Lang is used, has_colors() must be called regardless
125 of whether we are interested in its result */
126 if (has_colors (disable
, force
) && !disable
)
132 /* --------------------------------------------------------------------------------------------- */
135 tty_color_deinit_lib (void)
139 /* --------------------------------------------------------------------------------------------- */
142 tty_color_try_alloc_pair_lib (tty_color_pair_t
* mc_color_pair
)
145 if (mc_color_pair
->ifg
<= (int) SPEC_A_REVERSE
)
147 switch (mc_color_pair
->ifg
)
150 mc_tty_color_pair_init_special (mc_color_pair
,
151 "black", "white", "black", "lightgray", SLTT_REV_MASK
);
154 mc_tty_color_pair_init_special (mc_color_pair
,
155 "white", "black", "white", "black", SLTT_BOLD_MASK
);
157 case SPEC_A_BOLD_REVERSE
:
159 mc_tty_color_pair_init_special (mc_color_pair
,
161 "white", "white", SLTT_BOLD_MASK
| SLTT_REV_MASK
);
163 case SPEC_A_UNDERLINE
:
164 mc_tty_color_pair_init_special (mc_color_pair
,
165 "white", "black", "white", "black", SLTT_ULINE_MASK
);
171 fg
= (mc_color_pair
->cfg
) ? mc_color_pair
->cfg
: "default";
172 bg
= (mc_color_pair
->cbg
) ? mc_color_pair
->cbg
: "default";
173 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg
, (char *) bg
);
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 /* --------------------------------------------------------------------------------------------- */