Linenoise hints callback. */
| 713 | |
| 714 | /* Linenoise hints callback. */ |
| 715 | static 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 | |
| 763 | static void freeHintsCallback(void *ptr) { |
| 764 | sdsfree(ptr); |
no test coverage detected