mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-10 15:52:12 +00:00
Don't print escape sequences in logs, print raw
This commit is contained in:
parent
b25fee150a
commit
a8ed99a7b4
@ -146,7 +146,7 @@ void PrintColored(std::string text, std::string fgColor, std::string bgColor, bo
|
||||
int LogWarning(const string& warningText)
|
||||
{
|
||||
PrintColored("WARNING: ", yellowFGColor, "", true);
|
||||
PrintColored(warningText, yellowFGColor, "", true);
|
||||
PrintColored(escaped(warningText), yellowFGColor, "", true);
|
||||
cerr << std::endl;
|
||||
//cout << "\x1B[33mWARNING: " << warningText << "\033[0m\t\t" << endl;
|
||||
return 1;
|
||||
@ -184,7 +184,7 @@ int InterpreterLog(const string& logText)
|
||||
|
||||
PrintColored("[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] ", blueFGColor, "", true);
|
||||
PrintColored("ZSharp: ", yellowFGColor, "", true);
|
||||
PrintColored(logText, greenFGColor, "", true);
|
||||
PrintColored(escaped(logText), greenFGColor, "", true);
|
||||
cout << std::endl;
|
||||
//cout << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mZSharp: \x1B[32m" << logText << "\033[0m\t\t" << endl;
|
||||
return 1;
|
||||
@ -221,7 +221,7 @@ int LogCriticalError(const string& errorText)
|
||||
|
||||
PrintColored("[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] ", blueFGColor, "", true);
|
||||
PrintColored("ZSharp: ", yellowFGColor, "", true);
|
||||
PrintColored(errorText, redFGColor, "", true);
|
||||
PrintColored(escaped(errorText), redFGColor, "", true);
|
||||
cerr << std::endl;
|
||||
InterpreterLog("Press Enter to Exit...");
|
||||
cin.ignore();
|
||||
|
||||
@ -51,6 +51,26 @@ string unescape(const string& s)
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string escaped(const std::string& input)
|
||||
{
|
||||
std::string output;
|
||||
output.reserve(input.size());
|
||||
for (const char c : input) {
|
||||
switch (c) {
|
||||
case '\a': output += "\\a"; break;
|
||||
case '\b': output += "\\b"; break;
|
||||
case '\f': output += "\\f"; break;
|
||||
case '\n': output += "\\n"; break;
|
||||
case '\r': output += "\\r"; break;
|
||||
case '\t': output += "\\t"; break;
|
||||
case '\v': output += "\\v"; break;
|
||||
default: output += c; break;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
string StringRaw(const string& s)
|
||||
{
|
||||
string str = trim(s);
|
||||
|
||||
@ -69,4 +69,6 @@ bool isEscaped(const string& str, int curChar);
|
||||
|
||||
bool startsWith(const string& str, const string& lookFor);
|
||||
|
||||
std::string escaped(const std::string& input);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user