po/ru.po: fixed plural forms.
[midnight-commander.git] / lib / tty / color-slang.c
blobc3f84a7872b36b5d6be5a8080cd15cab077e7784
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.
5 Written by:
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
26 #include <config.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
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 /* --------------------------------------------------------------------------------------------- */
52 static int
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;
66 char *s;
67 size_t i;
69 /* check color_terminal_string */
70 while (*cts != '\0')
72 while (*cts == ' ' || *cts == '\t')
73 cts++;
74 s = cts;
75 i = 0;
77 while (*cts != '\0' && *cts != ',')
79 cts++;
80 i++;
83 if ((i != 0) && (i == len) && (strncmp (s, terminal, i) == 0))
84 SLtt_Use_Ansi_Colors = 1;
86 if (*cts == ',')
87 cts++;
90 return SLtt_Use_Ansi_Colors;
93 /* --------------------------------------------------------------------------------------------- */
95 static void
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);
106 else
108 SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg2, (char *) bg2);
111 else
113 SLtt_set_mono (mc_color_pair->pair_index, NULL, mask);
117 /* --------------------------------------------------------------------------------------------- */
118 /*** public functions ****************************************************************************/
119 /* --------------------------------------------------------------------------------------------- */
121 void
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)
128 use_colors = TRUE;
132 /* --------------------------------------------------------------------------------------------- */
134 void
135 tty_color_deinit_lib (void)
139 /* --------------------------------------------------------------------------------------------- */
141 void
142 tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
144 const char *fg, *bg;
145 if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE)
147 switch (mc_color_pair->ifg)
149 case SPEC_A_REVERSE:
150 mc_tty_color_pair_init_special (mc_color_pair,
151 "black", "white", "black", "lightgray", SLTT_REV_MASK);
152 break;
153 case SPEC_A_BOLD:
154 mc_tty_color_pair_init_special (mc_color_pair,
155 "white", "black", "white", "black", SLTT_BOLD_MASK);
156 break;
157 case SPEC_A_BOLD_REVERSE:
159 mc_tty_color_pair_init_special (mc_color_pair,
160 "white", "white",
161 "white", "white", SLTT_BOLD_MASK | SLTT_REV_MASK);
162 break;
163 case SPEC_A_UNDERLINE:
164 mc_tty_color_pair_init_special (mc_color_pair,
165 "white", "black", "white", "black", SLTT_ULINE_MASK);
166 break;
169 else
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 /* --------------------------------------------------------------------------------------------- */
179 void
180 tty_setcolor (int color)
182 SLsmg_set_color (color);
185 /* --------------------------------------------------------------------------------------------- */
187 * Set colorpair by index, don't interpret S-Lang "emulated attributes"
190 void
191 tty_lowlevel_setcolor (int color)
193 SLsmg_set_color (color & 0x7F);
196 /* --------------------------------------------------------------------------------------------- */
198 void
199 tty_set_normal_attrs (void)
201 SLsmg_normal_video ();
204 /* --------------------------------------------------------------------------------------------- */