Переглянути джерело

[editbox] Allow for password widgets that do not display their contents

tags/v0.9.7
Michael Brown 15 роки тому
джерело
коміт
67ee41ad6d

+ 8
- 3
src/hci/mucurses/widgets/editbox.c Переглянути файл

@@ -38,11 +38,11 @@
38 38
  * @v row		Row
39 39
  * @v col		Starting column
40 40
  * @v width		Width
41
- *
41
+ * @v flags		Flags
42 42
  */
43 43
 void init_editbox ( struct edit_box *box, char *buf, size_t len,
44 44
 		    WINDOW *win, unsigned int row, unsigned int col,
45
-		    unsigned int width ) {
45
+		    unsigned int width, unsigned int flags ) {
46 46
 	memset ( box, 0, sizeof ( *box ) );
47 47
 	box->string.buf = buf;
48 48
 	box->string.len = len;
@@ -51,6 +51,7 @@ void init_editbox ( struct edit_box *box, char *buf, size_t len,
51 51
 	box->row = row;
52 52
 	box->col = col;
53 53
 	box->width = width;
54
+	box->flags = flags;
54 55
 }
55 56
 
56 57
 /**
@@ -86,7 +87,11 @@ void draw_editbox ( struct edit_box *box ) {
86 87
 	len = ( strlen ( box->string.buf ) - first );
87 88
 	if ( len > width )
88 89
 		len = width;
89
-	memcpy ( buf, ( box->string.buf + first ), len );
90
+	if ( box->flags & EDITBOX_STARS ) {
91
+		memset ( buf, '*', len );
92
+	} else {
93
+		memcpy ( buf, ( box->string.buf + first ), len );
94
+	}
90 95
 
91 96
 	/* Print box content and move cursor */
92 97
 	if ( ! box->win )

+ 1
- 1
src/hci/tui/settings_ui.c Переглянути файл

@@ -123,7 +123,7 @@ static void load_setting ( struct setting_widget *widget ) {
123 123
 	init_editbox ( &widget->editbox, widget->value,
124 124
 		       sizeof ( widget->value ), NULL, widget->row,
125 125
 		       ( widget->col + offsetof ( struct setting_row, value )),
126
-		       sizeof ( ( ( struct setting_row * ) NULL )->value ) );
126
+		       sizeof ( ( ( struct setting_row * ) NULL )->value ), 0);
127 127
 }
128 128
 
129 129
 /**

+ 10
- 2
src/include/gpxe/editbox.h Переглянути файл

@@ -24,14 +24,22 @@ struct edit_box {
24 24
 	unsigned int width;
25 25
 	/** First displayed character */
26 26
 	unsigned int first;
27
+	/** Flags */
28
+	unsigned int flags;
29
+};
30
+
31
+/** Editable text box widget flags */
32
+enum edit_box_flags {
33
+	/** Show stars instead of contents (for password widgets) */
34
+	EDITBOX_STARS = 0x0001,
27 35
 };
28 36
 
29 37
 extern void init_editbox ( struct edit_box *box, char *buf, size_t len,
30 38
 			   WINDOW *win, unsigned int row, unsigned int col,
31
-			   unsigned int width ) 
39
+			   unsigned int width, unsigned int flags )
32 40
 			   __attribute__ (( nonnull (1, 2) ));
33 41
 extern void draw_editbox ( struct edit_box *box ) __nonnull;
34
-static inline int __pure edit_editbox ( struct edit_box *box, int key ) __nonnull;
42
+static inline int edit_editbox ( struct edit_box *box, int key ) __nonnull;
35 43
 
36 44
 /**
37 45
  * Edit text box widget

Завантаження…
Відмінити
Зберегти