MCPcopy Create free account
hub / github.com/78/tenbox / StripHostTerminalResponses

Function StripHostTerminalResponses

src/client/client.cpp:152–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152std::string StripHostTerminalResponses(const char* data, size_t size) {
153 std::string out;
154 out.reserve(size);
155 for (size_t i = 0; i < size;) {
156 const unsigned char ch = static_cast<unsigned char>(data[i]);
157 if (ch == 0x1b && i + 1 < size) {
158 if (data[i + 1] == '[') {
159 size_t j = i + 2;
160 while (j < size) {
161 const unsigned char c = static_cast<unsigned char>(data[j]);
162 if (c >= 0x40 && c <= 0x7e) break;
163 ++j;
164 }
165 if (j < size && (data[j] == 'R' || data[j] == 'c')) {
166 i = j + 1;
167 continue;
168 }
169 } else if (data[i + 1] == ']') {
170 size_t j = i + 2;
171 while (j < size) {
172 if (data[j] == '\a') {
173 ++j;
174 break;
175 }
176 if (data[j] == 0x1b && j + 1 < size && data[j + 1] == '\\') {
177 j += 2;
178 break;
179 }
180 ++j;
181 }
182 if (j <= size) {
183 i = j;
184 continue;
185 }
186 } else if (data[i + 1] == 'P') {
187 size_t j = i + 2;
188 while (j + 1 < size) {
189 if (data[j] == 0x1b && data[j + 1] == '\\') {
190 j += 2;
191 break;
192 }
193 ++j;
194 }
195 if (j <= size) {
196 i = j;
197 continue;
198 }
199 }
200 }
201 out.push_back(data[i++]);
202 }
203 return out;
204}
205
206void HandleConsoleEvent(const nlohmann::json& event) {
207 if (event.value("type", "") == "console.data") {

Callers 1

AttachConsoleMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected