iPXE
Functions
prompt.h File Reference

Prompt for keypress. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int prompt (const char *text, unsigned long timeout, int key)
 Prompt for keypress.

Detailed Description

Prompt for keypress.

Definition in file prompt.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int prompt ( const char *  text,
unsigned long  timeout,
int  key 
)

Prompt for keypress.

Parameters:
textPrompt string
timeoutTimeout period, in ticks (0=indefinite)
keyKey to wait for (0=any key)
Return values:
rcReturn status code

Returns success if the specified key was pressed within the specified timeout period.

Definition at line 48 of file prompt.c.

References ECANCELED, ETIMEDOUT, getkey(), and printf().

Referenced by prompt_exec(), and shell_banner().

                                                                {
        int key_pressed;

        /* Display prompt */
        printf ( "%s", text );

        /* Wait for key */
        key_pressed = getkey ( timeout );

        /* Clear the prompt line */
        while ( *(text++) )
                printf ( "\b \b" );

        /* Check for timeout */
        if ( key_pressed < 0 )
                return -ETIMEDOUT;

        /* Check for correct key pressed */
        if ( key && ( key_pressed != key ) )
                return -ECANCELED;

        return 0;
}