|
@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
21
|
21
|
|
22
|
22
|
#include <assert.h>
|
23
|
23
|
#include <string.h>
|
|
24
|
+#include <ctype.h>
|
24
|
25
|
#include <ipxe/keys.h>
|
25
|
26
|
#include <ipxe/editstring.h>
|
26
|
27
|
|
|
@@ -37,6 +38,8 @@ static void insert_character ( struct edit_string *string,
|
37
|
38
|
unsigned int character ) __nonnull;
|
38
|
39
|
static void delete_character ( struct edit_string *string ) __nonnull;
|
39
|
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
|
43
|
static void kill_sol ( struct edit_string *string ) __nonnull;
|
41
|
44
|
static void kill_eol ( struct edit_string *string ) __nonnull;
|
42
|
45
|
|
|
@@ -110,10 +113,37 @@ static void backspace ( struct edit_string *string ) {
|
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
|
144
|
* Delete to start of line
|
115
|
145
|
*
|
116
|
|
- * @v string Editable string
|
|
146
|
+ * @v string Editable string
|
117
|
147
|
*/
|
118
|
148
|
static void kill_sol ( struct edit_string *string ) {
|
119
|
149
|
size_t old_cursor = string->cursor;
|
|
@@ -181,6 +211,10 @@ int edit_string ( struct edit_string *string, int key ) {
|
181
|
211
|
/* Delete character */
|
182
|
212
|
delete_character ( string );
|
183
|
213
|
break;
|
|
214
|
+ case CTRL_W:
|
|
215
|
+ /* Delete word */
|
|
216
|
+ kill_word ( string );
|
|
217
|
+ break;
|
184
|
218
|
case CTRL_U:
|
185
|
219
|
/* Delete to start of line */
|
186
|
220
|
kill_sol ( string );
|