2009-06-12 14:55:06 +04:00
|
|
|
/* Internal stuff of color setup
|
|
|
|
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
|
|
|
2007, 2008, 2009 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by:
|
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009.
|
2009-09-04 18:22:49 +04:00
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2009.
|
2009-06-12 14:55:06 +04: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
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
2009-05-10 19:01:15 +04:00
|
|
|
|
|
|
|
/** \file color-internal.c
|
|
|
|
* \brief Source: Internal stuff of color setup
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
#include <string.h> /* strcmp */
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "color.h" /* colors and attributes */
|
|
|
|
#include "color-internal.h"
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
2009-09-09 18:56:52 +04:00
|
|
|
gboolean mc_tty_color_disable;
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
typedef struct mc_tty_color_table_struct {
|
|
|
|
const char *name;
|
2009-09-17 02:07:04 +04:00
|
|
|
int value;
|
2009-09-04 18:22:49 +04:00
|
|
|
} mc_tty_color_table_t;
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
mc_tty_color_table_t const color_table[] = {
|
2009-05-10 19:01:15 +04: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 },
|
|
|
|
{ "white", COLOR_WHITE | A_BOLD },
|
2009-09-14 17:43:03 +04:00
|
|
|
{ "default", -1 }, /* default color of the terminal */
|
2009-09-09 18:56:52 +04:00
|
|
|
/* special colors */
|
|
|
|
{ "A_REVERSE", SPEC_A_REVERSE },
|
|
|
|
{ "A_BOLD", SPEC_A_BOLD},
|
|
|
|
{ "A_BOLD_REVERSE", SPEC_A_BOLD_REVERSE },
|
|
|
|
{ "A_UNDERLINE", SPEC_A_UNDERLINE },
|
|
|
|
/* End of list */
|
2009-09-04 18:22:49 +04:00
|
|
|
{ NULL, 0}
|
2009-05-10 19:01:15 +04:00
|
|
|
};
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
const char *
|
2009-09-14 17:43:03 +04:00
|
|
|
tty_color_get_valid_name (const char *color_name)
|
2009-05-10 19:01:15 +04:00
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
int i;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
if (color_name != NULL)
|
2009-09-17 02:07:04 +04:00
|
|
|
for (i = 0; color_table[i].name != NULL; i++)
|
|
|
|
if (strcmp (color_name, color_table[i].name) == 0)
|
|
|
|
return color_table[i].name;
|
2009-09-04 18:22:49 +04:00
|
|
|
return NULL;
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
2009-09-14 17:43:03 +04:00
|
|
|
tty_color_get_index_by_name (const char *color_name)
|
2009-05-10 19:01:15 +04:00
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
int i;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
if (color_name != NULL)
|
2009-09-17 02:07:04 +04:00
|
|
|
for (i = 0; color_table[i].name != NULL; i++)
|
|
|
|
if (strcmp (color_name, color_table[i].name) == 0)
|
|
|
|
return color_table[i].value;
|
2009-09-04 18:22:49 +04:00
|
|
|
return -1;
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|