소스 검색

Add instruction row, and save option

tags/v0.9.3
Michael Brown 18 년 전
부모
커밋
666b309c0c
1개의 변경된 파일58개의 추가작업 그리고 17개의 파일을 삭제
  1. 58
    17
      src/hci/tui/settings_ui.c

+ 58
- 17
src/hci/tui/settings_ui.c 파일 보기

@@ -23,16 +23,18 @@
23 23
 #include <console.h>
24 24
 #include <gpxe/settings.h>
25 25
 #include <gpxe/editbox.h>
26
+#include <gpxe/settings_ui.h>
26 27
 
27 28
 /** @file
28 29
  *
29
- * Configuration settings UI
30
+ * Option configuration console
30 31
  *
31 32
  */
32 33
 
33 34
 #include <gpxe/nvo.h>
34 35
 extern struct nvo_block *ugly_nvo_hack;
35 36
 
37
+
36 38
 /* Colour pairs */
37 39
 #define CPAIR_NORMAL	1
38 40
 #define CPAIR_SELECT	2
@@ -40,11 +42,13 @@ extern struct nvo_block *ugly_nvo_hack;
40 42
 #define CPAIR_ALERT	4
41 43
 
42 44
 /* Screen layout */
43
-#define BANNER_ROW		1
45
+#define TITLE_ROW		1
44 46
 #define SETTINGS_LIST_ROW	3
45 47
 #define SETTINGS_LIST_COL	1
46 48
 #define INFO_ROW		20
47 49
 #define ALERT_ROW		20
50
+#define INSTRUCTION_ROW		22
51
+#define INSTRUCTION_PAD "     "
48 52
 
49 53
 /** Layout of text within a setting widget */
50 54
 struct setting_row {
@@ -69,7 +73,7 @@ struct setting_widget {
69 73
 	unsigned int col;
70 74
 	/** Edit box widget used for editing setting */
71 75
 	struct edit_box editbox;
72
-	/** Editing active flag */
76
+	/** Editing in progress flag */
73 77
 	int editing;
74 78
 	/** Buffer for setting's value */
75 79
 	char value[256]; /* enough size for a DHCP string */
@@ -275,6 +279,45 @@ static void alert ( const char *fmt, ... ) {
275 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 321
 static void main_loop ( struct config_context *context ) {
279 322
 	struct setting_widget widget;
280 323
 	unsigned int current = 0;
@@ -284,21 +327,17 @@ static void main_loop ( struct config_context *context ) {
284 327
 	int rc;
285 328
 
286 329
 	/* Print initial screen content */
330
+	draw_title_row();
287 331
 	color_set ( CPAIR_NORMAL, NULL );
288
-	attron ( A_BOLD );
289
-	msg ( BANNER_ROW, "gPXE option configuration console" );
290
-	attroff ( A_BOLD );
291 332
 	for ( i = ( NUM_SETTINGS - 1 ) ; i >= 0 ; i-- ) {
292 333
 		init_setting_index ( &widget, context, i );
293 334
 		draw_setting ( &widget );
294 335
 	}
295 336
 
296 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 342
 		/* Redraw current setting */
304 343
 		color_set ( ( widget.editing ? CPAIR_EDIT : CPAIR_SELECT ),
@@ -335,6 +374,12 @@ static void main_loop ( struct config_context *context ) {
335 374
 				if ( next > 0 )
336 375
 					next--;
337 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 383
 			default:
339 384
 				edit_setting ( &widget, key );
340 385
 				break;
@@ -349,11 +394,7 @@ static void main_loop ( struct config_context *context ) {
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 398
 	initscr();
358 399
 	start_color();
359 400
 	init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE );
@@ -363,7 +404,7 @@ void uitest ( void ) {
363 404
 	color_set ( CPAIR_NORMAL, NULL );
364 405
 	erase();
365 406
 	
366
-	main_loop ( &dummy_context );
407
+	main_loop ( context );
367 408
 
368 409
 	endwin();
369 410
 }

Loading…
취소
저장