/* color.cc * This file is part of ncursesxx library * Copyright (c) 2003,2004 by Stanislav Ievlev * * This file is covered by the GNU Library General Public License, * which should be included with libncursesxx as the file COPYING. */ #include #include #include #include using ncurses::color; static std::map, short> color_pairs; static short make_pair (short fg, short bg) { auto pair = std::make_pair (fg, bg); auto found = color_pairs.find (pair); if (found != color_pairs.end ()) return found->second; static short color_counter; color_pairs.insert ({ pair, ++color_counter }); return color_counter; } color::color () : attr_ (WA_NORMAL) , num_ (-1) { } color::color (short f, short b, attr_t attr) : attr_ (attr) , num_ (make_pair (f, b)) { if (has_colors ()) return_unless (init_pair (num_, f, b) == OK); } color::~color () { } attr_t color::attr () const { return attr_; } short color::num () const { return num_; }