src/cforth/linenoise.c
static int completeLine(struct linenoiseState *ls) {
    linenoiseCompletions lc = { 0, NULL };
    int nwritten;
    int c = 0;

    completionCallback(ls->buf,&lc);
    if (lc.len == 0) {
        linenoiseBeep();
    } else {
        size_t stop = 0, i = 0;

        while(!stop) {
            /* Show completion or original buffer */
            if (i < lc.len) {
                struct linenoiseState saved = *ls;

                ls->len = ls->pos = strlen(lc.cvec[i]);
                ls->buf = lc.cvec[i];
                refreshLine(ls);
                ls->len = saved.len;
                ls->pos = saved.pos;
                ls->buf = saved.buf;
            } else {
                refreshLine(ls);
            }

	    c = key();
	    if (c == -1) {
                freeCompletions(&lc);
                return -1;
	    }

            switch(c) {
                case 9: /* tab */
                    i = (i+1) % (lc.len+1);
                    if (i == lc.len) linenoiseBeep();
                    break;
                case 27: /* escape */
                    /* Re-show original buffer */
                    if (i < lc.len) refreshLine(ls);
                    stop = 1;
                    break;
                default:
                    /* Update buffer and return */
                    if (i < lc.len) {
                        nwritten = snprintf(ls->buf,ls->buflen,"%s",lc.cvec[i]);
                        ls->len = ls->pos = nwritten;
                    }
                    stop = 1;
                    break;
            }
        }
    }

    freeCompletions(&lc);
    return c; /* Return last read character */
}
/* This is an helper function for linenoiseEdit() and is called when the
 * user types the <tab> key in order to complete the string currently in the
 * input.
 * 
 * The state of the editing is encapsulated into the pointed linenoiseState
 * structure as described in the structure definition. */
This is an helper function for linenoiseEdit() and is called when the
user types the  key in order to complete the string currently in the
input.

The state of the editing is encapsulated into the pointed linenoiseState
structure as described in the structure definition.
This is an helper function for linenoiseEdit () and is called when the user types the key in order to complete the string currently in the input . The state of the editing is encapsulated into the pointed linenoiseState structure as described in the structure definition .
static int completeLine(struct linenoiseState *ls) {
    linenoiseCompletions lc = { 0, NULL };
    int nwritten;
    int c = 0;
    completionCallback(ls->buf,&lc);
    if (lc.len == 0) {
        linenoiseBeep();
    } else {
        size_t stop = 0, i = 0;
        while(!stop) {
            if (i < lc.len) {
                struct linenoiseState saved = *ls;
                ls->len = ls->pos = strlen(lc.cvec[i]);
                ls->buf = lc.cvec[i];
                refreshLine(ls);
                ls->len = saved.len;
                ls->pos = saved.pos;
                ls->buf = saved.buf;
            } else {
                refreshLine(ls);
            }
	    c = key();
	    if (c == -1) {
                freeCompletions(&lc);
                return -1;
	    }
            switch(c) {
                case 9: 
                    i = (i+1) % (lc.len+1);
                    if (i == lc.len) linenoiseBeep();
                    break;
                case 27: 
                    if (i < lc.len) refreshLine(ls);
                    stop = 1;
                    break;
                default:
                    if (i < lc.len) {
                        nwritten = snprintf(ls->buf,ls->buflen,"%s",lc.cvec[i]);
                        ls->len = ls->pos = nwritten;
                    }
                    stop = 1;
                    break;
            }
        }
    }
    freeCompletions(&lc);
    return c; 
}
static int completeLine ( struct linenoiseState * ls ) { linenoiseCompletions lc = { 0 , NULL } ; int nwritten ; int c = 0 ; completionCallback ( ls -> buf , & lc ) ; if ( lc . len == 0 ) { linenoiseBeep ( ) ; } else { size_t stop = 0 , i = 0 ; while ( ! stop ) { if ( i < lc . len ) { struct linenoiseState saved = * ls ; ls -> len = ls -> pos = strlen ( lc . cvec [ i ] ) ; ls -> buf = lc . cvec [ i ] ; refreshLine ( ls ) ; ls -> len = saved . len ; ls -> pos = saved . pos ; ls -> buf = saved . buf ; } else { refreshLine ( ls ) ; } c = key ( ) ; if ( c == -1 ) { freeCompletions ( & lc ) ; return -1 ; } switch ( c ) { case 9 : i = ( i + 1 ) % ( lc . len + 1 ) ; if ( i == lc . len ) linenoiseBeep ( ) ; break ; case 27 : if ( i < lc . len ) refreshLine ( ls ) ; stop = 1 ; break ; default : if ( i < lc . len ) { nwritten = snprintf ( ls -> buf , ls -> buflen , " " , lc . cvec [ i ] ) ; ls -> len = ls -> pos = nwritten ; } stop = 1 ; break ; } } } freeCompletions ( & lc ) ; return c ; }
This is an helper function for linenoiseEdit() and is called when the
 user types the <tab> key in order to complete the string currently in the
 input.
This is an helper function for linenoiseEdit () and is called when the user types the <tab > key in order to complete the string currently in the input .
/* Show completion or original buffer */ /* tab */ /* escape */ /* Re-show original buffer */ /* Update buffer and return */ /* Return last read character */