]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
kconfig: Add print_title helper in lxdialog
authorSam Ravnborg <sam@mars.ravnborg.org>
Sat, 19 Nov 2005 22:38:06 +0000 (23:38 +0100)
committerSam Ravnborg <sam@mars.ravnborg.org>
Sat, 19 Nov 2005 22:38:06 +0000 (23:38 +0100)
Simplify check for long title and use a helper function in util.c

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
scripts/lxdialog/checklist.c
scripts/lxdialog/dialog.h
scripts/lxdialog/inputbox.c
scripts/lxdialog/menubox.c
scripts/lxdialog/msgbox.c
scripts/lxdialog/textbox.c
scripts/lxdialog/util.c
scripts/lxdialog/yesno.c

index ae40a2b3b88543257f0ebafa9a9408d863b6f53c..3fb681fb9632d96f9cd2839039311c82ea70bc1f 100644 (file)
@@ -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);
index 3cf3d3526ef06e42e7ab3907c5800328bbd9236d..f882204cb3c279d5492732c89241dc8c2e19bb29 100644 (file)
@@ -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);
index bc135c7093d921ce5a98415829a8f58a1074fb6a..779503726b0a77b9eb08ab3f3b9d7abc921415a7 100644 (file)
@@ -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);
index ff3a6179833d0e5844fad4ce69f4bdcd26b29e5d..ebfe6a3c8cccc3d9155f5c1a7a3acb6f87a69ad7 100644 (file)
@@ -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);
index b39405717da1872cde077f21f229e5257b6cee67..7323f5471f69cec57b7ac46aad169c815ce070cb 100644 (file)
@@ -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);
 
index fa8d92ea02b6efbc1b7980f38a46534f4f477caa..77848bb8e07f8795fbffeebee7980a0ee1adc269 100644 (file)
@@ -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 */
index ce411474d72979bb66beb6097f48025e66af711c..f82cebb9ff06d718f758f24f5674a671c17a36e1 100644 (file)
@@ -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
index 84f3e8e005e41efe913421852c9fc1493592a41e..cb2568aae3ed7609a68dd04a81750e3e7c52ab2c 100644 (file)
@@ -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);