summaryrefslogtreecommitdiffstats
path: root/src/hci/tui
diff options
context:
space:
mode:
authorMichael Brown2011-03-22 22:07:22 +0100
committerMichael Brown2011-03-22 22:25:46 +0100
commit48b66e4f1a1ea70966dd9abc5c6fcb3ec7efb7a7 (patch)
treeacb4a90aa2eb80f70dda2f758df3c633a83ba99d /src/hci/tui
parent[settings] Display canonical setting name in output of "show" command (diff)
downloadipxe-48b66e4f1a1ea70966dd9abc5c6fcb3ec7efb7a7.tar.gz
ipxe-48b66e4f1a1ea70966dd9abc5c6fcb3ec7efb7a7.tar.xz
ipxe-48b66e4f1a1ea70966dd9abc5c6fcb3ec7efb7a7.zip
[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>
Diffstat (limited to 'src/hci/tui')
-rw-r--r--src/hci/tui/settings_ui.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/hci/tui/settings_ui.c b/src/hci/tui/settings_ui.c
index ff2f9af1..cf92e93b 100644
--- a/src/hci/tui/settings_ui.c
+++ b/src/hci/tui/settings_ui.c
@@ -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: