aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/lxdialog/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/lxdialog/util.c')
-rw-r--r--scripts/kconfig/lxdialog/util.c502
1 files changed, 391 insertions, 111 deletions
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index f82cebb9ff06..ebc781b493d7 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -21,85 +21,217 @@
21 21
22#include "dialog.h" 22#include "dialog.h"
23 23
24/* use colors by default? */ 24struct dialog_info dlg;
25bool use_colors = 1;
26 25
27const char *backtitle = NULL; 26static void set_mono_theme(void)
27{
28 dlg.screen.atr = A_NORMAL;
29 dlg.shadow.atr = A_NORMAL;
30 dlg.dialog.atr = A_NORMAL;
31 dlg.title.atr = A_BOLD;
32 dlg.border.atr = A_NORMAL;
33 dlg.button_active.atr = A_REVERSE;
34 dlg.button_inactive.atr = A_DIM;
35 dlg.button_key_active.atr = A_REVERSE;
36 dlg.button_key_inactive.atr = A_BOLD;
37 dlg.button_label_active.atr = A_REVERSE;
38 dlg.button_label_inactive.atr = A_NORMAL;
39 dlg.inputbox.atr = A_NORMAL;
40 dlg.inputbox_border.atr = A_NORMAL;
41 dlg.searchbox.atr = A_NORMAL;
42 dlg.searchbox_title.atr = A_BOLD;
43 dlg.searchbox_border.atr = A_NORMAL;
44 dlg.position_indicator.atr = A_BOLD;
45 dlg.menubox.atr = A_NORMAL;
46 dlg.menubox_border.atr = A_NORMAL;
47 dlg.item.atr = A_NORMAL;
48 dlg.item_selected.atr = A_REVERSE;
49 dlg.tag.atr = A_BOLD;
50 dlg.tag_selected.atr = A_REVERSE;
51 dlg.tag_key.atr = A_BOLD;
52 dlg.tag_key_selected.atr = A_REVERSE;
53 dlg.check.atr = A_BOLD;
54 dlg.check_selected.atr = A_REVERSE;
55 dlg.uarrow.atr = A_BOLD;
56 dlg.darrow.atr = A_BOLD;
57}
58
59#define DLG_COLOR(dialog, f, b, h) \
60do { \
61 dlg.dialog.fg = (f); \
62 dlg.dialog.bg = (b); \
63 dlg.dialog.hl = (h); \
64} while (0)
65
66static void set_classic_theme(void)
67{
68 DLG_COLOR(screen, COLOR_CYAN, COLOR_BLUE, true);
69 DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, true);
70 DLG_COLOR(dialog, COLOR_BLACK, COLOR_WHITE, false);
71 DLG_COLOR(title, COLOR_YELLOW, COLOR_WHITE, true);
72 DLG_COLOR(border, COLOR_WHITE, COLOR_WHITE, true);
73 DLG_COLOR(button_active, COLOR_WHITE, COLOR_BLUE, true);
74 DLG_COLOR(button_inactive, COLOR_BLACK, COLOR_WHITE, false);
75 DLG_COLOR(button_key_active, COLOR_WHITE, COLOR_BLUE, true);
76 DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_WHITE, false);
77 DLG_COLOR(button_label_active, COLOR_YELLOW, COLOR_BLUE, true);
78 DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_WHITE, true);
79 DLG_COLOR(inputbox, COLOR_BLACK, COLOR_WHITE, false);
80 DLG_COLOR(inputbox_border, COLOR_BLACK, COLOR_WHITE, false);
81 DLG_COLOR(searchbox, COLOR_BLACK, COLOR_WHITE, false);
82 DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_WHITE, true);
83 DLG_COLOR(searchbox_border, COLOR_WHITE, COLOR_WHITE, true);
84 DLG_COLOR(position_indicator, COLOR_YELLOW, COLOR_WHITE, true);
85 DLG_COLOR(menubox, COLOR_BLACK, COLOR_WHITE, false);
86 DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true);
87 DLG_COLOR(item, COLOR_BLACK, COLOR_WHITE, false);
88 DLG_COLOR(item_selected, COLOR_WHITE, COLOR_BLUE, true);
89 DLG_COLOR(tag, COLOR_YELLOW, COLOR_WHITE, true);
90 DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_BLUE, true);
91 DLG_COLOR(tag_key, COLOR_YELLOW, COLOR_WHITE, true);
92 DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_BLUE, true);
93 DLG_COLOR(check, COLOR_BLACK, COLOR_WHITE, false);
94 DLG_COLOR(check_selected, COLOR_WHITE, COLOR_BLUE, true);
95 DLG_COLOR(uarrow, COLOR_GREEN, COLOR_WHITE, true);
96 DLG_COLOR(darrow, COLOR_GREEN, COLOR_WHITE, true);
97}
98
99static void set_blackbg_theme(void)
100{
101 DLG_COLOR(screen, COLOR_RED, COLOR_BLACK, true);
102 DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, false);
103 DLG_COLOR(dialog, COLOR_WHITE, COLOR_BLACK, false);
104 DLG_COLOR(title, COLOR_RED, COLOR_BLACK, false);
105 DLG_COLOR(border, COLOR_BLACK, COLOR_BLACK, true);
106
107 DLG_COLOR(button_active, COLOR_YELLOW, COLOR_RED, false);
108 DLG_COLOR(button_inactive, COLOR_YELLOW, COLOR_BLACK, false);
109 DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_RED, true);
110 DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_BLACK, false);
111 DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_RED, false);
112 DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_BLACK, true);
113
114 DLG_COLOR(inputbox, COLOR_YELLOW, COLOR_BLACK, false);
115 DLG_COLOR(inputbox_border, COLOR_YELLOW, COLOR_BLACK, false);
116
117 DLG_COLOR(searchbox, COLOR_YELLOW, COLOR_BLACK, false);
118 DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_BLACK, true);
119 DLG_COLOR(searchbox_border, COLOR_BLACK, COLOR_BLACK, true);
120
121 DLG_COLOR(position_indicator, COLOR_RED, COLOR_BLACK, false);
122
123 DLG_COLOR(menubox, COLOR_YELLOW, COLOR_BLACK, false);
124 DLG_COLOR(menubox_border, COLOR_BLACK, COLOR_BLACK, true);
125
126 DLG_COLOR(item, COLOR_WHITE, COLOR_BLACK, false);
127 DLG_COLOR(item_selected, COLOR_WHITE, COLOR_RED, false);
128
129 DLG_COLOR(tag, COLOR_RED, COLOR_BLACK, false);
130 DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_RED, true);
131 DLG_COLOR(tag_key, COLOR_RED, COLOR_BLACK, false);
132 DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_RED, true);
133
134 DLG_COLOR(check, COLOR_YELLOW, COLOR_BLACK, false);
135 DLG_COLOR(check_selected, COLOR_YELLOW, COLOR_RED, true);
136
137 DLG_COLOR(uarrow, COLOR_RED, COLOR_BLACK, false);
138 DLG_COLOR(darrow, COLOR_RED, COLOR_BLACK, false);
139}
140
141static void set_bluetitle_theme(void)
142{
143 set_classic_theme();
144 DLG_COLOR(title, COLOR_BLUE, COLOR_WHITE, true);
145 DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_BLUE, true);
146 DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_BLUE, true);
147 DLG_COLOR(searchbox_title, COLOR_BLUE, COLOR_WHITE, true);
148 DLG_COLOR(position_indicator, COLOR_BLUE, COLOR_WHITE, true);
149 DLG_COLOR(tag, COLOR_BLUE, COLOR_WHITE, true);
150 DLG_COLOR(tag_key, COLOR_BLUE, COLOR_WHITE, true);
151
152}
28 153
29/* 154/*
30 * Attribute values, default is for mono display 155 * Select color theme
31 */ 156 */
32chtype attributes[] = { 157static int set_theme(const char *theme)
33 A_NORMAL, /* screen_attr */ 158{
34 A_NORMAL, /* shadow_attr */ 159 int use_color = 1;
35 A_NORMAL, /* dialog_attr */ 160 if (!theme)
36 A_BOLD, /* title_attr */ 161 set_bluetitle_theme();
37 A_NORMAL, /* border_attr */ 162 else if (strcmp(theme, "classic") == 0)
38 A_REVERSE, /* button_active_attr */ 163 set_classic_theme();
39 A_DIM, /* button_inactive_attr */ 164 else if (strcmp(theme, "bluetitle") == 0)
40 A_REVERSE, /* button_key_active_attr */ 165 set_bluetitle_theme();
41 A_BOLD, /* button_key_inactive_attr */ 166 else if (strcmp(theme, "blackbg") == 0)
42 A_REVERSE, /* button_label_active_attr */ 167 set_blackbg_theme();
43 A_NORMAL, /* button_label_inactive_attr */ 168 else if (strcmp(theme, "mono") == 0)
44 A_NORMAL, /* inputbox_attr */ 169 use_color = 0;
45 A_NORMAL, /* inputbox_border_attr */ 170
46 A_NORMAL, /* searchbox_attr */ 171 return use_color;
47 A_BOLD, /* searchbox_title_attr */ 172}
48 A_NORMAL, /* searchbox_border_attr */ 173
49 A_BOLD, /* position_indicator_attr */ 174static void init_one_color(struct dialog_color *color)
50 A_NORMAL, /* menubox_attr */ 175{
51 A_NORMAL, /* menubox_border_attr */ 176 static int pair = 0;
52 A_NORMAL, /* item_attr */ 177
53 A_REVERSE, /* item_selected_attr */ 178 pair++;
54 A_BOLD, /* tag_attr */ 179 init_pair(pair, color->fg, color->bg);
55 A_REVERSE, /* tag_selected_attr */ 180 if (color->hl)
56 A_BOLD, /* tag_key_attr */ 181 color->atr = A_BOLD | COLOR_PAIR(pair);
57 A_REVERSE, /* tag_key_selected_attr */ 182 else
58 A_BOLD, /* check_attr */ 183 color->atr = COLOR_PAIR(pair);
59 A_REVERSE, /* check_selected_attr */ 184}
60 A_BOLD, /* uarrow_attr */ 185
61 A_BOLD /* darrow_attr */ 186static void init_dialog_colors(void)
62}; 187{
63 188 init_one_color(&dlg.screen);
64#include "colors.h" 189 init_one_color(&dlg.shadow);
190 init_one_color(&dlg.dialog);
191 init_one_color(&dlg.title);
192 init_one_color(&dlg.border);
193 init_one_color(&dlg.button_active);
194 init_one_color(&dlg.button_inactive);
195 init_one_color(&dlg.button_key_active);
196 init_one_color(&dlg.button_key_inactive);
197 init_one_color(&dlg.button_label_active);
198 init_one_color(&dlg.button_label_inactive);
199 init_one_color(&dlg.inputbox);
200 init_one_color(&dlg.inputbox_border);
201 init_one_color(&dlg.searchbox);
202 init_one_color(&dlg.searchbox_title);
203 init_one_color(&dlg.searchbox_border);
204 init_one_color(&dlg.position_indicator);
205 init_one_color(&dlg.menubox);
206 init_one_color(&dlg.menubox_border);
207 init_one_color(&dlg.item);
208 init_one_color(&dlg.item_selected);
209 init_one_color(&dlg.tag);
210 init_one_color(&dlg.tag_selected);
211 init_one_color(&dlg.tag_key);
212 init_one_color(&dlg.tag_key_selected);
213 init_one_color(&dlg.check);
214 init_one_color(&dlg.check_selected);
215 init_one_color(&dlg.uarrow);
216 init_one_color(&dlg.darrow);
217}
65 218
66/* 219/*
67 * Table of color values 220 * Setup for color display
68 */ 221 */
69int color_table[][3] = { 222static void color_setup(const char *theme)
70 {SCREEN_FG, SCREEN_BG, SCREEN_HL}, 223{
71 {SHADOW_FG, SHADOW_BG, SHADOW_HL}, 224 if (set_theme(theme)) {
72 {DIALOG_FG, DIALOG_BG, DIALOG_HL}, 225 if (has_colors()) { /* Terminal supports color? */
73 {TITLE_FG, TITLE_BG, TITLE_HL}, 226 start_color();
74 {BORDER_FG, BORDER_BG, BORDER_HL}, 227 init_dialog_colors();
75 {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL}, 228 }
76 {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL}, 229 }
77 {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL}, 230 else
78 {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, 231 {
79 BUTTON_KEY_INACTIVE_HL}, 232 set_mono_theme();
80 {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, 233 }
81 BUTTON_LABEL_ACTIVE_HL}, 234}
82 {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG,
83 BUTTON_LABEL_INACTIVE_HL},
84 {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL},
85 {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL},
86 {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL},
87 {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL},
88 {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL},
89 {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL},
90 {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL},
91 {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL},
92 {ITEM_FG, ITEM_BG, ITEM_HL},
93 {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL},
94 {TAG_FG, TAG_BG, TAG_HL},
95 {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL},
96 {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL},
97 {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL},
98 {CHECK_FG, CHECK_BG, CHECK_HL},
99 {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL},
100 {UARROW_FG, UARROW_BG, UARROW_HL},
101 {DARROW_FG, DARROW_BG, DARROW_HL},
102}; /* color_table */
103 235
104/* 236/*
105 * Set window to attribute 'attr' 237 * Set window to attribute 'attr'
@@ -119,13 +251,13 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr)
119 251
120void dialog_clear(void) 252void dialog_clear(void)
121{ 253{
122 attr_clear(stdscr, LINES, COLS, screen_attr); 254 attr_clear(stdscr, LINES, COLS, dlg.screen.atr);
123 /* Display background title if it exists ... - SLH */ 255 /* Display background title if it exists ... - SLH */
124 if (backtitle != NULL) { 256 if (dlg.backtitle != NULL) {
125 int i; 257 int i;
126 258
127 wattrset(stdscr, screen_attr); 259 wattrset(stdscr, dlg.screen.atr);
128 mvwaddstr(stdscr, 0, 1, (char *)backtitle); 260 mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle);
129 wmove(stdscr, 1, 1); 261 wmove(stdscr, 1, 1);
130 for (i = 1; i < COLS - 1; i++) 262 for (i = 1; i < COLS - 1; i++)
131 waddch(stdscr, ACS_HLINE); 263 waddch(stdscr, ACS_HLINE);
@@ -136,40 +268,22 @@ void dialog_clear(void)
136/* 268/*
137 * Do some initialization for dialog 269 * Do some initialization for dialog
138 */ 270 */
139void init_dialog(void) 271void init_dialog(const char *backtitle)
272{
273 dlg.backtitle = backtitle;
274 color_setup(getenv("MENUCONFIG_COLOR"));
275}
276
277void reset_dialog(void)
140{ 278{
141 initscr(); /* Init curses */ 279 initscr(); /* Init curses */
142 keypad(stdscr, TRUE); 280 keypad(stdscr, TRUE);
143 cbreak(); 281 cbreak();
144 noecho(); 282 noecho();
145
146 if (use_colors) /* Set up colors */
147 color_setup();
148
149 dialog_clear(); 283 dialog_clear();
150} 284}
151 285
152/* 286/*
153 * Setup for color display
154 */
155void color_setup(void)
156{
157 int i;
158
159 if (has_colors()) { /* Terminal supports color? */
160 start_color();
161
162 /* Initialize color pairs */
163 for (i = 0; i < ATTRIBUTE_COUNT; i++)
164 init_pair(i + 1, color_table[i][0], color_table[i][1]);
165
166 /* Setup color attributes */
167 for (i = 0; i < ATTRIBUTE_COUNT; i++)
168 attributes[i] = C_ATTR(color_table[i][2], i + 1);
169 }
170}
171
172/*
173 * End using dialog functions. 287 * End using dialog functions.
174 */ 288 */
175void end_dialog(void) 289void end_dialog(void)
@@ -184,7 +298,7 @@ void print_title(WINDOW *dialog, const char *title, int width)
184{ 298{
185 if (title) { 299 if (title) {
186 int tlen = MIN(width - 2, strlen(title)); 300 int tlen = MIN(width - 2, strlen(title));
187 wattrset(dialog, title_attr); 301 wattrset(dialog, dlg.title.atr);
188 mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' '); 302 mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' ');
189 mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen); 303 mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen);
190 waddch(dialog, ' '); 304 waddch(dialog, ' ');
@@ -264,21 +378,23 @@ void print_button(WINDOW * win, const char *label, int y, int x, int selected)
264 int i, temp; 378 int i, temp;
265 379
266 wmove(win, y, x); 380 wmove(win, y, x);
267 wattrset(win, selected ? button_active_attr : button_inactive_attr); 381 wattrset(win, selected ? dlg.button_active.atr
382 : dlg.button_inactive.atr);
268 waddstr(win, "<"); 383 waddstr(win, "<");
269 temp = strspn(label, " "); 384 temp = strspn(label, " ");
270 label += temp; 385 label += temp;
271 wattrset(win, selected ? button_label_active_attr 386 wattrset(win, selected ? dlg.button_label_active.atr
272 : button_label_inactive_attr); 387 : dlg.button_label_inactive.atr);
273 for (i = 0; i < temp; i++) 388 for (i = 0; i < temp; i++)
274 waddch(win, ' '); 389 waddch(win, ' ');
275 wattrset(win, selected ? button_key_active_attr 390 wattrset(win, selected ? dlg.button_key_active.atr
276 : button_key_inactive_attr); 391 : dlg.button_key_inactive.atr);
277 waddch(win, label[0]); 392 waddch(win, label[0]);
278 wattrset(win, selected ? button_label_active_attr 393 wattrset(win, selected ? dlg.button_label_active.atr
279 : button_label_inactive_attr); 394 : dlg.button_label_inactive.atr);
280 waddstr(win, (char *)label + 1); 395 waddstr(win, (char *)label + 1);
281 wattrset(win, selected ? button_active_attr : button_inactive_attr); 396 wattrset(win, selected ? dlg.button_active.atr
397 : dlg.button_inactive.atr);
282 waddstr(win, ">"); 398 waddstr(win, ">");
283 wmove(win, y, x + temp + 1); 399 wmove(win, y, x + temp + 1);
284} 400}
@@ -326,7 +442,7 @@ void draw_shadow(WINDOW * win, int y, int x, int height, int width)
326 int i; 442 int i;
327 443
328 if (has_colors()) { /* Whether terminal supports color? */ 444 if (has_colors()) { /* Whether terminal supports color? */
329 wattrset(win, shadow_attr); 445 wattrset(win, dlg.shadow.atr);
330 wmove(win, y + height, x + 2); 446 wmove(win, y + height, x + 2);
331 for (i = 0; i < width; i++) 447 for (i = 0; i < width; i++)
332 waddch(win, winch(win) & A_CHARTEXT); 448 waddch(win, winch(win) & A_CHARTEXT);
@@ -360,3 +476,167 @@ int first_alpha(const char *string, const char *exempt)
360 476
361 return 0; 477 return 0;
362} 478}
479
480/*
481 * ncurses uses ESC to detect escaped char sequences. This resutl in
482 * a small timeout before ESC is actually delivered to the application.
483 * lxdialog suggest <ESC> <ESC> which is correctly translated to two
484 * times esc. But then we need to ignore the second esc to avoid stepping
485 * out one menu too much. Filter away all escaped key sequences since
486 * keypad(FALSE) turn off ncurses support for escape sequences - and thats
487 * needed to make notimeout() do as expected.
488 */
489int on_key_esc(WINDOW *win)
490{
491 int key;
492 int key2;
493 int key3;
494
495 nodelay(win, TRUE);
496 keypad(win, FALSE);
497 key = wgetch(win);
498 key2 = wgetch(win);
499 do {
500 key3 = wgetch(win);
501 } while (key3 != ERR);
502 nodelay(win, FALSE);
503 keypad(win, TRUE);
504 if (key == KEY_ESC && key2 == ERR)
505 return KEY_ESC;
506 else if (key != ERR && key != KEY_ESC && key2 == ERR)
507 ungetch(key);
508
509 return -1;
510}
511
512/* redraw screen in new size */
513int on_key_resize(void)
514{
515 dialog_clear();
516 return KEY_RESIZE;
517}
518
519struct dialog_list *item_cur;
520struct dialog_list item_nil;
521struct dialog_list *item_head;
522
523void item_reset(void)
524{
525 struct dialog_list *p, *next;
526
527 for (p = item_head; p; p = next) {
528 next = p->next;
529 free(p);
530 }
531 item_head = NULL;
532 item_cur = &item_nil;
533}
534
535void item_make(const char *fmt, ...)
536{
537 va_list ap;
538 struct dialog_list *p = malloc(sizeof(*p));
539
540 if (item_head)
541 item_cur->next = p;
542 else
543 item_head = p;
544 item_cur = p;
545 memset(p, 0, sizeof(*p));
546
547 va_start(ap, fmt);
548 vsnprintf(item_cur->node.str, sizeof(item_cur->node.str), fmt, ap);
549 va_end(ap);
550}
551
552void item_add_str(const char *fmt, ...)
553{
554 va_list ap;
555 size_t avail;
556
557 avail = sizeof(item_cur->node.str) - strlen(item_cur->node.str);
558
559 va_start(ap, fmt);
560 vsnprintf(item_cur->node.str + strlen(item_cur->node.str),
561 avail, fmt, ap);
562 item_cur->node.str[sizeof(item_cur->node.str) - 1] = '\0';
563 va_end(ap);
564}
565
566void item_set_tag(char tag)
567{
568 item_cur->node.tag = tag;
569}
570void item_set_data(void *ptr)
571{
572 item_cur->node.data = ptr;
573}
574
575void item_set_selected(int val)
576{
577 item_cur->node.selected = val;
578}
579
580int item_activate_selected(void)
581{
582 item_foreach()
583 if (item_is_selected())
584 return 1;
585 return 0;
586}
587
588void *item_data(void)
589{
590 return item_cur->node.data;
591}
592
593char item_tag(void)
594{
595 return item_cur->node.tag;
596}
597
598int item_count(void)
599{
600 int n = 0;
601 struct dialog_list *p;
602
603 for (p = item_head; p; p = p->next)
604 n++;
605 return n;
606}
607
608void item_set(int n)
609{
610 int i = 0;
611 item_foreach()
612 if (i++ == n)
613 return;
614}
615
616int item_n(void)
617{
618 int n = 0;
619 struct dialog_list *p;
620
621 for (p = item_head; p; p = p->next) {
622 if (p == item_cur)
623 return n;
624 n++;
625 }
626 return 0;
627}
628
629const char *item_str(void)
630{
631 return item_cur->node.str;
632}
633
634int item_is_selected(void)
635{
636 return (item_cur->node.selected != 0);
637}
638
639int item_is_tag(char tag)
640{
641 return (item_cur->node.tag == tag);
642}