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.
diff --git a/linenoise.c b/linenoise.c
index 940c5a4..b352106 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");