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 */
42 has_colors (gboolean disable
, gboolean force
)
44 mc_tty_color_disable
= disable
;
46 if (force
|| (getenv ("COLORTERM") != NULL
))
47 SLtt_Use_Ansi_Colors
= 1;
49 if (!mc_tty_color_disable
) {
50 const char *terminal
= getenv ("TERM");
51 const size_t len
= strlen (terminal
);
53 char *cts
= color_terminal_string
;
57 /* check color_terminal_string */
58 while (*cts
!= '\0') {
59 while (*cts
== ' ' || *cts
== '\t')
64 while (*cts
!= '\0' && *cts
!= ',') {
69 if ((i
!= 0) && (i
== len
) && (strncmp (s
, terminal
, i
) == 0))
70 SLtt_Use_Ansi_Colors
= 1;
76 return SLtt_Use_Ansi_Colors
;
80 mc_tty_color_pair_init_special (tty_color_pair_t
* mc_color_pair
,
81 const char *fg1
, const char *bg1
,
82 const char *fg2
, const char *bg2
, SLtt_Char_Type mask
)
84 if (SLtt_Use_Ansi_Colors
!= 0) {
85 if (!mc_tty_color_disable
) {
86 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg1
, (char *) bg1
);
88 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg2
, (char *) bg2
);
91 SLtt_set_mono (mc_color_pair
->pair_index
, NULL
, mask
);
96 tty_color_init_lib (gboolean disable
, gboolean force
)
98 /* FIXME: if S-Lang is used, has_colors() must be called regardless
99 of whether we are interested in its result */
100 if (has_colors (disable
, force
) && !disable
) {
106 tty_color_deinit_lib (void)
111 tty_color_try_alloc_pair_lib (tty_color_pair_t
* mc_color_pair
)
114 if (mc_color_pair
->ifg
<= (int) SPEC_A_REVERSE
) {
115 switch (mc_color_pair
->ifg
) {
117 mc_tty_color_pair_init_special (mc_color_pair
,
118 "black", "white", "black", "lightgray", SLTT_REV_MASK
);
121 mc_tty_color_pair_init_special (mc_color_pair
,
122 "white", "black", "white", "black", SLTT_BOLD_MASK
);
124 case SPEC_A_BOLD_REVERSE
:
126 mc_tty_color_pair_init_special (mc_color_pair
,
128 "white", "white", SLTT_BOLD_MASK
| SLTT_REV_MASK
);
130 case SPEC_A_UNDERLINE
:
131 mc_tty_color_pair_init_special (mc_color_pair
,
132 "white", "black", "white", "black", SLTT_ULINE_MASK
);
136 fg
= (mc_color_pair
->cfg
) ? mc_color_pair
->cfg
: "default";
137 bg
= (mc_color_pair
->cbg
) ? mc_color_pair
->cbg
: "default";
138 SLtt_set_color (mc_color_pair
->pair_index
, (char *) "", (char *) fg
, (char *) bg
);
143 tty_setcolor (int color
)
145 SLsmg_set_color (color
);
148 /* Set colorpair by index, don't interpret S-Lang "emulated attributes" */
150 tty_lowlevel_setcolor (int color
)
152 SLsmg_set_color (color
& 0x7F);
156 tty_set_normal_attrs (void)
158 SLsmg_normal_video ();