david/ipxe
Archived
1
0

[settings] Display only applicable settings in "config" user interface

Display only settings relevant to the current scope.  For example,
"config net0" no longer displays SMBIOS settings, and "config smbios"
displays only SMBIOS settings.

Originally-implemented-by: Glenn Brown <glenn@myri.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2011-03-22 21:07:22 +00:00
parent 5fbd0207b2
commit 48b66e4f1a

View File

@ -66,6 +66,8 @@ struct setting_row {
struct setting_widget { struct setting_widget {
/** Settings block */ /** Settings block */
struct settings *settings; struct settings *settings;
/** Number of applicable settings */
unsigned int num_settings;
/** Index of the first visible setting, for scrolling. */ /** Index of the first visible setting, for scrolling. */
unsigned int first_visible; unsigned int first_visible;
/** Configuration setting */ /** Configuration setting */
@ -82,9 +84,6 @@ struct setting_widget {
char value[256]; /* enough size for a DHCP string */ char value[256]; /* enough size for a DHCP string */
}; };
/** Number of registered configuration settings */
#define NUM_SETTINGS table_num_entries ( SETTINGS )
static void load_setting ( struct setting_widget *widget ) __nonnull; static void load_setting ( struct setting_widget *widget ) __nonnull;
static int save_setting ( struct setting_widget *widget ) __nonnull; static int save_setting ( struct setting_widget *widget ) __nonnull;
static void init_widget ( struct setting_widget *widget, static void init_widget ( struct setting_widget *widget,
@ -143,8 +142,14 @@ static int save_setting ( struct setting_widget *widget ) {
*/ */
static void init_widget ( struct setting_widget *widget, static void init_widget ( struct setting_widget *widget,
struct settings *settings ) { struct settings *settings ) {
struct setting *setting;
memset ( widget, 0, sizeof ( *widget ) ); memset ( widget, 0, sizeof ( *widget ) );
widget->settings = settings; widget->settings = settings;
for_each_table_entry ( setting, SETTINGS ) {
if ( setting_applies ( settings, setting ) )
widget->num_settings++;
}
widget->first_visible = SETTINGS_LIST_ROWS; widget->first_visible = SETTINGS_LIST_ROWS;
reveal ( widget, 0 ); reveal ( widget, 0 );
} }
@ -210,14 +215,18 @@ static int edit_setting ( struct setting_widget *widget, int key ) {
*/ */
static void select_setting ( struct setting_widget *widget, static void select_setting ( struct setting_widget *widget,
unsigned int index ) { unsigned int index ) {
struct setting *all_settings = table_start ( SETTINGS );
unsigned int skip = offsetof ( struct setting_widget, setting ); unsigned int skip = offsetof ( struct setting_widget, setting );
/* Reset the widget, preserving static state. */ /* Reset the widget, preserving static state. */
memset ( ( char * ) widget + skip, 0, sizeof ( *widget ) - skip ); memset ( ( char * ) widget + skip, 0, sizeof ( *widget ) - skip );
widget->setting = &all_settings[index];
widget->row = SETTINGS_LIST_ROW + index - widget->first_visible; widget->row = SETTINGS_LIST_ROW + index - widget->first_visible;
widget->col = SETTINGS_LIST_COL; widget->col = SETTINGS_LIST_COL;
for_each_table_entry ( widget->setting, SETTINGS ) {
if ( ! setting_applies ( widget->settings, widget->setting ) )
continue;
if ( index-- == 0 )
break;
}
/* Read current setting value */ /* Read current setting value */
load_setting ( widget ); load_setting ( widget );
@ -359,13 +368,12 @@ static void reveal ( struct setting_widget *widget, unsigned int n)
widget->first_visible > 0 ? "..." : " " ); widget->first_visible > 0 ? "..." : " " );
mvaddstr ( SETTINGS_LIST_ROW + SETTINGS_LIST_ROWS, mvaddstr ( SETTINGS_LIST_ROW + SETTINGS_LIST_ROWS,
SETTINGS_LIST_COL + 1, SETTINGS_LIST_COL + 1,
( widget->first_visible + SETTINGS_LIST_ROWS < NUM_SETTINGS ( ( widget->first_visible + SETTINGS_LIST_ROWS )
? "..." < widget->num_settings ? "..." : " " ) );
: " " ) );
/* Draw visible settings. */ /* Draw visible settings. */
for ( i = 0; i < SETTINGS_LIST_ROWS; i++ ) { for ( i = 0; i < SETTINGS_LIST_ROWS; i++ ) {
if ( widget->first_visible + i < NUM_SETTINGS ) { if ( ( widget->first_visible + i ) < widget->num_settings ) {
select_setting ( widget, widget->first_visible + i ); select_setting ( widget, widget->first_visible + i );
draw_setting ( widget ); draw_setting ( widget );
} else { } else {
@ -424,7 +432,7 @@ static int main_loop ( struct settings *settings ) {
next = current; next = current;
switch ( key ) { switch ( key ) {
case KEY_DOWN: case KEY_DOWN:
if ( next < ( NUM_SETTINGS - 1 ) ) if ( next < ( widget.num_settings - 1 ) )
reveal ( &widget, ++next ); reveal ( &widget, ++next );
break; break;
case KEY_UP: case KEY_UP: