#ifndef INCLUDE_NCURSES_COLORS_HPP_ #define INCLUDE_NCURSES_COLORS_HPP_ #include "ncurses/utils/macros.hpp" #include #include namespace NCURSES_CPP_NAMESPACE { // TODO: there is no usage for this for now enum class curs_color { black = COLOR_BLACK, red = COLOR_RED, green = COLOR_GREEN, yellow = COLOR_YELLOW, blue = COLOR_BLUE, magenta = COLOR_MAGENTA, cyan = COLOR_CYAN, white = COLOR_WHITE }; struct rgb_color { unsigned char r; unsigned char g; unsigned char b; }; NCURSES_CPP_CONSTEXPR_INLINE static int rgb_to_curses(unsigned char c) NCURSES_CPP_NOEXCEPT { return static_cast(c) * 1000 / 255; } NCURSES_CPP_CONSTEXPR_INLINE static unsigned char curses_to_rgb(int c) NCURSES_CPP_NOEXCEPT { return static_cast((c * 255 / 1000) + (c * 255 % 1000 == 0 ? 0 : 1)); } // TODO: start_color maybe needs to be defined somewhere else inline bool has_colors() { return static_cast(::has_colors()); } inline bool can_change_color() { return static_cast(::can_change_color()); } inline bool init_color(int index, int r, int g, int b) { return init_extended_color(index, rgb_to_curses(r), rgb_to_curses(g), rgb_to_curses(b)) == OK ? true : false; } inline bool color_content(int index, int *r, int *g, int *b) { int res = extended_color_content(index, r, g, b); if (res == ERR) return false; *r = curses_to_rgb(*r); *g = curses_to_rgb(*g); *b = curses_to_rgb(*b); return true; } inline bool init_pair(int index, int fg, int bg) { return init_extended_pair(index, fg, bg) == OK ? true : false; } inline bool pair_content(int index, int *fg, int *bg) { return extended_pair_content(index, fg, bg); } class color_pair { public: using value_type = chtype; NCURSES_CPP_CONSTEXPR color_pair(int index) NCURSES_CPP_NOEXCEPT : index_(index) {} explicit NCURSES_CPP_CONSTEXPR operator value_type() const NCURSES_CPP_NOEXCEPT { return COLOR_PAIR(index_); } private: int index_; }; } // namespace NCURSES_CPP_NAMESPACE #endif // INCLUDE_NCURSES_COLORS_HPP_