From 2a123df86d5f1f17679d95fbdff9bcf0078904a2 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 26 Mar 2023 21:49:54 +0200 Subject: [PATCH] Avoid use of non-standard escape character to avoid MSVC warning about it --- io/ansiescapecodes.cpp | 24 ++++++++++++------------ io/ansiescapecodes.h | 18 +++++++++--------- tests/argumentparsertests.cpp | 16 ++++++++-------- tests/iotests.cpp | 18 +++++++++--------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/io/ansiescapecodes.cpp b/io/ansiescapecodes.cpp index a6a1759..f7287ef 100644 --- a/io/ansiescapecodes.cpp +++ b/io/ansiescapecodes.cpp @@ -164,30 +164,30 @@ std::string_view formattedPhraseString(Phrases phrase) using namespace std::string_view_literals; switch (phrase) { case Phrases::Error: - return "\e[1;31mError: \e[0m\e[1m"sv; + return "\033[1;31mError: \033[0m\033[1m"sv; case Phrases::Warning: - return "\e[1;33mWarning: \e[0m\e[1m"sv; + return "\033[1;33mWarning: \033[0m\033[1m"sv; case Phrases::PlainMessage: - return " \e[0m\e[1m"sv; + return " \033[0m\033[1m"sv; case Phrases::SuccessMessage: - return "\e[1;32m==> \e[0m\e[1m"sv; + return "\033[1;32m==> \033[0m\033[1m"sv; case Phrases::SubMessage: - return "\e[1;32m -> \e[0m\e[1m"sv; + return "\033[1;32m -> \033[0m\033[1m"sv; case Phrases::ErrorMessage: - return "\e[1;31m==> ERROR: \e[0m\e[1m"sv; + return "\033[1;31m==> ERROR: \033[0m\033[1m"sv; case Phrases::WarningMessage: - return "\e[1;33m==> WARNING: \e[0m\e[1m"; + return "\033[1;33m==> WARNING: \033[0m\033[1m"; case Phrases::Info: - return "\e[1;34mInfo: \e[0m\e[1m"sv; + return "\033[1;34mInfo: \033[0m\033[1m"sv; case Phrases::SubError: - return "\e[1;31m -> ERROR: \e[0m\e[1m"sv; + return "\033[1;31m -> ERROR: \033[0m\033[1m"sv; case Phrases::SubWarning: - return "\e[1;33m -> WARNING: \e[0m\e[1m"sv; + return "\033[1;33m -> WARNING: \033[0m\033[1m"sv; case Phrases::InfoMessage: - return "\e[1;37m==> \e[0m\e[1m"sv; + return "\033[1;37m==> \033[0m\033[1m"sv; case Phrases::End: case Phrases::EndFlush: - return "\e[0m\n"; + return "\033[0m\n"; default: return std::string_view{}; } diff --git a/io/ansiescapecodes.h b/io/ansiescapecodes.h index 8898ecf..f9755df 100644 --- a/io/ansiescapecodes.h +++ b/io/ansiescapecodes.h @@ -34,7 +34,7 @@ enum class Direction : char { Up = 'A', Down = 'B', Forward = 'C', Backward = 'D inline void setStyle(std::ostream &stream, TextAttribute displayAttribute = TextAttribute::Reset) { if (enabled) { - stream << '\e' << '[' << static_cast(displayAttribute) << 'm'; + stream << '\033' << '[' << static_cast(displayAttribute) << 'm'; } } @@ -42,14 +42,14 @@ inline void setStyle( std::ostream &stream, Color color, ColorContext context = ColorContext::Foreground, TextAttribute displayAttribute = TextAttribute::Reset) { if (enabled) { - stream << '\e' << '[' << static_cast(displayAttribute) << ';' << static_cast(context) << static_cast(color) << 'm'; + stream << '\033' << '[' << static_cast(displayAttribute) << ';' << static_cast(context) << static_cast(color) << 'm'; } } inline void setStyle(std::ostream &stream, Color foregroundColor, Color backgroundColor, TextAttribute displayAttribute = TextAttribute::Reset) { if (enabled) { - stream << '\e' << '[' << static_cast(displayAttribute) << ';' << static_cast(ColorContext::Foreground) + stream << '\033' << '[' << static_cast(displayAttribute) << ';' << static_cast(ColorContext::Foreground) << static_cast(foregroundColor) << ';' << static_cast(ColorContext::Background) << static_cast(backgroundColor) << 'm'; } @@ -58,42 +58,42 @@ inline void setStyle(std::ostream &stream, Color foregroundColor, Color backgrou inline void resetStyle(std::ostream &stream) { if (enabled) { - stream << '\e' << '[' << static_cast(TextAttribute::Reset) << 'm'; + stream << '\033' << '[' << static_cast(TextAttribute::Reset) << 'm'; } } inline void setCursor(std::ostream &stream, unsigned int row = 0, unsigned int col = 0) { if (enabled) { - stream << '\e' << '[' << row << ';' << col << 'H'; + stream << '\033' << '[' << row << ';' << col << 'H'; } } inline void moveCursor(std::ostream &stream, unsigned int cells, Direction direction) { if (enabled) { - stream << '\e' << '[' << cells << static_cast(direction); + stream << '\033' << '[' << cells << static_cast(direction); } } inline void saveCursor(std::ostream &stream) { if (enabled) { - stream << "\e[s"; + stream << "\033[s"; } } inline void restoreCursor(std::ostream &stream) { if (enabled) { - stream << "\e[u"; + stream << "\033[u"; } } inline void eraseDisplay(std::ostream &stream) { if (enabled) { - stream << "\e[2J"; + stream << "\033[2J"; } } diff --git a/tests/argumentparsertests.cpp b/tests/argumentparsertests.cpp index 918c955..5987131 100644 --- a/tests/argumentparsertests.cpp +++ b/tests/argumentparsertests.cpp @@ -816,30 +816,30 @@ void ArgumentParserTests::testHelp() // parse args and assert output const char *const argv[] = { "app", "-h" }; { - const OutputCheck c("\e[1m" APP_NAME ", version " APP_VERSION "\n" + const OutputCheck c("\033[1m" APP_NAME ", version " APP_VERSION "\n" "\n" - "\e[0m" APP_DESCRIPTION "\n" + "\033[0m" APP_DESCRIPTION "\n" "\n" "Available operations:\n" - "\e[1mverbose, -v\e[0m\n" + "\033[1mverbose, -v\033[0m\n" " be verbose\n" " example: actually not an operation\n" "\n" "Available top-level options:\n" - "\e[1m--files, -f\e[0m\n" + "\033[1m--files, -f\033[0m\n" " specifies the path of the file(s) to be opened\n" - " \e[1m--sub\e[0m\n" + " \033[1m--sub\033[0m\n" " sub arg\n" " particularities: mandatory if parent argument is present\n" - " \e[1m--nested-sub\e[0m [value1] [value2] ...\n" + " \033[1m--nested-sub\033[0m [value1] [value2] ...\n" " nested sub arg\n" " example: sub arg example\n" "\n" - "\e[1m--env\e[0m [file] [value 2]\n" + "\033[1m--env\033[0m [file] [value 2]\n" " env\n" " default environment variable: FILES\n" "\n" - "\e[1m--no-color\e[0m\n" + "\033[1m--no-color\033[0m\n" " disables formatted/colorized output\n" " default environment variable: ENABLE_ESCAPE_CODES\n" "\n" diff --git a/tests/iotests.cpp b/tests/iotests.cpp index e2c6f3b..c19f6ca 100644 --- a/tests/iotests.cpp +++ b/tests/iotests.cpp @@ -650,15 +650,15 @@ void IoTests::testAnsiEscapeCodes() << "blue, blinking text on red background" << EscapeCodes::TextAttribute::Reset << '\n'; cout << "\noutput for formatting with ANSI escape codes:\n" << ss1.str() << "---------------------------------------------\n"; fstream("/tmp/test.txt", ios_base::out | ios_base::trunc) << ss1.str(); - CPPUNIT_ASSERT_EQUAL("\e[1;31mError: \e[0m\e[1msome error\e[0m\n" - "\e[1;33mWarning: \e[0m\e[1msome warning\e[0m\n" - "\e[1;34mInfo: \e[0m\e[1msome info\e[0m\n" - "\e[1;31m==> ERROR: \e[0m\e[1mArch-style error\e[0m\n" - "\e[1;33m==> WARNING: \e[0m\e[1mArch-style warning\e[0m\n" - " \e[0m\e[1mArch-style message\e[0m\n" - "\e[1;32m==> \e[0m\e[1mArch-style success\e[0m\n" - "\e[1;32m -> \e[0m\e[1mArch-style sub-message\e[0m\n" - "\e[5;34;41mblue, blinking text on red background\e[0m\n"s, + CPPUNIT_ASSERT_EQUAL("\033[1;31mError: \033[0m\033[1msome error\033[0m\n" + "\033[1;33mWarning: \033[0m\033[1msome warning\033[0m\n" + "\033[1;34mInfo: \033[0m\033[1msome info\033[0m\n" + "\033[1;31m==> ERROR: \033[0m\033[1mArch-style error\033[0m\n" + "\033[1;33m==> WARNING: \033[0m\033[1mArch-style warning\033[0m\n" + " \033[0m\033[1mArch-style message\033[0m\n" + "\033[1;32m==> \033[0m\033[1mArch-style success\033[0m\n" + "\033[1;32m -> \033[0m\033[1mArch-style sub-message\033[0m\n" + "\033[5;34;41mblue, blinking text on red background\033[0m\n"s, ss1.str()); stringstream ss2;