1
0
Fork 0
This commit is contained in:
Frank Celler 2016-03-10 23:02:59 +01:00
parent f4335d4a7e
commit ab6224e2ae
1 changed files with 57 additions and 68 deletions

View File

@ -151,7 +151,7 @@ static void _print2(std::string const& s) {
SetConsoleTextAttribute(handle, CONSOLE_ATTRIBUTE | CONSOLE_COLOR); SetConsoleTextAttribute(handle, CONSOLE_ATTRIBUTE | CONSOLE_COLOR);
DWORD n; DWORD n;
WriteConsoleW(handle, wBuf, (DWORD) wLen, &n, NULL); WriteConsoleW(handle, wBuf, (DWORD)wLen, &n, NULL);
} else { } else {
fprintf(stdout, "window error: '%d' \r\n", GetLastError()); fprintf(stdout, "window error: '%d' \r\n", GetLastError());
fprintf(stdout, "%s\r\n", s.c_str()); fprintf(stdout, "%s\r\n", s.c_str());
@ -162,17 +162,14 @@ static void _print2(std::string const& s) {
} }
} }
static void _newLine() { static void _newLine() { fprintf(stdout, "\n"); }
fprintf(stdout, "\n");
}
static void _print(std::string const& s) { static void _print(std::string const& s) {
auto pos = s.find_first_of("\x1b"); auto pos = s.find_first_of("\x1b");
if (pos == std::string::npos) { if (pos == std::string::npos) {
_print2(s); _print2(s);
} } else {
else {
std::vector<std::string> lines = StringUtils::split(s, '\x1b', '\0'); std::vector<std::string> lines = StringUtils::split(s, '\x1b', '\0');
int i = 0; int i = 0;
@ -191,12 +188,12 @@ static void _print(std::string const& s) {
if ('0' <= c && c <= '9') { if ('0' <= c && c <= '9') {
code = code * 10 + (c - '0'); code = code * 10 + (c - '0');
} } else if (c == 'm' || c == ';') {
else if (c == 'm' || c == ';') {
switch (code) { switch (code) {
case 0: case 0:
CONSOLE_ATTRIBUTE = 0; CONSOLE_ATTRIBUTE = 0;
CONSOLE_COLOR = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE; CONSOLE_COLOR =
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE;
break; break;
case 1: // BOLD case 1: // BOLD
@ -205,7 +202,8 @@ static void _print(std::string const& s) {
break; break;
case 30: case 30:
CONSOLE_COLOR = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN; CONSOLE_COLOR =
BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN;
break; break;
case 31: case 31:
@ -233,7 +231,8 @@ static void _print(std::string const& s) {
break; break;
case 37: case 37:
CONSOLE_COLOR = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE; CONSOLE_COLOR =
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE;
break; break;
case 39: case 39:
@ -252,7 +251,6 @@ static void _print(std::string const& s) {
} }
} }
if (line.size() > pos) { if (line.size() > pos) {
_print2(line.substr(pos)); _print2(line.substr(pos));
} }
@ -307,7 +305,6 @@ void ConsoleFeature::printLine(std::string const& s) {
} }
if (true) { if (true) {
std::vector<std::string> lines = StringUtils::split(s, '\n', '\0'); std::vector<std::string> lines = StringUtils::split(s, '\n', '\0');
for (auto& line : lines) { for (auto& line : lines) {
@ -322,9 +319,7 @@ void ConsoleFeature::printLine(std::string const& s) {
} }
} }
void ConsoleFeature::printErrorLine(std::string const& s) { void ConsoleFeature::printErrorLine(std::string const& s) { printLine(s); }
printLine(s);
}
std::string ConsoleFeature::readPassword(std::string const& message) { std::string ConsoleFeature::readPassword(std::string const& message) {
std::string password; std::string password;
@ -391,13 +386,7 @@ static std::string StripBinary(std::string const& value) {
void ConsoleFeature::print(std::string const& message) { void ConsoleFeature::print(std::string const& message) {
if (_toPager == stdout) { if (_toPager == stdout) {
#ifdef _WIN32 printContinuous(message);
// at moment the formating is ignored in windows
printLine(message);
#else
fprintf(_toPager, "%s", message.c_str());
#endif
} else { } else {
std::string sanitized = StripBinary(message.c_str()); std::string sanitized = StripBinary(message.c_str());
fprintf(_toPager, "%s", sanitized.c_str()); fprintf(_toPager, "%s", sanitized.c_str());