aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-05-17 12:30:44 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-05-17 12:30:44 +0200
commit1118d9b213e4cad56e6f79c1753e0a52defadaa5 (patch)
tree65c77fa078816d1100900998433440e365b1bd5f
parent786cce1871ade4240c629187d6609de155fe3536 (diff)
downloadbusybox-w32-1118d9b213e4cad56e6f79c1753e0a52defadaa5.tar.gz
busybox-w32-1118d9b213e4cad56e6f79c1753e0a52defadaa5.tar.bz2
busybox-w32-1118d9b213e4cad56e6f79c1753e0a52defadaa5.zip
lineedit: fix insertion deep inside line (*several lines* before end)
function old new delta input_backward 212 229 +17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/lineedit.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 36d057bbb..f7d3ffed8 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -486,15 +486,22 @@ static void input_backward(unsigned num)
486 while (cursor < sv_cursor) 486 while (cursor < sv_cursor)
487 put_cur_glyph_and_inc_cursor(); 487 put_cur_glyph_and_inc_cursor();
488 } else { 488 } else {
489 int count_y; 489 int lines_up;
490 unsigned w; 490 unsigned width;
491 /* num = chars to go back from the beginning of current line: */
491 num -= cmdedit_x; 492 num -= cmdedit_x;
492 w = cmdedit_termw; /* read volatile var once */ 493 width = cmdedit_termw; /* read volatile var once */
493 count_y = 1 + (num / w); 494 /* num=1...w: one line up, w+1...2w: two, etc: */
494 cmdedit_y -= count_y; 495 lines_up = 1 + (num - 1) / width;
495 cmdedit_x = w * count_y - num; 496 cmdedit_x = (width * cmdedit_y - num) % width;
496 /* go to 1st column; go up; go to correct column */ 497 cmdedit_y -= lines_up;
497 printf("\r" "\033[%uA" "\033[%uC", count_y, cmdedit_x); 498 /* go to 1st column; go up */
499 printf("\r" "\033[%uA", lines_up);
500 /* go to correct column.
501 * xtarm, konsole, Linux VT interpret 0 as 1 below! wow.
502 * Need to *make sure* we skip it if cmdedit_x == 0 */
503 if (cmdedit_x)
504 printf("\033[%uC", cmdedit_x);
498 } 505 }
499} 506}
500 507