Commit d895173d679be70bcd8b23041fff3e458e1a3506

Salvatore Sanfilippo 2024-02-23T08:59:30

Merge pull request #221 from 9Ajiang/master advance enableRawMode() before getColumns()

diff --git a/linenoise.c b/linenoise.c
index 5e8aee5..574ab1f 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -880,6 +880,10 @@ int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, ch
     l->plen = strlen(prompt);
     l->oldpos = l->pos = 0;
     l->len = 0;
+
+    /* Enter raw mode. */
+    if (enableRawMode(l->ifd) == -1) return -1;
+
     l->cols = getColumns(stdin_fd, stdout_fd);
     l->oldrows = 0;
     l->history_index = 0;
@@ -893,9 +897,6 @@ int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, ch
      * mode later, in linenoiseEditFeed(). */
     if (!isatty(l->ifd)) return 0;
 
-    /* Enter raw mode. */
-    if (enableRawMode(l->ifd) == -1) return -1;
-
     /* The latest history entry is always our current buffer, that
      * initially is just an empty string. */
     linenoiseHistoryAdd("");