MCPcopy Create free account
hub / github.com/F-Stack/f-stack / hintsCallback

Function hintsCallback

app/redis-6.2.6/src/redis-cli.c:715–761  ·  view source on GitHub ↗

Linenoise hints callback. */

Source from the content-addressed store, hash-verified

713
714/* Linenoise hints callback. */
715static char *hintsCallback(const char *buf, int *color, int *bold) {
716 if (!pref.hints) return NULL;
717
718 int i, argc, buflen = strlen(buf);
719 sds *argv = sdssplitargs(buf,&argc);
720 int endspace = buflen && isspace(buf[buflen-1]);
721
722 /* Check if the argument list is empty and return ASAP. */
723 if (argc == 0) {
724 sdsfreesplitres(argv,argc);
725 return NULL;
726 }
727
728 for (i = 0; i < helpEntriesLen; i++) {
729 if (!(helpEntries[i].type & CLI_HELP_COMMAND)) continue;
730
731 if (strcasecmp(argv[0],helpEntries[i].full) == 0 ||
732 strcasecmp(buf,helpEntries[i].full) == 0)
733 {
734 *color = 90;
735 *bold = 0;
736 sds hint = sdsnew(helpEntries[i].org->params);
737
738 /* Remove arguments from the returned hint to show only the
739 * ones the user did not yet typed. */
740 int toremove = argc-1;
741 while(toremove > 0 && sdslen(hint)) {
742 if (hint[0] == '[') break;
743 if (hint[0] == ' ') toremove--;
744 sdsrange(hint,1,-1);
745 }
746
747 /* Add an initial space if needed. */
748 if (!endspace) {
749 sds newhint = sdsnewlen(" ",1);
750 newhint = sdscatsds(newhint,hint);
751 sdsfree(hint);
752 hint = newhint;
753 }
754
755 sdsfreesplitres(argv,argc);
756 return hint;
757 }
758 }
759 sdsfreesplitres(argv,argc);
760 return NULL;
761}
762
763static void freeHintsCallback(void *ptr) {
764 sdsfree(ptr);

Callers 1

refreshShowHintsFunction · 0.85

Calls 10

sdssplitargsFunction · 0.85
isspaceFunction · 0.85
sdsfreesplitresFunction · 0.85
strcasecmpFunction · 0.85
sdsnewFunction · 0.85
sdslenFunction · 0.85
sdsrangeFunction · 0.85
sdsnewlenFunction · 0.85
sdscatsdsFunction · 0.85
sdsfreeFunction · 0.85

Tested by

no test coverage detected