Helper of refreshSingleLine() and refreshMultiLine() to show hints * to the right of the prompt. */
| 1396 | /* Helper of refreshSingleLine() and refreshMultiLine() to show hints |
| 1397 | * to the right of the prompt. */ |
| 1398 | void refreshShowHints(AppendBuffer& append_buffer, struct linenoiseState* l, int plen) { |
| 1399 | char seq[64]; |
| 1400 | if (hintsCallback && plen + l->len < l->cols) { |
| 1401 | int color = -1, bold = 0; |
| 1402 | char* hint = hintsCallback(l->buf, &color, &bold); |
| 1403 | if (hint) { |
| 1404 | int hintlen = strlen(hint); |
| 1405 | int hintmaxlen = l->cols - (plen + l->len); |
| 1406 | if (hintlen > hintmaxlen) |
| 1407 | hintlen = hintmaxlen; |
| 1408 | if (bold == 1 && color == -1) |
| 1409 | color = 37; |
| 1410 | if (color != -1 || bold != 0) |
| 1411 | snprintf(seq, 64, "\033[%d;%d;49m", bold, color); |
| 1412 | else |
| 1413 | seq[0] = '\0'; |
| 1414 | append_buffer.abAppend(seq, strlen(seq)); |
| 1415 | append_buffer.abAppend(hint, hintlen); |
| 1416 | if (color != -1 || bold != 0) |
| 1417 | append_buffer.abAppend("\033[0m"); |
| 1418 | /* Call the function to free the hint returned. */ |
| 1419 | if (freeHintsCallback) |
| 1420 | freeHintsCallback(hint); |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | uint32_t linenoiseComputeRenderWidth(const char* buf, size_t len) { |
| 1426 | // UTF8 in prompt, get render width. |
no test coverage detected