[PATCH] readline: make ctrl-u to work like linux console

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: DU HUANPENG <u74147@xxxxxxxxx>

currtly, the ctrl-u discards the whole line, in most linux
boxes, ctrl-u just remove character before cursor.
this patch make ctrl-u to do this.

Signed-off-by: DU HUANPENG <u74147@xxxxxxxxx>
---
 lib/readline.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/lib/readline.c b/lib/readline.c
index d026af1..eba3da4 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -291,8 +291,35 @@ int readline(const char *prompt, char *buf, int len)
 			break;
 		case BB_KEY_ERASE_LINE:
 		case CTL_CH('u'):
-			BEGINNING_OF_LINE();
-			ERASE_TO_EOL();
+			if(num >= eol_num) {
+				BEGINNING_OF_LINE();
+				ERASE_TO_EOL();
+			} else {
+				for(i=num; i<eol_num; i++) {
+					buf[i-num] = buf[i];
+				}
+				buf[i] = '\0';
+
+				for(i=0; i<num; i++) {
+					putchar(CTL_BACKSPACE);
+				}
+				for(i=0; i<eol_num; i++) {
+					putchar(' ');
+				}
+				for(i=0; i<eol_num; i++) {
+					putchar(CTL_BACKSPACE);
+				}
+
+				eol_num -= num;
+				num = 0;
+
+				for(i=0; i<eol_num; i++) {
+					putchar(buf[i]);
+				}
+				for(i=0; i<eol_num; i++) {
+					putchar(CTL_BACKSPACE);
+				}
+			}
 			break;
 		case DEL:
 		case BB_KEY_DEL7:
-- 
2.7.4




_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux