Browse Source

Add instruction row, and save option

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
666b309c0c
1 changed files with 58 additions and 17 deletions
  1. 58
    17
      src/hci/tui/settings_ui.c

+ 58
- 17
src/hci/tui/settings_ui.c View File

23
 #include <console.h>
23
 #include <console.h>
24
 #include <gpxe/settings.h>
24
 #include <gpxe/settings.h>
25
 #include <gpxe/editbox.h>
25
 #include <gpxe/editbox.h>
26
+#include <gpxe/settings_ui.h>
26
 
27
 
27
 /** @file
28
 /** @file
28
  *
29
  *
29
- * Configuration settings UI
30
+ * Option configuration console
30
  *
31
  *
31
  */
32
  */
32
 
33
 
33
 #include <gpxe/nvo.h>
34
 #include <gpxe/nvo.h>
34
 extern struct nvo_block *ugly_nvo_hack;
35
 extern struct nvo_block *ugly_nvo_hack;
35
 
36
 
37
+
36
 /* Colour pairs */
38
 /* Colour pairs */
37
 #define CPAIR_NORMAL	1
39
 #define CPAIR_NORMAL	1
38
 #define CPAIR_SELECT	2
40
 #define CPAIR_SELECT	2
40
 #define CPAIR_ALERT	4
42
 #define CPAIR_ALERT	4
41
 
43
 
42
 /* Screen layout */
44
 /* Screen layout */
43
-#define BANNER_ROW		1
45
+#define TITLE_ROW		1
44
 #define SETTINGS_LIST_ROW	3
46
 #define SETTINGS_LIST_ROW	3
45
 #define SETTINGS_LIST_COL	1
47
 #define SETTINGS_LIST_COL	1
46
 #define INFO_ROW		20
48
 #define INFO_ROW		20
47
 #define ALERT_ROW		20
49
 #define ALERT_ROW		20
50
+#define INSTRUCTION_ROW		22
51
+#define INSTRUCTION_PAD "     "
48
 
52
 
49
 /** Layout of text within a setting widget */
53
 /** Layout of text within a setting widget */
50
 struct setting_row {
54
 struct setting_row {
69
 	unsigned int col;
73
 	unsigned int col;
70
 	/** Edit box widget used for editing setting */
74
 	/** Edit box widget used for editing setting */
71
 	struct edit_box editbox;
75
 	struct edit_box editbox;
72
-	/** Editing active flag */
76
+	/** Editing in progress flag */
73
 	int editing;
77
 	int editing;
74
 	/** Buffer for setting's value */
78
 	/** Buffer for setting's value */
75
 	char value[256]; /* enough size for a DHCP string */
79
 	char value[256]; /* enough size for a DHCP string */
275
 	va_end ( args );
279
 	va_end ( args );
276
 }
280
 }
277
 
281
 
282
+/**
283
+ * Draw title row
284
+ */
285
+static void draw_title_row ( void ) {
286
+	attron ( A_BOLD );
287
+	msg ( TITLE_ROW, "gPXE option configuration console" );
288
+	attroff ( A_BOLD );
289
+}
290
+
291
+/**
292
+ * Draw information row
293
+ *
294
+ * @v setting		Current configuration setting
295
+ */
296
+static void draw_info_row ( struct config_setting *setting ) {
297
+	clearmsg ( INFO_ROW );
298
+	attron ( A_BOLD );
299
+	msg ( INFO_ROW, "%s (%s) - %s", setting->name,
300
+	      setting->type->description, setting->description );
301
+	attroff ( A_BOLD );
302
+}
303
+
304
+/**
305
+ * Draw instruction row
306
+ *
307
+ * @v editing		Editing in progress flag
308
+ */
309
+static void draw_instruction_row ( int editing ) {
310
+	clearmsg ( INSTRUCTION_ROW );
311
+	if ( editing ) {
312
+		msg ( INSTRUCTION_ROW,
313
+		      "Enter - accept changes" INSTRUCTION_PAD
314
+		      "Ctrl-C - discard changes" );
315
+	} else {
316
+		msg ( INSTRUCTION_ROW,
317
+		      "Ctrl-S - save configuration" );
318
+	}
319
+}
320
+
278
 static void main_loop ( struct config_context *context ) {
321
 static void main_loop ( struct config_context *context ) {
279
 	struct setting_widget widget;
322
 	struct setting_widget widget;
280
 	unsigned int current = 0;
323
 	unsigned int current = 0;
284
 	int rc;
327
 	int rc;
285
 
328
 
286
 	/* Print initial screen content */
329
 	/* Print initial screen content */
330
+	draw_title_row();
287
 	color_set ( CPAIR_NORMAL, NULL );
331
 	color_set ( CPAIR_NORMAL, NULL );
288
-	attron ( A_BOLD );
289
-	msg ( BANNER_ROW, "gPXE option configuration console" );
290
-	attroff ( A_BOLD );
291
 	for ( i = ( NUM_SETTINGS - 1 ) ; i >= 0 ; i-- ) {
332
 	for ( i = ( NUM_SETTINGS - 1 ) ; i >= 0 ; i-- ) {
292
 		init_setting_index ( &widget, context, i );
333
 		init_setting_index ( &widget, context, i );
293
 		draw_setting ( &widget );
334
 		draw_setting ( &widget );
294
 	}
335
 	}
295
 
336
 
296
 	while ( 1 ) {
337
 	while ( 1 ) {
297
-		/* Redraw information row */
298
-		clearmsg ( INFO_ROW );
299
-		msg ( INFO_ROW, "%s (%s) - %s", widget.setting->name,
300
-		      widget.setting->type->description,
301
-		      widget.setting->description );
338
+		/* Redraw information and instruction rows */
339
+		draw_info_row ( widget.setting );
340
+		draw_instruction_row ( widget.editing );
302
 
341
 
303
 		/* Redraw current setting */
342
 		/* Redraw current setting */
304
 		color_set ( ( widget.editing ? CPAIR_EDIT : CPAIR_SELECT ),
343
 		color_set ( ( widget.editing ? CPAIR_EDIT : CPAIR_SELECT ),
335
 				if ( next > 0 )
374
 				if ( next > 0 )
336
 					next--;
375
 					next--;
337
 				break;
376
 				break;
377
+			case 0x13: /* Ctrl-S */
378
+				if ( ( rc = nvo_save ( ugly_nvo_hack ) ) != 0){
379
+					alert ( " Could not save options: %s ",
380
+						strerror ( rc ) );
381
+				}
382
+				return;
338
 			default:
383
 			default:
339
 				edit_setting ( &widget, key );
384
 				edit_setting ( &widget, key );
340
 				break;
385
 				break;
349
 	
394
 	
350
 }
395
 }
351
 
396
 
352
-void uitest ( void ) {
353
-	struct config_context dummy_context;
354
-
355
-	dummy_context.options = ugly_nvo_hack->options;
356
-
397
+void settings_ui ( struct config_context *context ) {
357
 	initscr();
398
 	initscr();
358
 	start_color();
399
 	start_color();
359
 	init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE );
400
 	init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE );
363
 	color_set ( CPAIR_NORMAL, NULL );
404
 	color_set ( CPAIR_NORMAL, NULL );
364
 	erase();
405
 	erase();
365
 	
406
 	
366
-	main_loop ( &dummy_context );
407
+	main_loop ( context );
367
 
408
 
368
 	endwin();
409
 	endwin();
369
 }
410
 }

Loading…
Cancel
Save