]> git.lizzy.rs Git - linenoise.git/blobdiff - linenoise.c
New feature: Accessor for the history max len.
[linenoise.git] / linenoise.c
index 5d82865daafc14819a1d2ddee9c0972ccd7f73d1..21f62f5061b6250203062642b2d9224db3768eaf 100644 (file)
@@ -187,6 +187,7 @@ void linenoiseHistoryFree(void) {
             free(history[j]);
         free(history);
         history = NULL;
+        history_len = 0;
     }
 }
 
@@ -268,7 +269,10 @@ static void linenoiseAtExit(void) {
     linenoiseHistoryFree();
 }
 
-/* gcc/glibc insists that we care about the return code of write! */
+/* gcc/glibc insists that we care about the return code of write!
+ * Clarification: This means that a void-cast like "(void) (EXPR)"
+ * does not work.
+ */
 #define IGNORE_RC(EXPR) if (EXPR) {}
 
 /* This is fdprintf() on some systems, but use a different
@@ -538,7 +542,7 @@ static int outputChars(struct current *current, const char *buf, int len)
 {
     COORD pos = { (SHORT)current->x, (SHORT)current->y };
     DWORD n;
-       
+
     WriteConsoleOutputCharacter(current->outh, buf, len, pos, &n);
     current->x += len;
     return 0;
@@ -955,7 +959,7 @@ static int linenoisePrompt(struct current *current) {
         /* Only autocomplete when the callback is set. It returns < 0 when
          * there was an error reading from fd. Otherwise it will return the
          * character that should be handled next. */
-        if (c == 9 && completionCallback != NULL) {
+        if (c == '\t' && current->pos == current->chars && completionCallback != NULL) {
             c = completeLine(current);
             /* Return on errors */
             if (c < 0) return current->len;
@@ -1226,10 +1230,10 @@ char *linenoise(const char *prompt)
     char buf[LINENOISE_MAX_LINE];
 
     if (enableRawMode(&current) == -1) {
-       printf("%s", prompt);
+        printf("%s", prompt);
         fflush(stdout);
         if (fgets(buf, sizeof(buf), stdin) == NULL) {
-               return NULL;
+            return NULL;
         }
         count = strlen(buf);
         if (count && buf[count-1] == '\n') {
@@ -1284,6 +1288,10 @@ int linenoiseHistoryAdd(const char *line) {
     return 1;
 }
 
+int linenoiseHistoryGetMaxLen(void) {
+    return history_max_len;
+}
+
 int linenoiseHistorySetMaxLen(int len) {
     char **newHistory;