| 476 | rawmode = 0; |
| 477 | } |
| 478 | void prompt_refresh() |
| 479 | { |
| 480 | char seq[64]; |
| 481 | int cols = get_columns(); |
| 482 | int plen = prompt.size() % cols; |
| 483 | int len = raw_buffer.size(); |
| 484 | int begin = 0; |
| 485 | int cooked_cursor = raw_cursor; |
| 486 | if ((plen+cooked_cursor) >= cols) |
| 487 | { |
| 488 | const int text_over = plen + cooked_cursor + 1 - cols; |
| 489 | begin = text_over; |
| 490 | len -= text_over; |
| 491 | cooked_cursor -= text_over; |
| 492 | } |
| 493 | if (plen+len > cols) |
| 494 | len -= plen+len - cols; |
| 495 | std::string mbstr; |
| 496 | try { |
| 497 | mbstr = toLocaleMB(raw_buffer.substr(begin,len)); |
| 498 | } |
| 499 | catch (std::out_of_range&) { |
| 500 | // fallback check in case begin is still out of range |
| 501 | // (this behaves badly but at least doesn't crash) |
| 502 | mbstr = toLocaleMB(raw_buffer); |
| 503 | } |
| 504 | /* Cursor to left edge */ |
| 505 | snprintf(seq,64,"\x1b[1G"); |
| 506 | if (::write(STDIN_FILENO,seq,strlen(seq)) == -1) return; |
| 507 | /* Write the prompt and the current buffer content */ |
| 508 | if (::write(STDIN_FILENO,prompt.c_str(),plen) == -1) return; |
| 509 | if (::write(STDIN_FILENO,mbstr.c_str(),mbstr.length()) == -1) return; |
| 510 | /* Erase to right */ |
| 511 | snprintf(seq,64,"\x1b[0K"); |
| 512 | if (::write(STDIN_FILENO,seq,strlen(seq)) == -1) return; |
| 513 | /* Move cursor to original position. */ |
| 514 | snprintf(seq,64,"\x1b[1G\x1b[%dC", (int)(cooked_cursor+plen)); |
| 515 | if (::write(STDIN_FILENO,seq,strlen(seq)) == -1) return; |
| 516 | } |
| 517 | |
| 518 | int prompt_loop(std::recursive_mutex * lock, CommandHistory & history) |
| 519 | { |
nothing calls this directly
no test coverage detected