diff options
author | Sam Ravnborg <sam@mars.ravnborg.org> | 2005-11-19 23:38:06 +0100 |
---|---|---|
committer | Sam Ravnborg <sam@mars.ravnborg.org> | 2005-11-19 23:38:06 +0100 |
commit | fa7009d5b59b8acd8071f7b3057d36eeeaf08146 (patch) | |
tree | ba88e9f448aed4c047d8ce311ba44c8731ee96c2 /scripts | |
parent | a06104af7dcf2f5bafaf18f373c8b2554cbfe014 (diff) | |
download | kernel-common-fa7009d5b59b8acd8071f7b3057d36eeeaf08146.tar.gz kernel-common-fa7009d5b59b8acd8071f7b3057d36eeeaf08146.tar.bz2 kernel-common-fa7009d5b59b8acd8071f7b3057d36eeeaf08146.zip |
kconfig: Add print_title helper in lxdialog
Simplify check for long title and use a helper function in util.c
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lxdialog/checklist.c | 15 | ||||
-rw-r--r-- | scripts/lxdialog/dialog.h | 1 | ||||
-rw-r--r-- | scripts/lxdialog/inputbox.c | 15 | ||||
-rw-r--r-- | scripts/lxdialog/menubox.c | 15 | ||||
-rw-r--r-- | scripts/lxdialog/msgbox.c | 14 | ||||
-rw-r--r-- | scripts/lxdialog/textbox.c | 14 | ||||
-rw-r--r-- | scripts/lxdialog/util.c | 14 | ||||
-rw-r--r-- | scripts/lxdialog/yesno.c | 15 |
8 files changed, 21 insertions, 82 deletions
diff --git a/scripts/lxdialog/checklist.c b/scripts/lxdialog/checklist.c index ae40a2b3b885..3fb681fb9632 100644 --- a/scripts/lxdialog/checklist.c +++ b/scripts/lxdialog/checklist.c @@ -158,20 +158,7 @@ int dialog_checklist(const char *title, const char *prompt, int height, wattrset(dialog, dialog_attr); waddch(dialog, ACS_RTEE); - if (title != NULL && strlen(title) >= width - 2) { - /* truncate long title -- mec */ - char *title2 = malloc(width - 2 + 1); - memcpy(title2, title, width - 2); - title2[width - 2] = '\0'; - title = title2; - } - - if (title != NULL) { - wattrset(dialog, title_attr); - mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' '); - waddstr(dialog, (char *)title); - waddch(dialog, ' '); - } + print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); diff --git a/scripts/lxdialog/dialog.h b/scripts/lxdialog/dialog.h index 3cf3d3526ef0..f882204cb3c2 100644 --- a/scripts/lxdialog/dialog.h +++ b/scripts/lxdialog/dialog.h @@ -145,6 +145,7 @@ void dialog_clear(void); void color_setup(void); void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x); void print_button(WINDOW * win, const char *label, int y, int x, int selected); +void print_title(WINDOW *dialog, const char *title, int width); void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box, chtype border); void draw_shadow(WINDOW * win, int y, int x, int height, int width); diff --git a/scripts/lxdialog/inputbox.c b/scripts/lxdialog/inputbox.c index bc135c7093d9..779503726b0a 100644 --- a/scripts/lxdialog/inputbox.c +++ b/scripts/lxdialog/inputbox.c @@ -66,20 +66,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width wattrset(dialog, dialog_attr); waddch(dialog, ACS_RTEE); - if (title != NULL && strlen(title) >= width - 2) { - /* truncate long title -- mec */ - char *title2 = malloc(width - 2 + 1); - memcpy(title2, title, width - 2); - title2[width - 2] = '\0'; - title = title2; - } - - if (title != NULL) { - wattrset(dialog, title_attr); - mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' '); - waddstr(dialog, (char *)title); - waddch(dialog, ' '); - } + print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c index ff3a6179833d..ebfe6a3c8ccc 100644 --- a/scripts/lxdialog/menubox.c +++ b/scripts/lxdialog/menubox.c @@ -189,20 +189,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, wbkgdset(dialog, dialog_attr & A_COLOR); waddch(dialog, ACS_RTEE); - if (title != NULL && strlen(title) >= width - 2) { - /* truncate long title -- mec */ - char *title2 = malloc(width - 2 + 1); - memcpy(title2, title, width - 2); - title2[width - 2] = '\0'; - title = title2; - } - - if (title != NULL) { - wattrset(dialog, title_attr); - mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' '); - waddstr(dialog, (char *)title); - waddch(dialog, ' '); - } + print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); diff --git a/scripts/lxdialog/msgbox.c b/scripts/lxdialog/msgbox.c index b39405717da1..7323f5471f69 100644 --- a/scripts/lxdialog/msgbox.c +++ b/scripts/lxdialog/msgbox.c @@ -42,20 +42,8 @@ int dialog_msgbox(const char *title, const char *prompt, int height, int width, draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); - if (title != NULL && strlen(title) >= width - 2) { - /* truncate long title -- mec */ - char *title2 = malloc(width - 2 + 1); - memcpy(title2, title, width - 2); - title2[width - 2] = '\0'; - title = title2; - } + print_title(dialog, title, width); - if (title != NULL) { - wattrset(dialog, title_attr); - mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' '); - waddstr(dialog, (char *)title); - waddch(dialog, ' '); - } wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 2); diff --git a/scripts/lxdialog/textbox.c b/scripts/lxdialog/textbox.c index fa8d92ea02b6..77848bb8e07f 100644 --- a/scripts/lxdialog/textbox.c +++ b/scripts/lxdialog/textbox.c @@ -103,20 +103,8 @@ int dialog_textbox(const char *title, const char *file, int height, int width) wbkgdset(dialog, dialog_attr & A_COLOR); waddch(dialog, ACS_RTEE); - if (title != NULL && strlen(title) >= width - 2) { - /* truncate long title -- mec */ - char *title2 = malloc(width - 2 + 1); - memcpy(title2, title, width - 2); - title2[width - 2] = '\0'; - title = title2; - } + print_title(dialog, title, width); - if (title != NULL) { - wattrset(dialog, title_attr); - mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' '); - waddstr(dialog, (char *)title); - waddch(dialog, ' '); - } print_button(dialog, " Exit ", height - 2, width / 2 - 4, TRUE); wnoutrefresh(dialog); getyx(dialog, cur_y, cur_x); /* Save cursor position */ diff --git a/scripts/lxdialog/util.c b/scripts/lxdialog/util.c index ce411474d729..f82cebb9ff06 100644 --- a/scripts/lxdialog/util.c +++ b/scripts/lxdialog/util.c @@ -177,6 +177,20 @@ void end_dialog(void) endwin(); } +/* Print the title of the dialog. Center the title and truncate + * tile if wider than dialog (- 2 chars). + **/ +void print_title(WINDOW *dialog, const char *title, int width) +{ + if (title) { + int tlen = MIN(width - 2, strlen(title)); + wattrset(dialog, title_attr); + mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' '); + mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen); + waddch(dialog, ' '); + } +} + /* * Print a string of text in a window, automatically wrap around to the * next line if the string is too long to fit on one line. Newline diff --git a/scripts/lxdialog/yesno.c b/scripts/lxdialog/yesno.c index 84f3e8e005e4..cb2568aae3ed 100644 --- a/scripts/lxdialog/yesno.c +++ b/scripts/lxdialog/yesno.c @@ -61,20 +61,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) wattrset(dialog, dialog_attr); waddch(dialog, ACS_RTEE); - if (title != NULL && strlen(title) >= width - 2) { - /* truncate long title -- mec */ - char *title2 = malloc(width - 2 + 1); - memcpy(title2, title, width - 2); - title2[width - 2] = '\0'; - title = title2; - } - - if (title != NULL) { - wattrset(dialog, title_attr); - mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' '); - waddstr(dialog, (char *)title); - waddch(dialog, ' '); - } + print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); |