| 119 | } |
| 120 | |
| 121 | void StdInOutConsole::WriteLine(const std::string& s, FormatToken colourFormat) |
| 122 | { |
| 123 | std::string formatBegin; |
| 124 | switch (colourFormat) |
| 125 | { |
| 126 | case FormatToken::colourRed: |
| 127 | formatBegin = "\033[31m"; |
| 128 | break; |
| 129 | case FormatToken::colourYellow: |
| 130 | formatBegin = "\033[33m"; |
| 131 | break; |
| 132 | default: |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | if (!Platform::IsColourTerminalSupported()) |
| 137 | { |
| 138 | std::printf("%s\n", s.c_str()); |
| 139 | std::fflush(stdout); |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | if (_isPromptShowing) |
| 144 | { |
| 145 | auto* mainString = s.c_str(); |
| 146 | |
| 147 | // If string contains \n, we need to replace with \r\n |
| 148 | std::string newString; |
| 149 | if (s.find('\n') != std::string::npos) |
| 150 | { |
| 151 | for (auto ch : s) |
| 152 | { |
| 153 | if (ch == '\n') |
| 154 | newString += "\r\n"; |
| 155 | else |
| 156 | newString += ch; |
| 157 | } |
| 158 | mainString = newString.c_str(); |
| 159 | } |
| 160 | |
| 161 | std::printf("\r%s%s\x1b[0m\x1b[0K\r\n", formatBegin.c_str(), mainString); |
| 162 | std::fflush(stdout); |
| 163 | linenoise::linenoiseEditRefreshLine(); |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | std::printf("%s%s\x1b[0m\n", formatBegin.c_str(), s.c_str()); |
| 168 | std::fflush(stdout); |
| 169 | } |
| 170 | } |
| 171 | } |
no test coverage detected