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