From c84d0a02ce46439f501580bc5c42cf0fc61381dd Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 3 Sep 2014 10:11:31 +0200 Subject: [PATCH] Don't emit ESC [ n C with n=0. This fixes a bug introduced with ANSI.SYS compatibility. When we want to move at a specific column, we need to emit the sequence to move the cursor to the right (after we moved 999 positions to the left) only if we want to actually move right at least 1 position, since a count of zero will still move the cursor one position to the right. --- linenoise.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/linenoise.c b/linenoise.c index 940c5a43..b352106e 100644 --- a/linenoise.c +++ b/linenoise.c @@ -505,6 +505,7 @@ static void refreshMultiLine(struct linenoiseState *l) { int rows = (plen+l->len+l->cols-1)/l->cols; /* rows used by current buf. */ int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */ int rpos2; /* rpos after refresh. */ + int col; /* colum position, zero-based. */ int old_rows = l->maxrows; int fd = l->ofd, j; struct abuf ab; @@ -563,8 +564,12 @@ static void refreshMultiLine(struct linenoiseState *l) { } /* Set column. */ - lndebug("set col %d", 1+((plen+(int)l->pos) % (int)l->cols)); - snprintf(seq,64,"\x1b[999D\x1b[%dC", (plen+(int)l->pos) % (int)l->cols); + col = (plen+(int)l->pos) % (int)l->cols; + lndebug("set col %d", 1+col); + if (col) + snprintf(seq,64,"\x1b[999D\x1b[%dC", col); + else + snprintf(seq,64,"\x1b[999D"); abAppend(&ab,seq,strlen(seq)); lndebug("\n");