Browse Source

[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>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
48b66e4f1a
1 changed files with 18 additions and 10 deletions
  1. 18
    10
      src/hci/tui/settings_ui.c

+ 18
- 10
src/hci/tui/settings_ui.c View File

66
 struct setting_widget {
66
 struct setting_widget {
67
 	/** Settings block */
67
 	/** Settings block */
68
 	struct settings *settings;
68
 	struct settings *settings;
69
+	/** Number of applicable settings */
70
+	unsigned int num_settings;
69
         /** Index of the first visible setting, for scrolling. */
71
         /** Index of the first visible setting, for scrolling. */
70
 	unsigned int first_visible;
72
 	unsigned int first_visible;
71
 	/** Configuration setting */
73
 	/** Configuration setting */
82
 	char value[256]; /* enough size for a DHCP string */
84
 	char value[256]; /* enough size for a DHCP string */
83
 };
85
 };
84
 
86
 
85
-/** Number of registered configuration settings */
86
-#define NUM_SETTINGS table_num_entries ( SETTINGS )
87
-
88
 static void load_setting ( struct setting_widget *widget ) __nonnull;
87
 static void load_setting ( struct setting_widget *widget ) __nonnull;
89
 static int save_setting ( struct setting_widget *widget ) __nonnull;
88
 static int save_setting ( struct setting_widget *widget ) __nonnull;
90
 static void init_widget ( struct setting_widget *widget,
89
 static void init_widget ( struct setting_widget *widget,
143
  */
142
  */
144
 static void init_widget ( struct setting_widget *widget,
143
 static void init_widget ( struct setting_widget *widget,
145
 			  struct settings *settings ) {
144
 			  struct settings *settings ) {
145
+	struct setting *setting;
146
+
146
 	memset ( widget, 0, sizeof ( *widget ) );
147
 	memset ( widget, 0, sizeof ( *widget ) );
147
 	widget->settings = settings;
148
 	widget->settings = settings;
149
+	for_each_table_entry ( setting, SETTINGS ) {
150
+		if ( setting_applies ( settings, setting ) )
151
+			widget->num_settings++;
152
+	}
148
 	widget->first_visible = SETTINGS_LIST_ROWS;
153
 	widget->first_visible = SETTINGS_LIST_ROWS;
149
 	reveal ( widget, 0 );
154
 	reveal ( widget, 0 );
150
 }
155
 }
210
  */
215
  */
211
 static void select_setting ( struct setting_widget *widget,
216
 static void select_setting ( struct setting_widget *widget,
212
 			     unsigned int index ) {
217
 			     unsigned int index ) {
213
-	struct setting *all_settings = table_start ( SETTINGS );
214
 	unsigned int skip = offsetof ( struct setting_widget, setting );
218
 	unsigned int skip = offsetof ( struct setting_widget, setting );
215
 
219
 
216
 	/* Reset the widget, preserving static state. */
220
 	/* Reset the widget, preserving static state. */
217
 	memset ( ( char * ) widget + skip, 0, sizeof ( *widget ) - skip );
221
 	memset ( ( char * ) widget + skip, 0, sizeof ( *widget ) - skip );
218
-	widget->setting = &all_settings[index];
219
 	widget->row = SETTINGS_LIST_ROW + index - widget->first_visible;
222
 	widget->row = SETTINGS_LIST_ROW + index - widget->first_visible;
220
 	widget->col = SETTINGS_LIST_COL;
223
 	widget->col = SETTINGS_LIST_COL;
224
+	for_each_table_entry ( widget->setting, SETTINGS ) {
225
+		if ( ! setting_applies ( widget->settings, widget->setting ) )
226
+			continue;
227
+		if ( index-- == 0 )
228
+			break;
229
+	}
221
 
230
 
222
 	/* Read current setting value */
231
 	/* Read current setting value */
223
 	load_setting ( widget );
232
 	load_setting ( widget );
359
 		   widget->first_visible > 0 ? "..." : "   " );
368
 		   widget->first_visible > 0 ? "..." : "   " );
360
 	mvaddstr ( SETTINGS_LIST_ROW + SETTINGS_LIST_ROWS,
369
 	mvaddstr ( SETTINGS_LIST_ROW + SETTINGS_LIST_ROWS,
361
 		   SETTINGS_LIST_COL + 1,
370
 		   SETTINGS_LIST_COL + 1,
362
-		   ( widget->first_visible + SETTINGS_LIST_ROWS < NUM_SETTINGS
363
-		     ? "..."
364
-		     : "   " ) );
371
+		   ( ( widget->first_visible + SETTINGS_LIST_ROWS )
372
+		     < widget->num_settings ? "..." : "   " ) );
365
 	
373
 	
366
 	/* Draw visible settings. */
374
 	/* Draw visible settings. */
367
 	for ( i = 0; i < SETTINGS_LIST_ROWS; i++ ) {
375
 	for ( i = 0; i < SETTINGS_LIST_ROWS; i++ ) {
368
-		if ( widget->first_visible + i < NUM_SETTINGS ) {
376
+		if ( ( widget->first_visible + i ) < widget->num_settings ) {
369
 			select_setting ( widget, widget->first_visible + i );
377
 			select_setting ( widget, widget->first_visible + i );
370
 			draw_setting ( widget );
378
 			draw_setting ( widget );
371
 		} else {
379
 		} else {
424
 			next = current;
432
 			next = current;
425
 			switch ( key ) {
433
 			switch ( key ) {
426
 			case KEY_DOWN:
434
 			case KEY_DOWN:
427
-				if ( next < ( NUM_SETTINGS - 1 ) )
435
+				if ( next < ( widget.num_settings - 1 ) )
428
 					reveal ( &widget, ++next );
436
 					reveal ( &widget, ++next );
429
 				break;
437
 				break;
430
 			case KEY_UP:
438
 			case KEY_UP:

Loading…
Cancel
Save