mirror of
https://github.com/antirez/linenoise.git
synced 2025-11-16 12:34:48 +00:00
Multiline: just remember last num of rows, not max.
For some reason, the old code was always cleaning the maximum number of rows used so far while editing in multi line mode. Actually we need to clean just the number of rows used by the last line. The old behavior created problems in multiplexing mode, where the line is refreshed at a different row, if the user used linenoiseHide() / show() in order to print something. With the new behavior, all looks fine, so far.
This commit is contained in:
11
linenoise.c
11
linenoise.c
@@ -175,7 +175,7 @@ FILE *lndebug_fp = NULL;
|
|||||||
fprintf(lndebug_fp, \
|
fprintf(lndebug_fp, \
|
||||||
"[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
|
"[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
|
||||||
(int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
|
(int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
|
||||||
(int)l->maxrows,old_rows); \
|
(int)l->oldrows,old_rows); \
|
||||||
} \
|
} \
|
||||||
fprintf(lndebug_fp, ", " __VA_ARGS__); \
|
fprintf(lndebug_fp, ", " __VA_ARGS__); \
|
||||||
fflush(lndebug_fp); \
|
fflush(lndebug_fp); \
|
||||||
@@ -600,12 +600,11 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) {
|
|||||||
int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */
|
int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */
|
||||||
int rpos2; /* rpos after refresh. */
|
int rpos2; /* rpos after refresh. */
|
||||||
int col; /* colum position, zero-based. */
|
int col; /* colum position, zero-based. */
|
||||||
int old_rows = l->maxrows;
|
int old_rows = l->oldrows;
|
||||||
int fd = l->ofd, j;
|
int fd = l->ofd, j;
|
||||||
struct abuf ab;
|
struct abuf ab;
|
||||||
|
|
||||||
/* Update maxrows if needed. */
|
l->oldrows = rows;
|
||||||
if (rows > (int)l->maxrows) l->maxrows = rows;
|
|
||||||
|
|
||||||
/* First step: clear all the lines used before. To do so start by
|
/* First step: clear all the lines used before. To do so start by
|
||||||
* going to the last row. */
|
* going to the last row. */
|
||||||
@@ -657,7 +656,7 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) {
|
|||||||
snprintf(seq,64,"\r");
|
snprintf(seq,64,"\r");
|
||||||
abAppend(&ab,seq,strlen(seq));
|
abAppend(&ab,seq,strlen(seq));
|
||||||
rows++;
|
rows++;
|
||||||
if (rows > (int)l->maxrows) l->maxrows = rows;
|
if (rows > (int)l->oldrows) l->oldrows = rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move cursor to right position. */
|
/* Move cursor to right position. */
|
||||||
@@ -882,7 +881,7 @@ int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, ch
|
|||||||
l->oldpos = l->pos = 0;
|
l->oldpos = l->pos = 0;
|
||||||
l->len = 0;
|
l->len = 0;
|
||||||
l->cols = getColumns(stdin_fd, stdout_fd);
|
l->cols = getColumns(stdin_fd, stdout_fd);
|
||||||
l->maxrows = 0;
|
l->oldrows = 0;
|
||||||
l->history_index = 0;
|
l->history_index = 0;
|
||||||
|
|
||||||
/* Buffer starts empty. */
|
/* Buffer starts empty. */
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ struct linenoiseState {
|
|||||||
size_t oldpos; /* Previous refresh cursor position. */
|
size_t oldpos; /* Previous refresh cursor position. */
|
||||||
size_t len; /* Current edited line length. */
|
size_t len; /* Current edited line length. */
|
||||||
size_t cols; /* Number of columns in terminal. */
|
size_t cols; /* Number of columns in terminal. */
|
||||||
size_t maxrows; /* Maximum num of rows used so far (multiline mode) */
|
size_t oldrows; /* Rows used by last refrehsed line (multiline mode) */
|
||||||
int history_index; /* The history index we are currently editing. */
|
int history_index; /* The history index we are currently editing. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user