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)
 
 FILE_SECBOOT (PERMITTED)
 
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  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 49 of file prompt.c.

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

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

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