static int linenoiseRaw(char* buf, size_t buflen, const char* prompt) { int count = -1; if (buflen != 0) { if (enableRawMode() == -1) return -1; count = linenoisePrompt(buf, buflen, prompt); disableRawMode(); printf("\n"); } return count; }
int linenoise_getline( int id, char *buffer, int maxinput, const char *prompt ) { int count; if( history_max_lengths[ id ] == 0 ) { fputs( prompt, stdout ); fflush( stdout ); return fgets( buffer, maxinput, stdin ) == NULL ? -1 : 0; } while( 1 ) { count = linenoisePrompt( id, buffer, maxinput, prompt ); if( count != -1 ) printf( "\n" ); if( count != LINENOISE_CTRL_C ) { if( count > 0 && buffer[ count ] != '\0' ) buffer[ count ] = '\0'; return count; } } }
char *linenoise(const char *prompt) { shouldTerminate = 0; if(requestedInteractiveTermination()){ return NULL; } int count; struct current current; char buf[LINENOISE_MAX_LINE]; if (enableRawMode(¤t) == -1) { printf("%s", prompt); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) { return NULL; } count = strlen(buf); if (count && buf[count-1] == '\n') { count--; buf[count] = '\0'; } } else { current.buf = buf; current.bufmax = sizeof(buf); current.len = 0; current.chars = 0; current.pos = 0; current.prompt = prompt; count = linenoisePrompt(¤t); disableRawMode(¤t); printf("\n"); if (count == -1) { return NULL; } } return my_strdup(buf); }
static int linenoiseRaw(char *buf, size_t buflen, const char *prompt) { int fd = STDIN_FILENO; int count; if (buflen == 0) { errno = EINVAL; return -1; } if (!isatty(STDIN_FILENO)) { if (fgets(buf, buflen, stdin) == NULL) return -1; count = strlen(buf); if (count && buf[count-1] == '\n') { count--; buf[count] = '\0'; } } else { if (enableRawMode(fd) == -1) return -1; count = linenoisePrompt(fd, buf, buflen, prompt); disableRawMode(fd); printf("\n"); } return count; }
//---------------------------------------------------------------------------------- int term_linenoise_getline( int id, char* buffer, int maxinput, const char* prompt ) { int count; if( history_max_lengths[ id ] == 0 ) { fputs( prompt, stdout ); fflush( stdout ); return fgets( buffer, maxinput, stdin ) == NULL ? -1 : 0; } while ( 1 ) { count = linenoisePrompt( id, buffer, maxinput, prompt ); printf( "\n" ); if ( count == LINENOISE_CTRL_D ) { // No input which makes lua interpreter close return 0; } if (buffer[ count ] != '\0') buffer[ count ] = '\0'; if ( count > 0) return count; // return to Lua } }