color-internal.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Internal stuff of color setup
  2. Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  3. 2007, 2008, 2009 Free Software Foundation, Inc.
  4. Written by:
  5. Andrew Borodin <aborodin@vmail.ru>, 2009.
  6. Slava Zanko <slavazanko@gmail.com>, 2009.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  18. /** \file color-internal.c
  19. * \brief Source: Internal stuff of color setup
  20. */
  21. #include <config.h>
  22. #include <string.h> /* strcmp */
  23. #include "color.h" /* colors and attributes */
  24. #include "color-internal.h"
  25. /*** global variables ****************************************************************************/
  26. gboolean mc_tty_color_disable;
  27. /*** file scope macro definitions ****************************************************************/
  28. /*** file scope type declarations ****************************************************************/
  29. typedef struct mc_tty_color_table_struct {
  30. const char *name;
  31. int value;
  32. } mc_tty_color_table_t;
  33. /*** file scope variables ************************************************************************/
  34. mc_tty_color_table_t const color_table[] = {
  35. { "black", COLOR_BLACK },
  36. { "gray", COLOR_BLACK | A_BOLD },
  37. { "red", COLOR_RED },
  38. { "brightred", COLOR_RED | A_BOLD },
  39. { "green", COLOR_GREEN },
  40. { "brightgreen", COLOR_GREEN | A_BOLD },
  41. { "brown", COLOR_YELLOW },
  42. { "yellow", COLOR_YELLOW | A_BOLD },
  43. { "blue", COLOR_BLUE },
  44. { "brightblue", COLOR_BLUE | A_BOLD },
  45. { "magenta", COLOR_MAGENTA },
  46. { "brightmagenta", COLOR_MAGENTA | A_BOLD },
  47. { "cyan", COLOR_CYAN },
  48. { "brightcyan", COLOR_CYAN | A_BOLD },
  49. { "lightgray", COLOR_WHITE },
  50. { "white", COLOR_WHITE | A_BOLD },
  51. { "default", -1 }, /* default color of the terminal */
  52. /* special colors */
  53. { "A_REVERSE", SPEC_A_REVERSE },
  54. { "A_BOLD", SPEC_A_BOLD},
  55. { "A_BOLD_REVERSE", SPEC_A_BOLD_REVERSE },
  56. { "A_UNDERLINE", SPEC_A_UNDERLINE },
  57. /* End of list */
  58. { NULL, 0}
  59. };
  60. /*** file scope functions ************************************************************************/
  61. /* --------------------------------------------------------------------------------------------- */
  62. /*** public functions ****************************************************************************/
  63. /* --------------------------------------------------------------------------------------------- */
  64. const char *
  65. tty_color_get_valid_name (const char *color_name)
  66. {
  67. int i;
  68. if (color_name != NULL)
  69. for (i = 0; color_table[i].name != NULL; i++)
  70. if (strcmp (color_name, color_table[i].name) == 0)
  71. return color_table[i].name;
  72. return NULL;
  73. }
  74. /* --------------------------------------------------------------------------------------------- */
  75. int
  76. tty_color_get_index_by_name (const char *color_name)
  77. {
  78. int i;
  79. if (color_name != NULL)
  80. for (i = 0; color_table[i].name != NULL; i++)
  81. if (strcmp (color_name, color_table[i].name) == 0)
  82. return color_table[i].value;
  83. return -1;
  84. }
  85. /* --------------------------------------------------------------------------------------------- */