Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * textbox.c -- implements the text box |
| 3 | * |
| 4 | * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) |
| 5 | * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "dialog.h" |
| 23 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 24 | static void back_lines(int n); |
| 25 | static void print_page(WINDOW * win, int height, int width); |
| 26 | static void print_line(WINDOW * win, int row, int width); |
| 27 | static char *get_line(void); |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 28 | static void print_position(WINDOW * win); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 30 | static int hscroll; |
| 31 | static int begin_reached, end_reached, page_length; |
| 32 | static const char *buf; |
| 33 | static const char *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | /* |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 36 | * refresh window content |
| 37 | */ |
| 38 | static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, |
| 39 | int cur_y, int cur_x) |
| 40 | { |
| 41 | print_page(box, boxh, boxw); |
| 42 | print_position(dialog); |
| 43 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
| 44 | wrefresh(dialog); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * Display text from a file in a dialog box. |
| 50 | */ |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 51 | int dialog_textbox(const char *title, const char *tbuf, |
| 52 | int initial_height, int initial_width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 54 | int i, x, y, cur_x, cur_y, key = 0; |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 55 | int height, width, boxh, boxw; |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 56 | int passed_end; |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 57 | WINDOW *dialog, *box; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 59 | begin_reached = 1; |
| 60 | end_reached = 0; |
| 61 | page_length = 0; |
| 62 | hscroll = 0; |
| 63 | buf = tbuf; |
| 64 | page = buf; /* page is pointer to start of page to be displayed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 66 | do_resize: |
| 67 | getmaxyx(stdscr, height, width); |
| 68 | if (height < 8 || width < 8) |
| 69 | return -ERRDISPLAYTOOSMALL; |
| 70 | if (initial_height != 0) |
| 71 | height = initial_height; |
| 72 | else |
| 73 | if (height > 4) |
| 74 | height -= 4; |
| 75 | else |
| 76 | height = 0; |
| 77 | if (initial_width != 0) |
| 78 | width = initial_width; |
| 79 | else |
| 80 | if (width > 5) |
| 81 | width -= 5; |
| 82 | else |
| 83 | width = 0; |
| 84 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 85 | /* center dialog box on screen */ |
| 86 | x = (COLS - width) / 2; |
| 87 | y = (LINES - height) / 2; |
| 88 | |
| 89 | draw_shadow(stdscr, y, x, height, width); |
| 90 | |
| 91 | dialog = newwin(height, width, y, x); |
| 92 | keypad(dialog, TRUE); |
| 93 | |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 94 | /* Create window for box region, used for scrolling text */ |
| 95 | boxh = height - 4; |
| 96 | boxw = width - 2; |
| 97 | box = subwin(dialog, boxh, boxw, y + 1, x + 1); |
| 98 | wattrset(box, dlg.dialog.atr); |
| 99 | wbkgdset(box, dlg.dialog.atr & A_COLOR); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 100 | |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 101 | keypad(box, TRUE); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 102 | |
| 103 | /* register the new window, along with its borders */ |
Sam Ravnborg | 98e5a15 | 2006-07-24 21:40:46 +0200 | [diff] [blame] | 104 | draw_box(dialog, 0, 0, height, width, |
| 105 | dlg.dialog.atr, dlg.border.atr); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 106 | |
Sam Ravnborg | 98e5a15 | 2006-07-24 21:40:46 +0200 | [diff] [blame] | 107 | wattrset(dialog, dlg.border.atr); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 108 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
| 109 | for (i = 0; i < width - 2; i++) |
| 110 | waddch(dialog, ACS_HLINE); |
Sam Ravnborg | 98e5a15 | 2006-07-24 21:40:46 +0200 | [diff] [blame] | 111 | wattrset(dialog, dlg.dialog.atr); |
| 112 | wbkgdset(dialog, dlg.dialog.atr & A_COLOR); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 113 | waddch(dialog, ACS_RTEE); |
| 114 | |
Sam Ravnborg | fa7009d | 2005-11-19 23:38:06 +0100 | [diff] [blame] | 115 | print_title(dialog, title, width); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 116 | |
EGRY Gabor | 75c0a8a | 2008-01-11 23:42:54 +0100 | [diff] [blame] | 117 | print_button(dialog, gettext(" Exit "), height - 2, width / 2 - 4, TRUE); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 118 | wnoutrefresh(dialog); |
| 119 | getyx(dialog, cur_y, cur_x); /* Save cursor position */ |
| 120 | |
| 121 | /* Print first page of text */ |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 122 | attr_clear(box, boxh, boxw, dlg.dialog.atr); |
| 123 | refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 124 | |
Sam Ravnborg | f3cbcdc | 2006-07-28 23:57:48 +0200 | [diff] [blame] | 125 | while ((key != KEY_ESC) && (key != '\n')) { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 126 | key = wgetch(dialog); |
| 127 | switch (key) { |
| 128 | case 'E': /* Exit */ |
| 129 | case 'e': |
| 130 | case 'X': |
| 131 | case 'x': |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 132 | delwin(box); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 133 | delwin(dialog); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 134 | return 0; |
| 135 | case 'g': /* First page */ |
| 136 | case KEY_HOME: |
| 137 | if (!begin_reached) { |
| 138 | begin_reached = 1; |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 139 | page = buf; |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 140 | refresh_text_box(dialog, box, boxh, boxw, |
| 141 | cur_y, cur_x); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 142 | } |
| 143 | break; |
| 144 | case 'G': /* Last page */ |
| 145 | case KEY_END: |
| 146 | |
| 147 | end_reached = 1; |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 148 | /* point to last char in buf */ |
| 149 | page = buf + strlen(buf); |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 150 | back_lines(boxh); |
| 151 | refresh_text_box(dialog, box, boxh, boxw, |
| 152 | cur_y, cur_x); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 153 | break; |
| 154 | case 'K': /* Previous line */ |
| 155 | case 'k': |
| 156 | case KEY_UP: |
| 157 | if (!begin_reached) { |
| 158 | back_lines(page_length + 1); |
| 159 | |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 160 | /* We don't call print_page() here but use |
| 161 | * scrolling to ensure faster screen update. |
| 162 | * However, 'end_reached' and 'page_length' |
| 163 | * should still be updated, and 'page' should |
| 164 | * point to start of next page. This is done |
| 165 | * by calling get_line() in the following |
| 166 | * 'for' loop. */ |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 167 | scrollok(box, TRUE); |
| 168 | wscrl(box, -1); /* Scroll box region down one line */ |
| 169 | scrollok(box, FALSE); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 170 | page_length = 0; |
| 171 | passed_end = 0; |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 172 | for (i = 0; i < boxh; i++) { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 173 | if (!i) { |
| 174 | /* print first line of page */ |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 175 | print_line(box, 0, boxw); |
| 176 | wnoutrefresh(box); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 177 | } else |
| 178 | /* Called to update 'end_reached' and 'page' */ |
| 179 | get_line(); |
| 180 | if (!passed_end) |
| 181 | page_length++; |
| 182 | if (end_reached && !passed_end) |
| 183 | passed_end = 1; |
| 184 | } |
| 185 | |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 186 | print_position(dialog); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 187 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
| 188 | wrefresh(dialog); |
| 189 | } |
| 190 | break; |
| 191 | case 'B': /* Previous page */ |
| 192 | case 'b': |
| 193 | case KEY_PPAGE: |
| 194 | if (begin_reached) |
| 195 | break; |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 196 | back_lines(page_length + boxh); |
| 197 | refresh_text_box(dialog, box, boxh, boxw, |
| 198 | cur_y, cur_x); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 199 | break; |
| 200 | case 'J': /* Next line */ |
| 201 | case 'j': |
| 202 | case KEY_DOWN: |
| 203 | if (!end_reached) { |
| 204 | begin_reached = 0; |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 205 | scrollok(box, TRUE); |
| 206 | scroll(box); /* Scroll box region up one line */ |
| 207 | scrollok(box, FALSE); |
| 208 | print_line(box, boxh - 1, boxw); |
| 209 | wnoutrefresh(box); |
| 210 | print_position(dialog); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 211 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
| 212 | wrefresh(dialog); |
| 213 | } |
| 214 | break; |
| 215 | case KEY_NPAGE: /* Next page */ |
| 216 | case ' ': |
| 217 | if (end_reached) |
| 218 | break; |
| 219 | |
| 220 | begin_reached = 0; |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 221 | refresh_text_box(dialog, box, boxh, boxw, |
| 222 | cur_y, cur_x); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 223 | break; |
| 224 | case '0': /* Beginning of line */ |
| 225 | case 'H': /* Scroll left */ |
| 226 | case 'h': |
| 227 | case KEY_LEFT: |
| 228 | if (hscroll <= 0) |
| 229 | break; |
| 230 | |
| 231 | if (key == '0') |
| 232 | hscroll = 0; |
| 233 | else |
| 234 | hscroll--; |
| 235 | /* Reprint current page to scroll horizontally */ |
| 236 | back_lines(page_length); |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 237 | refresh_text_box(dialog, box, boxh, boxw, |
| 238 | cur_y, cur_x); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 239 | break; |
| 240 | case 'L': /* Scroll right */ |
| 241 | case 'l': |
| 242 | case KEY_RIGHT: |
| 243 | if (hscroll >= MAX_LEN) |
| 244 | break; |
| 245 | hscroll++; |
| 246 | /* Reprint current page to scroll horizontally */ |
| 247 | back_lines(page_length); |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 248 | refresh_text_box(dialog, box, boxh, boxw, |
| 249 | cur_y, cur_x); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 250 | break; |
Sam Ravnborg | f3cbcdc | 2006-07-28 23:57:48 +0200 | [diff] [blame] | 251 | case KEY_ESC: |
| 252 | key = on_key_esc(dialog); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 253 | break; |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 254 | case KEY_RESIZE: |
| 255 | back_lines(height); |
| 256 | delwin(box); |
| 257 | delwin(dialog); |
| 258 | on_key_resize(); |
| 259 | goto do_resize; |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 260 | } |
| 261 | } |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 262 | delwin(box); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 263 | delwin(dialog); |
Sam Ravnborg | f3cbcdc | 2006-07-28 23:57:48 +0200 | [diff] [blame] | 264 | return key; /* ESC pressed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 268 | * Go back 'n' lines in text. Called by dialog_textbox(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | * 'page' will be updated to point to the desired line in 'buf'. |
| 270 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 271 | static void back_lines(int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 273 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 275 | begin_reached = 0; |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 276 | /* Go back 'n' lines */ |
| 277 | for (i = 0; i < n; i++) { |
| 278 | if (*page == '\0') { |
| 279 | if (end_reached) { |
| 280 | end_reached = 0; |
| 281 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 283 | } |
| 284 | if (page == buf) { |
| 285 | begin_reached = 1; |
| 286 | return; |
| 287 | } |
| 288 | page--; |
| 289 | do { |
| 290 | if (page == buf) { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 291 | begin_reached = 1; |
| 292 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 294 | page--; |
| 295 | } while (*page != '\n'); |
| 296 | page++; |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* |
| 301 | * Print a new page of text. Called by dialog_textbox(). |
| 302 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 303 | static void print_page(WINDOW * win, int height, int width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 305 | int i, passed_end = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 307 | page_length = 0; |
| 308 | for (i = 0; i < height; i++) { |
| 309 | print_line(win, i, width); |
| 310 | if (!passed_end) |
| 311 | page_length++; |
| 312 | if (end_reached && !passed_end) |
| 313 | passed_end = 1; |
| 314 | } |
| 315 | wnoutrefresh(win); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Print a new line of text. Called by dialog_textbox() and print_page(). |
| 320 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 321 | static void print_line(WINDOW * win, int row, int width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 323 | char *line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 325 | line = get_line(); |
| 326 | line += MIN(strlen(line), hscroll); /* Scroll horizontally */ |
| 327 | wmove(win, row, 0); /* move cursor to correct line */ |
| 328 | waddch(win, ' '); |
| 329 | waddnstr(win, line, MIN(strlen(line), width - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 331 | /* Clear 'residue' of previous line */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | #if OLD_NCURSES |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 333 | { |
Lucas De Marchi | 702a945 | 2011-08-20 02:28:53 -0300 | [diff] [blame] | 334 | int x = getcurx(win); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 335 | int i; |
| 336 | for (i = 0; i < width - x; i++) |
| 337 | waddch(win, ' '); |
| 338 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | #else |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 340 | wclrtoeol(win); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | #endif |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Return current line of text. Called by dialog_textbox() and print_line(). |
| 346 | * 'page' should point to start of current line before calling, and will be |
| 347 | * updated to point to start of next line. |
| 348 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 349 | static char *get_line(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 351 | int i = 0; |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 352 | static char line[MAX_LEN + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 354 | end_reached = 0; |
| 355 | while (*page != '\n') { |
| 356 | if (*page == '\0') { |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 357 | if (!end_reached) { |
| 358 | end_reached = 1; |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | } else if (i < MAX_LEN) |
| 362 | line[i++] = *(page++); |
| 363 | else { |
| 364 | /* Truncate lines longer than MAX_LEN characters */ |
| 365 | if (i == MAX_LEN) |
| 366 | line[i++] = '\0'; |
| 367 | page++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 370 | if (i <= MAX_LEN) |
| 371 | line[i] = '\0'; |
| 372 | if (!end_reached) |
| 373 | page++; /* move pass '\n' */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 375 | return line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Print current position |
| 380 | */ |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 381 | static void print_position(WINDOW * win) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 383 | int percent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Sam Ravnborg | 98e5a15 | 2006-07-24 21:40:46 +0200 | [diff] [blame] | 385 | wattrset(win, dlg.position_indicator.atr); |
| 386 | wbkgdset(win, dlg.position_indicator.atr & A_COLOR); |
Sam Ravnborg | 2982de6 | 2006-07-27 22:10:27 +0200 | [diff] [blame] | 387 | percent = (page - buf) * 100 / strlen(buf); |
Sam Ravnborg | c8dc68a | 2006-07-29 22:48:57 +0200 | [diff] [blame] | 388 | wmove(win, getmaxy(win) - 3, getmaxx(win) - 9); |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 389 | wprintw(win, "(%3d%%)", percent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |