prompt.c File Reference

Prompt for keypress. More...

#include <errno.h>
#include <stdio.h>
#include <ipxe/console.h>
#include <usr/prompt.h>

Go to the source code of this file.


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

Detailed Description

Prompt for keypress.

Definition in file prompt.c.

Function Documentation

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

Prompt for keypress.

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;