]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[readline] Allow a prefilled input string to be provided
authorMichael Brown <mcb30@ipxe.org>
Thu, 25 Oct 2012 03:16:15 +0000 (20:16 -0700)
committerMichael Brown <mcb30@ipxe.org>
Thu, 25 Oct 2012 03:42:42 +0000 (20:42 -0700)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/hci/readline.c
src/hci/shell.c
src/include/readline/readline.h

index 2ecb8f278067e5174e224c48098e24c5041b6e36..a199fb0e183d4c4b17361f085f483849a4e3f3f8 100644 (file)
@@ -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 );
 }
index 33438da0996224fcfe2e11c73177a21e0a36e82b..f4cf9bc8d555379725737ad018b2f85af2e912eb 100644 (file)
@@ -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 );
index 42dfd8c4cf6daf3e35ad477d748257c7f5a939f3..8b1599753d2a13ad55867bba46c888208d5554cf 100644 (file)
@@ -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 );