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

Function refreshShowHints

linenoise.c:1289–1326  ·  view source on GitHub ↗

Helper of refreshSingleLine() and refreshMultiLine() to show hints * to the right of the prompt. Now uses display widths for proper UTF-8. */

Source from the content-addressed store, hash-verified

1287
1288/* Clear all remembered fold ranges. */
1289static void linenoiseFoldClear(struct linenoiseState *l) {
1290 l->fold_count = 0;
1291}
1292
1293/* Remove one remembered fold range. */
1294static void linenoiseFoldRemove(struct linenoiseState *l, int j) {
1295 memmove(l->fold_start+j,l->fold_start+j+1,
1296 sizeof(size_t)*(l->fold_count-j-1));
1297 memmove(l->fold_end+j,l->fold_end+j+1,
1298 sizeof(size_t)*(l->fold_count-j-1));
1299 l->fold_count--;
1300}
1301
1302/* Return true if [pos,pos+len) overlaps any folded range. */
1303static int linenoiseRangeOverlapsFold(struct linenoiseState *l, size_t pos, size_t len) {
1304 size_t end = pos + len;
1305 int j;
1306
1307 for (j = 0; j < l->fold_count; j++) {
1308 if (end > l->fold_start[j] && pos < l->fold_end[j])
1309 return 1;
1310 }
1311 return 0;
1312}
1313
1314/* Adjust fold ranges after an insertion. If insertion somehow lands inside a
1315 * fold, remove that fold because it no longer maps to an unchanged range. */
1316static void linenoiseAdjustFoldsAfterInsert(struct linenoiseState *l, size_t pos, size_t len) {
1317 int j = 0;
1318
1319 while (j < l->fold_count) {
1320 if (pos <= l->fold_start[j]) {
1321 l->fold_start[j] += len;
1322 l->fold_end[j] += len;
1323 j++;
1324 } else if (pos < l->fold_end[j]) {
1325 linenoiseFoldRemove(l,j);
1326 } else {
1327 j++;
1328 }
1329 }

Callers 2

refreshSingleLineFunction · 0.85
refreshMultiLineFunction · 0.85

Calls 4

utf8StrWidthFunction · 0.85
utf8NextCharLenFunction · 0.85
utf8SingleCharWidthFunction · 0.85
abAppendFunction · 0.85

Tested by

no test coverage detected