diff options
author | Michael Brown <mcb30@ipxe.org> | 2012-10-24 20:16:15 -0700 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2012-10-24 20:42:42 -0700 |
commit | 4dedccfa1fece8d8e2d6d22c81023817aebd7e2e (patch) | |
tree | bd448b2fce7ae26286df576241d6e170464a2d9f /src | |
parent | c86790df5cd50b47b8a6b69a3c2367bd28f6cf3c (diff) | |
download | ipxe-4dedccfa1fece8d8e2d6d22c81023817aebd7e2e.tar.gz |
[readline] Allow a prefilled input string to be provided
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/hci/readline.c | 11 | ||||
-rw-r--r-- | src/hci/shell.c | 2 | ||||
-rw-r--r-- | src/include/readline/readline.h | 1 |
3 files changed, 11 insertions, 3 deletions
diff --git a/src/hci/readline.c b/src/hci/readline.c index 2ecb8f278..a199fb0e1 100644 --- a/src/hci/readline.c +++ b/src/hci/readline.c @@ -241,13 +241,14 @@ void history_free ( struct readline_history *history ) { * Read line from console (with history) * * @v prompt Prompt string + * @v prefill Prefill string, or NULL for no prefill * @v history History buffer, or NULL for no history * @ret line Line read from console (excluding terminating newline) * * The returned line is allocated with malloc(); the caller must * eventually call free() to release the storage. */ -char * readline_history ( const char *prompt, +char * readline_history ( const char *prompt, const char *prefill, struct readline_history *history ) { char buf[READLINE_MAX]; struct edit_string string; @@ -265,6 +266,12 @@ char * readline_history ( const char *prompt, init_editstring ( &string, buf, sizeof ( buf ) ); buf[0] = '\0'; + /* Prefill string, if applicable */ + if ( prefill ) { + replace_string ( &string, prefill ); + sync_console ( &string ); + } + while ( 1 ) { /* Handle keypress */ key = edit_string ( &string, getkey ( 0 ) ); @@ -321,5 +328,5 @@ char * readline_history ( const char *prompt, * eventually call free() to release the storage. */ char * readline ( const char *prompt ) { - return readline_history ( prompt, NULL ); + return readline_history ( prompt, NULL, NULL ); } diff --git a/src/hci/shell.c b/src/hci/shell.c index 33438da09..f4cf9bc8d 100644 --- a/src/hci/shell.c +++ b/src/hci/shell.c @@ -86,7 +86,7 @@ int shell ( void ) { /* Read and execute commands */ do { - line = readline_history ( shell_prompt, &history ); + line = readline_history ( shell_prompt, NULL, &history ); if ( line ) { rc = system ( line ); free ( line ); diff --git a/src/include/readline/readline.h b/src/include/readline/readline.h index 42dfd8c4c..8b1599753 100644 --- a/src/include/readline/readline.h +++ b/src/include/readline/readline.h @@ -51,6 +51,7 @@ struct readline_history { extern void history_free ( struct readline_history *history ); extern char * __malloc readline_history ( const char *prompt, + const char *prefill, struct readline_history *history ); extern char * __malloc readline ( const char *prompt ); |