Skip to content

Commit

Permalink
Don't emit ESC [ n C with n=0.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antirez committed Sep 3, 2014
1 parent 471e754 commit c84d0a0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions linenoise.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit c84d0a0

Please sign in to comment.