#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <curses.h>
#include <console.h>
#include <gpxe/settings.h>
#include <gpxe/editbox.h>
#include <gpxe/keys.h>
#include <gpxe/settings_ui.h>
Go to the source code of this file.
Data Structures | |
| struct | setting_row |
| Layout of text within a setting widget. More... | |
| struct | setting_widget |
| A setting widget. More... | |
Defines | |
| #define | CPAIR_NORMAL 1 |
| #define | CPAIR_SELECT 2 |
| #define | CPAIR_EDIT 3 |
| #define | CPAIR_ALERT 4 |
| #define | TITLE_ROW 1 |
| #define | SETTINGS_LIST_ROW 3 |
| #define | SETTINGS_LIST_COL 1 |
| #define | INFO_ROW 20 |
| #define | ALERT_ROW 20 |
| #define | INSTRUCTION_ROW 22 |
| #define | INSTRUCTION_PAD " " |
| #define | NUM_SETTINGS table_num_entries ( SETTINGS ) |
| Number of registered configuration settings. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static void | load_setting (struct setting_widget *widget) |
| Load setting widget value from configuration settings. | |
| static int | save_setting (struct setting_widget *widget) |
| Save setting widget value back to configuration settings. | |
| static void | init_setting (struct setting_widget *widget, struct settings *settings, struct setting *setting, unsigned int row, unsigned int col) |
| Initialise setting widget. | |
| static void | draw_setting (struct setting_widget *widget) |
| Draw setting widget. | |
| static int | edit_setting (struct setting_widget *widget, int key) |
| Edit setting widget. | |
| static void | init_setting_index (struct setting_widget *widget, struct settings *settings, unsigned int index) |
| Initialise setting widget by index. | |
| static void | vmsg (unsigned int row, const char *fmt, va_list args) |
| Print message centred on specified row. | |
| static void | msg (unsigned int row, const char *fmt,...) |
| Print message centred on specified row. | |
| static void | valert (const char *fmt, va_list args) |
| Print alert message. | |
| static void | alert (const char *fmt,...) |
| Print alert message. | |
| static void | draw_info_row (struct setting *setting) |
| Draw information row. | |
| static int | main_loop (struct settings *settings) __nonnull |
| static void | clearmsg (unsigned int row) |
| Clear message on specified row. | |
| static void | draw_title_row (void) |
| Draw title row. | |
| static void | draw_instruction_row (int editing) |
| Draw instruction row. | |
| int | settings_ui (struct settings *settings) |
Definition in file settings_ui.c.
| #define CPAIR_NORMAL 1 |
Definition at line 39 of file settings_ui.c.
| #define CPAIR_SELECT 2 |
Definition at line 40 of file settings_ui.c.
Referenced by main_loop(), pxe_menu_draw_item(), pxe_menu_select(), and settings_ui().
| #define CPAIR_EDIT 3 |
| #define CPAIR_ALERT 4 |
| #define TITLE_ROW 1 |
| #define SETTINGS_LIST_ROW 3 |
| #define SETTINGS_LIST_COL 1 |
| #define INFO_ROW 20 |
| #define ALERT_ROW 20 |
| #define INSTRUCTION_ROW 22 |
| #define INSTRUCTION_PAD " " |
| #define NUM_SETTINGS table_num_entries ( SETTINGS ) |
Number of registered configuration settings.
Definition at line 83 of file settings_ui.c.
Referenced by main_loop().
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| static void load_setting | ( | struct setting_widget * | widget | ) | [static] |
Load setting widget value from configuration settings.
| widget | Setting widget |
Definition at line 109 of file settings_ui.c.
References fetchf_setting(), init_editbox(), NULL, and offsetof.
Referenced by init_setting(), and main_loop().
00109 { 00110 00111 /* Mark as not editing */ 00112 widget->editing = 0; 00113 00114 /* Read current setting value */ 00115 if ( fetchf_setting ( widget->settings, widget->setting, 00116 widget->value, sizeof ( widget->value ) ) < 0 ) { 00117 widget->value[0] = '\0'; 00118 } 00119 00120 /* Initialise edit box */ 00121 init_editbox ( &widget->editbox, widget->value, 00122 sizeof ( widget->value ), NULL, widget->row, 00123 ( widget->col + offsetof ( struct setting_row, value )), 00124 sizeof ( ( ( struct setting_row * ) NULL )->value ), 0); 00125 }
| static int save_setting | ( | struct setting_widget * | widget | ) | [static] |
Save setting widget value back to configuration settings.
| widget | Setting widget |
Definition at line 132 of file settings_ui.c.
References setting_widget::setting, setting_widget::settings, storef_setting(), and setting_widget::value.
Referenced by main_loop().
00132 { 00133 return storef_setting ( widget->settings, widget->setting, 00134 widget->value ); 00135 }
| static void init_setting | ( | struct setting_widget * | widget, | |
| struct settings * | settings, | |||
| struct setting * | setting, | |||
| unsigned int | row, | |||
| unsigned int | col | |||
| ) | [static] |
Initialise setting widget.
| widget | Setting widget | |
| settings | Settings block | |
| setting | Configuration setting | |
| row | Screen row | |
| col | Screen column |
Definition at line 146 of file settings_ui.c.
References setting_widget::col, load_setting(), memset(), setting_widget::row, setting_widget::setting, and setting_widget::settings.
Referenced by init_setting_index().
00149 { 00150 00151 /* Initialise widget structure */ 00152 memset ( widget, 0, sizeof ( *widget ) ); 00153 widget->settings = settings; 00154 widget->setting = setting; 00155 widget->row = row; 00156 widget->col = col; 00157 00158 /* Read current setting value */ 00159 load_setting ( widget ); 00160 }
| static void draw_setting | ( | struct setting_widget * | widget | ) | [static] |
Draw setting widget.
| widget | Setting widget |
Definition at line 167 of file settings_ui.c.
References setting_widget::col, draw_editbox(), setting_widget::editbox, setting_widget::editing, memcpy, memset(), move(), mvprintw, setting::name, setting_row::name, setting_row::nul, offsetof, setting_widget::row, setting_widget::setting, setting_row::start, strlen(), setting_widget::value, and setting_row::value.
Referenced by main_loop().
00167 { 00168 struct setting_row row; 00169 unsigned int len; 00170 unsigned int curs_col; 00171 char *value; 00172 00173 /* Fill row with spaces */ 00174 memset ( &row, ' ', sizeof ( row ) ); 00175 row.nul = '\0'; 00176 00177 /* Construct dot-padded name */ 00178 memset ( row.name, '.', sizeof ( row.name ) ); 00179 len = strlen ( widget->setting->name ); 00180 if ( len > sizeof ( row.name ) ) 00181 len = sizeof ( row.name ); 00182 memcpy ( row.name, widget->setting->name, len ); 00183 00184 /* Construct space-padded value */ 00185 value = widget->value; 00186 if ( ! *value ) 00187 value = "<not specified>"; 00188 len = strlen ( value ); 00189 if ( len > sizeof ( row.value ) ) 00190 len = sizeof ( row.value ); 00191 memcpy ( row.value, value, len ); 00192 curs_col = ( widget->col + offsetof ( typeof ( row ), value ) 00193 + len ); 00194 00195 /* Print row */ 00196 mvprintw ( widget->row, widget->col, "%s", row.start ); 00197 move ( widget->row, curs_col ); 00198 if ( widget->editing ) 00199 draw_editbox ( &widget->editbox ); 00200 }
| static int edit_setting | ( | struct setting_widget * | widget, | |
| int | key | |||
| ) | [static] |
Edit setting widget.
| widget | Setting widget | |
| key | Key pressed by user |
| key | Key returned to application, or zero |
Definition at line 209 of file settings_ui.c.
References edit_editbox(), setting_widget::editbox, and setting_widget::editing.
Referenced by main_loop().
00209 { 00210 widget->editing = 1; 00211 return edit_editbox ( &widget->editbox, key ); 00212 }
| static void init_setting_index | ( | struct setting_widget * | widget, | |
| struct settings * | settings, | |||
| unsigned int | index | |||
| ) | [static] |
Initialise setting widget by index.
Definition at line 221 of file settings_ui.c.
References init_setting(), SETTINGS, SETTINGS_LIST_COL, SETTINGS_LIST_ROW, and table_start.
Referenced by main_loop().
00223 { 00224 struct setting *all_settings = table_start ( SETTINGS ); 00225 00226 init_setting ( widget, settings, &all_settings[index], 00227 ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL ); 00228 }
| static void vmsg | ( | unsigned int | row, | |
| const char * | fmt, | |||
| va_list | args | |||
| ) | [static] |
Print message centred on specified row.
Definition at line 237 of file settings_ui.c.
References COLS, mvprintw, and vsnprintf().
Referenced by msg(), and valert().
00237 { 00238 char buf[COLS]; 00239 size_t len; 00240 00241 len = vsnprintf ( buf, sizeof ( buf ), fmt, args ); 00242 mvprintw ( row, ( ( COLS - len ) / 2 ), "%s", buf ); 00243 }
| static void msg | ( | unsigned int | row, | |
| const char * | fmt, | |||
| ... | ||||
| ) | [static] |
Print message centred on specified row.
Definition at line 252 of file settings_ui.c.
References va_end, va_start, and vmsg().
Referenced by draw_info_row(), draw_instruction_row(), draw_title_row(), and sis190_phy_task().
00252 { 00253 va_list args; 00254 00255 va_start ( args, fmt ); 00256 vmsg ( row, fmt, args ); 00257 va_end ( args ); 00258 }
| static void valert | ( | const char * | fmt, | |
| va_list | args | |||
| ) | [static] |
Print alert message.
Definition at line 276 of file settings_ui.c.
References ALERT_ROW, clearmsg(), color_set, CPAIR_ALERT, CPAIR_NORMAL, NULL, sleep(), and vmsg().
Referenced by alert().
00276 { 00277 clearmsg ( ALERT_ROW ); 00278 color_set ( CPAIR_ALERT, NULL ); 00279 vmsg ( ALERT_ROW, fmt, args ); 00280 sleep ( 2 ); 00281 color_set ( CPAIR_NORMAL, NULL ); 00282 clearmsg ( ALERT_ROW ); 00283 }
| static void alert | ( | const char * | fmt, | |
| ... | ||||
| ) | [static] |
Print alert message.
Definition at line 291 of file settings_ui.c.
References va_end, va_start, and valert().
Referenced by main_loop(), and tls_new_alert().
00291 { 00292 va_list args; 00293 00294 va_start ( args, fmt ); 00295 valert ( fmt, args ); 00296 va_end ( args ); 00297 }
| static void draw_info_row | ( | struct setting * | setting | ) | [static] |
Draw information row.
Definition at line 313 of file settings_ui.c.
References A_BOLD, attroff(), attron(), clearmsg(), setting::description, INFO_ROW, msg(), and setting::name.
Referenced by main_loop().
00313 { 00314 clearmsg ( INFO_ROW ); 00315 attron ( A_BOLD ); 00316 msg ( INFO_ROW, "%s - %s", setting->name, setting->description ); 00317 attroff ( A_BOLD ); 00318 }
| static int main_loop | ( | struct settings * | settings | ) | [static] |
Definition at line 337 of file settings_ui.c.
References alert(), color_set, CPAIR_EDIT, CPAIR_NORMAL, CPAIR_SELECT, CR, CTRL_C, CTRL_X, draw_info_row(), draw_instruction_row(), draw_setting(), draw_title_row(), edit_setting(), setting_widget::editing, getkey(), init_setting_index(), KEY_DOWN, KEY_UP, LF, load_setting(), setting::name, NULL, NUM_SETTINGS, save_setting(), setting_widget::setting, and strerror().
Referenced by settings_ui().
00337 { 00338 struct setting_widget widget; 00339 unsigned int current = 0; 00340 unsigned int next; 00341 int i; 00342 int key; 00343 int rc; 00344 00345 /* Print initial screen content */ 00346 draw_title_row(); 00347 color_set ( CPAIR_NORMAL, NULL ); 00348 for ( i = ( NUM_SETTINGS - 1 ) ; i >= 0 ; i-- ) { 00349 init_setting_index ( &widget, settings, i ); 00350 draw_setting ( &widget ); 00351 } 00352 00353 while ( 1 ) { 00354 /* Redraw information and instruction rows */ 00355 draw_info_row ( widget.setting ); 00356 draw_instruction_row ( widget.editing ); 00357 00358 /* Redraw current setting */ 00359 color_set ( ( widget.editing ? CPAIR_EDIT : CPAIR_SELECT ), 00360 NULL ); 00361 draw_setting ( &widget ); 00362 color_set ( CPAIR_NORMAL, NULL ); 00363 00364 key = getkey(); 00365 if ( widget.editing ) { 00366 key = edit_setting ( &widget, key ); 00367 switch ( key ) { 00368 case CR: 00369 case LF: 00370 if ( ( rc = save_setting ( &widget ) ) != 0 ) { 00371 alert ( " Could not set %s: %s ", 00372 widget.setting->name, 00373 strerror ( rc ) ); 00374 } 00375 /* Fall through */ 00376 case CTRL_C: 00377 load_setting ( &widget ); 00378 break; 00379 default: 00380 /* Do nothing */ 00381 break; 00382 } 00383 } else { 00384 next = current; 00385 switch ( key ) { 00386 case KEY_DOWN: 00387 if ( next < ( NUM_SETTINGS - 1 ) ) 00388 next++; 00389 break; 00390 case KEY_UP: 00391 if ( next > 0 ) 00392 next--; 00393 break; 00394 case CTRL_X: 00395 return 0; 00396 default: 00397 edit_setting ( &widget, key ); 00398 break; 00399 } 00400 if ( next != current ) { 00401 draw_setting ( &widget ); 00402 init_setting_index ( &widget, settings, next ); 00403 current = next; 00404 } 00405 } 00406 } 00407 00408 }
| static void clearmsg | ( | unsigned int | row | ) | [static] |
Clear message on specified row.
| row | Row |
Definition at line 265 of file settings_ui.c.
References clrtoeol(), and move().
Referenced by draw_info_row(), draw_instruction_row(), and valert().
| static void draw_title_row | ( | void | ) | [static] |
| static void draw_instruction_row | ( | int | editing | ) | [static] |
Draw instruction row.
| editing | Editing in progress flag |
Definition at line 325 of file settings_ui.c.
References clearmsg(), INSTRUCTION_PAD, INSTRUCTION_ROW, and msg().
Referenced by main_loop().
00325 { 00326 clearmsg ( INSTRUCTION_ROW ); 00327 if ( editing ) { 00328 msg ( INSTRUCTION_ROW, 00329 "Enter - accept changes" INSTRUCTION_PAD 00330 "Ctrl-C - discard changes" ); 00331 } else { 00332 msg ( INSTRUCTION_ROW, 00333 "Ctrl-X - exit configuration utility" ); 00334 } 00335 }
| int settings_ui | ( | struct settings * | settings | ) |
Definition at line 410 of file settings_ui.c.
References COLOR_BLACK, COLOR_BLUE, COLOR_CYAN, COLOR_RED, color_set, COLOR_WHITE, CPAIR_ALERT, CPAIR_EDIT, CPAIR_NORMAL, CPAIR_SELECT, endwin(), erase(), init_pair(), initscr(), main_loop(), NULL, and start_color.
Referenced by config_exec().
00410 { 00411 int rc; 00412 00413 initscr(); 00414 start_color(); 00415 init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE ); 00416 init_pair ( CPAIR_SELECT, COLOR_WHITE, COLOR_RED ); 00417 init_pair ( CPAIR_EDIT, COLOR_BLACK, COLOR_CYAN ); 00418 init_pair ( CPAIR_ALERT, COLOR_WHITE, COLOR_RED ); 00419 color_set ( CPAIR_NORMAL, NULL ); 00420 erase(); 00421 00422 rc = main_loop ( settings ); 00423 00424 endwin(); 00425 00426 return rc; 00427 }
1.5.7.1