Config: reformat all descriptions to fill 80 columns
[ncmpcpp.git] / src / curses / formatted_color.cpp
blobb8006431a735e9031af3f93d92cf415eed17cc49
1 /***************************************************************************
2 * Copyright (C) 2008-2017 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
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. *
9 * *
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. *
14 * *
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"
23 namespace {
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)
50 NC::Color c;
51 is >> c;
52 if (!is.eof() && is.peek() == ':')
54 is.get();
55 NC::FormattedColor::Formats formats;
56 while (!is.eof() && isalpha(is.peek()))
58 char flag = is.get();
59 switch (flag)
61 case 'b':
62 formats.push_back(NC::Format::Bold);
63 break;
64 case 'u':
65 formats.push_back(NC::Format::Underline);
66 break;
67 case 'r':
68 formats.push_back(NC::Format::Reverse);
69 break;
70 case 'a':
71 formats.push_back(NC::Format::AltCharset);
72 break;
73 default:
74 is.setstate(std::ios::failbit);
75 break;
78 fc = NC::FormattedColor(c, std::move(formats));
80 else
81 fc = NC::FormattedColor(c, {});
82 return is;