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 ***************************************************************************/
21 #include "formatted_color.h"
25 void verifyFormats(const NC::FormattedColor::Formats
&formats
)
27 for (auto &fmt
: formats
)
29 if (fmt
== NC::Format::NoBold
30 || fmt
== NC::Format::NoUnderline
31 || fmt
== NC::Format::NoReverse
32 || fmt
== NC::Format::NoAltCharset
)
33 throw std::logic_error("FormattedColor can't hold disabling formats");
39 NC::FormattedColor::FormattedColor(Color color_
, Formats formats_
)
41 if (color_
== NC::Color::End
)
42 throw std::logic_error("FormattedColor can't hold Color::End");
43 m_color
= std::move(color_
);
44 verifyFormats(formats_
);
45 m_formats
= std::move(formats_
);
48 std::istream
&NC::operator>>(std::istream
&is
, NC::FormattedColor
&fc
)
52 if (!is
.eof() && is
.peek() == ':')
55 NC::FormattedColor::Formats formats
;
56 while (!is
.eof() && isalpha(is
.peek()))
62 formats
.push_back(NC::Format::Bold
);
65 formats
.push_back(NC::Format::Underline
);
68 formats
.push_back(NC::Format::Reverse
);
71 formats
.push_back(NC::Format::AltCharset
);
74 is
.setstate(std::ios::failbit
);
78 fc
= NC::FormattedColor(c
, std::move(formats
));
81 fc
= NC::FormattedColor(c
, {});