Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'cli-rebased' into cli-cccp
Browse files Browse the repository at this point in the history
  • Loading branch information
basxto committed Aug 25, 2019
2 parents 26e37f8 + 0e60fc8 commit 4bb64fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
26 changes: 15 additions & 11 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,29 @@ void LoadingSplashProgressReport(std::string reportString, bool newItem = false)
{
std::cout << std::endl;
}
// overwrite current line
// Overwrite current line
std::cout << "\r";
size_t startPos = 0;
// convert characters to unicode
// just make sure to really overwrite all old output
// Just make sure to really overwrite all old output
// " - done! ✓" is shorter than "reading line 700"
std::string unicoded = reportString + " ";
// also uses terminal coloring
std::string to = "\033[1;32m✓\033[0;0m";
// Colorize output with ANSI escape code
std::string greenTick = "\033[1;32m✓\033[0;0m";
// Convert all ✓ characters to unicode
// It's the 42th from last character in CC's custom font
while ((startPos = unicoded.find(-42, startPos)) != std::string::npos)
{
unicoded.replace(startPos, 1, to);
startPos += to.length();
unicoded.replace(startPos, 1, greenTick);
// We don't have to check indices we just overwrote
startPos += greenTick.length();
}
startPos = 0;
to = "\033[1;33m•\033[0;0m";
std::string yellowDot = "\033[1;33m•\033[0;0m";
// Convert all • characters to unicode
while ((startPos = unicoded.find(-43, startPos)) != std::string::npos)
{
unicoded.replace(startPos, 1, to);
startPos += to.length();
unicoded.replace(startPos, 1, yellowDot);
startPos += yellowDot.length();
}
std::cout << unicoded << std::flush;
}
Expand Down Expand Up @@ -2503,7 +2507,7 @@ bool HandleMainArgs(int argc, char *argv[], int &appExitVar)
for (int i = 1; i < argc; i++)
{
// Print loading screen console to cout
if (strcmp(argv[1], "-cout") == 0)
if (strcmp(argv[i], "-cout") == 0)
{
g_LogToCli = true;
}
Expand Down
19 changes: 13 additions & 6 deletions Managers/ConsoleMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,19 @@ void ConsoleMan::PrintString(string toPrint)
m_pConsoleText->SetText(m_pConsoleText->GetText() + "\n" + toPrint);
if(m_LogToCli)
{
std::regex re_error("(ERROR|SYSTEM):");
toPrint = std::regex_replace(toPrint, re_error, "\033[1;31m$&\033[0;0m");//red
std::regex re_path("\\w*\\.rte\\/(\\w| |\\.|\\/)*(\\/|\\.bmp|\\.wav|\\.lua|\\.ini)");
toPrint = std::regex_replace(toPrint, re_path, "\033[1;32m$&\033[0;0m");//green
std::regex re_name("(\"[A-Z].*\"|\'[A-Z].*\')");
toPrint = std::regex_replace(toPrint, re_name, "\033[1;33m$&\033[0;0m");//yellow
// Color the words ERROR: and SYSTEM: red
std::regex regexError("(ERROR|SYSTEM):");
toPrint = std::regex_replace(toPrint, regexError, "\033[1;31m$&\033[0;0m");

// Color .rte-paths green
std::regex regexPath("\\w*\\.rte\\/(\\w| |\\.|\\/)*(\\/|\\.bmp|\\.wav|\\.lua|\\.ini)");
toPrint = std::regex_replace(toPrint, regexPath, "\033[1;32m$&\033[0;0m");

// Color names in quotes yellow
// They have to start with an upper case letter to sort out apostrophes
std::regex regexName("(\"[A-Z].*\"|\'[A-Z].*\')");
toPrint = std::regex_replace(toPrint, regexName, "\033[1;33m$&\033[0;0m");

std::cout << "\r" << toPrint << std::endl;
}
}
Expand Down

0 comments on commit 4bb64fa

Please sign in to comment.