Procházet zdrojové kódy

Alert when saving settings fails

tags/v0.9.3
Michael Brown před 18 roky
rodič
revize
65e97c4f22
1 změnil soubory, kde provedl 27 přidání a 5 odebrání
  1. 27
    5
      src/hci/tui/settings_ui.c

+ 27
- 5
src/hci/tui/settings_ui.c Zobrazit soubor

@@ -16,6 +16,7 @@
16 16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18 18
 
19
+#include <unistd.h>
19 20
 #include <string.h>
20 21
 #include <curses.h>
21 22
 #include <console.h>
@@ -35,10 +36,12 @@ extern struct nvo_block *ugly_nvo_hack;
35 36
 #define CPAIR_NORMAL	1
36 37
 #define CPAIR_SELECT	2
37 38
 #define CPAIR_EDIT	3
39
+#define CPAIR_ALERT	4
38 40
 
39 41
 /* Screen layout */
40 42
 #define SETTINGS_LIST_ROW	3
41 43
 #define SETTINGS_LIST_COL	1
44
+#define ALERT_ROW		20
42 45
 
43 46
 /** Layout of text within a setting widget */
44 47
 struct setting_row {
@@ -107,7 +110,6 @@ static void load_setting ( struct setting_widget *widget ) {
107 110
  * @v widget		Setting widget
108 111
  */
109 112
 static int save_setting ( struct setting_widget *widget ) {
110
-	widget->editing = 0;
111 113
 	return widget->setting->type->set ( widget->context, widget->setting,
112 114
 					    widget->value );
113 115
 }
@@ -203,6 +205,23 @@ static void init_setting_index ( struct setting_widget *widget,
203 205
 		       ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );
204 206
 }
205 207
 
208
+static void alert ( const char *fmt, ... ) {
209
+	char buf[COLS];
210
+	va_list args;
211
+	size_t len;
212
+
213
+	va_start ( args, fmt );
214
+	len = vsnprintf ( buf, sizeof ( buf ), fmt, args );
215
+	va_end ( args );
216
+
217
+	color_set ( CPAIR_ALERT, NULL );
218
+	mvprintw ( ALERT_ROW, ( ( COLS - len ) / 2 ), "%s", buf );
219
+	sleep ( 2 );
220
+	color_set ( CPAIR_NORMAL, NULL );
221
+	move ( ALERT_ROW, 0 );
222
+	clrtoeol();
223
+}
224
+
206 225
 static void main_loop ( struct config_context *context ) {
207 226
 	struct setting_widget widget;
208 227
 	unsigned int current = 0;
@@ -231,9 +250,11 @@ static void main_loop ( struct config_context *context ) {
231 250
 			switch ( key ) {
232 251
 			case 0x0a: /* Enter */
233 252
 				if ( ( rc = save_setting ( &widget ) ) != 0 ) {
234
-					
253
+					alert ( " Could not set %s: %s ",
254
+						widget.setting->name,
255
+						strerror ( -rc ) );
235 256
 				}
236
-				break;
257
+				/* Fall through */
237 258
 			case 0x03: /* Ctrl-C */
238 259
 				load_setting ( &widget );
239 260
 				break;
@@ -274,8 +295,9 @@ void uitest ( void ) {
274 295
 	initscr();
275 296
 	start_color();
276 297
 	init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE );
277
-	init_pair ( CPAIR_SELECT, COLOR_WHITE, COLOR_RED );
278
-	init_pair ( CPAIR_EDIT, COLOR_BLACK, COLOR_GREEN );
298
+	init_pair ( CPAIR_SELECT, COLOR_BLACK, COLOR_WHITE );
299
+	init_pair ( CPAIR_EDIT, COLOR_BLACK, COLOR_CYAN );
300
+	init_pair ( CPAIR_ALERT, COLOR_WHITE, COLOR_RED );
279 301
 	color_set ( CPAIR_NORMAL, NULL );
280 302
 	erase();
281 303
 	

Načítá se…
Zrušit
Uložit