Przeglądaj źródła

[readline] Allow a prefilled input string to be provided

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 lat temu
rodzic
commit
4dedccfa1f
3 zmienionych plików z 11 dodań i 3 usunięć
  1. 9
    2
      src/hci/readline.c
  2. 1
    1
      src/hci/shell.c
  3. 1
    0
      src/include/readline/readline.h

+ 9
- 2
src/hci/readline.c Wyświetl plik

@@ -241,13 +241,14 @@ void history_free ( struct readline_history *history ) {
241 241
  * Read line from console (with history)
242 242
  *
243 243
  * @v prompt		Prompt string
244
+ * @v prefill		Prefill string, or NULL for no prefill
244 245
  * @v history		History buffer, or NULL for no history
245 246
  * @ret line		Line read from console (excluding terminating newline)
246 247
  *
247 248
  * The returned line is allocated with malloc(); the caller must
248 249
  * eventually call free() to release the storage.
249 250
  */
250
-char * readline_history ( const char *prompt,
251
+char * readline_history ( const char *prompt, const char *prefill,
251 252
 			  struct readline_history *history ) {
252 253
 	char buf[READLINE_MAX];
253 254
 	struct edit_string string;
@@ -265,6 +266,12 @@ char * readline_history ( const char *prompt,
265 266
 	init_editstring ( &string, buf, sizeof ( buf ) );
266 267
 	buf[0] = '\0';
267 268
 
269
+	/* Prefill string, if applicable */
270
+	if ( prefill ) {
271
+		replace_string ( &string, prefill );
272
+		sync_console ( &string );
273
+	}
274
+
268 275
 	while ( 1 ) {
269 276
 		/* Handle keypress */
270 277
 		key = edit_string ( &string, getkey ( 0 ) );
@@ -321,5 +328,5 @@ char * readline_history ( const char *prompt,
321 328
  * eventually call free() to release the storage.
322 329
  */
323 330
 char * readline ( const char *prompt ) {
324
-	return readline_history ( prompt, NULL );
331
+	return readline_history ( prompt, NULL, NULL );
325 332
 }

+ 1
- 1
src/hci/shell.c Wyświetl plik

@@ -86,7 +86,7 @@ int shell ( void ) {
86 86
 
87 87
 	/* Read and execute commands */
88 88
 	do {
89
-		line = readline_history ( shell_prompt, &history );
89
+		line = readline_history ( shell_prompt, NULL, &history );
90 90
 		if ( line ) {
91 91
 			rc = system ( line );
92 92
 			free ( line );

+ 1
- 0
src/include/readline/readline.h Wyświetl plik

@@ -51,6 +51,7 @@ struct readline_history {
51 51
 
52 52
 extern void history_free ( struct readline_history *history );
53 53
 extern char * __malloc readline_history ( const char *prompt,
54
+					  const char *prefill,
54 55
 					  struct readline_history *history );
55 56
 extern char * __malloc readline ( const char *prompt );
56 57
 

Ładowanie…
Anuluj
Zapisz