MCPcopy Create free account
hub / github.com/antirez/ds4 / refreshMultiLine

Function refreshMultiLine

linenoise.c:1426–1587  ·  view source on GitHub ↗

Multi line low level line refresh. * * Rewrite the currently edited line accordingly to the buffer content, * cursor position, and number of columns of the terminal. * * Flags is REFRESH_* macros. The function can just remove the old * prompt, just write it, or both. * * This function is UTF-8 aware and uses display widths for positioning. */

Source from the content-addressed store, hash-verified

1424 * We need to trim full UTF-8 characters from the left until the
1425 * cursor position fits within the terminal width. */
1426 while (pwidth + poscol >= l->cols) {
1427 size_t clen = utf8NextCharLen(buf, 0, len);
1428 int cwidth = utf8SingleCharWidth(buf, clen);
1429 buf += clen;
1430 len -= clen;
1431 pos -= clen;
1432 poscol -= cwidth;
1433 lencol -= cwidth;
1434 }
1435
1436 /* Trim from the right if the line still doesn't fit. */
1437 while (pwidth + lencol > l->cols) {
1438 size_t clen = utf8PrevCharLen(buf, len);
1439 int cwidth = utf8SingleCharWidth(buf + len - clen, clen);
1440 len -= clen;
1441 lencol -= cwidth;
1442 }
1443
1444 abInit(&ab);
1445 /* Cursor to left edge */
1446 snprintf(seq,sizeof(seq),"\r");
1447 abAppend(&ab,seq,strlen(seq));
1448
1449 if (flags & REFRESH_WRITE) {
1450 /* Write the prompt and the current buffer content */
1451 abAppend(&ab,l->prompt,l->plen);
1452 if (maskmode == 1) {
1453 /* In mask mode, we output one '*' per UTF-8 character, not byte */
1454 size_t i = 0;
1455 while (i < len) {
1456 abAppend(&ab,"*",1);
1457 i += utf8NextCharLen(buf, i, len);
1458 }
1459 } else {
1460 abAppend(&ab,buf,len);
1461 }
1462 /* Show hints if any. */
1463 refreshShowHints(&ab,l,pwidth,fullwidth);
1464 }
1465
1466 /* Erase to right */
1467 snprintf(seq,sizeof(seq),"\x1b[0K");
1468 abAppend(&ab,seq,strlen(seq));
1469
1470 if (flags & REFRESH_WRITE) {
1471 /* Move cursor to original position (using display column, not byte). */
1472 snprintf(seq,sizeof(seq),"\r\x1b[%dC", (int)(poscol+pwidth));
1473 abAppend(&ab,seq,strlen(seq));
1474 }
1475
1476 if (linenoiseWrite(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
1477 abFree(&ab);
1478 free(render);
1479}
1480
1481/* Multi line low level line refresh.
1482 *
1483 * Rewrite the currently edited line accordingly to the buffer content,

Callers 1

refreshLineWithFlagsFunction · 0.85

Calls 10

utf8StrWidthFunction · 0.85
linenoiseRenderBufferFunction · 0.85
abInitFunction · 0.85
abAppendFunction · 0.85
abFreeFunction · 0.85
linenoiseStatusRowsFunction · 0.85
utf8NextCharLenFunction · 0.85
refreshShowHintsFunction · 0.85
linenoiseStatusActiveFunction · 0.85
refreshStatusLineFunction · 0.85

Tested by

no test coverage detected