mirror of https://github.com/ipxe/ipxe.git
[readline] Allow a prefilled input string to be provided
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/598/head
parent
c86790df5c
commit
4dedccfa1f
|
@ -241,13 +241,14 @@ void history_free ( struct readline_history *history ) {
|
||||||
* Read line from console (with history)
|
* Read line from console (with history)
|
||||||
*
|
*
|
||||||
* @v prompt Prompt string
|
* @v prompt Prompt string
|
||||||
|
* @v prefill Prefill string, or NULL for no prefill
|
||||||
* @v history History buffer, or NULL for no history
|
* @v history History buffer, or NULL for no history
|
||||||
* @ret line Line read from console (excluding terminating newline)
|
* @ret line Line read from console (excluding terminating newline)
|
||||||
*
|
*
|
||||||
* The returned line is allocated with malloc(); the caller must
|
* The returned line is allocated with malloc(); the caller must
|
||||||
* eventually call free() to release the storage.
|
* 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 ) {
|
struct readline_history *history ) {
|
||||||
char buf[READLINE_MAX];
|
char buf[READLINE_MAX];
|
||||||
struct edit_string string;
|
struct edit_string string;
|
||||||
|
@ -265,6 +266,12 @@ char * readline_history ( const char *prompt,
|
||||||
init_editstring ( &string, buf, sizeof ( buf ) );
|
init_editstring ( &string, buf, sizeof ( buf ) );
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
|
/* Prefill string, if applicable */
|
||||||
|
if ( prefill ) {
|
||||||
|
replace_string ( &string, prefill );
|
||||||
|
sync_console ( &string );
|
||||||
|
}
|
||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
/* Handle keypress */
|
/* Handle keypress */
|
||||||
key = edit_string ( &string, getkey ( 0 ) );
|
key = edit_string ( &string, getkey ( 0 ) );
|
||||||
|
@ -321,5 +328,5 @@ char * readline_history ( const char *prompt,
|
||||||
* eventually call free() to release the storage.
|
* eventually call free() to release the storage.
|
||||||
*/
|
*/
|
||||||
char * readline ( const char *prompt ) {
|
char * readline ( const char *prompt ) {
|
||||||
return readline_history ( prompt, NULL );
|
return readline_history ( prompt, NULL, NULL );
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ int shell ( void ) {
|
||||||
|
|
||||||
/* Read and execute commands */
|
/* Read and execute commands */
|
||||||
do {
|
do {
|
||||||
line = readline_history ( shell_prompt, &history );
|
line = readline_history ( shell_prompt, NULL, &history );
|
||||||
if ( line ) {
|
if ( line ) {
|
||||||
rc = system ( line );
|
rc = system ( line );
|
||||||
free ( line );
|
free ( line );
|
||||||
|
|
|
@ -51,6 +51,7 @@ struct readline_history {
|
||||||
|
|
||||||
extern void history_free ( struct readline_history *history );
|
extern void history_free ( struct readline_history *history );
|
||||||
extern char * __malloc readline_history ( const char *prompt,
|
extern char * __malloc readline_history ( const char *prompt,
|
||||||
|
const char *prefill,
|
||||||
struct readline_history *history );
|
struct readline_history *history );
|
||||||
extern char * __malloc readline ( const char *prompt );
|
extern char * __malloc readline ( const char *prompt );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue