mirror of https://github.com/ipxe/ipxe.git
[prompt] Replace shell_banner() with a generic prompt() function
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1/head
parent
9d633bdc71
commit
c4b6c244b0
|
@ -18,8 +18,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <ipxe/init.h>
|
#include <ipxe/init.h>
|
||||||
#include <ipxe/features.h>
|
#include <ipxe/features.h>
|
||||||
#include <ipxe/shell.h>
|
#include <ipxe/shell.h>
|
||||||
#include <ipxe/shell_banner.h>
|
|
||||||
#include <ipxe/image.h>
|
#include <ipxe/image.h>
|
||||||
|
#include <ipxe/keys.h>
|
||||||
|
#include <usr/prompt.h>
|
||||||
#include <usr/autoboot.h>
|
#include <usr/autoboot.h>
|
||||||
#include <config/general.h>
|
#include <config/general.h>
|
||||||
|
|
||||||
|
@ -27,6 +28,21 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#define BOLD "\033[1m"
|
#define BOLD "\033[1m"
|
||||||
#define CYAN "\033[36m"
|
#define CYAN "\033[36m"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prompt for shell entry
|
||||||
|
*
|
||||||
|
* @ret enter_shell User wants to enter shell
|
||||||
|
*/
|
||||||
|
static int shell_banner ( void ) {
|
||||||
|
|
||||||
|
/* Skip prompt if timeout is zero */
|
||||||
|
if ( BANNER_TIMEOUT <= 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return ( prompt ( "\nPress Ctrl-B for the iPXE command line...",
|
||||||
|
( BANNER_TIMEOUT * 100 ), CTRL_B ) == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point
|
* Main entry point
|
||||||
*
|
*
|
||||||
|
|
|
@ -237,6 +237,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#define ERRFILE_gdbstub_cmd ( ERRFILE_OTHER | 0x001f0000 )
|
#define ERRFILE_gdbstub_cmd ( ERRFILE_OTHER | 0x001f0000 )
|
||||||
#define ERRFILE_sanboot_cmd ( ERRFILE_OTHER | 0x00200000 )
|
#define ERRFILE_sanboot_cmd ( ERRFILE_OTHER | 0x00200000 )
|
||||||
#define ERRFILE_bofm ( ERRFILE_OTHER | 0x00210000 )
|
#define ERRFILE_bofm ( ERRFILE_OTHER | 0x00210000 )
|
||||||
|
#define ERRFILE_prompt ( ERRFILE_OTHER | 0x00220000 )
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
#ifndef _IPXE_SHELL_BANNER_H
|
|
||||||
#define _IPXE_SHELL_BANNER_H
|
|
||||||
|
|
||||||
/** @file
|
|
||||||
*
|
|
||||||
* Shell startup banner
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
|
||||||
|
|
||||||
extern int shell_banner ( void );
|
|
||||||
|
|
||||||
#endif /* _IPXE_SHELL_BANNER_H */
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef _USR_PROMPT_H
|
||||||
|
#define _USR_PROMPT_H
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Prompt for keypress
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
extern int prompt ( const char *text, unsigned int wait_ms, int key );
|
||||||
|
|
||||||
|
#endif /* _USR_PROMPT_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
* Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
@ -18,39 +18,49 @@
|
||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <console.h>
|
|
||||||
#include <config/general.h>
|
|
||||||
#include <ipxe/keys.h>
|
|
||||||
#include <ipxe/timer.h>
|
|
||||||
#include <ipxe/shell_banner.h>
|
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
*
|
*
|
||||||
* Shell startup banner
|
* Prompt for keypress
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <console.h>
|
||||||
|
#include <ipxe/timer.h>
|
||||||
|
#include <usr/prompt.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print shell banner and prompt for shell entry
|
* Prompt for keypress
|
||||||
*
|
*
|
||||||
* @ret enter_shell User wants to enter shell
|
* @v text Prompt string
|
||||||
|
* @v wait_ms Time to wait, in milliseconds (0=indefinite)
|
||||||
|
* @v key Key to wait for (0=any key)
|
||||||
|
* @ret rc Return status code
|
||||||
|
*
|
||||||
|
* Returns success if the specified key was pressed within the
|
||||||
|
* specified timeout period.
|
||||||
*/
|
*/
|
||||||
int shell_banner ( void ) {
|
int prompt ( const char *text, unsigned int wait_ms, int key ) {
|
||||||
int key;
|
int key_pressed;
|
||||||
|
|
||||||
/* Skip prompt if timeout is zero */
|
|
||||||
if ( BANNER_TIMEOUT <= 0 )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Display prompt */
|
/* Display prompt */
|
||||||
printf ( "\nPress Ctrl-B for the iPXE command line..." );
|
printf ( "%s", text );
|
||||||
|
|
||||||
/* Wait for key */
|
/* Wait for key */
|
||||||
key = getkey ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 );
|
key_pressed = getkey ( ( wait_ms * TICKS_PER_SEC ) / 1000 );
|
||||||
|
|
||||||
/* Clear the "Press Ctrl-B" line */
|
/* Clear the prompt line */
|
||||||
printf ( "\r \r" );
|
while ( *(text++) )
|
||||||
|
printf ( "\b \b" );
|
||||||
|
|
||||||
return ( key == CTRL_B );
|
/* Check for timeout */
|
||||||
|
if ( key_pressed < 0 )
|
||||||
|
return -ETIMEDOUT;
|
||||||
|
|
||||||
|
/* Check for correct key pressed */
|
||||||
|
if ( key && ( key_pressed != key ) )
|
||||||
|
return -ECANCELED;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue