mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] readline: make ctrl-u to work like linux console
@ 2019-10-15 21:02 sendpatch
  0 siblings, 0 replies; 6+ messages in thread
From: sendpatch @ 2019-10-15 21:02 UTC (permalink / raw)
  To: barebox; +Cc: DU HUANPENG

From: DU HUANPENG <u74147@gmail.com>

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@gmail.com>
---
 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] readline: make ctrl-u to work like linux console
  2019-10-16  5:34 sendpatch
@ 2019-10-16  5:59 ` Oleksij Rempel
  0 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2019-10-16  5:59 UTC (permalink / raw)
  To: sendpatch, barebox; +Cc: DU HUANPENG


[-- Attachment #1.1.1: Type: text/plain, Size: 1948 bytes --]

Hi,

Am 16.10.19 um 07:34 schrieb sendpatch@qq.com:
> From: DU HUANPENG <u74147@gmail.com>
> 
> currtly, the ctrl-u discards the whole line, in most linux
> boxes, ctrl-u just erase characters before cursor to the
> begginning of the line. this patch make ctrl-u to do this.

Cool, didnÄt know i can use ctrl-u like this :)

> 
> Signed-off-by: DU HUANPENG <u74147@gmail.com>
> ---
>  lib/readline.c | 34 +++++++++++++++++++++++++++++++---
>  1 file changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/readline.c b/lib/readline.c
> index d026af1..c0b194c 100644
> --- a/lib/readline.c
> +++ b/lib/readline.c
> @@ -188,9 +188,10 @@ int readline(const char *prompt, char *buf, int len)
>  	unsigned wlen;
>  	int ichar;
>  	int insert = 1;
> +	int i;
>  #ifdef CONFIG_AUTO_COMPLETE
>  	char tmp;
> -	int reprint, i;
> +	int reprint;
>  	char *completestr;
>  
>  	complete_reset();
> @@ -291,8 +292,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();

Please use kernel/barebox coding style.
./scripts/checkpatch.pl in barebox repository can help you.


> +			} else {
> +				for(i=num; i<eol_num; i++) {
> +					buf[i-num] = buf[i];
> +				}
> +				buf[i] = '\0';
> +
> +				for(i=0; i<num; i++) {
> +					getcmd_putch(CTL_BACKSPACE);
> +				}
> +				for(i=0; i<eol_num; i++) {
> +					getcmd_putch(' ');
> +				}
> +				for(i=0; i<eol_num; i++) {
> +					getcmd_putch(CTL_BACKSPACE);
> +				}
> +
> +				eol_num -= num;
> +				num = 0;
> +
> +				for(i=0; i<eol_num; i++) {
> +					getcmd_putch(buf[i]);
> +				}
> +				for(i=0; i<eol_num; i++) {
> +					getcmd_putch(CTL_BACKSPACE);
> +				}
> +			}
>  			break;
>  		case DEL:
>  		case BB_KEY_DEL7:
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] readline: make ctrl-u to work like linux console
@ 2019-10-16  5:34 sendpatch
  2019-10-16  5:59 ` Oleksij Rempel
  0 siblings, 1 reply; 6+ messages in thread
From: sendpatch @ 2019-10-16  5:34 UTC (permalink / raw)
  To: barebox; +Cc: DU HUANPENG

From: DU HUANPENG <u74147@gmail.com>

currtly, the ctrl-u discards the whole line, in most linux
boxes, ctrl-u just erase characters before cursor to the
begginning of the line. this patch make ctrl-u to do this.

Signed-off-by: DU HUANPENG <u74147@gmail.com>
---
 lib/readline.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/lib/readline.c b/lib/readline.c
index d026af1..c0b194c 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -188,9 +188,10 @@ int readline(const char *prompt, char *buf, int len)
 	unsigned wlen;
 	int ichar;
 	int insert = 1;
+	int i;
 #ifdef CONFIG_AUTO_COMPLETE
 	char tmp;
-	int reprint, i;
+	int reprint;
 	char *completestr;
 
 	complete_reset();
@@ -291,8 +292,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++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(' ');
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+
+				eol_num -= num;
+				num = 0;
+
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(buf[i]);
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+			}
 			break;
 		case DEL:
 		case BB_KEY_DEL7:
-- 
2.7.4


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] readline: make ctrl-u to work like linux console
  2019-10-15 21:54 sendpatch
@ 2019-10-16  5:29 ` duhuanpeng
  0 siblings, 0 replies; 6+ messages in thread
From: duhuanpeng @ 2019-10-16  5:29 UTC (permalink / raw)
  To: barebox; +Cc: DU HUANPENG

> 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.

Hello, sorry for the typo, it should be characters.

Regards,
duhuanpeng



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] readline: make ctrl-u to work like linux console
@ 2019-10-15 21:54 sendpatch
  2019-10-16  5:29 ` duhuanpeng
  0 siblings, 1 reply; 6+ messages in thread
From: sendpatch @ 2019-10-15 21:54 UTC (permalink / raw)
  To: barebox; +Cc: DU HUANPENG

From: DU HUANPENG <u74147@gmail.com>

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@gmail.com>
---
 lib/readline.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/lib/readline.c b/lib/readline.c
index d026af1..c0b194c 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -188,9 +188,10 @@ int readline(const char *prompt, char *buf, int len)
 	unsigned wlen;
 	int ichar;
 	int insert = 1;
+	int i;
 #ifdef CONFIG_AUTO_COMPLETE
 	char tmp;
-	int reprint, i;
+	int reprint;
 	char *completestr;
 
 	complete_reset();
@@ -291,8 +292,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++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(' ');
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+
+				eol_num -= num;
+				num = 0;
+
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(buf[i]);
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+			}
 			break;
 		case DEL:
 		case BB_KEY_DEL7:
-- 
2.7.4




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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] readline: make ctrl-u to work like linux console
@ 2019-10-15 21:29 sendpatch
  0 siblings, 0 replies; 6+ messages in thread
From: sendpatch @ 2019-10-15 21:29 UTC (permalink / raw)
  To: barebox; +Cc: DU HUANPENG

From: DU HUANPENG <u74147@gmail.com>

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@gmail.com>
---
 lib/readline.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/lib/readline.c b/lib/readline.c
index d026af1..c0b194c 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -188,9 +188,10 @@ int readline(const char *prompt, char *buf, int len)
 	unsigned wlen;
 	int ichar;
 	int insert = 1;
+	int i;
 #ifdef CONFIG_AUTO_COMPLETE
 	char tmp;
-	int reprint, i;
+	int reprint;
 	char *completestr;
 
 	complete_reset();
@@ -291,8 +292,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++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(' ');
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+
+				eol_num -= num;
+				num = 0;
+
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(buf[i]);
+				}
+				for(i=0; i<eol_num; i++) {
+					getcmd_putch(CTL_BACKSPACE);
+				}
+			}
 			break;
 		case DEL:
 		case BB_KEY_DEL7:
-- 
2.7.4




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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-10-16  5:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-15 21:02 [PATCH] readline: make ctrl-u to work like linux console sendpatch
2019-10-15 21:29 sendpatch
2019-10-15 21:54 sendpatch
2019-10-16  5:29 ` duhuanpeng
2019-10-16  5:34 sendpatch
2019-10-16  5:59 ` Oleksij Rempel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox