Browse Source

Add function to get string representation of phrase

charconv
Martchus 2 years ago
parent
commit
5020214498
  1. 4
      CMakeLists.txt
  2. 31
      io/ansiescapecodes.cpp
  3. 2
      io/ansiescapecodes.h

4
CMakeLists.txt

@ -112,8 +112,8 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities")
set(META_FEATURES_FOR_COMPILER_DETECTION_HEADER cxx_thread_local)
set(META_VERSION_MAJOR 5)
set(META_VERSION_MINOR 1)
set(META_VERSION_PATCH 1)
set(META_VERSION_MINOR 2)
set(META_VERSION_PATCH 0)
# find required 3rd party libraries
include(3rdParty)

31
io/ansiescapecodes.cpp

@ -114,6 +114,37 @@ std::ostream &operator<<(std::ostream &stream, Phrases phrase)
return stream;
}
std::string_view phraseString(Phrases phrase)
{
using namespace std::string_view_literals;
switch (phrase) {
case Phrases::Error:
return "Error: "sv;
case Phrases::Warning:
return "Warning: "sv;
case Phrases::PlainMessage:
return " "sv;
case Phrases::SuccessMessage:
return "==> "sv;
case Phrases::SubMessage:
return " -> "sv;
case Phrases::ErrorMessage:
return "==> ERROR: "sv;
case Phrases::WarningMessage:
return "==> WARNING: ";
case Phrases::Info:
return "Info: "sv;
case Phrases::SubError:
return " -> ERROR: "sv;
case Phrases::SubWarning:
return " -> WARNING: "sv;
case Phrases::InfoMessage:
return "==> "sv;
default:
return std::string_view{};
}
}
} // namespace EscapeCodes
} // namespace CppUtilities

2
io/ansiescapecodes.h

@ -5,6 +5,7 @@
#include "../misc/traits.h"
#include <ostream>
#include <string_view>
#include <tuple>
namespace CppUtilities {
@ -150,6 +151,7 @@ enum class Phrases {
InfoMessage, /**< bold, white "==> " */
};
CPP_UTILITIES_EXPORT std::ostream &operator<<(std::ostream &stream, Phrases phrase);
CPP_UTILITIES_EXPORT std::string_view phraseString(Phrases phrase);
} // namespace EscapeCodes
} // namespace CppUtilities

Loading…
Cancel
Save