Commit a8c25f91 by Maarten L. Hekkelman

new colouring of output

parent cb82ec9b
...@@ -174,76 +174,6 @@ namespace colour ...@@ -174,76 +174,6 @@ namespace colour
constexpr auto reset = cif::coloured(none, none, regular); constexpr auto reset = cif::coloured(none, none, regular);
} }
template <typename String, typename CharT>
struct ColouredString
{
static_assert(std::is_reference<String>::value or std::is_pointer<String>::value, "String type must be pointer or reference");
ColouredString(String s, StringColour fore, StringColour back, bool bold = true)
: m_s(s)
, m_fore(30 + static_cast<int>(fore))
, m_back(40 + static_cast<int>(back))
, m_bold(bold)
{
}
ColouredString &operator=(const ColouredString &) = delete;
String m_s;
int m_fore, m_back;
bool m_bold;
};
template <typename CharT, typename Traits>
std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os, const ColouredString<const CharT *, CharT> &s)
{
if (isatty(STDOUT_FILENO))
{
std::basic_ostringstream<CharT, Traits> ostr;
ostr << "\033[" << s.m_fore << ';' << (s.m_bold ? "1" : "22") << ';' << s.m_back << 'm'
<< s.m_s
<< "\033[0m";
return os << ostr.str();
}
else
return os << s.m_s;
}
template <typename CharT, typename Traits, typename String>
std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os, const ColouredString<String, CharT> &s)
{
if (isatty(STDOUT_FILENO))
{
std::basic_ostringstream<CharT, Traits> ostr;
ostr << "\033[" << s.m_fore << ';' << (s.m_bold ? "1" : "22") << ';' << s.m_back << 'm'
<< s.m_s
<< "\033[0m";
return os << ostr.str();
}
else
return os << s.m_s;
}
template <typename CharT>
inline auto coloured(const CharT *s, StringColour fore = StringColour::WHITE, StringColour back = StringColour::RED, bool bold = true)
{
return ColouredString<const CharT *, CharT>(s, fore, back, bold);
}
template <typename CharT, typename Traits, typename Alloc>
inline auto coloured(const std::basic_string<CharT, Traits, Alloc> &s, StringColour fore = StringColour::WHITE, StringColour back = StringColour::RED, bool bold = true)
{
return ColouredString<const std::basic_string<CharT, Traits, Alloc>, CharT>(s, fore, back, bold);
}
template <typename CharT, typename Traits, typename Alloc>
inline auto coloured(std::basic_string<CharT, Traits, Alloc> &s, StringColour fore = StringColour::WHITE, StringColour back = StringColour::RED, bool bold = true)
{
return ColouredString<std::basic_string<CharT, Traits, Alloc>, CharT>(s, fore, back, bold);
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// A progress bar // A progress bar
......
...@@ -1056,7 +1056,11 @@ bool Remark3Parser::match(const char *expr, int nextState) ...@@ -1056,7 +1056,11 @@ bool Remark3Parser::match(const char *expr, int nextState)
if (result) if (result)
mState = nextState; mState = nextState;
else if (cif::VERBOSE >= 3) else if (cif::VERBOSE >= 3)
std::cerr << cif::coloured("No match:", cif::StringColour::WHITE, cif::StringColour::RED) << " '" << expr << '\'' << std::endl; {
using namespace colour;
std::cerr << coloured(white, red, bold) << "No match:" << reset << " '" << expr << '\'' << std::endl;
}
return result; return result;
} }
...@@ -1116,7 +1120,11 @@ float Remark3Parser::parse() ...@@ -1116,7 +1120,11 @@ float Remark3Parser::parse()
} }
if (cif::VERBOSE >= 2) if (cif::VERBOSE >= 2)
std::cerr << cif::coloured("Dropping line:", cif::StringColour::WHITE, cif::StringColour::RED) << " '" << mLine << '\'' << std::endl; {
using namespace colour;
std::cerr << coloured(white, red, bold) << "Dropping line:" << reset << " '" << mLine << '\'' << std::endl;
}
++dropped; ++dropped;
} }
......
...@@ -136,10 +136,8 @@ void dump_selection(const std::vector<tls_residue> &selected, size_t indentLevel ...@@ -136,10 +136,8 @@ void dump_selection(const std::vector<tls_residue> &selected, size_t indentLevel
if (first) if (first)
{ {
if (isatty(STDOUT_FILENO)) using namespace colour;
std::cout << indent << cif::coloured("Empty selection") << std::endl; std::cout << indent << coloured(white, red, bold) << "Empty selection" << reset << std::endl;
else
std::cout << indent << "Empty selection" << std::endl;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment