]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[settings] Display only applicable settings in "config" user interface
authorMichael Brown <mcb30@ipxe.org>
Tue, 22 Mar 2011 21:07:22 +0000 (21:07 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 22 Mar 2011 21:25:46 +0000 (21:25 +0000)
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>
src/hci/tui/settings_ui.c

index ff2f9af11af460bec16d9bf5da539ffb1c4f3a89..cf92e93bf1115ee70ccbd9fc5ec0e8d065b28445 100644 (file)
@@ -66,6 +66,8 @@ struct setting_row {
 struct setting_widget {
        /** Settings block */
        struct settings *settings;
+       /** Number of applicable settings */
+       unsigned int num_settings;
         /** Index of the first visible setting, for scrolling. */
        unsigned int first_visible;
        /** Configuration setting */
@@ -82,9 +84,6 @@ struct setting_widget {
        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 int save_setting ( struct setting_widget *widget ) __nonnull;
 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,
                          struct settings *settings ) {
+       struct setting *setting;
+
        memset ( widget, 0, sizeof ( *widget ) );
        widget->settings = settings;
+       for_each_table_entry ( setting, SETTINGS ) {
+               if ( setting_applies ( settings, setting ) )
+                       widget->num_settings++;
+       }
        widget->first_visible = SETTINGS_LIST_ROWS;
        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,
                             unsigned int index ) {
-       struct setting *all_settings = table_start ( SETTINGS );
        unsigned int skip = offsetof ( struct setting_widget, setting );
 
        /* Reset the widget, preserving static state. */
        memset ( ( char * ) widget + skip, 0, sizeof ( *widget ) - skip );
-       widget->setting = &all_settings[index];
        widget->row = SETTINGS_LIST_ROW + index - widget->first_visible;
        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 */
        load_setting ( widget );
@@ -359,13 +368,12 @@ static void reveal ( struct setting_widget *widget, unsigned int n)
                   widget->first_visible > 0 ? "..." : "   " );
        mvaddstr ( SETTINGS_LIST_ROW + SETTINGS_LIST_ROWS,
                   SETTINGS_LIST_COL + 1,
-                  ( widget->first_visible + SETTINGS_LIST_ROWS < NUM_SETTINGS
-                    ? "..."
-                    : "   " ) );
+                  ( ( widget->first_visible + SETTINGS_LIST_ROWS )
+                    < widget->num_settings ? "..." : "   " ) );
        
        /* Draw visible settings. */
        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 );
                        draw_setting ( widget );
                } else {
@@ -424,7 +432,7 @@ static int main_loop ( struct settings *settings ) {
                        next = current;
                        switch ( key ) {
                        case KEY_DOWN:
-                               if ( next < ( NUM_SETTINGS - 1 ) )
+                               if ( next < ( widget.num_settings - 1 ) )
                                        reveal ( &widget, ++next );
                                break;
                        case KEY_UP: