Skip to contentSkip to conversation

readline: add ctrl-w handling (cut-the-last-word)

RFC In review Antony Pavlov 2 participants 7 messages Oct 26, 2012 – Oct 29, 2012 Library code

lore
Share & tools
lore
#0 lore raw

cover readline: add ctrl-w handling (cut-the-last-word)

The popular 'bash' command interpreter has the ctrl-w keystroke for cutting the last word in the command line. This keystroke is very handy for me and I really miss it in barebox.

This patch series adds ctrl-w support to barebox's readline and in addition fixes a typo.

[RFC 1/3] readline: move backspace key handling to the DO_BACKSPACE [RFC 2/3] readline: add ctrl-w handling (cut-the-last-word) [RFC 3/3] readline: fix the 'new blank line at EOF' typo

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

RFC 1/3 readline: move backspace key handling to the DO_BACKSPACE macro

---
 lib/readline.c |   23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
lib/readline.c +13 -10
index 5717a17..086b7f1 100644
@@ -137,6 +137,18 @@ static char* hist_next(void)
 	}					\
 }
 
+#define DO_BACKSPACE()						\
+		wlen = eol_num - num;				\
+		num--;						\
+		memmove(buf + num, buf + num + 1, wlen);	\
+		getcmd_putch(CTL_BACKSPACE);			\
+		putnstr(buf + num, wlen);			\
+		getcmd_putch(' ');				\
+		do {						\
+			getcmd_putch(CTL_BACKSPACE);		\
+		} while (wlen--);				\
+		eol_num--;
+
 static void cread_add_char(char ichar, int insert, unsigned long *num,
 	       unsigned long *eol_num, char *buf, unsigned long len)
 {
@@ -273,16 +285,7 @@ int readline(const char *prompt, char *buf, int len)
 		case KEY_DEL7:
 		case 8:
 			if (num) {
-				wlen = eol_num - num;
-				num--;
-				memmove(buf + num, buf + num + 1, wlen);
-				getcmd_putch(CTL_BACKSPACE);
-				putnstr(buf + num, wlen);
-				getcmd_putch(' ');
-				do {
-					getcmd_putch(CTL_BACKSPACE);
-				} while (wlen--);
-				eol_num--;
+				DO_BACKSPACE();
 			}
 			break;
 		case KEY_DEL:
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

RFC 2/3 readline: add ctrl-w handling (cut-the-last-word)

In reply to Antony Pavlov
---
 lib/readline.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
lib/readline.c +10 -0
index 086b7f1..37566c3 100644
@@ -328,6 +328,16 @@ int readline(const char *prompt, char *buf, int len)
 			REFRESH_TO_EOL();
 			continue;
 		}
+		case CTL_CH('w'):
+			while ((num >= 1) && (buf[num - 1] == ' ')) {
+				DO_BACKSPACE();
+			}
+
+			while ((num >= 1) && (buf[num - 1] != ' ')) {
+				DO_BACKSPACE();
+			}
+
+			break;
 		default:
 			if (isascii(ichar) && isprint(ichar))
 				cread_add_char(ichar, insert, &num, &eol_num, buf, len);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

RFC 3/3 readline: fix the 'new blank line at EOF' typo

In reply to Antony Pavlov
---
 lib/readline.c |    1 -
 1 file changed, 1 deletion(-)
lib/readline.c +0 -1
index 37566c3..3fb620e 100644
@@ -353,4 +353,3 @@ int readline(const char *prompt, char *buf, int len)
 
 	return rc < 0 ? rc : len;
 }
-
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw
In reply to Antony Pavlov

Hi Antony,

Quoted 10 lines · Antony Pavlov

The popular 'bash' command interpreter has the ctrl-w keystroke for cutting the last word in the command line. This keystroke is very handy for me and I really miss it in barebox.

This patch series adds ctrl-w support to barebox's readline and in addition fixes a typo.

[RFC 1/3] readline: move backspace key handling to the DO_BACKSPACE [RFC 2/3] readline: add ctrl-w handling (cut-the-last-word) [RFC 3/3] readline: fix the 'new blank line at EOF' typo

Looks good.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw
Quoted 7 lines · Sascha Hauer

Hi Antony,

Quoted 4 lines · Antony Pavlov

The popular 'bash' command interpreter has the ctrl-w keystroke for cutting the last word in the command line. This keystroke is very handy for me and I really miss it in barebox.

Quoted 8 lines
Quoted 6 lines

This patch series adds ctrl-w support to barebox's readline and in addition fixes a typo.

[RFC 1/3] readline: move backspace key handling to the DO_BACKSPACE [RFC 2/3] readline: add ctrl-w handling (cut-the-last-word) [RFC 3/3] readline: fix the 'new blank line at EOF' typo

Looks good.

So apply the patches, please.

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw
Quoted 11 lines · Antony Pavlov
Quoted 10 lines · Sascha Hauer

Hi Antony,

Quoted 7 lines · Antony Pavlov

The popular 'bash' command interpreter has the ctrl-w keystroke for cutting the last word in the command line. This keystroke is very handy for me and I really miss it in barebox.

This patch series adds ctrl-w support to barebox's readline and in addition fixes a typo.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

[RFC 1/3] readline: move backspace key handling to the DO_BACKSPACE [RFC 2/3] readline: add ctrl-w handling (cut-the-last-word) [RFC 3/3] readline: fix the 'new blank line at EOF' typo

Looks good.

So apply the patches, please.

Just did that.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox