1 /***************************************************************************
2 * Copyright (C) 2008-2017 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * 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 *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
22 #include "formatted_color.h"
26 void verifyFormats(const NC::FormattedColor::Formats
&formats
)
28 for (auto &fmt
: formats
)
30 if (fmt
== NC::Format::NoBold
31 || fmt
== NC::Format::NoUnderline
32 || fmt
== NC::Format::NoReverse
33 || fmt
== NC::Format::NoAltCharset
)
34 throw std::logic_error("FormattedColor can't hold disabling formats");
40 NC::FormattedColor::FormattedColor(Color color_
, Formats formats_
)
42 if (color_
== NC::Color::End
)
43 throw std::logic_error("FormattedColor can't hold Color::End");
44 m_color
= std::move(color_
);
45 verifyFormats(formats_
);
46 m_formats
= std::move(formats_
);
49 std::istream
&NC::operator>>(std::istream
&is
, NC::FormattedColor
&fc
)
53 if (!is
.eof() && is
.peek() == ':')
56 NC::FormattedColor::Formats formats
;
57 while (!is
.eof() && isalpha(is
.peek()))
63 formats
.push_back(NC::Format::Bold
);
66 formats
.push_back(NC::Format::Underline
);
69 formats
.push_back(NC::Format::Reverse
);
72 formats
.push_back(NC::Format::AltCharset
);
75 is
.setstate(std::ios::failbit
);
79 fc
= NC::FormattedColor(c
, std::move(formats
));
82 fc
= NC::FormattedColor(c
, {});