MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / refreshSearchMultiLine

Function refreshSearchMultiLine

tools/shell/linenoise.cpp:2552–2680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2550}
2551
2552static void refreshSearchMultiLine(struct linenoiseState* l, const char* searchPrompt,
2553 const char* searchText) {
2554 char seq[64];
2555 std::string strBuf = l->buf;
2556 uint32_t plen = linenoiseComputeRenderWidth(l->prompt, strlen(l->prompt));
2557 int rows = 1; /* Rows used by current buf. */
2558 int rpos = 1; /* Cursor relative row. */
2559 int rpos2; /* rpos after refresh. */
2560 int old_rows = l->search_maxrows;
2561 int fd = l->ofd, j;
2562 AppendBuffer append_buffer;
2563 char highlightBuf[LINENOISE_MAX_LINE];
2564 char buf[LINENOISE_MAX_LINE];
2565 size_t len = l->len;
2566 size_t render_pos = 0;
2567 l->search_maxrows = 1;
2568
2569 // replace every newline with space for single line printing
2570 for (size_t i = 0; i < len; i++) {
2571 if (strBuf[i] == '\n' || strBuf[i] == '\r') {
2572 strBuf[i] = ' ';
2573 }
2574 }
2575
2576 char* buffer = (char*)strBuf.c_str();
2577 truncateText(buffer, len, l->pos, l->cols, plen, highlightEnabled, render_pos, highlightBuf);
2578 if (strlen(highlightBuf) > 0) {
2579 highlightSearchMatch(highlightBuf, buf, searchText);
2580 } else {
2581 highlightSearchMatch(buffer, buf, searchText);
2582 }
2583 len = strlen(buf);
2584
2585 /* First step: clear all the lines used before. To do so start by
2586 * going to the last row. */
2587 if (mlmode && search_mlmode) {
2588 search_mlmode = 0;
2589 int multi_old_rows = l->maxrows ? l->maxrows : 1;
2590 if (multi_old_rows < old_rows) {
2591 multi_old_rows = old_rows;
2592 }
2593 if (l->oldpos < static_cast<size_t>(multi_old_rows)) {
2594 const int rows_to_move_down = multi_old_rows - static_cast<int>(l->oldpos);
2595 lndebug("go down %d", rows_to_move_down);
2596 snprintf(seq, 64, "\x1b[%dB", rows_to_move_down);
2597 append_buffer.abAppend(seq);
2598 }
2599
2600 /* Now for every row clear it, go up. */
2601 for (int j = 0; j < multi_old_rows - 1; j++) {
2602 lndebug("clear+up");
2603 append_buffer.abAppend("\r\x1b[0K\x1b[1A");
2604 }
2605 } else {
2606 if (old_rows - rpos > 0) {
2607 lndebug("go down %d", old_rows - rpos);
2608 snprintf(seq, 64, "\x1b[%dB", old_rows - rpos);
2609 append_buffer.abAppend(seq);

Callers 2

refreshSearchFunction · 0.85
cancelSearchFunction · 0.85

Calls 6

truncateTextFunction · 0.85
highlightSearchMatchFunction · 0.85
refreshShowHintsFunction · 0.85
abAppendMethod · 0.80
abWriteMethod · 0.80

Tested by

no test coverage detected