Skip to content

Commit

Permalink
Added descriptive text for settings and setting types, and display it in
Browse files Browse the repository at this point in the history
the option config UI.
  • Loading branch information
Michael Brown committed Dec 20, 2006
1 parent 35edeca commit b93ff48
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/core/settings.c
Expand Up @@ -19,6 +19,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <byteswap.h>
#include <errno.h>
#include <assert.h>
Expand Down Expand Up @@ -56,7 +57,7 @@ find_config_setting_type ( const char *name ) {

for ( type = config_setting_types ; type < config_setting_types_end ;
type++ ) {
if ( strcmp ( name, type->name ) == 0 )
if ( strcasecmp ( name, type->name ) == 0 )
return type;
}
return NULL;
Expand All @@ -73,7 +74,7 @@ static struct config_setting * find_config_setting ( const char *name ) {

for ( setting = config_settings ; setting < config_settings_end ;
setting++ ) {
if ( strcmp ( name, setting->name ) == 0 )
if ( strcasecmp ( name, setting->name ) == 0 )
return setting;
}
return NULL;
Expand Down Expand Up @@ -216,6 +217,7 @@ static int set_string ( struct config_context *context,
/** A string configuration setting */
struct config_setting_type config_setting_type_string __config_setting_type = {
.name = "string",
.description = "Text string",
.show = show_string,
.set = set_string,
};
Expand Down Expand Up @@ -269,6 +271,7 @@ static int set_ipv4 ( struct config_context *context,
/** An IPv4 configuration setting */
struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
.name = "ipv4",
.description = "IPv4 address",
.show = show_ipv4,
.set = set_ipv4,
};
Expand Down Expand Up @@ -348,38 +351,45 @@ static int set_int8 ( struct config_context *context,
/** An 8-bit integer configuration setting */
struct config_setting_type config_setting_type_int8 __config_setting_type = {
.name = "int8",
.description = "8-bit integer",
.show = show_int,
.set = set_int8,
};

/** Some basic setting definitions */
struct config_setting ip_config_setting __config_setting = {
.name = "ip",
.description = "IP address of this machine (e.g. 192.168.0.1)",
.tag = DHCP_EB_YIADDR,
.type = &config_setting_type_ipv4,
};
struct config_setting hostname_config_setting __config_setting = {
.name = "hostname",
.description = "Host name of this machine",
.tag = DHCP_HOST_NAME,
.type = &config_setting_type_string,
};
struct config_setting username_config_setting __config_setting = {
.name = "username",
.description = "User name for authentication to servers",
.tag = DHCP_EB_USERNAME,
.type = &config_setting_type_string,
};
struct config_setting password_config_setting __config_setting = {
.name = "password",
.description = "Password for authentication to servers",
.tag = DHCP_EB_PASSWORD,
.type = &config_setting_type_string,
};
struct config_setting root_path_config_setting __config_setting = {
.name = "root-path",
.description = "NFS/iSCSI root path",
.tag = DHCP_ROOT_PATH,
.type = &config_setting_type_string,
};
struct config_setting priority_config_setting __config_setting = {
.name = "priority",
.description = "Priority of these options",
.tag = DHCP_EB_PRIORITY,
.type = &config_setting_type_int8,
};
77 changes: 70 additions & 7 deletions src/hci/tui/settings_ui.c
Expand Up @@ -16,6 +16,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <curses.h>
Expand All @@ -39,8 +40,10 @@ extern struct nvo_block *ugly_nvo_hack;
#define CPAIR_ALERT 4

/* Screen layout */
#define BANNER_ROW 1
#define SETTINGS_LIST_ROW 3
#define SETTINGS_LIST_COL 1
#define INFO_ROW 20
#define ALERT_ROW 20

/** Layout of text within a setting widget */
Expand Down Expand Up @@ -203,21 +206,72 @@ static void init_setting_index ( struct setting_widget *widget,
( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );
}

static void alert ( const char *fmt, ... ) {
/**
* Print message centred on specified row
*
* @v row Row
* @v fmt printf() format string
* @v args printf() argument list
*/
static void vmsg ( unsigned int row, const char *fmt, va_list args ) {
char buf[COLS];
va_list args;
size_t len;

va_start ( args, fmt );
len = vsnprintf ( buf, sizeof ( buf ), fmt, args );
mvprintw ( row, ( ( COLS - len ) / 2 ), "%s", buf );
}

/**
* Print message centred on specified row
*
* @v row Row
* @v fmt printf() format string
* @v .. printf() arguments
*/
static void msg ( unsigned int row, const char *fmt, ... ) {
va_list args;

va_start ( args, fmt );
vmsg ( row, fmt, args );
va_end ( args );
}

/**
* Clear message on specified row
*
* @v row Row
*/
static void clearmsg ( unsigned int row ) {
move ( row, 0 );
clrtoeol();
}

/**
* Print alert message
*
* @v fmt printf() format string
* @v args printf() argument list
*/
static void valert ( const char *fmt, va_list args ) {
color_set ( CPAIR_ALERT, NULL );
mvprintw ( ALERT_ROW, ( ( COLS - len ) / 2 ), "%s", buf );
vmsg ( ALERT_ROW, fmt, args );
sleep ( 2 );
color_set ( CPAIR_NORMAL, NULL );
move ( ALERT_ROW, 0 );
clrtoeol();
clearmsg ( ALERT_ROW );
}

/**
* Print alert message
*
* @v fmt printf() format string
* @v ... printf() arguments
*/
static void alert ( const char *fmt, ... ) {
va_list args;

va_start ( args, fmt );
valert ( fmt, args );
va_end ( args );
}

static void main_loop ( struct config_context *context ) {
Expand All @@ -230,12 +284,21 @@ static void main_loop ( struct config_context *context ) {

/* Print initial screen content */
color_set ( CPAIR_NORMAL, NULL );
attron ( A_BOLD );
msg ( BANNER_ROW, "gPXE option configuration console" );
attroff ( A_BOLD );
for ( i = ( NUM_SETTINGS - 1 ) ; i >= 0 ; i-- ) {
init_setting_index ( &widget, context, i );
draw_setting ( &widget );
}

while ( 1 ) {
/* Redraw information row */
clearmsg ( INFO_ROW );
msg ( INFO_ROW, "%s (%s) - %s", widget.setting->name,
widget.setting->type->description,
widget.setting->description );

/* Redraw current setting */
color_set ( ( widget.editing ? CPAIR_EDIT : CPAIR_SELECT ),
NULL );
Expand Down Expand Up @@ -293,7 +356,7 @@ void uitest ( void ) {
initscr();
start_color();
init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE );
init_pair ( CPAIR_SELECT, COLOR_BLACK, COLOR_WHITE );
init_pair ( CPAIR_SELECT, COLOR_WHITE, COLOR_RED );
init_pair ( CPAIR_EDIT, COLOR_BLACK, COLOR_CYAN );
init_pair ( CPAIR_ALERT, COLOR_WHITE, COLOR_RED );
color_set ( CPAIR_NORMAL, NULL );
Expand Down
4 changes: 4 additions & 0 deletions src/include/gpxe/settings.h
Expand Up @@ -40,6 +40,8 @@ struct config_setting_type {
* This is the name exposed to the user (e.g. "string").
*/
const char *name;
/** Description */
const char *description;
/** Show value of setting
*
* @v context Configuration context
Expand Down Expand Up @@ -79,6 +81,8 @@ struct config_setting {
* dhcp-options(5)).
*/
const char *name;
/** Description */
const char *description;
/** DHCP option tag
*
* This is the DHCP tag used to identify the option in DHCP
Expand Down

0 comments on commit b93ff48

Please sign in to comment.