Chris Allegretta | 11b0011 | 2000-08-06 21:13:45 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * winio.c * |
| 4 | * * |
| 5 | * Copyright (C) 1999 Chris Allegretta * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 1, or (at your option) * |
| 9 | * any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * |
| 19 | * * |
| 20 | **************************************************************************/ |
| 21 | |
| 22 | #include <stdarg.h> |
| 23 | #include <string.h> |
Chris Allegretta | dba37ae | 2000-07-07 05:13:09 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 25 | #include "config.h" |
| 26 | #include "proto.h" |
| 27 | #include "nano.h" |
| 28 | |
| 29 | #ifndef NANO_SMALL |
| 30 | #include <libintl.h> |
| 31 | #define _(string) gettext(string) |
| 32 | #else |
| 33 | #define _(string) (string) |
| 34 | #endif |
| 35 | |
| 36 | static int statblank = 0; /* Number of keystrokes left after |
| 37 | we call statubar() before we |
| 38 | actually blank the statusbar */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 39 | |
| 40 | /* Local Function Prototypes for only winio.c */ |
| 41 | inline int get_page_from_virtual(int virtual); |
| 42 | inline int get_page_start_virtual(int page); |
| 43 | inline int get_page_end_virtual(int page); |
| 44 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 45 | /* Window I/O */ |
| 46 | |
| 47 | int do_first_line(void) |
| 48 | { |
| 49 | current = fileage; |
| 50 | placewewant = 0; |
| 51 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 52 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 53 | return 1; |
| 54 | } |
| 55 | |
| 56 | int do_last_line(void) |
| 57 | { |
| 58 | current = filebot; |
| 59 | placewewant = 0; |
| 60 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 61 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | /* Like xplustabs, but for a specifc index of a speficific filestruct */ |
| 66 | int xpt(filestruct * fileptr, int index) |
| 67 | { |
| 68 | int i, tabs = 0; |
| 69 | |
| 70 | if (fileptr == NULL || fileptr->data == NULL) |
| 71 | return 0; |
| 72 | |
| 73 | for (i = 0; i < index && fileptr->data[i] != 0; i++) { |
| 74 | tabs++; |
| 75 | |
| 76 | if (fileptr->data[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 77 | if (tabs % tabsize == 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 78 | else |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 79 | tabs += tabsize - (tabs % tabsize); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 80 | } else if (fileptr->data[i] & 0x80) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 81 | /* Make 8 bit chars only 1 collumn! */ |
| 82 | ; |
| 83 | else if (fileptr->data[i] < 32) |
| 84 | tabs++; |
| 85 | } |
| 86 | |
| 87 | return tabs; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /* Return the actual place on the screen of current->data[current_x], which |
| 92 | should always be > current_x */ |
| 93 | int xplustabs(void) |
| 94 | { |
| 95 | return xpt(current, current_x); |
| 96 | } |
| 97 | |
| 98 | |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 99 | /* Return what current_x should be, given xplustabs() for the line, |
| 100 | * given a start position in the filestruct's data */ |
| 101 | int actual_x_from_start(filestruct * fileptr, int xplus, int start) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 102 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 103 | int i, tot = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 104 | |
| 105 | if (fileptr == NULL || fileptr->data == NULL) |
| 106 | return 0; |
| 107 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 108 | for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 109 | if (fileptr->data[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 110 | if (tot % tabsize == 0) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 111 | tot++; |
| 112 | else |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 113 | tot += tabsize - (tot % tabsize); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 114 | } else if (fileptr->data[i] & 0x80) |
| 115 | tot++; /* Make 8 bit chars only 1 column (again) */ |
| 116 | else if (fileptr->data[i] < 32) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 117 | tot += 2; |
| 118 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 119 | #ifdef DEBUG |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 120 | fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"), |
| 121 | xplus, i); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 122 | #endif |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 123 | return i - start; |
| 124 | } |
| 125 | |
| 126 | /* Opposite of xplustabs */ |
| 127 | inline int actual_x(filestruct * fileptr, int xplus) |
| 128 | { |
| 129 | return actual_x_from_start(fileptr, xplus, 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /* a strlen with tabs factored in, similar to xplustabs() */ |
| 133 | int strlenpt(char *buf) |
| 134 | { |
| 135 | int i, tabs = 0; |
| 136 | |
| 137 | if (buf == NULL) |
| 138 | return 0; |
| 139 | |
| 140 | for (i = 0; buf[i] != 0; i++) { |
| 141 | tabs++; |
| 142 | |
| 143 | if (buf[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 144 | if (tabs % tabsize == 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 145 | else |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 146 | tabs += tabsize - (tabs % tabsize); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 147 | } else if (buf[i] & 0x80) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 148 | /* Make 8 bit chars only 1 collumn! */ |
| 149 | ; |
| 150 | else if (buf[i] < 32) |
| 151 | tabs++; |
| 152 | } |
| 153 | |
| 154 | return tabs; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /* resets current_y based on the position of current and puts the cursor at |
| 159 | (current_y, current_x) */ |
| 160 | void reset_cursor(void) |
| 161 | { |
| 162 | filestruct *ptr = edittop; |
| 163 | int x; |
| 164 | |
| 165 | current_y = 0; |
| 166 | |
| 167 | while (ptr != current && ptr != editbot && ptr->next != NULL) { |
| 168 | ptr = ptr->next; |
| 169 | current_y++; |
| 170 | } |
| 171 | |
| 172 | x = xplustabs(); |
| 173 | if (x <= COLS - 2) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 174 | wmove(edit, current_y, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 175 | else |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 176 | wmove(edit, current_y, x - |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 177 | get_page_start_virtual(get_page_from_virtual(x))); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 178 | |
| 179 | } |
| 180 | |
| 181 | void blank_bottombars(void) |
| 182 | { |
| 183 | int i = no_help()? 3 : 1; |
| 184 | |
| 185 | for (; i <= 2; i++) |
| 186 | mvwaddstr(bottomwin, i, 0, hblank); |
| 187 | |
| 188 | } |
| 189 | |
| 190 | void blank_edit(void) |
| 191 | { |
| 192 | int i; |
| 193 | for (i = 0; i <= editwinrows - 1; i++) |
| 194 | mvwaddstr(edit, i, 0, hblank); |
| 195 | wrefresh(edit); |
| 196 | } |
| 197 | |
| 198 | |
| 199 | void blank_statusbar(void) |
| 200 | { |
| 201 | mvwaddstr(bottomwin, 0, 0, hblank); |
| 202 | } |
| 203 | |
| 204 | void blank_statusbar_refresh(void) |
| 205 | { |
| 206 | blank_statusbar(); |
| 207 | wrefresh(bottomwin); |
| 208 | } |
| 209 | |
| 210 | void check_statblank(void) |
| 211 | { |
| 212 | |
| 213 | if (statblank > 1) |
| 214 | statblank--; |
| 215 | else if (statblank == 1 && !ISSET(CONSTUPDATE)) { |
| 216 | statblank--; |
| 217 | blank_statusbar_refresh(); |
| 218 | } |
| 219 | } |
| 220 | |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 221 | /* Repaint the statusbar when getting a character in nanogetstr */ |
| 222 | void nanoget_repaint(char *buf, char *inputbuf, int x) |
| 223 | { |
| 224 | blank_statusbar(); |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame^] | 225 | if (x <= COLS) { |
| 226 | mvwaddstr(bottomwin, 0, 0, buf); |
| 227 | waddnstr(bottomwin, inputbuf, COLS - strlen(buf)); |
| 228 | |
| 229 | } else if (x > COLS && x <= COLS * 2) |
| 230 | mvwaddnstr(bottomwin, 0, 0, &inputbuf[COLS - strlen(buf)], COLS); |
| 231 | else |
| 232 | mvwaddnstr(bottomwin, 0, 0, &inputbuf[COLS * (x / COLS) - |
| 233 | strlen(buf)], COLS); |
| 234 | |
| 235 | wmove(bottomwin, 0, (x % COLS)); |
| 236 | |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 239 | /* Get the input from the kb, this should only be called from statusq */ |
| 240 | int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x) |
| 241 | { |
| 242 | int kbinput = 0, j = 0, x = 0, xend; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame^] | 243 | int x_left = 0, inputlen; |
| 244 | char *inputbuf; |
| 245 | |
| 246 | inputbuf = nmalloc(strlen(def) + 1); |
| 247 | inputbuf[0] = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 248 | |
| 249 | x_left = strlen(buf); |
| 250 | x = strlen(def) + x_left; |
| 251 | |
| 252 | /* Get the input! */ |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame^] | 253 | if (strlen(def) > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 254 | strcpy(inputbuf, def); |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame^] | 255 | |
| 256 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 257 | |
| 258 | while ((kbinput = wgetch(bottomwin)) != 13) { |
| 259 | for (j = 0; j <= slen - 1; j++) { |
| 260 | if (kbinput == s[j].val) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 261 | strcpy(answer, ""); |
| 262 | return s[j].val; |
| 263 | } |
| 264 | } |
| 265 | xend = strlen(buf) + strlen(inputbuf); |
| 266 | |
| 267 | switch (kbinput) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 268 | /* Stuff we want to equate with <enter>, ASCII 13 */ |
| 269 | case 343: |
Chris Allegretta | f9b6c9b | 2000-10-18 19:35:59 +0000 | [diff] [blame] | 270 | ungetch(13); /* Enter on iris-ansi $TERM, sometimes */ |
| 271 | break; |
| 272 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 273 | case KEY_HOME: |
| 274 | x = x_left; |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 275 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 276 | break; |
| 277 | case KEY_END: |
| 278 | x = x_left + strlen(inputbuf); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 279 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 280 | break; |
| 281 | case KEY_RIGHT: |
| 282 | |
| 283 | if (x < xend) |
| 284 | x++; |
| 285 | wmove(bottomwin, 0, x); |
| 286 | break; |
| 287 | case NANO_CONTROL_D: |
| 288 | if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) { |
| 289 | memmove(inputbuf + (x - x_left), |
| 290 | inputbuf + (x - x_left) + 1, |
| 291 | strlen(inputbuf) - (x - x_left) - 1); |
| 292 | inputbuf[strlen(inputbuf) - 1] = 0; |
| 293 | } |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 294 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 295 | break; |
| 296 | case NANO_CONTROL_K: |
| 297 | case NANO_CONTROL_U: |
| 298 | *inputbuf = 0; |
| 299 | x = x_left; |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 300 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 301 | break; |
| 302 | case KEY_BACKSPACE: |
| 303 | case KEY_DC: |
| 304 | case 127: |
| 305 | case NANO_CONTROL_H: |
| 306 | if (strlen(inputbuf) > 0) { |
| 307 | if (x == (x_left + strlen(inputbuf))) |
| 308 | inputbuf[strlen(inputbuf) - 1] = 0; |
| 309 | else if (x - x_left) { |
| 310 | memmove(inputbuf + (x - x_left) - 1, |
| 311 | inputbuf + (x - x_left), |
| 312 | strlen(inputbuf) - (x - x_left)); |
| 313 | inputbuf[strlen(inputbuf) - 1] = 0; |
| 314 | } |
| 315 | } |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame^] | 316 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 317 | case KEY_LEFT: |
| 318 | if (x > strlen(buf)) |
| 319 | x--; |
| 320 | wmove(bottomwin, 0, x); |
| 321 | break; |
| 322 | case KEY_UP: |
| 323 | case KEY_DOWN: |
| 324 | break; |
| 325 | |
| 326 | case 27: |
| 327 | switch (kbinput = wgetch(edit)) { |
| 328 | case 79: |
| 329 | switch (kbinput = wgetch(edit)) { |
| 330 | case 70: |
| 331 | x = x_left + strlen(inputbuf); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 332 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 333 | break; |
| 334 | case 72: |
| 335 | x = x_left; |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 336 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 337 | break; |
| 338 | } |
| 339 | break; |
| 340 | case 91: |
| 341 | switch (kbinput = wgetch(edit)) { |
| 342 | case 'C': |
| 343 | if (x < xend) |
| 344 | x++; |
| 345 | wmove(bottomwin, 0, x); |
| 346 | break; |
| 347 | case 'D': |
| 348 | if (x > strlen(buf)) |
| 349 | x--; |
| 350 | wmove(bottomwin, 0, x); |
| 351 | break; |
| 352 | case 49: |
| 353 | x = x_left; |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 354 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 355 | goto skip_126; |
| 356 | case 51: |
| 357 | if (strlen(inputbuf) > 0 |
| 358 | && (x - x_left) != strlen(inputbuf)) { |
| 359 | memmove(inputbuf + (x - x_left), |
| 360 | inputbuf + (x - x_left) + 1, |
| 361 | strlen(inputbuf) - (x - x_left) - 1); |
| 362 | inputbuf[strlen(inputbuf) - 1] = 0; |
| 363 | } |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 364 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 365 | goto skip_126; |
| 366 | case 52: |
| 367 | x = x_left + strlen(inputbuf); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 368 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 369 | goto skip_126; |
| 370 | skip_126: |
| 371 | nodelay(edit, TRUE); |
| 372 | kbinput = wgetch(edit); |
| 373 | if (kbinput == 126 || kbinput == ERR) |
| 374 | kbinput = -1; |
| 375 | nodelay(edit, FALSE); |
| 376 | break; |
| 377 | } |
| 378 | } |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 379 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 380 | break; |
| 381 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 382 | default: |
| 383 | if (kbinput < 32) |
| 384 | break; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame^] | 385 | |
| 386 | inputlen = strlen(inputbuf); |
| 387 | inputbuf = nrealloc(inputbuf, inputlen + 2); |
| 388 | |
| 389 | memmove(&inputbuf[x - x_left + 1], |
| 390 | &inputbuf[x - x_left], |
| 391 | inputlen - (x - x_left) + 1); |
| 392 | inputbuf[x - x_left] = kbinput; |
| 393 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 394 | x++; |
| 395 | |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 396 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 397 | #ifdef DEBUG |
| 398 | fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput); |
| 399 | #endif |
| 400 | } |
| 401 | wrefresh(bottomwin); |
| 402 | } |
| 403 | |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame^] | 404 | answer = mallocstrcpy(answer, inputbuf); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 405 | |
Chris Allegretta | 105da33 | 2000-10-31 05:10:10 +0000 | [diff] [blame] | 406 | /* Now that the text is editable instead of bracketed, we have to |
| 407 | check for answer == def, instead of answer == "" */ |
| 408 | /* if (!strcmp(answer, "")) */ |
| 409 | if (!strcmp(answer, def)) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 410 | return -2; |
| 411 | else |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | void horizbar(WINDOW * win, int y) |
| 416 | { |
| 417 | wattron(win, A_REVERSE); |
| 418 | mvwaddstr(win, 0, 0, hblank); |
| 419 | wattroff(win, A_REVERSE); |
| 420 | } |
| 421 | |
| 422 | void titlebar(void) |
| 423 | { |
| 424 | int namelen, space; |
| 425 | |
| 426 | horizbar(topwin, 0); |
| 427 | wattron(topwin, A_REVERSE); |
| 428 | mvwaddstr(topwin, 0, 3, VERMSG); |
| 429 | |
| 430 | space = COLS - strlen(VERMSG) - strlen(VERSION) - 21; |
| 431 | |
| 432 | namelen = strlen(filename); |
| 433 | |
| 434 | if (!strcmp(filename, "")) |
| 435 | mvwaddstr(topwin, 0, center_x - 6, _("New Buffer")); |
| 436 | else { |
| 437 | if (namelen > space) { |
| 438 | waddstr(topwin, _(" File: ...")); |
| 439 | waddstr(topwin, &filename[namelen - space]); |
| 440 | } else { |
| 441 | mvwaddstr(topwin, 0, center_x - (namelen / 2 + 1), "File: "); |
| 442 | waddstr(topwin, filename); |
| 443 | } |
| 444 | } |
| 445 | if (ISSET(MODIFIED)) |
| 446 | mvwaddstr(topwin, 0, COLS - 10, _("Modified")); |
| 447 | wattroff(topwin, A_REVERSE); |
| 448 | wrefresh(topwin); |
| 449 | reset_cursor(); |
| 450 | } |
| 451 | |
| 452 | void onekey(char *keystroke, char *desc) |
| 453 | { |
| 454 | char description[80]; |
| 455 | |
Chris Allegretta | e7034c6 | 2000-09-15 03:31:09 +0000 | [diff] [blame] | 456 | snprintf(description, 12, " %-10s", desc); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 457 | wattron(bottomwin, A_REVERSE); |
| 458 | waddstr(bottomwin, keystroke); |
| 459 | wattroff(bottomwin, A_REVERSE); |
| 460 | waddstr(bottomwin, description); |
| 461 | } |
| 462 | |
| 463 | void clear_bottomwin(void) |
| 464 | { |
| 465 | if (ISSET(NO_HELP)) |
| 466 | return; |
| 467 | |
| 468 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 469 | mvwaddstr(bottomwin, 2, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | void bottombars(shortcut s[], int slen) |
| 473 | { |
| 474 | int i, j, k; |
| 475 | char keystr[10]; |
| 476 | |
| 477 | if (ISSET(NO_HELP)) |
| 478 | return; |
| 479 | |
| 480 | /* Determine how many extra spaces are needed to fill the bottom of the screen */ |
| 481 | k = COLS / 6 - 13; |
| 482 | |
| 483 | clear_bottomwin(); |
| 484 | wmove(bottomwin, 1, 0); |
| 485 | for (i = 0; i <= slen - 1; i += 2) { |
Robert Siemborski | 6af1431 | 2000-07-01 21:34:26 +0000 | [diff] [blame] | 486 | snprintf(keystr, 10, "^%c", s[i].val + 64); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 487 | onekey(keystr, s[i].desc); |
| 488 | |
| 489 | for (j = 0; j < k; j++) |
| 490 | waddch(bottomwin, ' '); |
| 491 | } |
| 492 | |
| 493 | wmove(bottomwin, 2, 0); |
| 494 | for (i = 1; i <= slen - 1; i += 2) { |
Robert Siemborski | 6af1431 | 2000-07-01 21:34:26 +0000 | [diff] [blame] | 495 | snprintf(keystr, 10, "^%c", s[i].val + 64); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 496 | onekey(keystr, s[i].desc); |
| 497 | |
| 498 | for (j = 0; j < k; j++) |
| 499 | waddch(bottomwin, ' '); |
| 500 | } |
| 501 | |
| 502 | wrefresh(bottomwin); |
| 503 | |
| 504 | } |
| 505 | |
| 506 | /* If modified is not already set, set it and update titlebar */ |
| 507 | void set_modified(void) |
| 508 | { |
| 509 | if (!ISSET(MODIFIED)) { |
| 510 | SET(MODIFIED); |
| 511 | titlebar(); |
| 512 | wrefresh(topwin); |
| 513 | } |
| 514 | } |
| 515 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 516 | /* And so start the display update routines */ |
| 517 | /* Given a column, this returns the "page" it is on */ |
| 518 | /* "page" in the case of the display columns, means which set of 80 */ |
| 519 | /* characters is viewable (ie: page 1 shows from 1 to COLS) */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 520 | inline int get_page_from_virtual(int virtual) |
| 521 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 522 | int page = 2; |
| 523 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 524 | if (virtual <= COLS - 2) |
| 525 | return 1; |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 526 | virtual -= (COLS - 2); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 527 | |
| 528 | while (virtual > COLS - 2 - 7) { |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 529 | virtual -= (COLS - 2 - 7); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 530 | page++; |
| 531 | } |
| 532 | |
| 533 | return page; |
| 534 | } |
| 535 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 536 | /* The inverse of the above function */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 537 | inline int get_page_start_virtual(int page) |
| 538 | { |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 539 | int virtual; |
| 540 | virtual = --page * (COLS - 7); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 541 | if (page) |
| 542 | virtual -= 2 * page - 1; |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 543 | return virtual; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 546 | inline int get_page_end_virtual(int page) |
| 547 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 548 | return get_page_start_virtual(page) + COLS - 1; |
| 549 | } |
| 550 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 551 | #ifndef NANO_SMALL |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 552 | /* This takes care of the case where there is a mark that covers only */ |
| 553 | /* the current line. */ |
| 554 | |
Chris Allegretta | b275aac | 2000-07-08 01:22:33 +0000 | [diff] [blame] | 555 | /* It expects a line with no tab characers (ie: the type that edit_add */ |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 556 | /* deals with */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 557 | void add_marked_sameline(int begin, int end, filestruct * fileptr, int y, |
| 558 | int virt_cur_x, int this_page) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 559 | { |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 560 | /* |
| 561 | * The general idea is to break the line up into 3 sections: before |
| 562 | * the mark, the mark, and after the mark. We then paint each in |
| 563 | * turn (for those that are currently visible, of course |
| 564 | * |
| 565 | * 3 start points: 0 -> begin, begin->end, end->strlen(data) |
| 566 | * in data : pre sel post |
| 567 | */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 568 | int this_page_start = get_page_start_virtual(this_page), |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 569 | this_page_end = get_page_end_virtual(this_page); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 570 | |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 571 | /* likewise, 3 data lengths */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 572 | int pre_data_len = begin, sel_data_len = end - begin, post_data_len = 0; /* Determined from the other two */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 573 | |
| 574 | /* now fix the start locations & lengths according to the cursor's |
| 575 | * position (ie: our page) */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 576 | if (pre_data_len < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 577 | pre_data_len = 0; |
| 578 | else |
| 579 | pre_data_len -= this_page_start; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 580 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 581 | if (begin < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 582 | begin = this_page_start; |
| 583 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 584 | if (end < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 585 | end = this_page_start; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 586 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 587 | if (begin > this_page_end) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 588 | begin = this_page_end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 589 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 590 | if (end > this_page_end) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 591 | end = this_page_end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 592 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 593 | /* Now calculate the lengths */ |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 594 | sel_data_len = end - begin; |
| 595 | post_data_len = this_page_end - end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 596 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 597 | /* Paint this line! */ |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 598 | mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 599 | wattron(edit, A_REVERSE); |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 600 | mvwaddnstr(edit, y, begin - this_page_start, |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 601 | &fileptr->data[begin], sel_data_len); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 602 | wattroff(edit, A_REVERSE); |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 603 | mvwaddnstr(edit, y, end - this_page_start, |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 604 | &fileptr->data[end], post_data_len); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 605 | } |
| 606 | #endif |
| 607 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 608 | /* edit_add takes care of the job of actually painting a line into the |
| 609 | * edit window. |
| 610 | * |
| 611 | * Called only from update_line. Expects a converted-to-not-have-tabs |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 612 | * line */ |
| 613 | void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x, |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 614 | int virt_mark_beginx, int this_page) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 615 | { |
| 616 | #ifndef NANO_SMALL |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 617 | /* There are quite a few cases that could take place, we'll deal |
| 618 | * with them each in turn */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 619 | if (ISSET(MARK_ISSET) |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 620 | && !((fileptr->lineno > mark_beginbuf->lineno |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 621 | && fileptr->lineno > current->lineno) |
| 622 | || (fileptr->lineno < mark_beginbuf->lineno |
| 623 | && fileptr->lineno < current->lineno))) { |
| 624 | /* If we get here we are on a line that is atleast |
| 625 | * partially selected. The lineno checks above determined |
| 626 | * that */ |
| 627 | if (fileptr != mark_beginbuf && fileptr != current) { |
| 628 | /* We are on a completely marked line, paint it all |
| 629 | * inverse */ |
| 630 | wattron(edit, A_REVERSE); |
| 631 | mvwaddnstr(edit, yval, 0, fileptr->data, COLS); |
| 632 | wattroff(edit, A_REVERSE); |
| 633 | } else if (fileptr == mark_beginbuf && fileptr == current) { |
| 634 | /* Special case, we're still on the same line we started |
| 635 | * marking -- so we call our helper function */ |
| 636 | if (virt_cur_x < virt_mark_beginx) { |
| 637 | /* To the right of us is marked */ |
| 638 | add_marked_sameline(virt_cur_x, virt_mark_beginx, |
| 639 | fileptr, yval, virt_cur_x, this_page); |
| 640 | } else { |
| 641 | /* To the left of us is marked */ |
| 642 | add_marked_sameline(virt_mark_beginx, virt_cur_x, |
| 643 | fileptr, yval, virt_cur_x, this_page); |
| 644 | } |
| 645 | } else if (fileptr == mark_beginbuf) { |
| 646 | /* |
| 647 | * we're updating the line that was first marked |
| 648 | * but we're not currently on it. So we want to |
| 649 | * figur out which half to invert based on our |
| 650 | * relative line numbers. |
| 651 | * |
| 652 | * i.e. If we're above the "beginbuf" line, we want to |
| 653 | * mark the left side. Otherwise we're below, so we |
| 654 | * mark the right |
| 655 | */ |
| 656 | int target; |
| 657 | |
| 658 | if (mark_beginbuf->lineno > current->lineno) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 659 | wattron(edit, A_REVERSE); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 660 | |
| 661 | target = |
| 662 | (virt_mark_beginx < |
| 663 | COLS - 1) ? virt_mark_beginx : COLS - 1; |
| 664 | |
| 665 | mvwaddnstr(edit, yval, 0, fileptr->data, target); |
| 666 | |
| 667 | if (mark_beginbuf->lineno < current->lineno) |
| 668 | wattron(edit, A_REVERSE); |
| 669 | else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 670 | wattroff(edit, A_REVERSE); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 671 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 672 | target = (COLS - 1) - virt_mark_beginx; |
| 673 | if (target < 0) |
| 674 | target = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 675 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 676 | mvwaddnstr(edit, yval, virt_mark_beginx, |
| 677 | &fileptr->data[virt_mark_beginx], target); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 678 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 679 | if (mark_beginbuf->lineno < current->lineno) |
| 680 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 681 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 682 | } else if (fileptr == current) { |
| 683 | /* we're on the cursors line, but it's not the first |
| 684 | * one we marked. Similar to the previous logic. */ |
| 685 | int this_page_start = get_page_start_virtual(this_page), |
| 686 | this_page_end = get_page_end_virtual(this_page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 687 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 688 | if (mark_beginbuf->lineno < current->lineno) |
| 689 | wattron(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 690 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 691 | if (virt_cur_x > COLS - 2) { |
| 692 | mvwaddnstr(edit, yval, 0, |
| 693 | &fileptr->data[this_page_start], |
| 694 | virt_cur_x - this_page_start); |
| 695 | } else { |
| 696 | mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x); |
| 697 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 698 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 699 | if (mark_beginbuf->lineno > current->lineno) |
| 700 | wattron(edit, A_REVERSE); |
| 701 | else |
| 702 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 703 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 704 | if (virt_cur_x > COLS - 2) |
| 705 | mvwaddnstr(edit, yval, virt_cur_x - this_page_start, |
| 706 | &fileptr->data[virt_cur_x], |
| 707 | this_page_end - virt_cur_x); |
| 708 | else |
| 709 | mvwaddnstr(edit, yval, virt_cur_x, |
| 710 | &fileptr->data[virt_cur_x], COLS - virt_cur_x); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 711 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 712 | if (mark_beginbuf->lineno > current->lineno) |
| 713 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | } else |
| 717 | #endif |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 718 | /* Just paint the string (no mark on this line) */ |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 719 | mvwaddnstr(edit, yval, 0, &fileptr->data[start], |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 720 | get_page_end_virtual(this_page) - start); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /* |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 724 | * Just update one line in the edit buffer. Basically a wrapper for |
| 725 | * edit_add |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 726 | * |
| 727 | * index gives is a place in the string to update starting from. |
| 728 | * Likely args are current_x or 0. |
| 729 | */ |
| 730 | void update_line(filestruct * fileptr, int index) |
| 731 | { |
| 732 | filestruct *filetmp; |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 733 | int line = 0, col = 0; |
| 734 | int virt_cur_x = current_x, virt_mark_beginx = mark_beginx; |
| 735 | char *realdata, *tmp; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 736 | int i, pos, len, page; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 737 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 738 | if (!fileptr) |
| 739 | return; |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 740 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 741 | /* First, blank out the line (at a minimum) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 742 | for (filetmp = edittop; filetmp != fileptr && filetmp != editbot; |
| 743 | filetmp = filetmp->next) |
| 744 | line++; |
| 745 | |
| 746 | mvwaddstr(edit, line, 0, hblank); |
| 747 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 748 | /* Next, convert all the tabs to spaces so everything else is easy */ |
| 749 | index = xpt(fileptr, index); |
| 750 | |
| 751 | realdata = fileptr->data; |
| 752 | len = strlen(realdata); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 753 | fileptr->data = nmalloc(xpt(fileptr, len) + 1); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 754 | |
| 755 | pos = 0; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 756 | for (i = 0; i < len; i++) { |
| 757 | if (realdata[i] == '\t') { |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 758 | do { |
| 759 | fileptr->data[pos++] = ' '; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 760 | if (i < current_x) |
| 761 | virt_cur_x++; |
| 762 | if (i < mark_beginx) |
| 763 | virt_mark_beginx++; |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 764 | } while (pos % tabsize); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 765 | /* must decrement once to account for tab-is-one-character */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 766 | if (i < current_x) |
| 767 | virt_cur_x--; |
| 768 | if (i < mark_beginx) |
| 769 | virt_mark_beginx--; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 770 | } else if (realdata[i] >= 1 && realdata[i] <= 26) { |
| 771 | /* Treat control characters as ^letter */ |
Chris Allegretta | 6306a11 | 2000-09-02 07:55:41 +0000 | [diff] [blame] | 772 | fileptr->data[pos++] = '^'; |
| 773 | fileptr->data[pos++] = realdata[i] + 64; |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 774 | } else { |
| 775 | fileptr->data[pos++] = realdata[i]; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | fileptr->data[pos] = '\0'; |
| 780 | |
| 781 | /* Now, Paint the line */ |
| 782 | if (current == fileptr && index > COLS - 2) { |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 783 | /* This handles when the current line is beyond COLS */ |
| 784 | /* It requires figureing out what page we're at */ |
| 785 | page = get_page_from_virtual(index); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 786 | col = get_page_start_virtual(page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 787 | |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 788 | edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 789 | mvwaddch(edit, line, 0, '$'); |
| 790 | |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 791 | if (strlenpt(fileptr->data) > get_page_end_virtual(page)) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 792 | mvwaddch(edit, line, COLS - 1, '$'); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 793 | } else { |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 794 | /* It's not the current line means that it's at x=0 and page=1 */ |
| 795 | /* If it is the current line, then we're in the same boat */ |
| 796 | edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 797 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 798 | if (strlenpt(&filetmp->data[col]) > COLS) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 799 | mvwaddch(edit, line, COLS - 1, '$'); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 800 | } |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 801 | |
| 802 | /* Clean up our mess */ |
| 803 | tmp = fileptr->data; |
| 804 | fileptr->data = realdata; |
| 805 | free(tmp); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | void center_cursor(void) |
| 809 | { |
| 810 | current_y = editwinrows / 2; |
| 811 | wmove(edit, current_y, current_x); |
| 812 | } |
| 813 | |
| 814 | /* Refresh the screen without changing the position of lines */ |
| 815 | void edit_refresh(void) |
| 816 | { |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 817 | static int noloop = 0; |
Chris Allegretta | 95b0b52 | 2000-07-28 02:58:06 +0000 | [diff] [blame] | 818 | int lines = 0, i = 0, currentcheck = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 819 | filestruct *temp, *hold = current; |
| 820 | |
| 821 | if (current == NULL) |
| 822 | return; |
| 823 | |
| 824 | temp = edittop; |
| 825 | |
| 826 | while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) { |
| 827 | hold = temp; |
| 828 | update_line(temp, current_x); |
Chris Allegretta | 95b0b52 | 2000-07-28 02:58:06 +0000 | [diff] [blame] | 829 | if (temp == current) |
| 830 | currentcheck = 1; |
| 831 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 832 | temp = temp->next; |
| 833 | lines++; |
| 834 | } |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 835 | /* If noloop == 1, then we already did an edit_update without finishing |
| 836 | this function. So we don't run edit_update again */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 837 | if (!currentcheck && !noloop) { /* Then current has run off the screen... */ |
Chris Allegretta | da721be | 2000-07-31 01:26:42 +0000 | [diff] [blame] | 838 | edit_update(current, CENTER); |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 839 | noloop = 1; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 840 | } else if (noloop) |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 841 | noloop = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 842 | |
| 843 | if (lines <= editwinrows - 1) |
| 844 | while (lines <= editwinrows - 1) { |
| 845 | mvwaddstr(edit, lines, i, hblank); |
| 846 | lines++; |
| 847 | } |
| 848 | if (temp == NULL) |
| 849 | editbot = hold; |
| 850 | else |
| 851 | editbot = temp; |
| 852 | } |
| 853 | |
| 854 | /* |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 855 | * Same as above, but touch the window first so everything is redrawn. |
| 856 | */ |
| 857 | void edit_refresh_clearok(void) |
| 858 | { |
| 859 | clearok(edit, TRUE); |
| 860 | edit_refresh(); |
| 861 | clearok(edit, FALSE); |
| 862 | } |
| 863 | |
| 864 | /* |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 865 | * Nice generic routine to update the edit buffer given a pointer to the |
| 866 | * file struct =) |
| 867 | */ |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 868 | void edit_update(filestruct * fileptr, int topmidbot) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 869 | { |
Robert Siemborski | 29e9a76 | 2000-07-05 03:16:04 +0000 | [diff] [blame] | 870 | int i = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 871 | filestruct *temp; |
| 872 | |
| 873 | if (fileptr == NULL) |
| 874 | return; |
| 875 | |
| 876 | temp = fileptr; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 877 | if (topmidbot == 2); |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 878 | else if (topmidbot == 0) |
| 879 | for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++) |
| 880 | temp = temp->prev; |
| 881 | else |
| 882 | for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++) |
| 883 | temp = temp->prev; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 884 | |
Robert Siemborski | 29e9a76 | 2000-07-05 03:16:04 +0000 | [diff] [blame] | 885 | edittop = temp; |
| 886 | fix_editbot(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 887 | |
| 888 | edit_refresh(); |
| 889 | } |
| 890 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 891 | /* This function updates current based on where current_y is, reset_cursor |
| 892 | does the opposite */ |
| 893 | void update_cursor(void) |
| 894 | { |
| 895 | int i = 0; |
| 896 | |
| 897 | #ifdef DEBUG |
| 898 | fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y, |
| 899 | current_x); |
| 900 | #endif |
| 901 | |
| 902 | current = edittop; |
| 903 | while (i <= current_y - 1 && current->next != NULL) { |
| 904 | current = current->next; |
| 905 | i++; |
| 906 | } |
| 907 | |
| 908 | #ifdef DEBUG |
| 909 | fprintf(stderr, _("current->data = \"%s\"\n"), current->data); |
| 910 | #endif |
| 911 | |
| 912 | } |
| 913 | |
| 914 | /* |
| 915 | * Ask a question on the statusbar. Answer will be stored in answer |
| 916 | * global. Returns -1 on aborted enter, -2 on a blank string, and 0 |
| 917 | * otherwise, the valid shortcut key caught, Def is any editable text we |
| 918 | * want to put up by default. |
| 919 | */ |
| 920 | int statusq(shortcut s[], int slen, char *def, char *msg, ...) |
| 921 | { |
| 922 | va_list ap; |
| 923 | char foo[133]; |
| 924 | int ret; |
| 925 | |
| 926 | bottombars(s, slen); |
| 927 | |
| 928 | va_start(ap, msg); |
| 929 | vsnprintf(foo, 132, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 930 | va_end(ap); |
Chris Allegretta | a4d2162 | 2000-07-08 23:57:03 +0000 | [diff] [blame] | 931 | strncat(foo, ": ", 132); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 932 | |
| 933 | wattron(bottomwin, A_REVERSE); |
| 934 | ret = nanogetstr(foo, def, s, slen, (strlen(foo) + 3)); |
| 935 | wattroff(bottomwin, A_REVERSE); |
| 936 | |
| 937 | switch (ret) { |
| 938 | |
| 939 | case NANO_FIRSTLINE_KEY: |
| 940 | do_first_line(); |
| 941 | break; |
| 942 | case NANO_LASTLINE_KEY: |
| 943 | do_last_line(); |
| 944 | break; |
| 945 | case NANO_CANCEL_KEY: |
| 946 | return -1; |
| 947 | default: |
| 948 | blank_statusbar_refresh(); |
| 949 | } |
| 950 | |
| 951 | #ifdef DEBUG |
| 952 | fprintf(stderr, _("I got \"%s\"\n"), answer); |
| 953 | #endif |
| 954 | |
| 955 | return ret; |
| 956 | } |
| 957 | |
| 958 | /* |
| 959 | * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for |
| 960 | * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C) |
| 961 | */ |
| 962 | int do_yesno(int all, int leavecursor, char *msg, ...) |
| 963 | { |
| 964 | va_list ap; |
| 965 | char foo[133]; |
| 966 | int kbinput, ok = -1; |
| 967 | |
| 968 | /* Write the bottom of the screen */ |
| 969 | clear_bottomwin(); |
| 970 | wattron(bottomwin, A_REVERSE); |
| 971 | blank_statusbar_refresh(); |
| 972 | wattroff(bottomwin, A_REVERSE); |
| 973 | |
Jordi Mallach | 0b0fc49 | 2000-06-23 01:00:13 +0000 | [diff] [blame] | 974 | /* Remove gettext call for keybindings until we clear the thing up */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 975 | if (!ISSET(NO_HELP)) { |
| 976 | wmove(bottomwin, 1, 0); |
Jordi Mallach | 0b0fc49 | 2000-06-23 01:00:13 +0000 | [diff] [blame] | 977 | onekey(" Y", _("Yes")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 978 | if (all) |
Jordi Mallach | 0b0fc49 | 2000-06-23 01:00:13 +0000 | [diff] [blame] | 979 | onekey(" A", _("All")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 980 | wmove(bottomwin, 2, 0); |
Jordi Mallach | 0b0fc49 | 2000-06-23 01:00:13 +0000 | [diff] [blame] | 981 | onekey(" N", _("No")); |
| 982 | onekey("^C", _("Cancel")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 983 | } |
| 984 | va_start(ap, msg); |
| 985 | vsnprintf(foo, 132, msg, ap); |
| 986 | va_end(ap); |
| 987 | wattron(bottomwin, A_REVERSE); |
| 988 | mvwaddstr(bottomwin, 0, 0, foo); |
| 989 | wattroff(bottomwin, A_REVERSE); |
| 990 | wrefresh(bottomwin); |
| 991 | |
| 992 | if (leavecursor == 1) |
| 993 | reset_cursor(); |
| 994 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 995 | while (ok == -1) { |
| 996 | kbinput = wgetch(edit); |
| 997 | |
| 998 | switch (kbinput) { |
| 999 | case 'Y': |
| 1000 | case 'y': |
| 1001 | ok = 1; |
| 1002 | break; |
| 1003 | case 'N': |
| 1004 | case 'n': |
| 1005 | ok = 0; |
| 1006 | break; |
| 1007 | case 'A': |
| 1008 | case 'a': |
| 1009 | if (all) |
| 1010 | ok = 2; |
| 1011 | break; |
| 1012 | case NANO_CONTROL_C: |
| 1013 | ok = -2; |
| 1014 | break; |
| 1015 | } |
| 1016 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1017 | |
| 1018 | /* Then blank the screen */ |
| 1019 | blank_statusbar_refresh(); |
| 1020 | |
| 1021 | if (ok == -2) |
| 1022 | return -1; |
| 1023 | else |
| 1024 | return ok; |
| 1025 | } |
| 1026 | |
| 1027 | void statusbar(char *msg, ...) |
| 1028 | { |
| 1029 | va_list ap; |
| 1030 | char foo[133]; |
| 1031 | int start_x = 0; |
| 1032 | |
| 1033 | va_start(ap, msg); |
| 1034 | vsnprintf(foo, 132, msg, ap); |
| 1035 | va_end(ap); |
| 1036 | |
| 1037 | start_x = center_x - strlen(foo) / 2 - 1; |
| 1038 | |
| 1039 | /* Blank out line */ |
| 1040 | blank_statusbar(); |
| 1041 | |
| 1042 | wmove(bottomwin, 0, start_x); |
| 1043 | |
| 1044 | wattron(bottomwin, A_REVERSE); |
| 1045 | |
| 1046 | waddstr(bottomwin, "[ "); |
| 1047 | waddstr(bottomwin, foo); |
| 1048 | waddstr(bottomwin, " ]"); |
| 1049 | wattroff(bottomwin, A_REVERSE); |
| 1050 | wrefresh(bottomwin); |
| 1051 | |
| 1052 | if (ISSET(CONSTUPDATE)) |
| 1053 | statblank = 1; |
| 1054 | else |
| 1055 | statblank = 25; |
| 1056 | } |
| 1057 | |
| 1058 | void display_main_list(void) |
| 1059 | { |
| 1060 | bottombars(main_list, MAIN_VISIBLE); |
| 1061 | } |
| 1062 | |
| 1063 | int total_refresh(void) |
| 1064 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1065 | clearok(edit, TRUE); |
| 1066 | clearok(topwin, TRUE); |
| 1067 | clearok(bottomwin, TRUE); |
| 1068 | wnoutrefresh(edit); |
| 1069 | wnoutrefresh(topwin); |
| 1070 | wnoutrefresh(bottomwin); |
| 1071 | doupdate(); |
| 1072 | clearok(edit, FALSE); |
| 1073 | clearok(topwin, FALSE); |
| 1074 | clearok(bottomwin, FALSE); |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 1075 | edit_refresh(); |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1076 | titlebar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1077 | return 1; |
| 1078 | } |
| 1079 | |
| 1080 | void previous_line(void) |
| 1081 | { |
| 1082 | if (current_y > 0) |
| 1083 | current_y--; |
| 1084 | } |
| 1085 | |
| 1086 | int do_cursorpos(void) |
| 1087 | { |
| 1088 | filestruct *fileptr; |
| 1089 | float linepct, bytepct; |
| 1090 | int i, tot = 0; |
| 1091 | |
| 1092 | if (current == NULL || fileage == NULL) |
| 1093 | return 0; |
| 1094 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1095 | for (fileptr = fileage; fileptr != current && fileptr != NULL; |
| 1096 | fileptr = fileptr->next) |
| 1097 | tot += strlen(fileptr->data) + 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1098 | |
| 1099 | if (fileptr == NULL) |
| 1100 | return -1; |
| 1101 | |
| 1102 | i = tot + current_x;; |
| 1103 | |
| 1104 | for (fileptr = current->next; fileptr != NULL; fileptr = fileptr->next) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1105 | tot += strlen(fileptr->data) + 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1106 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1107 | if (totlines > 0) |
| 1108 | linepct = 100 * current->lineno / totlines; |
| 1109 | else |
| 1110 | linepct = 0; |
| 1111 | |
| 1112 | if (totsize > 0) |
| 1113 | bytepct = 100 * i / totsize; |
| 1114 | else |
| 1115 | bytepct = 0; |
| 1116 | |
| 1117 | #ifdef DEBUG |
| 1118 | fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"), |
| 1119 | linepct, bytepct); |
| 1120 | #endif |
| 1121 | |
| 1122 | statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"), |
| 1123 | current->lineno, totlines, linepct, i, totsize, bytepct); |
| 1124 | reset_cursor(); |
| 1125 | return 1; |
| 1126 | } |
| 1127 | |
| 1128 | /* Our broken, non-shortcut list compliant help function. |
| 1129 | But hey, it's better than nothing, and it's dynamic! */ |
| 1130 | int do_help(void) |
| 1131 | { |
| 1132 | #ifndef NANO_SMALL |
| 1133 | char *ptr = help_text, *end; |
| 1134 | int i, j, row = 0, page = 1, kbinput = 0, no_more = 0; |
| 1135 | int no_help_flag = 0; |
| 1136 | |
| 1137 | blank_edit(); |
| 1138 | curs_set(0); |
| 1139 | blank_statusbar(); |
| 1140 | |
| 1141 | if (ISSET(NO_HELP)) { |
| 1142 | |
| 1143 | no_help_flag = 1; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1144 | delwin(bottomwin); |
| 1145 | bottomwin = newwin(3, COLS, LINES - 3, 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1146 | keypad(bottomwin, TRUE); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1147 | |
| 1148 | editwinrows -= no_help(); |
| 1149 | UNSET(NO_HELP); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1150 | bottombars(help_list, HELP_LIST_LEN); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1151 | } else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1152 | bottombars(help_list, HELP_LIST_LEN); |
| 1153 | |
| 1154 | do { |
| 1155 | ptr = help_text; |
| 1156 | switch (kbinput) { |
| 1157 | case NANO_NEXTPAGE_KEY: |
| 1158 | case NANO_NEXTPAGE_FKEY: |
| 1159 | case KEY_NPAGE: |
| 1160 | if (!no_more) { |
| 1161 | blank_edit(); |
| 1162 | page++; |
| 1163 | } |
| 1164 | break; |
| 1165 | case NANO_PREVPAGE_KEY: |
| 1166 | case NANO_PREVPAGE_FKEY: |
| 1167 | case KEY_PPAGE: |
| 1168 | if (page > 1) { |
| 1169 | no_more = 0; |
| 1170 | blank_edit(); |
| 1171 | page--; |
| 1172 | } |
| 1173 | break; |
| 1174 | } |
| 1175 | |
| 1176 | /* Calculate where in the text we should be based on the page */ |
| 1177 | for (i = 1; i < page; i++) { |
| 1178 | row = 0; |
| 1179 | j = 0; |
Chris Allegretta | 44e73df | 2000-09-07 03:37:38 +0000 | [diff] [blame] | 1180 | |
| 1181 | while (row < editwinrows - 2 && *ptr != '\0') { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1182 | if (*ptr == '\n' || j == COLS - 5) { |
| 1183 | j = 0; |
| 1184 | row++; |
| 1185 | } |
| 1186 | ptr++; |
| 1187 | j++; |
| 1188 | } |
| 1189 | } |
| 1190 | |
Chris Allegretta | 44e73df | 2000-09-07 03:37:38 +0000 | [diff] [blame] | 1191 | if (i > 1) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1192 | |
Chris Allegretta | 44e73df | 2000-09-07 03:37:38 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1195 | i = 0; |
| 1196 | j = 0; |
| 1197 | while (i < editwinrows && *ptr != '\0') { |
| 1198 | end = ptr; |
| 1199 | while (*end != '\n' && *end != '\0' && j != COLS - 5) { |
| 1200 | end++; |
| 1201 | j++; |
| 1202 | } |
| 1203 | if (j == COLS - 5) { |
| 1204 | |
| 1205 | /* Don't print half a word if we've run of of space */ |
| 1206 | while (*end != ' ' && *end != '\0') { |
| 1207 | end--; |
| 1208 | j--; |
| 1209 | } |
| 1210 | } |
| 1211 | mvwaddnstr(edit, i, 0, ptr, j); |
| 1212 | j = 0; |
| 1213 | i++; |
| 1214 | if (*end == '\n') |
| 1215 | end++; |
| 1216 | ptr = end; |
| 1217 | } |
| 1218 | if (*ptr == '\0') { |
| 1219 | no_more = 1; |
| 1220 | continue; |
| 1221 | } |
| 1222 | } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1223 | if (no_help_flag) { |
| 1224 | werase(bottomwin); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1225 | wrefresh(bottomwin); |
| 1226 | delwin(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1227 | SET(NO_HELP); |
| 1228 | bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0); |
| 1229 | keypad(bottomwin, TRUE); |
| 1230 | editwinrows += no_help(); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1231 | } else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1232 | display_main_list(); |
| 1233 | |
| 1234 | curs_set(1); |
| 1235 | edit_refresh(); |
| 1236 | #else |
| 1237 | nano_small_msg(); |
| 1238 | #endif |
| 1239 | |
| 1240 | return 1; |
| 1241 | } |
| 1242 | |
| 1243 | /* Dump the current file structure to stderr */ |
| 1244 | void dump_buffer(filestruct * inptr) |
| 1245 | { |
| 1246 | #ifdef DEBUG |
| 1247 | filestruct *fileptr; |
| 1248 | |
| 1249 | if (inptr == fileage) |
| 1250 | fprintf(stderr, _("Dumping file buffer to stderr...\n")); |
| 1251 | else if (inptr == cutbuffer) |
| 1252 | fprintf(stderr, _("Dumping cutbuffer to stderr...\n")); |
| 1253 | else |
| 1254 | fprintf(stderr, _("Dumping a buffer to stderr...\n")); |
| 1255 | |
| 1256 | fileptr = inptr; |
| 1257 | while (fileptr != NULL) { |
| 1258 | fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data); |
| 1259 | fflush(stderr); |
| 1260 | fileptr = fileptr->next; |
| 1261 | } |
| 1262 | #endif /* DEBUG */ |
| 1263 | } |
| 1264 | |
| 1265 | void dump_buffer_reverse(filestruct * inptr) |
| 1266 | { |
| 1267 | #ifdef DEBUG |
| 1268 | filestruct *fileptr; |
| 1269 | |
| 1270 | fileptr = filebot; |
| 1271 | while (fileptr != NULL) { |
| 1272 | fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data); |
| 1273 | fflush(stderr); |
| 1274 | fileptr = fileptr->prev; |
| 1275 | } |
| 1276 | #endif /* DEBUG */ |
| 1277 | } |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1278 | |
| 1279 | /* Fix editbot based on the assumption that edittop is correct */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1280 | void fix_editbot(void) |
| 1281 | { |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1282 | int i; |
| 1283 | editbot = edittop; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1284 | for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL) |
| 1285 | && (editbot != filebot); i++, editbot = editbot->next); |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1286 | } |