1998-02-27 07:54:42 +03:00
|
|
|
/* Color setup
|
2007-09-26 14:22:25 +04:00
|
|
|
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
|
|
|
2007 Free Software Foundation, Inc.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <stdlib.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <string.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
2009-01-30 21:28:35 +03:00
|
|
|
#include <mhl/memory.h>
|
2009-01-30 22:10:40 +03:00
|
|
|
#include <mhl/string.h>
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
#include "global.h"
|
2001-09-03 08:32:16 +04:00
|
|
|
#include "tty.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "setup.h" /* For the externs */
|
|
|
|
#include "color.h"
|
|
|
|
|
|
|
|
/* Set to force black and white display at program startup */
|
|
|
|
int disable_colors = 0;
|
|
|
|
|
|
|
|
/* Set if we are actually using colors */
|
|
|
|
int use_colors = 0;
|
|
|
|
|
2002-08-31 04:29:48 +04:00
|
|
|
/* Color styles for normal and error dialogs */
|
1998-02-27 07:54:42 +03:00
|
|
|
int dialog_colors [4];
|
2002-08-31 04:29:48 +04:00
|
|
|
int alarm_colors [4];
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
|
|
|
|
|
2001-09-03 08:32:16 +04:00
|
|
|
#ifdef HAVE_SLANG
|
2002-07-15 01:41:12 +04:00
|
|
|
# define color_map_fg(n) color_map[n].fg
|
|
|
|
# define color_map_bg(n) color_map[n].bg
|
1998-02-27 07:54:42 +03:00
|
|
|
#else
|
2002-07-15 02:18:12 +04:00
|
|
|
# define color_map_fg(n) (color_map[n].fg & COLOR_WHITE)
|
|
|
|
# define color_map_bg(n) (color_map[n].bg & COLOR_WHITE)
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
|
|
|
|
1998-05-17 07:27:53 +04:00
|
|
|
struct colorpair {
|
2004-08-30 02:38:06 +04:00
|
|
|
const char *name; /* Name of the entry */
|
1998-04-24 22:52:40 +04:00
|
|
|
CTYPE fg; /* foreground color */
|
|
|
|
CTYPE bg; /* background color */
|
|
|
|
};
|
|
|
|
|
2003-10-15 01:58:56 +04:00
|
|
|
static struct colorpair color_map [] = {
|
1998-12-29 19:52:49 +03:00
|
|
|
{ "normal=", 0, 0 }, /* normal */ /* 1 */
|
1998-02-27 07:54:42 +03:00
|
|
|
{ "selected=", 0, 0 }, /* selected */
|
|
|
|
{ "marked=", 0, 0 }, /* marked */
|
|
|
|
{ "markselect=", 0, 0 }, /* marked/selected */
|
|
|
|
{ "errors=", 0, 0 }, /* errors */
|
|
|
|
{ "menu=", 0, 0 }, /* menu entry */
|
|
|
|
{ "reverse=", 0, 0 }, /* reverse */
|
|
|
|
|
|
|
|
/* Dialog colors */
|
1998-12-29 19:52:49 +03:00
|
|
|
{ "dnormal=", 0, 0 }, /* Dialog normal */ /* 8 */
|
1998-02-27 07:54:42 +03:00
|
|
|
{ "dfocus=", 0, 0 }, /* Dialog focused */
|
|
|
|
{ "dhotnormal=", 0, 0 }, /* Dialog normal/hot */
|
|
|
|
{ "dhotfocus=", 0, 0 }, /* Dialog focused/hot */
|
|
|
|
|
1998-12-29 19:52:49 +03:00
|
|
|
{ "viewunderline=", 0, 0 }, /* _\b? sequence in view, underline in editor */
|
|
|
|
{ "menusel=", 0, 0 }, /* Menu selected color */ /* 13 */
|
1998-02-27 07:54:42 +03:00
|
|
|
{ "menuhot=", 0, 0 }, /* Color for menu hotkeys */
|
|
|
|
{ "menuhotsel=", 0, 0 }, /* Menu hotkeys/selected entry */
|
|
|
|
|
1998-12-29 19:52:49 +03:00
|
|
|
{ "helpnormal=", 0, 0 }, /* Help normal */ /* 16 */
|
1998-02-27 07:54:42 +03:00
|
|
|
{ "helpitalic=", 0, 0 }, /* Italic in help */
|
|
|
|
{ "helpbold=", 0, 0 }, /* Bold in help */
|
|
|
|
{ "helplink=", 0, 0 }, /* Not selected hyperlink */
|
|
|
|
{ "helpslink=", 0, 0 }, /* Selected hyperlink */
|
|
|
|
|
1998-12-29 19:52:49 +03:00
|
|
|
{ "gauge=", 0, 0 }, /* Color of the progress bar (percentage) *//* 21 */
|
1998-02-27 07:54:42 +03:00
|
|
|
{ "input=", 0, 0 },
|
|
|
|
|
|
|
|
/* Per file types colors */
|
1998-12-29 19:52:49 +03:00
|
|
|
{ "directory=", 0, 0 }, /* 23 */
|
|
|
|
{ "executable=", 0, 0 },
|
2002-10-14 02:23:17 +04:00
|
|
|
{ "link=", 0, 0 }, /* symbolic link (neither stale nor link to directory) */
|
|
|
|
{ "stalelink=", 0, 0 }, /* stale symbolic link */
|
1998-02-27 07:54:42 +03:00
|
|
|
{ "device=", 0, 0 },
|
1998-12-29 19:52:49 +03:00
|
|
|
{ "special=", 0, 0 }, /* sockets, fifo */
|
|
|
|
{ "core=", 0, 0 }, /* core files */ /* 29 */
|
1998-12-11 01:04:54 +03:00
|
|
|
|
1998-12-29 19:52:49 +03:00
|
|
|
{ 0, 0, 0 }, /* not usable (DEFAULT_COLOR_INDEX) *//* 30 */
|
|
|
|
{ 0, 0, 0 }, /* unused */
|
|
|
|
{ 0, 0, 0 }, /* not usable (A_REVERSE) */
|
|
|
|
{ 0, 0, 0 }, /* not usable (A_REVERSE_BOLD) */
|
|
|
|
|
|
|
|
/* editor colors start at 34 */
|
|
|
|
{ "editnormal=", 0, 0 }, /* normal */ /* 34 */
|
1998-12-11 01:04:54 +03:00
|
|
|
{ "editbold=", 0, 0 }, /* search->found */
|
|
|
|
{ "editmarked=", 0, 0 }, /* marked/selected */
|
2007-08-27 16:06:02 +04:00
|
|
|
{ "editwhitespace=", 0, 0 }, /* whitespace */
|
2004-09-02 02:33:43 +04:00
|
|
|
|
2007-08-27 16:06:02 +04:00
|
|
|
/* error dialog colors start at 38 */
|
|
|
|
{ "errdhotnormal=", 0, 0 }, /* Error dialog normal/hot */ /* 38 */
|
2004-09-02 02:33:43 +04:00
|
|
|
{ "errdhotfocus=", 0, 0 }, /* Error dialog focused/hot */
|
1998-02-27 07:54:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct color_table_s {
|
2004-08-30 02:38:06 +04:00
|
|
|
const char *name;
|
1998-02-27 07:54:42 +03:00
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-07-31 14:32:50 +04:00
|
|
|
static struct color_table_s const color_table [] = {
|
1998-02-27 07:54:42 +03:00
|
|
|
{ "black", COLOR_BLACK },
|
|
|
|
{ "gray", COLOR_BLACK | A_BOLD },
|
|
|
|
{ "red", COLOR_RED },
|
|
|
|
{ "brightred", COLOR_RED | A_BOLD },
|
|
|
|
{ "green", COLOR_GREEN },
|
|
|
|
{ "brightgreen", COLOR_GREEN | A_BOLD },
|
|
|
|
{ "brown", COLOR_YELLOW },
|
|
|
|
{ "yellow", COLOR_YELLOW | A_BOLD },
|
|
|
|
{ "blue", COLOR_BLUE },
|
|
|
|
{ "brightblue", COLOR_BLUE | A_BOLD },
|
|
|
|
{ "magenta", COLOR_MAGENTA },
|
|
|
|
{ "brightmagenta", COLOR_MAGENTA | A_BOLD },
|
|
|
|
{ "cyan", COLOR_CYAN },
|
|
|
|
{ "brightcyan", COLOR_CYAN | A_BOLD },
|
|
|
|
{ "lightgray", COLOR_WHITE },
|
1998-10-30 04:28:09 +03:00
|
|
|
{ "white", COLOR_WHITE | A_BOLD },
|
2002-11-28 21:57:05 +03:00
|
|
|
{ "default", 0 } /* default color of the terminal */
|
1998-02-27 07:54:42 +03:00
|
|
|
};
|
|
|
|
|
2004-08-30 02:38:06 +04:00
|
|
|
static const char *default_colors =
|
2003-06-22 13:32:52 +04:00
|
|
|
"normal=lightgray,blue:"
|
|
|
|
"selected=black,cyan:"
|
|
|
|
"marked=yellow,blue:"
|
|
|
|
"markselect=yellow,cyan:"
|
|
|
|
"errors=white,red:"
|
|
|
|
"menu=white,cyan:"
|
|
|
|
"reverse=black,lightgray:"
|
|
|
|
"dnormal=black,lightgray:"
|
|
|
|
"dfocus=black,cyan:"
|
|
|
|
"dhotnormal=blue,lightgray:"
|
|
|
|
"dhotfocus=blue,cyan:"
|
|
|
|
"viewunderline=brightred,blue:"
|
|
|
|
"menuhot=yellow,cyan:"
|
|
|
|
"menusel=white,black:"
|
|
|
|
"menuhotsel=yellow,black:"
|
|
|
|
"helpnormal=black,lightgray:"
|
|
|
|
"helpitalic=red,lightgray:"
|
|
|
|
"helpbold=blue,lightgray:"
|
|
|
|
"helplink=black,cyan:"
|
|
|
|
"helpslink=yellow,blue:"
|
|
|
|
"gauge=white,black:"
|
|
|
|
"input=black,cyan:"
|
|
|
|
"directory=white,blue:"
|
|
|
|
"executable=brightgreen,blue:"
|
|
|
|
"link=lightgray,blue:"
|
|
|
|
"stalelink=brightred,blue:"
|
|
|
|
"device=brightmagenta,blue:"
|
|
|
|
"core=red,blue:"
|
|
|
|
"special=black,blue:"
|
|
|
|
"editnormal=lightgray,blue:"
|
|
|
|
"editbold=yellow,blue:"
|
2004-09-02 02:33:43 +04:00
|
|
|
"editmarked=black,cyan:"
|
2007-08-27 16:06:02 +04:00
|
|
|
"editwhitespace=brightblue,blue:"
|
2004-09-02 02:33:43 +04:00
|
|
|
"errdhotnormal=yellow,red:"
|
|
|
|
"errdhotfocus=yellow,lightgray";
|
2003-06-22 13:32:52 +04:00
|
|
|
|
2001-09-03 08:32:16 +04:00
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
# define color_value(i) color_table [i].name
|
|
|
|
# define color_name(i) color_table [i].name
|
1998-02-27 07:54:42 +03:00
|
|
|
#else
|
2001-09-03 08:32:16 +04:00
|
|
|
# define color_value(i) color_table [i].value
|
|
|
|
# define color_name(i) color_table [i].name
|
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2004-08-30 02:38:06 +04:00
|
|
|
static void get_color (const char *cpp, CTYPE *colp)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2004-08-16 07:12:05 +04:00
|
|
|
size_t i;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
for (i = 0; i < ELEMENTS(color_table); i++){
|
|
|
|
if (strcmp (cpp, color_name (i)) == 0){
|
|
|
|
*colp = color_value (i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_two_colors (char **cpp, struct colorpair *colorpairp)
|
|
|
|
{
|
|
|
|
char *p = *cpp;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
state = 0;
|
|
|
|
|
|
|
|
for (; *p; p++){
|
|
|
|
if (*p == ':'){
|
|
|
|
*p = 0;
|
|
|
|
get_color (*cpp, state ? &colorpairp->bg : &colorpairp->fg);
|
|
|
|
*p = ':';
|
|
|
|
*cpp = p + 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p == ','){
|
|
|
|
state = 1;
|
|
|
|
*p = 0;
|
|
|
|
get_color (*cpp, &colorpairp->fg);
|
|
|
|
*p = ',';
|
|
|
|
*cpp = p + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
get_color (*cpp, state ? &colorpairp->bg : &colorpairp->fg);
|
|
|
|
}
|
|
|
|
|
2004-08-30 02:38:06 +04:00
|
|
|
static void configure_colors_string (const char *the_color_string)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-04-15 10:05:34 +04:00
|
|
|
char *color_string, *p;
|
2004-08-16 07:12:05 +04:00
|
|
|
size_t i;
|
|
|
|
int found;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!the_color_string)
|
|
|
|
return;
|
|
|
|
|
2009-01-30 22:10:40 +03:00
|
|
|
p = color_string = mhl_str_dup (the_color_string);
|
1998-02-27 07:54:42 +03:00
|
|
|
while (color_string && *color_string){
|
|
|
|
while (*color_string == ' ' || *color_string == '\t')
|
|
|
|
color_string++;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
for (i = 0; i < ELEMENTS(color_map); i++){
|
1998-12-29 19:52:49 +03:00
|
|
|
int klen;
|
|
|
|
|
|
|
|
if (!color_map [i].name)
|
|
|
|
continue;
|
|
|
|
klen = strlen (color_map [i].name);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (strncmp (color_string, color_map [i].name, klen) == 0){
|
|
|
|
color_string += klen;
|
|
|
|
get_two_colors (&color_string, &color_map [i]);
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found){
|
|
|
|
while (*color_string && *color_string != ':')
|
|
|
|
color_string++;
|
|
|
|
if (*color_string)
|
|
|
|
color_string++;
|
|
|
|
}
|
|
|
|
}
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void configure_colors (void)
|
|
|
|
{
|
|
|
|
extern char *command_line_colors;
|
|
|
|
|
2003-06-22 13:32:52 +04:00
|
|
|
configure_colors_string (default_colors);
|
1998-02-27 07:54:42 +03:00
|
|
|
configure_colors_string (setup_color_string);
|
|
|
|
configure_colors_string (term_color_string);
|
|
|
|
configure_colors_string (getenv ("MC_COLOR_TABLE"));
|
|
|
|
configure_colors_string (command_line_colors);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_SLANG
|
1999-02-14 00:39:18 +03:00
|
|
|
#define MAX_PAIRS 64
|
1998-02-27 07:54:42 +03:00
|
|
|
int attr_pairs [MAX_PAIRS];
|
|
|
|
#endif
|
|
|
|
|
1998-05-16 02:54:54 +04:00
|
|
|
static void
|
|
|
|
load_dialog_colors (void)
|
|
|
|
{
|
|
|
|
dialog_colors [0] = COLOR_NORMAL;
|
|
|
|
dialog_colors [1] = COLOR_FOCUS;
|
|
|
|
dialog_colors [2] = COLOR_HOT_NORMAL;
|
|
|
|
dialog_colors [3] = COLOR_HOT_FOCUS;
|
2002-08-31 04:29:48 +04:00
|
|
|
|
|
|
|
alarm_colors [0] = ERROR_COLOR;
|
|
|
|
alarm_colors [1] = REVERSE_COLOR;
|
2004-09-02 02:33:43 +04:00
|
|
|
alarm_colors [2] = ERROR_HOT_NORMAL;
|
|
|
|
alarm_colors [3] = ERROR_HOT_FOCUS;
|
1998-05-16 02:54:54 +04:00
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
void init_colors (void)
|
|
|
|
{
|
2004-08-16 07:12:05 +04:00
|
|
|
size_t i;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-08 21:30:52 +04:00
|
|
|
int hascolors;
|
|
|
|
|
|
|
|
/* FIXME: if S-Lang is used, this function must be called regardless
|
|
|
|
of whether we are interested in its result */
|
1998-02-27 07:54:42 +03:00
|
|
|
hascolors = has_colors ();
|
|
|
|
|
|
|
|
if (!disable_colors && hascolors){
|
|
|
|
use_colors = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_colors){
|
|
|
|
start_color ();
|
|
|
|
configure_colors ();
|
|
|
|
|
|
|
|
#ifndef HAVE_SLANG
|
|
|
|
if (ELEMENTS (color_map) > MAX_PAIRS){
|
|
|
|
/* This message should only be seen by the developers */
|
|
|
|
fprintf (stderr,
|
|
|
|
"Too many defined colors, resize MAX_PAIRS on color.c");
|
|
|
|
exit (1);
|
|
|
|
}
|
2001-09-03 08:32:16 +04:00
|
|
|
#endif /* !HAVE_SLANG */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2001-05-29 21:02:28 +04:00
|
|
|
if (use_colors) {
|
2001-05-30 02:02:16 +04:00
|
|
|
#ifdef HAVE_SLANG
|
2001-05-29 21:02:28 +04:00
|
|
|
/*
|
|
|
|
* We are relying on undocumented feature of
|
|
|
|
* S-Lang to make COLOR_PAIR(DEFAULT_COLOR_INDEX)
|
|
|
|
* the default fg/bg of the terminal.
|
|
|
|
* Hopefully, future versions of S-Lang will
|
|
|
|
* document this feature.
|
|
|
|
*/
|
2001-05-30 02:02:16 +04:00
|
|
|
SLtt_set_color (DEFAULT_COLOR_INDEX, NULL, "default", "default");
|
2001-09-03 08:32:16 +04:00
|
|
|
#else
|
2001-05-29 21:02:28 +04:00
|
|
|
/* Always white on black */
|
2002-07-15 01:41:12 +04:00
|
|
|
mc_init_pair(DEFAULT_COLOR_INDEX, COLOR_WHITE, COLOR_BLACK);
|
2001-09-03 08:32:16 +04:00
|
|
|
#endif /* !HAVE_SLANG */
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ELEMENTS (color_map); i++){
|
1998-12-29 19:52:49 +03:00
|
|
|
if (!color_map [i].name)
|
|
|
|
continue;
|
|
|
|
|
2002-07-15 01:41:12 +04:00
|
|
|
mc_init_pair (i+1, color_map_fg(i), color_map_bg(i));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#ifndef HAVE_SLANG
|
|
|
|
/*
|
2002-07-15 01:41:12 +04:00
|
|
|
* ncurses doesn't remember bold attribute in the color pairs,
|
|
|
|
* so we should keep track of it in a separate array.
|
1998-02-27 07:54:42 +03:00
|
|
|
*/
|
|
|
|
attr_pairs [i+1] = color_map [i].fg & A_BOLD;
|
2001-09-03 08:32:16 +04:00
|
|
|
#endif /* !HAVE_SLANG */
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
1998-05-16 02:54:54 +04:00
|
|
|
load_dialog_colors ();
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2002-07-15 01:41:12 +04:00
|
|
|
|
|
|
|
/* Functions necessary to implement syntax highlighting */
|
|
|
|
|
|
|
|
static int max_index = 0;
|
|
|
|
|
|
|
|
static int
|
|
|
|
alloc_color_pair (CTYPE foreground, CTYPE background)
|
|
|
|
{
|
|
|
|
mc_init_pair (++max_index, foreground, background);
|
|
|
|
return max_index;
|
|
|
|
}
|
|
|
|
|
2002-07-25 17:04:19 +04:00
|
|
|
static struct colors_avail {
|
2002-07-15 01:41:12 +04:00
|
|
|
struct colors_avail *next;
|
|
|
|
char *fg, *bg;
|
|
|
|
int index;
|
2002-07-25 17:04:19 +04:00
|
|
|
} c = { 0, 0, 0, 0 };
|
2002-07-15 01:41:12 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
void
|
|
|
|
mc_init_pair (int index, CTYPE foreground, CTYPE background)
|
|
|
|
{
|
2002-11-28 21:57:05 +03:00
|
|
|
if (!background)
|
|
|
|
background = "default";
|
|
|
|
|
|
|
|
if (!foreground)
|
|
|
|
foreground = "default";
|
2002-07-15 01:41:12 +04:00
|
|
|
|
2004-09-01 03:34:18 +04:00
|
|
|
SLtt_set_color (index, "", (char *) foreground, (char *) background);
|
2002-07-15 01:41:12 +04:00
|
|
|
if (index > max_index)
|
|
|
|
max_index = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-08-29 20:42:40 +04:00
|
|
|
try_alloc_color_pair (const char *fg, const char *bg)
|
2002-07-15 01:41:12 +04:00
|
|
|
{
|
|
|
|
struct colors_avail *p = &c;
|
|
|
|
|
|
|
|
c.index = EDITOR_NORMAL_COLOR_INDEX;
|
|
|
|
for (;;) {
|
|
|
|
if (((fg && p->fg) ? !strcmp (fg, p->fg) : fg == p->fg) != 0
|
|
|
|
&& ((bg && p->bg) ? !strcmp (bg, p->bg) : bg == p->bg) != 0)
|
|
|
|
return p->index;
|
|
|
|
if (!p->next)
|
|
|
|
break;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
p->next = g_new (struct colors_avail, 1);
|
|
|
|
p = p->next;
|
|
|
|
p->next = 0;
|
2009-01-30 22:10:40 +03:00
|
|
|
p->fg = fg ? mhl_str_dup (fg) : 0;
|
|
|
|
p->bg = bg ? mhl_str_dup (bg) : 0;
|
2002-07-15 01:41:12 +04:00
|
|
|
if (!fg)
|
|
|
|
/* Index in color_map array = COLOR_INDEX - 1 */
|
|
|
|
fg = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].fg;
|
|
|
|
if (!bg)
|
|
|
|
bg = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].bg;
|
|
|
|
p->index = alloc_color_pair (fg, bg);
|
|
|
|
return p->index;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !HAVE_SLANG */
|
|
|
|
void
|
|
|
|
mc_init_pair (int index, CTYPE foreground, CTYPE background)
|
|
|
|
{
|
|
|
|
init_pair (index, foreground, background);
|
|
|
|
if (index > max_index)
|
|
|
|
max_index = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-09-02 16:51:09 +04:00
|
|
|
try_alloc_color_pair (const char *fg, const char *bg)
|
2002-07-15 01:41:12 +04:00
|
|
|
{
|
|
|
|
int fg_index, bg_index;
|
|
|
|
int bold_attr;
|
|
|
|
struct colors_avail *p = &c;
|
|
|
|
|
|
|
|
c.index = EDITOR_NORMAL_COLOR_INDEX;
|
|
|
|
for (;;) {
|
|
|
|
if (((fg && p->fg) ? !strcmp (fg, p->fg) : fg == p->fg) != 0
|
|
|
|
&& ((bg && p->bg) ? !strcmp (bg, p->bg) : bg == p->bg) != 0)
|
|
|
|
return p->index;
|
|
|
|
if (!p->next)
|
|
|
|
break;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
p->next = g_new (struct colors_avail, 1);
|
|
|
|
p = p->next;
|
|
|
|
p->next = 0;
|
2009-01-30 22:10:40 +03:00
|
|
|
p->fg = fg ? mhl_str_dup (fg) : 0;
|
|
|
|
p->bg = bg ? mhl_str_dup (bg) : 0;
|
2002-07-15 01:41:12 +04:00
|
|
|
if (!fg)
|
|
|
|
/* Index in color_map array = COLOR_INDEX - 1 */
|
|
|
|
fg_index = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].fg;
|
|
|
|
else
|
|
|
|
get_color (fg, &fg_index);
|
|
|
|
|
|
|
|
if (!bg)
|
|
|
|
bg_index = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].bg;
|
|
|
|
else
|
|
|
|
get_color (bg, &bg_index);
|
|
|
|
|
|
|
|
bold_attr = fg_index & A_BOLD;
|
2002-07-15 02:18:12 +04:00
|
|
|
fg_index = fg_index & COLOR_WHITE;
|
|
|
|
bg_index = bg_index & COLOR_WHITE;
|
2002-07-15 01:41:12 +04:00
|
|
|
|
|
|
|
p->index = alloc_color_pair (fg_index, bg_index);
|
|
|
|
attr_pairs [p->index] = bold_attr;
|
|
|
|
return p->index;
|
|
|
|
}
|
|
|
|
#endif /* !HAVE_SLANG */
|
|
|
|
|
2002-07-25 17:04:19 +04:00
|
|
|
void
|
2003-10-25 00:55:23 +04:00
|
|
|
done_colors (void)
|
2002-07-25 17:04:19 +04:00
|
|
|
{
|
|
|
|
struct colors_avail *p, *next;
|
|
|
|
|
|
|
|
for (p = c.next; p; p = next) {
|
|
|
|
next = p->next;
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p->fg);
|
|
|
|
g_free (p->bg);
|
|
|
|
g_free (p);
|
2002-07-25 17:04:19 +04:00
|
|
|
}
|
|
|
|
c.next = NULL;
|
|
|
|
}
|
|
|
|
|