From 98e5a1579e7d34fe3803240750a1c48efcd9cb15 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Mon, 24 Jul 2006 21:40:46 +0200 Subject: kconfig/lxdialog: refactor color support Clean up and refactor color support. All color support are now in util.c including color definitions. In the process introduced a global variable named 'dlg' which is used all over to set color - thats the reason why all files are changed. Signed-off-by: Sam Ravnborg --- scripts/kconfig/lxdialog/util.c | 259 +++++++++++++++++++++++----------------- 1 file changed, 147 insertions(+), 112 deletions(-) (limited to 'scripts/kconfig/lxdialog/util.c') diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index f82cebb9ff0..08f98b1c4bb 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -21,85 +21,141 @@ #include "dialog.h" -/* use colors by default? */ -bool use_colors = 1; +struct dialog_info dlg; -const char *backtitle = NULL; +static void set_mono_theme(void) +{ + dlg.screen.atr = A_NORMAL; + dlg.shadow.atr = A_NORMAL; + dlg.dialog.atr = A_NORMAL; + dlg.title.atr = A_BOLD; + dlg.border.atr = A_NORMAL; + dlg.button_active.atr = A_REVERSE; + dlg.button_inactive.atr = A_DIM; + dlg.button_key_active.atr = A_REVERSE; + dlg.button_key_inactive.atr = A_BOLD; + dlg.button_label_active.atr = A_REVERSE; + dlg.button_label_inactive.atr = A_NORMAL; + dlg.inputbox.atr = A_NORMAL; + dlg.inputbox_border.atr = A_NORMAL; + dlg.searchbox.atr = A_NORMAL; + dlg.searchbox_title.atr = A_BOLD; + dlg.searchbox_border.atr = A_NORMAL; + dlg.position_indicator.atr = A_BOLD; + dlg.menubox.atr = A_NORMAL; + dlg.menubox_border.atr = A_NORMAL; + dlg.item.atr = A_NORMAL; + dlg.item_selected.atr = A_REVERSE; + dlg.tag.atr = A_BOLD; + dlg.tag_selected.atr = A_REVERSE; + dlg.tag_key.atr = A_BOLD; + dlg.tag_key_selected.atr = A_REVERSE; + dlg.check.atr = A_BOLD; + dlg.check_selected.atr = A_REVERSE; + dlg.uarrow.atr = A_BOLD; + dlg.darrow.atr = A_BOLD; +} -/* - * Attribute values, default is for mono display - */ -chtype attributes[] = { - A_NORMAL, /* screen_attr */ - A_NORMAL, /* shadow_attr */ - A_NORMAL, /* dialog_attr */ - A_BOLD, /* title_attr */ - A_NORMAL, /* border_attr */ - A_REVERSE, /* button_active_attr */ - A_DIM, /* button_inactive_attr */ - A_REVERSE, /* button_key_active_attr */ - A_BOLD, /* button_key_inactive_attr */ - A_REVERSE, /* button_label_active_attr */ - A_NORMAL, /* button_label_inactive_attr */ - A_NORMAL, /* inputbox_attr */ - A_NORMAL, /* inputbox_border_attr */ - A_NORMAL, /* searchbox_attr */ - A_BOLD, /* searchbox_title_attr */ - A_NORMAL, /* searchbox_border_attr */ - A_BOLD, /* position_indicator_attr */ - A_NORMAL, /* menubox_attr */ - A_NORMAL, /* menubox_border_attr */ - A_NORMAL, /* item_attr */ - A_REVERSE, /* item_selected_attr */ - A_BOLD, /* tag_attr */ - A_REVERSE, /* tag_selected_attr */ - A_BOLD, /* tag_key_attr */ - A_REVERSE, /* tag_key_selected_attr */ - A_BOLD, /* check_attr */ - A_REVERSE, /* check_selected_attr */ - A_BOLD, /* uarrow_attr */ - A_BOLD /* darrow_attr */ -}; - -#include "colors.h" +#define DLG_COLOR(dialog, f, b, h) \ +do { \ + dlg.dialog.fg = (f); \ + dlg.dialog.bg = (b); \ + dlg.dialog.hl = (h); \ +} while (0) + +static void set_classic_theme(void) +{ + DLG_COLOR(screen, COLOR_CYAN, COLOR_BLUE, true); + DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, true); + DLG_COLOR(dialog, COLOR_BLACK, COLOR_WHITE, false); + DLG_COLOR(title, COLOR_YELLOW, COLOR_WHITE, true); + DLG_COLOR(border, COLOR_WHITE, COLOR_WHITE, true); + DLG_COLOR(button_active, COLOR_WHITE, COLOR_BLUE, true); + DLG_COLOR(button_inactive, COLOR_BLACK, COLOR_WHITE, false); + DLG_COLOR(button_key_active, COLOR_WHITE, COLOR_BLUE, true); + DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_WHITE, false); + DLG_COLOR(button_label_active, COLOR_YELLOW, COLOR_BLUE, true); + DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_WHITE, true); + DLG_COLOR(inputbox, COLOR_BLACK, COLOR_WHITE, false); + DLG_COLOR(inputbox_border, COLOR_BLACK, COLOR_WHITE, false); + DLG_COLOR(searchbox, COLOR_BLACK, COLOR_WHITE, false); + DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_WHITE, true); + DLG_COLOR(searchbox_border, COLOR_WHITE, COLOR_WHITE, true); + DLG_COLOR(position_indicator, COLOR_YELLOW, COLOR_WHITE, true); + DLG_COLOR(menubox, COLOR_BLACK, COLOR_WHITE, false); + DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true); + DLG_COLOR(item, COLOR_BLACK, COLOR_WHITE, false); + DLG_COLOR(item_selected, COLOR_WHITE, COLOR_BLUE, true); + DLG_COLOR(tag, COLOR_YELLOW, COLOR_WHITE, true); + DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_BLUE, true); + DLG_COLOR(tag_key, COLOR_YELLOW, COLOR_WHITE, true); + DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_BLUE, true); + DLG_COLOR(check, COLOR_BLACK, COLOR_WHITE, false); + DLG_COLOR(check_selected, COLOR_WHITE, COLOR_BLUE, true); + DLG_COLOR(uarrow, COLOR_GREEN, COLOR_WHITE, true); + DLG_COLOR(darrow, COLOR_GREEN, COLOR_WHITE, true); +} + +static void init_one_color(struct dialog_color *color) +{ + static int pair = 0; + + pair++; + init_pair(pair, color->fg, color->bg); + if (color->hl) + color->atr = A_BOLD | COLOR_PAIR(pair); + else + color->atr = COLOR_PAIR(pair); +} + +static void init_dialog_colors(void) +{ + init_one_color(&dlg.screen); + init_one_color(&dlg.shadow); + init_one_color(&dlg.dialog); + init_one_color(&dlg.title); + init_one_color(&dlg.border); + init_one_color(&dlg.button_active); + init_one_color(&dlg.button_inactive); + init_one_color(&dlg.button_key_active); + init_one_color(&dlg.button_key_inactive); + init_one_color(&dlg.button_label_active); + init_one_color(&dlg.button_label_inactive); + init_one_color(&dlg.inputbox); + init_one_color(&dlg.inputbox_border); + init_one_color(&dlg.searchbox); + init_one_color(&dlg.searchbox_title); + init_one_color(&dlg.searchbox_border); + init_one_color(&dlg.position_indicator); + init_one_color(&dlg.menubox); + init_one_color(&dlg.menubox_border); + init_one_color(&dlg.item); + init_one_color(&dlg.item_selected); + init_one_color(&dlg.tag); + init_one_color(&dlg.tag_selected); + init_one_color(&dlg.tag_key); + init_one_color(&dlg.tag_key_selected); + init_one_color(&dlg.check); + init_one_color(&dlg.check_selected); + init_one_color(&dlg.uarrow); + init_one_color(&dlg.darrow); +} /* - * Table of color values + * Setup for color display */ -int color_table[][3] = { - {SCREEN_FG, SCREEN_BG, SCREEN_HL}, - {SHADOW_FG, SHADOW_BG, SHADOW_HL}, - {DIALOG_FG, DIALOG_BG, DIALOG_HL}, - {TITLE_FG, TITLE_BG, TITLE_HL}, - {BORDER_FG, BORDER_BG, BORDER_HL}, - {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL}, - {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL}, - {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL}, - {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, - BUTTON_KEY_INACTIVE_HL}, - {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, - BUTTON_LABEL_ACTIVE_HL}, - {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG, - BUTTON_LABEL_INACTIVE_HL}, - {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL}, - {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL}, - {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL}, - {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL}, - {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL}, - {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL}, - {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL}, - {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL}, - {ITEM_FG, ITEM_BG, ITEM_HL}, - {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL}, - {TAG_FG, TAG_BG, TAG_HL}, - {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL}, - {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL}, - {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL}, - {CHECK_FG, CHECK_BG, CHECK_HL}, - {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL}, - {UARROW_FG, UARROW_BG, UARROW_HL}, - {DARROW_FG, DARROW_BG, DARROW_HL}, -}; /* color_table */ +static void color_setup(void) +{ + if (has_colors()) { /* Terminal supports color? */ + start_color(); + set_classic_theme(); + init_dialog_colors(); + } + else + { + set_mono_theme(); + } +} /* * Set window to attribute 'attr' @@ -119,13 +175,13 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr) void dialog_clear(void) { - attr_clear(stdscr, LINES, COLS, screen_attr); + attr_clear(stdscr, LINES, COLS, dlg.screen.atr); /* Display background title if it exists ... - SLH */ - if (backtitle != NULL) { + if (dlg.backtitle != NULL) { int i; - wattrset(stdscr, screen_attr); - mvwaddstr(stdscr, 0, 1, (char *)backtitle); + wattrset(stdscr, dlg.screen.atr); + mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle); wmove(stdscr, 1, 1); for (i = 1; i < COLS - 1; i++) waddch(stdscr, ACS_HLINE); @@ -142,33 +198,10 @@ void init_dialog(void) keypad(stdscr, TRUE); cbreak(); noecho(); - - if (use_colors) /* Set up colors */ - color_setup(); - + color_setup(); dialog_clear(); } -/* - * Setup for color display - */ -void color_setup(void) -{ - int i; - - if (has_colors()) { /* Terminal supports color? */ - start_color(); - - /* Initialize color pairs */ - for (i = 0; i < ATTRIBUTE_COUNT; i++) - init_pair(i + 1, color_table[i][0], color_table[i][1]); - - /* Setup color attributes */ - for (i = 0; i < ATTRIBUTE_COUNT; i++) - attributes[i] = C_ATTR(color_table[i][2], i + 1); - } -} - /* * End using dialog functions. */ @@ -184,7 +217,7 @@ void print_title(WINDOW *dialog, const char *title, int width) { if (title) { int tlen = MIN(width - 2, strlen(title)); - wattrset(dialog, title_attr); + wattrset(dialog, dlg.title.atr); mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' '); mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen); waddch(dialog, ' '); @@ -264,21 +297,23 @@ void print_button(WINDOW * win, const char *label, int y, int x, int selected) int i, temp; wmove(win, y, x); - wattrset(win, selected ? button_active_attr : button_inactive_attr); + wattrset(win, selected ? dlg.button_active.atr + : dlg.button_inactive.atr); waddstr(win, "<"); temp = strspn(label, " "); label += temp; - wattrset(win, selected ? button_label_active_attr - : button_label_inactive_attr); + wattrset(win, selected ? dlg.button_label_active.atr + : dlg.button_label_inactive.atr); for (i = 0; i < temp; i++) waddch(win, ' '); - wattrset(win, selected ? button_key_active_attr - : button_key_inactive_attr); + wattrset(win, selected ? dlg.button_key_active.atr + : dlg.button_key_inactive.atr); waddch(win, label[0]); - wattrset(win, selected ? button_label_active_attr - : button_label_inactive_attr); + wattrset(win, selected ? dlg.button_label_active.atr + : dlg.button_label_inactive.atr); waddstr(win, (char *)label + 1); - wattrset(win, selected ? button_active_attr : button_inactive_attr); + wattrset(win, selected ? dlg.button_active.atr + : dlg.button_inactive.atr); waddstr(win, ">"); wmove(win, y, x + temp + 1); } @@ -326,7 +361,7 @@ void draw_shadow(WINDOW * win, int y, int x, int height, int width) int i; if (has_colors()) { /* Whether terminal supports color? */ - wattrset(win, shadow_attr); + wattrset(win, dlg.shadow.atr); wmove(win, y + height, x + 2); for (i = 0; i < width; i++) waddch(win, winch(win) & A_CHARTEXT); -- cgit From 458972132a705c4a869002354f7f10f395d08c18 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Mon, 24 Jul 2006 22:04:04 +0200 Subject: kconfig/lxdialog: add support for color themes and add blackbg theme The blackbg theme was originally made by: Han Boetes It was copied from a patch by "Randy.Dunlap" which was also the inspiration source for the color theme support. Signed-off-by: Sam Ravnborg --- scripts/kconfig/lxdialog/util.c | 73 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 6 deletions(-) (limited to 'scripts/kconfig/lxdialog/util.c') diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index 08f98b1c4bb..358f9cc19c5 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -96,6 +96,66 @@ static void set_classic_theme(void) DLG_COLOR(darrow, COLOR_GREEN, COLOR_WHITE, true); } +static void set_blackbg_theme(void) +{ + DLG_COLOR(screen, COLOR_RED, COLOR_BLACK, true); + DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, false); + DLG_COLOR(dialog, COLOR_WHITE, COLOR_BLACK, false); + DLG_COLOR(title, COLOR_RED, COLOR_BLACK, false); + DLG_COLOR(border, COLOR_BLACK, COLOR_BLACK, true); + + DLG_COLOR(button_active, COLOR_YELLOW, COLOR_RED, false); + DLG_COLOR(button_inactive, COLOR_YELLOW, COLOR_BLACK, false); + DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_RED, true); + DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_BLACK, false); + DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_RED, false); + DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_BLACK, true); + + DLG_COLOR(inputbox, COLOR_YELLOW, COLOR_BLACK, false); + DLG_COLOR(inputbox_border, COLOR_YELLOW, COLOR_BLACK, false); + + DLG_COLOR(searchbox, COLOR_YELLOW, COLOR_BLACK, false); + DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_BLACK, true); + DLG_COLOR(searchbox_border, COLOR_BLACK, COLOR_BLACK, true); + + DLG_COLOR(position_indicator, COLOR_RED, COLOR_BLACK, false); + + DLG_COLOR(menubox, COLOR_YELLOW, COLOR_BLACK, false); + DLG_COLOR(menubox_border, COLOR_BLACK, COLOR_BLACK, true); + + DLG_COLOR(item, COLOR_WHITE, COLOR_BLACK, false); + DLG_COLOR(item_selected, COLOR_WHITE, COLOR_RED, false); + + DLG_COLOR(tag, COLOR_RED, COLOR_BLACK, false); + DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_RED, true); + DLG_COLOR(tag_key, COLOR_RED, COLOR_BLACK, false); + DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_RED, true); + + DLG_COLOR(check, COLOR_YELLOW, COLOR_BLACK, false); + DLG_COLOR(check_selected, COLOR_YELLOW, COLOR_RED, true); + + DLG_COLOR(uarrow, COLOR_RED, COLOR_BLACK, false); + DLG_COLOR(darrow, COLOR_RED, COLOR_BLACK, false); +} + +/* + * Select color theme + */ +static int set_theme(const char *theme) +{ + int use_color = 1; + if (!theme) + set_classic_theme(); + else if (strcmp(theme, "classic") == 0) + set_classic_theme(); + else if (strcmp(theme, "blackbg") == 0) + set_blackbg_theme(); + else if (strcmp(theme, "mono") == 0) + use_color = 0; + + return use_color; +} + static void init_one_color(struct dialog_color *color) { static int pair = 0; @@ -144,12 +204,13 @@ static void init_dialog_colors(void) /* * Setup for color display */ -static void color_setup(void) +static void color_setup(const char *theme) { - if (has_colors()) { /* Terminal supports color? */ - start_color(); - set_classic_theme(); - init_dialog_colors(); + if (set_theme(theme)) { + if (has_colors()) { /* Terminal supports color? */ + start_color(); + init_dialog_colors(); + } } else { @@ -198,7 +259,7 @@ void init_dialog(void) keypad(stdscr, TRUE); cbreak(); noecho(); - color_setup(); + color_setup(getenv("MENUCONFIG_COLOR")); dialog_clear(); } -- cgit From 350b5b76384e77bcc58217f00455fdbec5cac594 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Mon, 24 Jul 2006 22:19:51 +0200 Subject: kconfig/lxdialog: add a new theme bluetitle which is now default The bluetitle theme is a slightly modified version of the colorscheme that -mm users has been used to. The bluetitle is more readable especially on some LCD screens so it is now default. Anyone that really wants the old color selection can get it by selecting the classic color theme: make MENUCONFIG_COLOR=classic menuconfig The bluetitle theme was modified by Roman Zippel to further improve readability on LCD screens. Signed-off-by: Sam Ravnborg --- scripts/kconfig/lxdialog/util.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'scripts/kconfig/lxdialog/util.c') diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index 358f9cc19c5..e73a36df93b 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -138,6 +138,19 @@ static void set_blackbg_theme(void) DLG_COLOR(darrow, COLOR_RED, COLOR_BLACK, false); } +static void set_bluetitle_theme(void) +{ + set_classic_theme(); + DLG_COLOR(title, COLOR_BLUE, COLOR_WHITE, true); + DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_BLUE, true); + DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_BLUE, true); + DLG_COLOR(searchbox_title, COLOR_BLUE, COLOR_WHITE, true); + DLG_COLOR(position_indicator, COLOR_BLUE, COLOR_WHITE, true); + DLG_COLOR(tag, COLOR_BLUE, COLOR_WHITE, true); + DLG_COLOR(tag_key, COLOR_BLUE, COLOR_WHITE, true); + +} + /* * Select color theme */ @@ -145,9 +158,11 @@ static int set_theme(const char *theme) { int use_color = 1; if (!theme) - set_classic_theme(); + set_bluetitle_theme(); else if (strcmp(theme, "classic") == 0) set_classic_theme(); + else if (strcmp(theme, "bluetitle") == 0) + set_bluetitle_theme(); else if (strcmp(theme, "blackbg") == 0) set_blackbg_theme(); else if (strcmp(theme, "mono") == 0) -- cgit From 2982de6993e6d9944f2215d7cb9b558b465a0c99 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Thu, 27 Jul 2006 22:10:27 +0200 Subject: kconfig/menuconfig: lxdialog is now built-in lxdialog was previously called as an external program causing screen to flicker when used. With this patch lxdialog is now built-in. It is loosly based om previous work by: Petr Baudis Following is a list of changes: o Moved build of dialog routings to kconfig Makefile o menubox + checklist uses a new item list to hold all menu items o in util.c implmented helper function to deal with item list o menubox now uses parameters to save scroll state (avoids temp file) o textbox now get text to be displayed as parameter and not a file o make sure to properly delete subwin's before main windows o killed unused files: lxdialog.c msgbox.c o modified return value for ESC to match direct calling o in a few places the code has been adjusted to 80 char wide o in textbox a small refactoring was made to make code remotely readable o in mconf removed all unused stuff (functions/variables) Following is a list of know short comings: a) pressing ESC twice will be interpreted as two ESC presses b) resize does not work. menuconfig needs to be restarted to be adjusted Signed-off-by: Sam Ravnborg --- scripts/kconfig/lxdialog/util.c | 134 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 2 deletions(-) (limited to 'scripts/kconfig/lxdialog/util.c') diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index e73a36df93b..0b3118df50d 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -268,13 +268,18 @@ void dialog_clear(void) /* * Do some initialization for dialog */ -void init_dialog(void) +void init_dialog(const char *backtitle) +{ + dlg.backtitle = backtitle; + color_setup(getenv("MENUCONFIG_COLOR")); +} + +void reset_dialog(void) { initscr(); /* Init curses */ keypad(stdscr, TRUE); cbreak(); noecho(); - color_setup(getenv("MENUCONFIG_COLOR")); dialog_clear(); } @@ -471,3 +476,128 @@ int first_alpha(const char *string, const char *exempt) return 0; } + +struct dialog_list *item_cur; +struct dialog_list item_nil; +struct dialog_list *item_head; + +void item_reset(void) +{ + struct dialog_list *p, *next; + + for (p = item_head; p; p = next) { + next = p->next; + free(p); + } + item_head = NULL; + item_cur = &item_nil; +} + +void item_make(const char *fmt, ...) +{ + va_list ap; + struct dialog_list *p = malloc(sizeof(*p)); + + if (item_head) + item_cur->next = p; + else + item_head = p; + item_cur = p; + memset(p, 0, sizeof(*p)); + + va_start(ap, fmt); + vsnprintf(item_cur->node.str, sizeof(item_cur->node.str), fmt, ap); + va_end(ap); +} + +void item_add_str(const char *fmt, ...) +{ + va_list ap; + size_t avail; + + avail = sizeof(item_cur->node.str) - strlen(item_cur->node.str); + + va_start(ap, fmt); + vsnprintf(item_cur->node.str + strlen(item_cur->node.str), + avail, fmt, ap); + item_cur->node.str[sizeof(item_cur->node.str) - 1] = '\0'; + va_end(ap); +} + +void item_set_tag(char tag) +{ + item_cur->node.tag = tag; +} +void item_set_data(void *ptr) +{ + item_cur->node.data = ptr; +} + +void item_set_selected(int val) +{ + item_cur->node.selected = val; +} + +int item_activate_selected(void) +{ + item_foreach() + if (item_is_selected()) + return 1; + return 0; +} + +void *item_data(void) +{ + return item_cur->node.data; +} + +char item_tag(void) +{ + return item_cur->node.tag; +} + +int item_count(void) +{ + int n = 0; + struct dialog_list *p; + + for (p = item_head; p; p = p->next) + n++; + return n; +} + +void item_set(int n) +{ + int i = 0; + item_foreach() + if (i++ == n) + return; +} + +int item_n(void) +{ + int n = 0; + struct dialog_list *p; + + for (p = item_head; p; p = p->next) { + if (p == item_cur) + return n; + n++; + } + return 0; +} + +const char *item_str(void) +{ + return item_cur->node.str; +} + +int item_is_selected(void) +{ + return (item_cur->node.selected != 0); +} + +int item_is_tag(char tag) +{ + return (item_cur->node.tag == tag); +} -- cgit From f3cbcdc955d0d2c8b4c52d6b73fc536b01b68c64 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Fri, 28 Jul 2006 23:57:48 +0200 Subject: kconfig/lxdialog: let behave as expected is used to step one back in the dialogs. When lxdialog became built-in pressing once would cause one step back and pressing would cause two steps back. This patch - based on concept from Roman Zippel - makes one a noop and pressing will cause one step backward. In addition the final yes/no dialog now has the option to go back to the the kernel configuration. So if you get too far out you can now go back to configuring the kernel without saving and starting all over again. Signed-off-by: Sam Ravnborg --- scripts/kconfig/lxdialog/util.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'scripts/kconfig/lxdialog/util.c') diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index 0b3118df50d..cb21dc4dd9f 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -477,6 +477,39 @@ int first_alpha(const char *string, const char *exempt) return 0; } +/* + * ncurses uses ESC to detect escaped char sequences. This resutl in + * a small timeout before ESC is actually delivered to the application. + * lxdialog suggest which is correctly translated to two + * times esc. But then we need to ignore the second esc to avoid stepping + * out one menu too much. Filter away all escaped key sequences since + * keypad(FALSE) turn off ncurses support for escape sequences - and thats + * needed to make notimeout() do as expected. + */ +int on_key_esc(WINDOW *win) +{ + int key; + int key2; + int key3; + + nodelay(win, TRUE); + keypad(win, FALSE); + key = wgetch(win); + key2 = wgetch(win); + do { + key3 = wgetch(win); + } while (key3 != ERR); + nodelay(win, FALSE); + keypad(win, TRUE); + if (key == KEY_ESC && key2 == ERR) + return KEY_ESC; + else if (key != ERR && key != KEY_ESC && key2 == ERR) + ungetch(key); + + return -1; +} + + struct dialog_list *item_cur; struct dialog_list item_nil; struct dialog_list *item_head; -- cgit From c8dc68ad0fbd934e78e913b8a8d7b45945db4930 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Sat, 29 Jul 2006 22:48:57 +0200 Subject: kconfig/lxdialog: support resize In all dialogs now properly catch KEY_RESIZE and take proper action. In mconf try to behave sensibly when a dialog routine returns -ERRDISPLAYTOOSMALL. The original check for a screnn size of 80x19 is kept for now. It may make sense to remove it later, but thats anyway what much text is adjusted for. Signed-off-by: Sam Ravnborg --- scripts/kconfig/lxdialog/util.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'scripts/kconfig/lxdialog/util.c') diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index cb21dc4dd9f..ebc781b493d 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -509,6 +509,12 @@ int on_key_esc(WINDOW *win) return -1; } +/* redraw screen in new size */ +int on_key_resize(void) +{ + dialog_clear(); + return KEY_RESIZE; +} struct dialog_list *item_cur; struct dialog_list item_nil; -- cgit