From 4111f1d6cd29e136b4e86a25d1dd859a1e00813b Mon Sep 17 00:00:00 2001 From: 9A <2581064152@qq.com> Date: Fri, 23 Feb 2024 15:44:25 +0800 Subject: [PATCH] advance enableRawMode() before getColumns() --- linenoise.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/linenoise.c b/linenoise.c index 5e8aee57..574ab1f1 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("");