From b93ff4817324aa4b1913c161b29d380bc4ff4146 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 20 Dec 2006 04:58:26 +0000 Subject: [PATCH] Added descriptive text for settings and setting types, and display it in the option config UI. --- src/core/settings.c | 14 ++++++- src/hci/tui/settings_ui.c | 79 +++++++++++++++++++++++++++++++++---- src/include/gpxe/settings.h | 4 ++ 3 files changed, 87 insertions(+), 10 deletions(-) diff --git a/src/core/settings.c b/src/core/settings.c index 5e025dc5..08b5afa1 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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; @@ -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; @@ -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, }; @@ -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, }; @@ -348,6 +351,7 @@ 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, }; @@ -355,31 +359,37 @@ struct config_setting_type config_setting_type_int8 __config_setting_type = { /** 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, }; diff --git a/src/hci/tui/settings_ui.c b/src/hci/tui/settings_ui.c index 7da95910..089e130f 100644 --- a/src/hci/tui/settings_ui.c +++ b/src/hci/tui/settings_ui.c @@ -16,6 +16,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include @@ -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 */ @@ -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 ); - va_end ( 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 ) { @@ -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 ); @@ -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 ); diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h index f84378af..d5be524d 100644 --- a/src/include/gpxe/settings.h +++ b/src/include/gpxe/settings.h @@ -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 @@ -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