Browse Source

[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>
tags/v1.20.1
Marin Hannache 10 years ago
parent
commit
8ab9f3ca38
1 changed files with 35 additions and 1 deletions
  1. 35
    1
      src/hci/editstring.c

+ 35
- 1
src/hci/editstring.c View File

21
 
21
 
22
 #include <assert.h>
22
 #include <assert.h>
23
 #include <string.h>
23
 #include <string.h>
24
+#include <ctype.h>
24
 #include <ipxe/keys.h>
25
 #include <ipxe/keys.h>
25
 #include <ipxe/editstring.h>
26
 #include <ipxe/editstring.h>
26
 
27
 
37
                                unsigned int character ) __nonnull;
38
                                unsigned int character ) __nonnull;
38
 static void delete_character ( struct edit_string *string ) __nonnull;
39
 static void delete_character ( struct edit_string *string ) __nonnull;
39
 static void backspace ( struct edit_string *string ) __nonnull;
40
 static void backspace ( struct edit_string *string ) __nonnull;
41
+static void previous_word ( struct edit_string *string ) __nonnull;
42
+static void kill_word ( struct edit_string *string ) __nonnull;
40
 static void kill_sol ( struct edit_string *string ) __nonnull;
43
 static void kill_sol ( struct edit_string *string ) __nonnull;
41
 static void kill_eol ( struct edit_string *string ) __nonnull;
44
 static void kill_eol ( struct edit_string *string ) __nonnull;
42
 
45
 
110
 	}
113
 	}
111
 }
114
 }
112
 
115
 
116
+/**
117
+ * Move to start of previous word
118
+ *
119
+ * @v string		Editable string
120
+ */
121
+static void previous_word ( struct edit_string *string ) {
122
+	while ( string->cursor &&
123
+		isspace ( string->buf[ string->cursor - 1 ] ) ) {
124
+		string->cursor--;
125
+	}
126
+	while ( string->cursor &&
127
+		( ! isspace ( string->buf[ string->cursor - 1 ] ) ) ) {
128
+		string->cursor--;
129
+	}
130
+}
131
+
132
+/**
133
+ * Delete to end of previous word
134
+ *
135
+ * @v string		Editable string
136
+ */
137
+static void kill_word ( struct edit_string *string ) {
138
+	size_t old_cursor = string->cursor;
139
+	previous_word ( string );
140
+	insert_delete ( string, ( old_cursor - string->cursor ), NULL );
141
+}
142
+
113
 /**
143
 /**
114
  * Delete to start of line
144
  * Delete to start of line
115
  *
145
  *
116
- * @v string           Editable string
146
+ * @v string		Editable string
117
  */
147
  */
118
 static void kill_sol ( struct edit_string *string ) {
148
 static void kill_sol ( struct edit_string *string ) {
119
 	size_t old_cursor = string->cursor;
149
 	size_t old_cursor = string->cursor;
181
 		/* Delete character */
211
 		/* Delete character */
182
 		delete_character ( string );
212
 		delete_character ( string );
183
 		break;
213
 		break;
214
+	case CTRL_W:
215
+		/* Delete word */
216
+		kill_word ( string );
217
+		break;
184
 	case CTRL_U:
218
 	case CTRL_U:
185
 		/* Delete to start of line */
219
 		/* Delete to start of line */
186
 		kill_sol ( string );
220
 		kill_sol ( string );

Loading…
Cancel
Save