color-internal.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. {
  31. const char *name;
  32. int value;
  33. } mc_tty_color_table_t;
  34. /*** file scope variables ************************************************************************/
  35. mc_tty_color_table_t const color_table[] = {
  36. {"black", COLOR_BLACK},
  37. {"gray", COLOR_BLACK | A_BOLD},
  38. {"red", COLOR_RED},
  39. {"brightred", COLOR_RED | A_BOLD},
  40. {"green", COLOR_GREEN},
  41. {"brightgreen", COLOR_GREEN | A_BOLD},
  42. {"brown", COLOR_YELLOW},
  43. {"yellow", COLOR_YELLOW | A_BOLD},
  44. {"blue", COLOR_BLUE},
  45. {"brightblue", COLOR_BLUE | A_BOLD},
  46. {"magenta", COLOR_MAGENTA},
  47. {"brightmagenta", COLOR_MAGENTA | A_BOLD},
  48. {"cyan", COLOR_CYAN},
  49. {"brightcyan", COLOR_CYAN | A_BOLD},
  50. {"lightgray", COLOR_WHITE},
  51. {"white", COLOR_WHITE | A_BOLD},
  52. {"default", -1}, /* default color of the terminal */
  53. /* special colors */
  54. {"A_REVERSE", SPEC_A_REVERSE},
  55. {"A_BOLD", SPEC_A_BOLD},
  56. {"A_BOLD_REVERSE", SPEC_A_BOLD_REVERSE},
  57. {"A_UNDERLINE", SPEC_A_UNDERLINE},
  58. /* End of list */
  59. {NULL, 0}
  60. };
  61. /*** file scope functions ************************************************************************/
  62. /* --------------------------------------------------------------------------------------------- */
  63. /*** public functions ****************************************************************************/
  64. /* --------------------------------------------------------------------------------------------- */
  65. const char *
  66. tty_color_get_valid_name (const char *color_name)
  67. {
  68. if (color_name != NULL)
  69. {
  70. size_t i;
  71. for (i = 0; color_table[i].name != NULL; i++)
  72. if (strcmp (color_name, color_table[i].name) == 0)
  73. return color_table[i].name;
  74. }
  75. return NULL;
  76. }
  77. /* --------------------------------------------------------------------------------------------- */
  78. int
  79. tty_color_get_index_by_name (const char *color_name)
  80. {
  81. if (color_name != NULL)
  82. {
  83. size_t i;
  84. for (i = 0; color_table[i].name != NULL; i++)
  85. if (strcmp (color_name, color_table[i].name) == 0)
  86. return color_table[i].value;
  87. }
  88. return -1;
  89. }
  90. /* --------------------------------------------------------------------------------------------- */