Add 'makepkg'-style messages to Phrases

experiment/srcref_basic_cfg
Martchus 5 years ago
parent ee66c56905
commit 784f3d963a
  1. 32
      io/ansiescapecodes.cpp
  2. 16
      io/ansiescapecodes.h

@ -2,6 +2,9 @@
namespace EscapeCodes {
/*!
* \brief Prints the specified \a phrase.
*/
std::ostream &operator<<(std::ostream &stream, Phrases phrase)
{
switch (phrase) {
@ -21,6 +24,35 @@ std::ostream &operator<<(std::ostream &stream, Phrases phrase)
setStyle(stream, TextAttribute::Reset);
stream << '\n';
break;
case Phrases::PlainMessage:
stream << " ";
setStyle(stream, TextAttribute::Reset);
setStyle(stream, TextAttribute::Bold);
break;
case Phrases::SuccessMessage:
setStyle(stream, Color::Green, ColorContext::Foreground, TextAttribute::Bold);
stream << "==> ";
setStyle(stream, TextAttribute::Reset);
setStyle(stream, TextAttribute::Bold);
break;
case Phrases::SubMessage:
setStyle(stream, Color::Green, ColorContext::Foreground, TextAttribute::Bold);
stream << " -> ";
setStyle(stream, TextAttribute::Reset);
setStyle(stream, TextAttribute::Bold);
break;
case Phrases::ErrorMessage:
setStyle(stream, Color::Green, ColorContext::Foreground, TextAttribute::Bold);
stream << "==> ERROR: ";
setStyle(stream, TextAttribute::Reset);
setStyle(stream, TextAttribute::Bold);
break;
case Phrases::WarningMessage:
setStyle(stream, Color::Green, ColorContext::Foreground, TextAttribute::Bold);
stream << "==> WARNING: ";
setStyle(stream, TextAttribute::Reset);
setStyle(stream, TextAttribute::Bold);
break;
}
return stream;
}

@ -98,10 +98,20 @@ inline std::ostream &operator<<(std::ostream &stream, std::tuple<Color, Color, T
return stream;
}
/*!
* \brief The Phrases enum contains standard phrases which can be printed to any std::ostream.
*
* Example: `std::cerr << Phrases::Error << "Something bad happened." << Phrases::End`
*/
enum class Phrases {
Error,
Warning,
End,
Error, /**< bold, red "Error: " */
Warning, /**< bold, yellow "Warning: " */
End, /**< resets the style */
PlainMessage, /**< bold, 4 spaces " " */
SuccessMessage, /**< bold, green "==> " */
SubMessage, /**< bold, blue " -> " */
ErrorMessage, /**< bold, red "==> ERROR: " */
WarningMessage, /**< bold, yellow "==> WARNING: " */
};
std::ostream &operator<<(std::ostream &stream, Phrases phrase);

Loading…
Cancel
Save