| 95 | } |
| 96 | |
| 97 | void ScriptConsole::write(const char* data, size_t len) |
| 98 | { |
| 99 | if (data == nullptr || len == 0) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | std::lock_guard<std::mutex> lock(mMutex); |
| 104 | for (size_t i = 0; i < len; i++) { |
| 105 | const char c = data[i]; |
| 106 | if (c == '\n') { |
| 107 | // Close the row. An empty run of newlines still produces blank |
| 108 | // rows, which is what a script printing "\n\n" means to see. |
| 109 | if (!mOpen) { |
| 110 | appendChar(' '); |
| 111 | mLines.back().clear(); |
| 112 | } |
| 113 | mOpen = false; |
| 114 | } |
| 115 | else if (c == '\t') { |
| 116 | const size_t col = (mOpen && !mLines.empty()) ? mLines.back().size() : 0; |
| 117 | for (size_t pad = TAB_WIDTH - (col % TAB_WIDTH); pad > 0; pad--) { |
| 118 | appendChar(' '); |
| 119 | } |
| 120 | } |
| 121 | else if (c == '\r' || (unsigned char)c < 0x20 || c == 0x7F) { |
| 122 | continue; // control characters have no cell in the pane |
| 123 | } |
| 124 | else { |
| 125 | appendChar(c); |
| 126 | } |
| 127 | } |
| 128 | mGen++; |
| 129 | } |
| 130 | |
| 131 | void ScriptConsole::log(const std::string& text) |
| 132 | { |
no test coverage detected