summaryrefslogtreecommitdiffstats
path: root/src/hci
diff options
context:
space:
mode:
authorMarin Hannache2014-08-19 13:05:36 +0200
committerMichael Brown2014-08-19 13:05:36 +0200
commit8ab9f3ca383bab73dbb71c5b3335334e1385dde6 (patch)
tree7e26fd52a8841f2bd834a034c8b9aca80ec512a9 /src/hci
parent[xen] Cope with unexpected initial backend states (diff)
downloadipxe-8ab9f3ca383bab73dbb71c5b3335334e1385dde6.tar.gz
ipxe-8ab9f3ca383bab73dbb71c5b3335334e1385dde6.tar.xz
ipxe-8ab9f3ca383bab73dbb71c5b3335334e1385dde6.zip
[readline] Add CTRL-W shortcut to remove a word
Signed-off-by: Marin Hannache <git@mareo.fr> Modified-by: Michael Brown <mcb30@ipxe.org> Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci')
-rw-r--r--src/hci/editstring.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/hci/editstring.c b/src/hci/editstring.c
index 8c56d233..5f6f04d5 100644
--- a/src/hci/editstring.c
+++ b/src/hci/editstring.c
@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <assert.h>
#include <string.h>
+#include <ctype.h>
#include <ipxe/keys.h>
#include <ipxe/editstring.h>
@@ -37,6 +38,8 @@ static void insert_character ( struct edit_string *string,
unsigned int character ) __nonnull;
static void delete_character ( struct edit_string *string ) __nonnull;
static void backspace ( struct edit_string *string ) __nonnull;
+static void previous_word ( struct edit_string *string ) __nonnull;
+static void kill_word ( struct edit_string *string ) __nonnull;
static void kill_sol ( struct edit_string *string ) __nonnull;
static void kill_eol ( struct edit_string *string ) __nonnull;
@@ -111,9 +114,36 @@ static void backspace ( struct edit_string *string ) {
}
/**
+ * Move to start of previous word
+ *
+ * @v string Editable string
+ */
+static void previous_word ( struct edit_string *string ) {
+ while ( string->cursor &&
+ isspace ( string->buf[ string->cursor - 1 ] ) ) {
+ string->cursor--;
+ }
+ while ( string->cursor &&
+ ( ! isspace ( string->buf[ string->cursor - 1 ] ) ) ) {
+ string->cursor--;
+ }
+}
+
+/**
+ * Delete to end of previous word
+ *
+ * @v string Editable string
+ */
+static void kill_word ( struct edit_string *string ) {
+ size_t old_cursor = string->cursor;
+ previous_word ( string );
+ insert_delete ( string, ( old_cursor - string->cursor ), NULL );
+}
+
+/**
* Delete to start of line
*
- * @v string Editable string
+ * @v string Editable string
*/
static void kill_sol ( struct edit_string *string ) {
size_t old_cursor = string->cursor;
@@ -181,6 +211,10 @@ int edit_string ( struct edit_string *string, int key ) {
/* Delete character */
delete_character ( string );
break;
+ case CTRL_W:
+ /* Delete word */
+ kill_word ( string );
+ break;
case CTRL_U:
/* Delete to start of line */
kill_sol ( string );