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

Function refreshSingleLine

linenoise.c:1338–1415  ·  view source on GitHub ↗

Single 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 (not byte counts) * for cursor positioning and horizontal scrolli

Source from the content-addressed store, hash-verified

1336 int j = 0;
1337
1338 while (j < l->fold_count) {
1339 if (end <= l->fold_start[j]) {
1340 l->fold_start[j] -= len;
1341 l->fold_end[j] -= len;
1342 j++;
1343 } else if (pos >= l->fold_end[j]) {
1344 j++;
1345 } else {
1346 linenoiseFoldRemove(l,j);
1347 }
1348 }
1349}
1350
1351/* Helper of refreshSingleLine() and refreshMultiLine() to show hints
1352 * to the right of the prompt. Now uses display widths for proper UTF-8. */
1353void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int pwidth, size_t bufwidth) {
1354 if (hintsCallback) {
1355 char seq[64];
1356 int color = -1, bold = 0;
1357 char *hint;
1358
1359 if (pwidth + bufwidth >= l->cols) return;
1360 hint = hintsCallback(l->buf,&color,&bold);
1361 if (hint) {
1362 size_t hintlen = strlen(hint);
1363 size_t hintwidth = utf8StrWidth(hint, hintlen);
1364 size_t hintmaxwidth = l->cols - (pwidth + bufwidth);
1365 /* Truncate hint to fit, respecting UTF-8 boundaries. */
1366 if (hintwidth > hintmaxwidth) {
1367 size_t i = 0, w = 0;
1368 while (i < hintlen) {
1369 size_t clen = utf8NextCharLen(hint, i, hintlen);
1370 int cwidth = utf8SingleCharWidth(hint + i, clen);
1371 if (w + cwidth > hintmaxwidth) break;
1372 w += cwidth;
1373 i += clen;
1374 }
1375 hintlen = i;
1376 }
1377 if (bold == 1 && color == -1) color = 37;
1378 if (color != -1 || bold != 0)
1379 snprintf(seq,64,"\033[%d;%d;49m",bold,color);
1380 else
1381 seq[0] = '\0';
1382 abAppend(ab,seq,strlen(seq));
1383 abAppend(ab,hint,hintlen);
1384 if (color != -1 || bold != 0)
1385 abAppend(ab,"\033[0m",4);
1386 /* Call the function to free the hint returned. */
1387 if (freeHintsCallback) freeHintsCallback(hint);
1388 }
1389 }
1390}
1391
1392/* Single line low level line refresh.
1393 *
1394 * Rewrite the currently edited line accordingly to the buffer content,
1395 * cursor position, and number of columns of the terminal.

Callers 1

refreshLineWithFlagsFunction · 0.85

Calls 9

utf8StrWidthFunction · 0.85
linenoiseRenderBufferFunction · 0.85
utf8NextCharLenFunction · 0.85
utf8SingleCharWidthFunction · 0.85
utf8PrevCharLenFunction · 0.85
abInitFunction · 0.85
abAppendFunction · 0.85
refreshShowHintsFunction · 0.85
abFreeFunction · 0.85

Tested by

no test coverage detected