Prints a string containing code-encoded text. The following escape sequences can be used in the string to control the text color: @@ prints a single '@' character. @R changes the color to red. @G changes the color to green. @Y changes the color to yellow. @D changes to the default terminal text color. TODO(wan@google.com): Write tests for this once we add stdout capturing to Goog
| 6701 | // TODO(wan@google.com): Write tests for this once we add stdout |
| 6702 | // capturing to Google Test. |
| 6703 | static void PrintColorEncoded(const char* str) { |
| 6704 | GTestColor color = COLOR_DEFAULT; // The current color. |
| 6705 | |
| 6706 | // Conceptually, we split the string into segments divided by escape |
| 6707 | // sequences. Then we print one segment at a time. At the end of |
| 6708 | // each iteration, the str pointer advances to the beginning of the |
| 6709 | // next segment. |
| 6710 | for (;;) { |
| 6711 | const char* p = strchr(str, '@'); |
| 6712 | if (p == NULL) { |
| 6713 | ColoredPrintf(color, "%s", str); |
| 6714 | return; |
| 6715 | } |
| 6716 | |
| 6717 | ColoredPrintf(color, "%s", std::string(str, p).c_str()); |
| 6718 | |
| 6719 | const char ch = p[1]; |
| 6720 | str = p + 2; |
| 6721 | if (ch == '@') { |
| 6722 | ColoredPrintf(color, "@"); |
| 6723 | } else if (ch == 'D') { |
| 6724 | color = COLOR_DEFAULT; |
| 6725 | } else if (ch == 'R') { |
| 6726 | color = COLOR_RED; |
| 6727 | } else if (ch == 'G') { |
| 6728 | color = COLOR_GREEN; |
| 6729 | } else if (ch == 'Y') { |
| 6730 | color = COLOR_YELLOW; |
| 6731 | } else { |
| 6732 | --str; |
| 6733 | } |
| 6734 | } |
| 6735 | } |
| 6736 | |
| 6737 | static const char kColorEncodedHelpMessage[] = |
| 6738 | "This program contains tests written using " GTEST_NAME_ ". You can use the\n" |
no test coverage detected