color.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * color.h - color support
  4. *
  5. * Copyright © 2015-2016 Guillem Jover <guillem@debian.org>
  6. *
  7. * This 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. *
  12. * This is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef LIBDPKG_COLOR_H
  21. #define LIBDPKG_COLOR_H
  22. #include <stdbool.h>
  23. #include <dpkg/macros.h>
  24. DPKG_BEGIN_DECLS
  25. /**
  26. * @defgroup color Color support
  27. * @ingroup dpkg-internal
  28. * @{
  29. */
  30. /* Standard ANSI colors and attributes. */
  31. #define COLOR_NORMAL ""
  32. #define COLOR_RESET "\e[0m"
  33. #define COLOR_BOLD "\e[1m"
  34. #define COLOR_BLACK "\e[30m"
  35. #define COLOR_RED "\e[31m"
  36. #define COLOR_GREEN "\e[32m"
  37. #define COLOR_YELLOW "\e[33m"
  38. #define COLOR_BLUE "\e[34m"
  39. #define COLOR_MAGENTA "\e[35m"
  40. #define COLOR_CYAN "\e[36m"
  41. #define COLOR_WHITE "\e[37m"
  42. #define COLOR_BOLD_BLACK "\e[1;30m"
  43. #define COLOR_BOLD_RED "\e[1;31m"
  44. #define COLOR_BOLD_GREEN "\e[1;32m"
  45. #define COLOR_BOLD_YELLOW "\e[1;33m"
  46. #define COLOR_BOLD_BLUE "\e[1;34m"
  47. #define COLOR_BOLD_MAGENTA "\e[1;35m"
  48. #define COLOR_BOLD_CYAN "\e[1;36m"
  49. #define COLOR_BOLD_WHITE "\e[1;37m"
  50. /* Current defaults. These might become configurable in the future. */
  51. #define COLOR_PROG COLOR_BOLD
  52. #define COLOR_INFO COLOR_GREEN
  53. #define COLOR_NOTICE COLOR_YELLOW
  54. #define COLOR_WARN COLOR_BOLD_YELLOW
  55. #define COLOR_ERROR COLOR_BOLD_RED
  56. enum color_mode {
  57. COLOR_MODE_UNKNOWN = -1,
  58. COLOR_MODE_NEVER,
  59. COLOR_MODE_ALWAYS,
  60. COLOR_MODE_AUTO,
  61. };
  62. bool
  63. color_set_mode(const char *mode);
  64. const char *
  65. color_get(const char *color);
  66. static inline const char *
  67. color_reset(void)
  68. {
  69. return color_get(COLOR_RESET);
  70. }
  71. /** @} */
  72. DPKG_END_DECLS
  73. #endif /* LIBDPKG_COLOR_H */