iPXE
Functions
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.

Functions

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

Detailed Description

Prompt for keypress.

Definition in file prompt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ prompt()

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.

48  {
49  int key_pressed;
50 
51  /* Display prompt */
52  printf ( "%s", text );
53 
54  /* Wait for key */
55  key_pressed = getkey ( timeout );
56 
57  /* Clear the prompt line */
58  while ( *(text++) )
59  printf ( "\b \b" );
60 
61  /* Check for timeout */
62  if ( key_pressed < 0 )
63  return -ETIMEDOUT;
64 
65  /* Check for correct key pressed */
66  if ( key && ( key_pressed != key ) )
67  return -ECANCELED;
68 
69  return 0;
70 }
int getkey(unsigned long timeout)
Get single keypress.
Definition: getkey.c:71
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define ECANCELED
Operation canceled.
Definition: errno.h:343
void timeout(int)
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
union @382 key
Sense key.
Definition: crypto.h:284

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

Referenced by prompt_exec(), readline(), readline_history(), and shell_banner().