| 314 | } |
| 315 | |
| 316 | void PrintChar(char ch){ |
| 317 | if(escapeSequence){ |
| 318 | if(isspace(ch)){ |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | if(!escapeType){ |
| 323 | escapeType = ch; |
| 324 | ch = 0; |
| 325 | } |
| 326 | |
| 327 | if(escapeType == ANSI_CSI || escapeType == ANSI_OSC){ |
| 328 | if(!isalpha(ch)){ // Found output sequence |
| 329 | if(strlen(escBuf) >= escBufMax){ |
| 330 | escapeSequence = false; |
| 331 | return; |
| 332 | } |
| 333 | char s[] = {ch, 0}; |
| 334 | strncat(escBuf, s, 2); // Add to buff |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | if(escapeType == ANSI_CSI){ |
| 339 | DoAnsiCSI(ch); |
| 340 | } else if (escapeType == ANSI_OSC) { |
| 341 | DoAnsiOSC(ch); |
| 342 | } |
| 343 | } else if (escapeType == ANSI_RIS){ |
| 344 | state = defaultState; |
| 345 | screenBuffer.clear(); |
| 346 | curPos = {0, 0}; |
| 347 | for(int i = 0; i < wSize.ws_row; i++){ |
| 348 | screenBuffer.push_back(std::vector<TerminalChar>()); |
| 349 | } |
| 350 | } else if(escapeType == ESC_SAVE_CURSOR) { |
| 351 | storedCurPos = curPos; |
| 352 | } else if(escapeType == ESC_RESTORE_CURSOR) { |
| 353 | curPos = storedCurPos; |
| 354 | } else { |
| 355 | //fprintf(stderr, "Unknown ANSI escape code '%c'\n", ch); |
| 356 | } |
| 357 | escapeSequence = 0; |
| 358 | escapeType = 0; |
| 359 | } else { |
| 360 | |
| 361 | switch (ch) |
| 362 | { |
| 363 | case ANSI_ESC: |
| 364 | escapeSequence = true; |
| 365 | escapeType = 0; |
| 366 | escBuf[0] = 0; |
| 367 | break; |
| 368 | case '\n': |
| 369 | curPos.y++; |
| 370 | curPos.x = 0; |
| 371 | Scroll(); |
| 372 | break; |
| 373 | case '\b': |