aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSam Ravnborg <sam@mars.ravnborg.org>2005-11-19 17:38:06 -0500
committerSam Ravnborg <sam@mars.ravnborg.org>2005-11-19 17:38:06 -0500
commitfa7009d5b59b8acd8071f7b3057d36eeeaf08146 (patch)
treeba88e9f448aed4c047d8ce311ba44c8731ee96c2 /scripts
parenta06104af7dcf2f5bafaf18f373c8b2554cbfe014 (diff)
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.c15
-rw-r--r--scripts/lxdialog/dialog.h1
-rw-r--r--scripts/lxdialog/inputbox.c15
-rw-r--r--scripts/lxdialog/menubox.c15
-rw-r--r--scripts/lxdialog/msgbox.c14
-rw-r--r--scripts/lxdialog/textbox.c14
-rw-r--r--scripts/lxdialog/util.c14
-rw-r--r--scripts/lxdialog/yesno.c15
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,
158 wattrset(dialog, dialog_attr); 158 wattrset(dialog, dialog_attr);
159 waddch(dialog, ACS_RTEE); 159 waddch(dialog, ACS_RTEE);
160 160
161 if (title != NULL && strlen(title) >= width - 2) { 161 print_title(dialog, title, width);
162 /* truncate long title -- mec */
163 char *title2 = malloc(width - 2 + 1);
164 memcpy(title2, title, width - 2);
165 title2[width - 2] = '\0';
166 title = title2;
167 }
168
169 if (title != NULL) {
170 wattrset(dialog, title_attr);
171 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
172 waddstr(dialog, (char *)title);
173 waddch(dialog, ' ');
174 }
175 162
176 wattrset(dialog, dialog_attr); 163 wattrset(dialog, dialog_attr);
177 print_autowrap(dialog, prompt, width - 2, 1, 3); 164 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);
145void color_setup(void); 145void color_setup(void);
146void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x); 146void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
147void print_button(WINDOW * win, const char *label, int y, int x, int selected); 147void print_button(WINDOW * win, const char *label, int y, int x, int selected);
148void print_title(WINDOW *dialog, const char *title, int width);
148void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box, 149void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
149 chtype border); 150 chtype border);
150void draw_shadow(WINDOW * win, int y, int x, int height, int width); 151void 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
66 wattrset(dialog, dialog_attr); 66 wattrset(dialog, dialog_attr);
67 waddch(dialog, ACS_RTEE); 67 waddch(dialog, ACS_RTEE);
68 68
69 if (title != NULL && strlen(title) >= width - 2) { 69 print_title(dialog, title, width);
70 /* truncate long title -- mec */
71 char *title2 = malloc(width - 2 + 1);
72 memcpy(title2, title, width - 2);
73 title2[width - 2] = '\0';
74 title = title2;
75 }
76
77 if (title != NULL) {
78 wattrset(dialog, title_attr);
79 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
80 waddstr(dialog, (char *)title);
81 waddch(dialog, ' ');
82 }
83 70
84 wattrset(dialog, dialog_attr); 71 wattrset(dialog, dialog_attr);
85 print_autowrap(dialog, prompt, width - 2, 1, 3); 72 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,
189 wbkgdset(dialog, dialog_attr & A_COLOR); 189 wbkgdset(dialog, dialog_attr & A_COLOR);
190 waddch(dialog, ACS_RTEE); 190 waddch(dialog, ACS_RTEE);
191 191
192 if (title != NULL && strlen(title) >= width - 2) { 192 print_title(dialog, title, width);
193 /* truncate long title -- mec */
194 char *title2 = malloc(width - 2 + 1);
195 memcpy(title2, title, width - 2);
196 title2[width - 2] = '\0';
197 title = title2;
198 }
199
200 if (title != NULL) {
201 wattrset(dialog, title_attr);
202 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
203 waddstr(dialog, (char *)title);
204 waddch(dialog, ' ');
205 }
206 193
207 wattrset(dialog, dialog_attr); 194 wattrset(dialog, dialog_attr);
208 print_autowrap(dialog, prompt, width - 2, 1, 3); 195 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,
42 42
43 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 43 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
44 44
45 if (title != NULL && strlen(title) >= width - 2) { 45 print_title(dialog, title, width);
46 /* truncate long title -- mec */
47 char *title2 = malloc(width - 2 + 1);
48 memcpy(title2, title, width - 2);
49 title2[width - 2] = '\0';
50 title = title2;
51 }
52 46
53 if (title != NULL) {
54 wattrset(dialog, title_attr);
55 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
56 waddstr(dialog, (char *)title);
57 waddch(dialog, ' ');
58 }
59 wattrset(dialog, dialog_attr); 47 wattrset(dialog, dialog_attr);
60 print_autowrap(dialog, prompt, width - 2, 1, 2); 48 print_autowrap(dialog, prompt, width - 2, 1, 2);
61 49
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)
103 wbkgdset(dialog, dialog_attr & A_COLOR); 103 wbkgdset(dialog, dialog_attr & A_COLOR);
104 waddch(dialog, ACS_RTEE); 104 waddch(dialog, ACS_RTEE);
105 105
106 if (title != NULL && strlen(title) >= width - 2) { 106 print_title(dialog, title, width);
107 /* truncate long title -- mec */
108 char *title2 = malloc(width - 2 + 1);
109 memcpy(title2, title, width - 2);
110 title2[width - 2] = '\0';
111 title = title2;
112 }
113 107
114 if (title != NULL) {
115 wattrset(dialog, title_attr);
116 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
117 waddstr(dialog, (char *)title);
118 waddch(dialog, ' ');
119 }
120 print_button(dialog, " Exit ", height - 2, width / 2 - 4, TRUE); 108 print_button(dialog, " Exit ", height - 2, width / 2 - 4, TRUE);
121 wnoutrefresh(dialog); 109 wnoutrefresh(dialog);
122 getyx(dialog, cur_y, cur_x); /* Save cursor position */ 110 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)
177 endwin(); 177 endwin();
178} 178}
179 179
180/* Print the title of the dialog. Center the title and truncate
181 * tile if wider than dialog (- 2 chars).
182 **/
183void print_title(WINDOW *dialog, const char *title, int width)
184{
185 if (title) {
186 int tlen = MIN(width - 2, strlen(title));
187 wattrset(dialog, title_attr);
188 mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' ');
189 mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen);
190 waddch(dialog, ' ');
191 }
192}
193
180/* 194/*
181 * Print a string of text in a window, automatically wrap around to the 195 * Print a string of text in a window, automatically wrap around to the
182 * next line if the string is too long to fit on one line. Newline 196 * 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)
61 wattrset(dialog, dialog_attr); 61 wattrset(dialog, dialog_attr);
62 waddch(dialog, ACS_RTEE); 62 waddch(dialog, ACS_RTEE);
63 63
64 if (title != NULL && strlen(title) >= width - 2) { 64 print_title(dialog, title, width);
65 /* truncate long title -- mec */
66 char *title2 = malloc(width - 2 + 1);
67 memcpy(title2, title, width - 2);
68 title2[width - 2] = '\0';
69 title = title2;
70 }
71
72 if (title != NULL) {
73 wattrset(dialog, title_attr);
74 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
75 waddstr(dialog, (char *)title);
76 waddch(dialog, ' ');
77 }
78 65
79 wattrset(dialog, dialog_attr); 66 wattrset(dialog, dialog_attr);
80 print_autowrap(dialog, prompt, width - 2, 1, 3); 67 print_autowrap(dialog, prompt, width - 2, 1, 3);