@@ -245,11 +245,12 @@ static size_t columnPos(const char *buf, size_t buf_len, size_t pos) {
245245static size_t columnPosForMultiLine (const char * buf , size_t buf_len , size_t pos , size_t cols , size_t ini_pos ) {
246246 size_t ret = 0 ;
247247 size_t colwid = ini_pos ;
248+ size_t len ;
248249
249250 size_t off = 0 ;
250251 while (off < buf_len ) {
251252 size_t col_len ;
252- size_t len = nextCharLen (buf ,buf_len ,off ,& col_len );
253+ len = nextCharLen (buf ,buf_len ,off ,& col_len );
253254
254255 int dif = (int )(colwid + col_len ) - (int )cols ;
255256 if (dif > 0 ) {
@@ -799,7 +800,7 @@ static void refreshSingleLine(struct linenoiseState *l, int flags) {
799800static void refreshMultiLine (struct linenoiseState * l , int flags ) {
800801 char seq [64 ];
801802 size_t pcollen = promptTextColumnLen (l -> prompt ,strlen (l -> prompt ));
802- int colpos = columnPosForMultiLine (l -> buf , l -> len , l -> len , l -> cols , pcollen );
803+ size_t colpos = columnPosForMultiLine (l -> buf , l -> len , l -> len , l -> cols , pcollen );
803804 int colpos2 ; /* cursor column position. */
804805 int rows = (pcollen + colpos + l -> cols - 1 )/l -> cols ; /* rows used by current buf. */
805806 int rpos = (pcollen + l -> oldcolpos + l -> cols )/l -> cols ; /* cursor relative row. */
@@ -815,6 +816,23 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) {
815816 * going to the last row. */
816817 abInit (& ab );
817818
819+ if ((l -> oldcollen < l -> len ) && // some character was added
820+ (l -> pos == l -> len ) && // at the end of the line
821+ (l -> pos <= l -> cols ) && // no multiline break
822+ (l -> prev_history_index == l -> history_index ) // no buffer change based on history
823+ ) {
824+ /* Ignore flags and just add one character.
825+ * This code was added because redundant ANSI escape codes make tcl-tests incapable.
826+ */
827+ abAppend (& ab ,l -> buf + l -> oldcollen ,strlen (l -> buf ) - l -> oldcollen );
828+ l -> oldcolpos = colpos ;
829+ l -> oldcollen = l -> len ;
830+ if (write (fd ,ab .b ,ab .len ) == -1 ) {} /* Can't recover from write error. */
831+ abFree (& ab );
832+ l -> prev_history_index = l -> history_index ;
833+ return ;
834+ }
835+
818836 if (flags & REFRESH_CLEAN ) {
819837 if (old_rows - rpos > 0 ) {
820838 lndebug ("go down %d" , old_rows - rpos );
@@ -890,6 +908,8 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) {
890908
891909 lndebug ("\n" );
892910 l -> oldcolpos = colpos2 ;
911+ l -> oldcollen = l -> len ;
912+ l -> prev_history_index = l -> history_index ;
893913
894914 if (write (fd ,ab .b ,ab .len ) == -1 ) {} /* Can't recover from write error. */
895915 abFree (& ab );
@@ -1096,6 +1116,7 @@ int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, ch
10961116 l -> prompt = prompt ;
10971117 l -> plen = strlen (prompt );
10981118 l -> oldcolpos = l -> pos = 0 ;
1119+ l -> oldcollen = 0 ;
10991120 l -> len = 0 ;
11001121
11011122 /* Enter raw mode. */
@@ -1104,6 +1125,7 @@ int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, ch
11041125 l -> cols = getColumns (stdin_fd , stdout_fd );
11051126 l -> oldrows = 0 ;
11061127 l -> history_index = 0 ;
1128+ l -> prev_history_index = 0 ;
11071129
11081130 /* Buffer starts empty. */
11091131 l -> buf [0 ] = '\0' ;
0 commit comments