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 | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 25 | #include <unistd.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 26 | #include "config.h" |
| 27 | #include "proto.h" |
| 28 | #include "nano.h" |
| 29 | |
| 30 | #ifndef NANO_SMALL |
| 31 | #include <libintl.h> |
| 32 | #define _(string) gettext(string) |
| 33 | #else |
| 34 | #define _(string) (string) |
| 35 | #endif |
| 36 | |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 37 | |
| 38 | /* winio.c statics */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 39 | static int statblank = 0; /* Number of keystrokes left after |
| 40 | we call statubar() before we |
| 41 | actually blank the statusbar */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 42 | |
| 43 | /* Local Function Prototypes for only winio.c */ |
| 44 | inline int get_page_from_virtual(int virtual); |
| 45 | inline int get_page_start_virtual(int page); |
| 46 | inline int get_page_end_virtual(int page); |
| 47 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 48 | /* Window I/O */ |
| 49 | |
| 50 | int do_first_line(void) |
| 51 | { |
| 52 | current = fileage; |
| 53 | placewewant = 0; |
| 54 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 55 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 56 | return 1; |
| 57 | } |
| 58 | |
| 59 | int do_last_line(void) |
| 60 | { |
| 61 | current = filebot; |
| 62 | placewewant = 0; |
| 63 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 64 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | /* Like xplustabs, but for a specifc index of a speficific filestruct */ |
| 69 | int xpt(filestruct * fileptr, int index) |
| 70 | { |
| 71 | int i, tabs = 0; |
| 72 | |
| 73 | if (fileptr == NULL || fileptr->data == NULL) |
| 74 | return 0; |
| 75 | |
| 76 | for (i = 0; i < index && fileptr->data[i] != 0; i++) { |
| 77 | tabs++; |
| 78 | |
| 79 | if (fileptr->data[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 80 | if (tabs % tabsize == 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 81 | else |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 82 | tabs += tabsize - (tabs % tabsize); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 83 | } else if (fileptr->data[i] & 0x80) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 84 | /* Make 8 bit chars only 1 collumn! */ |
| 85 | ; |
| 86 | else if (fileptr->data[i] < 32) |
| 87 | tabs++; |
| 88 | } |
| 89 | |
| 90 | return tabs; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | /* Return the actual place on the screen of current->data[current_x], which |
| 95 | should always be > current_x */ |
| 96 | int xplustabs(void) |
| 97 | { |
| 98 | return xpt(current, current_x); |
| 99 | } |
| 100 | |
| 101 | |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 102 | /* Return what current_x should be, given xplustabs() for the line, |
| 103 | * given a start position in the filestruct's data */ |
| 104 | int actual_x_from_start(filestruct * fileptr, int xplus, int start) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 105 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 106 | int i, tot = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 107 | |
| 108 | if (fileptr == NULL || fileptr->data == NULL) |
| 109 | return 0; |
| 110 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 111 | for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 112 | if (fileptr->data[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 113 | if (tot % tabsize == 0) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 114 | tot++; |
| 115 | else |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 116 | tot += tabsize - (tot % tabsize); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 117 | } else if (fileptr->data[i] & 0x80) |
| 118 | tot++; /* Make 8 bit chars only 1 column (again) */ |
| 119 | else if (fileptr->data[i] < 32) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 120 | tot += 2; |
| 121 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 122 | #ifdef DEBUG |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 123 | fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"), |
| 124 | xplus, i); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 125 | #endif |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 126 | return i - start; |
| 127 | } |
| 128 | |
| 129 | /* Opposite of xplustabs */ |
| 130 | inline int actual_x(filestruct * fileptr, int xplus) |
| 131 | { |
| 132 | return actual_x_from_start(fileptr, xplus, 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* a strlen with tabs factored in, similar to xplustabs() */ |
| 136 | int strlenpt(char *buf) |
| 137 | { |
| 138 | int i, tabs = 0; |
| 139 | |
| 140 | if (buf == NULL) |
| 141 | return 0; |
| 142 | |
| 143 | for (i = 0; buf[i] != 0; i++) { |
| 144 | tabs++; |
| 145 | |
| 146 | if (buf[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 147 | if (tabs % tabsize == 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 148 | else |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 149 | tabs += tabsize - (tabs % tabsize); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 150 | } else if (buf[i] & 0x80) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 151 | /* Make 8 bit chars only 1 collumn! */ |
| 152 | ; |
| 153 | else if (buf[i] < 32) |
| 154 | tabs++; |
| 155 | } |
| 156 | |
| 157 | return tabs; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | /* resets current_y based on the position of current and puts the cursor at |
| 162 | (current_y, current_x) */ |
| 163 | void reset_cursor(void) |
| 164 | { |
| 165 | filestruct *ptr = edittop; |
| 166 | int x; |
| 167 | |
| 168 | current_y = 0; |
| 169 | |
| 170 | while (ptr != current && ptr != editbot && ptr->next != NULL) { |
| 171 | ptr = ptr->next; |
| 172 | current_y++; |
| 173 | } |
| 174 | |
| 175 | x = xplustabs(); |
| 176 | if (x <= COLS - 2) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 177 | wmove(edit, current_y, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 178 | else |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 179 | wmove(edit, current_y, x - |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 180 | get_page_start_virtual(get_page_from_virtual(x))); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 181 | |
| 182 | } |
| 183 | |
| 184 | void blank_bottombars(void) |
| 185 | { |
| 186 | int i = no_help()? 3 : 1; |
| 187 | |
| 188 | for (; i <= 2; i++) |
| 189 | mvwaddstr(bottomwin, i, 0, hblank); |
| 190 | |
| 191 | } |
| 192 | |
| 193 | void blank_edit(void) |
| 194 | { |
| 195 | int i; |
| 196 | for (i = 0; i <= editwinrows - 1; i++) |
| 197 | mvwaddstr(edit, i, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
| 201 | void blank_statusbar(void) |
| 202 | { |
| 203 | mvwaddstr(bottomwin, 0, 0, hblank); |
| 204 | } |
| 205 | |
| 206 | void blank_statusbar_refresh(void) |
| 207 | { |
| 208 | blank_statusbar(); |
| 209 | wrefresh(bottomwin); |
| 210 | } |
| 211 | |
| 212 | void check_statblank(void) |
| 213 | { |
| 214 | |
| 215 | if (statblank > 1) |
| 216 | statblank--; |
| 217 | else if (statblank == 1 && !ISSET(CONSTUPDATE)) { |
| 218 | statblank--; |
| 219 | blank_statusbar_refresh(); |
| 220 | } |
| 221 | } |
| 222 | |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 223 | /* Repaint the statusbar when getting a character in nanogetstr */ |
| 224 | void nanoget_repaint(char *buf, char *inputbuf, int x) |
| 225 | { |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 226 | int len = strlen(buf); |
| 227 | int wid = COLS - len; |
| 228 | |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 229 | blank_statusbar(); |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 230 | if (x <= COLS - 1) { |
| 231 | /* Black magic */ |
| 232 | buf[len - 1] = ' '; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 233 | |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 234 | mvwaddstr(bottomwin, 0, 0, buf); |
| 235 | waddnstr(bottomwin, inputbuf, wid); |
| 236 | wmove(bottomwin, 0, (x % COLS)); |
| 237 | } |
| 238 | else { |
| 239 | /* Black magic */ |
| 240 | buf[len - 1] = '$'; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 241 | |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 242 | mvwaddstr(bottomwin, 0, 0, buf); |
| 243 | waddnstr(bottomwin, &inputbuf[wid * ((x - len) / (wid))], wid); |
| 244 | wmove(bottomwin, 0, ((x - len) % wid) + len); |
| 245 | } |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 248 | /* 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] | 249 | int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen, |
| 250 | int start_x) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 251 | { |
| 252 | int kbinput = 0, j = 0, x = 0, xend; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 253 | int x_left = 0, inputlen, tabbed = 0; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 254 | char *inputbuf; |
Rocco Corsi | 06aca1c | 2001-01-11 05:30:31 +0000 | [diff] [blame] | 255 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 256 | int shift = 0; |
| 257 | #endif |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 258 | |
| 259 | inputbuf = nmalloc(strlen(def) + 1); |
| 260 | inputbuf[0] = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 261 | |
| 262 | x_left = strlen(buf); |
| 263 | x = strlen(def) + x_left; |
| 264 | |
| 265 | /* Get the input! */ |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 266 | if (strlen(def) > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 267 | strcpy(inputbuf, def); |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 268 | |
| 269 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 270 | |
Chris Allegretta | 022b96f | 2000-11-14 17:47:58 +0000 | [diff] [blame] | 271 | /* Make sure any editor screen updates are displayed before getting input */ |
| 272 | wrefresh(edit); |
| 273 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 274 | while ((kbinput = wgetch(bottomwin)) != 13) { |
| 275 | for (j = 0; j <= slen - 1; j++) { |
| 276 | if (kbinput == s[j].val) { |
Chris Allegretta | 5bf51d3 | 2000-11-16 06:01:10 +0000 | [diff] [blame] | 277 | |
| 278 | /* We shouldn't discard the answer it gave, just because |
| 279 | we hit a keystroke, GEEZ! */ |
| 280 | answer = mallocstrcpy(answer, inputbuf); |
Chris Allegretta | 92d2bab | 2000-11-02 14:53:46 +0000 | [diff] [blame] | 281 | free(inputbuf); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 282 | return s[j].val; |
| 283 | } |
| 284 | } |
| 285 | xend = strlen(buf) + strlen(inputbuf); |
| 286 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 287 | if (kbinput != '\t') |
| 288 | tabbed = 0; |
| 289 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 290 | switch (kbinput) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 291 | /* Stuff we want to equate with <enter>, ASCII 13 */ |
| 292 | case 343: |
Chris Allegretta | f9b6c9b | 2000-10-18 19:35:59 +0000 | [diff] [blame] | 293 | ungetch(13); /* Enter on iris-ansi $TERM, sometimes */ |
| 294 | break; |
Chris Allegretta | 75155df | 2000-11-28 23:04:24 +0000 | [diff] [blame] | 295 | /* Stuff we want to ignore */ |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 296 | #ifdef PDCURSES |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 297 | case 541: |
| 298 | case 542: |
Chris Allegretta | 7262358 | 2000-11-29 23:43:28 +0000 | [diff] [blame] | 299 | case 543: /* Right ctrl again */ |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 300 | case 544: |
Chris Allegretta | 7262358 | 2000-11-29 23:43:28 +0000 | [diff] [blame] | 301 | case 545: /* Right alt again */ |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 302 | #endif |
Chris Allegretta | 75155df | 2000-11-28 23:04:24 +0000 | [diff] [blame] | 303 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 304 | case KEY_HOME: |
| 305 | x = x_left; |
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 KEY_END: |
| 309 | x = x_left + strlen(inputbuf); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 310 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 311 | break; |
| 312 | case KEY_RIGHT: |
| 313 | |
| 314 | if (x < xend) |
| 315 | x++; |
| 316 | wmove(bottomwin, 0, x); |
| 317 | break; |
| 318 | case NANO_CONTROL_D: |
| 319 | if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) { |
| 320 | memmove(inputbuf + (x - x_left), |
| 321 | inputbuf + (x - x_left) + 1, |
| 322 | strlen(inputbuf) - (x - x_left) - 1); |
| 323 | inputbuf[strlen(inputbuf) - 1] = 0; |
| 324 | } |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 325 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 326 | break; |
| 327 | case NANO_CONTROL_K: |
| 328 | case NANO_CONTROL_U: |
| 329 | *inputbuf = 0; |
| 330 | x = x_left; |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 331 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 332 | break; |
| 333 | case KEY_BACKSPACE: |
| 334 | case KEY_DC: |
| 335 | case 127: |
| 336 | case NANO_CONTROL_H: |
| 337 | if (strlen(inputbuf) > 0) { |
| 338 | if (x == (x_left + strlen(inputbuf))) |
| 339 | inputbuf[strlen(inputbuf) - 1] = 0; |
| 340 | else if (x - x_left) { |
| 341 | memmove(inputbuf + (x - x_left) - 1, |
| 342 | inputbuf + (x - x_left), |
| 343 | strlen(inputbuf) - (x - x_left)); |
| 344 | inputbuf[strlen(inputbuf) - 1] = 0; |
| 345 | } |
| 346 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 347 | if (x > strlen(buf)) |
| 348 | x--; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 349 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 350 | break; |
Rocco Corsi | 06aca1c | 2001-01-11 05:30:31 +0000 | [diff] [blame] | 351 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 352 | case NANO_CONTROL_I: |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 353 | if (allowtabs) { |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 354 | shift = 0; |
| 355 | inputbuf = input_tab(inputbuf, (x - x_left), |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 356 | &tabbed, &shift); |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 357 | x += shift; |
Chris Allegretta | e434b45 | 2001-01-27 19:25:00 +0000 | [diff] [blame] | 358 | if (x - x_left > strlen(inputbuf)) |
| 359 | x = strlen(inputbuf) + x_left; |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 360 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 361 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 362 | break; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 363 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 364 | case KEY_LEFT: |
| 365 | if (x > strlen(buf)) |
| 366 | x--; |
| 367 | wmove(bottomwin, 0, x); |
| 368 | break; |
| 369 | case KEY_UP: |
| 370 | case KEY_DOWN: |
| 371 | break; |
| 372 | |
| 373 | case 27: |
| 374 | switch (kbinput = wgetch(edit)) { |
| 375 | case 79: |
| 376 | switch (kbinput = wgetch(edit)) { |
| 377 | case 70: |
| 378 | x = x_left + strlen(inputbuf); |
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 | case 72: |
| 382 | x = x_left; |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 383 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 384 | break; |
| 385 | } |
| 386 | break; |
| 387 | case 91: |
| 388 | switch (kbinput = wgetch(edit)) { |
| 389 | case 'C': |
| 390 | if (x < xend) |
| 391 | x++; |
| 392 | wmove(bottomwin, 0, x); |
| 393 | break; |
| 394 | case 'D': |
| 395 | if (x > strlen(buf)) |
| 396 | x--; |
| 397 | wmove(bottomwin, 0, x); |
| 398 | break; |
| 399 | case 49: |
| 400 | x = x_left; |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 401 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 402 | goto skip_126; |
| 403 | case 51: |
| 404 | if (strlen(inputbuf) > 0 |
| 405 | && (x - x_left) != strlen(inputbuf)) { |
| 406 | memmove(inputbuf + (x - x_left), |
| 407 | inputbuf + (x - x_left) + 1, |
| 408 | strlen(inputbuf) - (x - x_left) - 1); |
| 409 | inputbuf[strlen(inputbuf) - 1] = 0; |
| 410 | } |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 411 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 412 | goto skip_126; |
| 413 | case 52: |
| 414 | x = x_left + strlen(inputbuf); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 415 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 416 | goto skip_126; |
| 417 | skip_126: |
| 418 | nodelay(edit, TRUE); |
| 419 | kbinput = wgetch(edit); |
| 420 | if (kbinput == 126 || kbinput == ERR) |
| 421 | kbinput = -1; |
| 422 | nodelay(edit, FALSE); |
| 423 | break; |
| 424 | } |
| 425 | } |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 426 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 427 | break; |
| 428 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 429 | default: |
| 430 | if (kbinput < 32) |
| 431 | break; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 432 | |
| 433 | inputlen = strlen(inputbuf); |
| 434 | inputbuf = nrealloc(inputbuf, inputlen + 2); |
| 435 | |
| 436 | memmove(&inputbuf[x - x_left + 1], |
| 437 | &inputbuf[x - x_left], |
| 438 | inputlen - (x - x_left) + 1); |
| 439 | inputbuf[x - x_left] = kbinput; |
| 440 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 441 | x++; |
| 442 | |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 443 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 444 | #ifdef DEBUG |
| 445 | fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput); |
| 446 | #endif |
| 447 | } |
| 448 | wrefresh(bottomwin); |
| 449 | } |
| 450 | |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 451 | answer = mallocstrcpy(answer, inputbuf); |
Chris Allegretta | 92d2bab | 2000-11-02 14:53:46 +0000 | [diff] [blame] | 452 | free(inputbuf); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 453 | |
Chris Allegretta | 105da33 | 2000-10-31 05:10:10 +0000 | [diff] [blame] | 454 | /* Now that the text is editable instead of bracketed, we have to |
| 455 | check for answer == def, instead of answer == "" */ |
Chris Allegretta | bf9a8cc | 2000-11-17 01:37:39 +0000 | [diff] [blame] | 456 | if (((ISSET(PICO_MODE)) && !strcmp(answer, "")) || |
| 457 | ((!ISSET(PICO_MODE)) && !strcmp(answer, def))) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 458 | return -2; |
| 459 | else |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | void horizbar(WINDOW * win, int y) |
| 464 | { |
| 465 | wattron(win, A_REVERSE); |
| 466 | mvwaddstr(win, 0, 0, hblank); |
| 467 | wattroff(win, A_REVERSE); |
| 468 | } |
| 469 | |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 470 | void titlebar(char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 471 | { |
| 472 | int namelen, space; |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 473 | char *what = path; |
| 474 | |
| 475 | if (path == NULL) |
| 476 | what = filename; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 477 | |
| 478 | horizbar(topwin, 0); |
| 479 | wattron(topwin, A_REVERSE); |
| 480 | mvwaddstr(topwin, 0, 3, VERMSG); |
| 481 | |
| 482 | space = COLS - strlen(VERMSG) - strlen(VERSION) - 21; |
| 483 | |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 484 | namelen = strlen(what); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 485 | |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 486 | if (!strcmp(what, "")) |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 487 | mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 488 | else { |
| 489 | if (namelen > space) { |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 490 | if (path == NULL) |
| 491 | waddstr(topwin, _(" File: ...")); |
| 492 | else |
| 493 | waddstr(topwin, _(" DIR: ...")); |
| 494 | waddstr(topwin, &what[namelen - space]); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 495 | } else { |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 496 | if (path == NULL) |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 497 | mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), "File: "); |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 498 | else |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 499 | mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), " DIR: "); |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 500 | waddstr(topwin, what); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | if (ISSET(MODIFIED)) |
| 504 | mvwaddstr(topwin, 0, COLS - 10, _("Modified")); |
| 505 | wattroff(topwin, A_REVERSE); |
| 506 | wrefresh(topwin); |
| 507 | reset_cursor(); |
| 508 | } |
| 509 | |
| 510 | void onekey(char *keystroke, char *desc) |
| 511 | { |
| 512 | char description[80]; |
| 513 | |
Chris Allegretta | e7034c6 | 2000-09-15 03:31:09 +0000 | [diff] [blame] | 514 | snprintf(description, 12, " %-10s", desc); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 515 | wattron(bottomwin, A_REVERSE); |
| 516 | waddstr(bottomwin, keystroke); |
| 517 | wattroff(bottomwin, A_REVERSE); |
| 518 | waddstr(bottomwin, description); |
| 519 | } |
| 520 | |
| 521 | void clear_bottomwin(void) |
| 522 | { |
| 523 | if (ISSET(NO_HELP)) |
| 524 | return; |
| 525 | |
| 526 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 527 | mvwaddstr(bottomwin, 2, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | void bottombars(shortcut s[], int slen) |
| 531 | { |
| 532 | int i, j, k; |
| 533 | char keystr[10]; |
| 534 | |
| 535 | if (ISSET(NO_HELP)) |
| 536 | return; |
| 537 | |
| 538 | /* Determine how many extra spaces are needed to fill the bottom of the screen */ |
| 539 | k = COLS / 6 - 13; |
| 540 | |
| 541 | clear_bottomwin(); |
| 542 | wmove(bottomwin, 1, 0); |
| 543 | for (i = 0; i <= slen - 1; i += 2) { |
Robert Siemborski | 6af1431 | 2000-07-01 21:34:26 +0000 | [diff] [blame] | 544 | snprintf(keystr, 10, "^%c", s[i].val + 64); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 545 | onekey(keystr, s[i].desc); |
| 546 | |
| 547 | for (j = 0; j < k; j++) |
| 548 | waddch(bottomwin, ' '); |
| 549 | } |
| 550 | |
| 551 | wmove(bottomwin, 2, 0); |
| 552 | for (i = 1; i <= slen - 1; i += 2) { |
Robert Siemborski | 6af1431 | 2000-07-01 21:34:26 +0000 | [diff] [blame] | 553 | snprintf(keystr, 10, "^%c", s[i].val + 64); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 554 | onekey(keystr, s[i].desc); |
| 555 | |
| 556 | for (j = 0; j < k; j++) |
| 557 | waddch(bottomwin, ' '); |
| 558 | } |
| 559 | |
| 560 | wrefresh(bottomwin); |
| 561 | |
| 562 | } |
| 563 | |
| 564 | /* If modified is not already set, set it and update titlebar */ |
| 565 | void set_modified(void) |
| 566 | { |
| 567 | if (!ISSET(MODIFIED)) { |
| 568 | SET(MODIFIED); |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 569 | titlebar(NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 570 | wrefresh(topwin); |
| 571 | } |
| 572 | } |
| 573 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 574 | /* And so start the display update routines */ |
| 575 | /* Given a column, this returns the "page" it is on */ |
| 576 | /* "page" in the case of the display columns, means which set of 80 */ |
| 577 | /* characters is viewable (ie: page 1 shows from 1 to COLS) */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 578 | inline int get_page_from_virtual(int virtual) |
| 579 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 580 | int page = 2; |
| 581 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 582 | if (virtual <= COLS - 2) |
| 583 | return 1; |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 584 | virtual -= (COLS - 2); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 585 | |
| 586 | while (virtual > COLS - 2 - 7) { |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 587 | virtual -= (COLS - 2 - 7); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 588 | page++; |
| 589 | } |
| 590 | |
| 591 | return page; |
| 592 | } |
| 593 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 594 | /* The inverse of the above function */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 595 | inline int get_page_start_virtual(int page) |
| 596 | { |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 597 | int virtual; |
| 598 | virtual = --page * (COLS - 7); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 599 | if (page) |
| 600 | virtual -= 2 * page - 1; |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 601 | return virtual; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 604 | inline int get_page_end_virtual(int page) |
| 605 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 606 | return get_page_start_virtual(page) + COLS - 1; |
| 607 | } |
| 608 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 609 | #ifndef NANO_SMALL |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 610 | /* This takes care of the case where there is a mark that covers only */ |
| 611 | /* the current line. */ |
| 612 | |
Chris Allegretta | b275aac | 2000-07-08 01:22:33 +0000 | [diff] [blame] | 613 | /* 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] | 614 | /* deals with */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 615 | void add_marked_sameline(int begin, int end, filestruct * fileptr, int y, |
| 616 | int virt_cur_x, int this_page) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 617 | { |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 618 | /* |
| 619 | * The general idea is to break the line up into 3 sections: before |
| 620 | * the mark, the mark, and after the mark. We then paint each in |
| 621 | * turn (for those that are currently visible, of course |
| 622 | * |
| 623 | * 3 start points: 0 -> begin, begin->end, end->strlen(data) |
| 624 | * in data : pre sel post |
| 625 | */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 626 | int this_page_start = get_page_start_virtual(this_page), |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 627 | this_page_end = get_page_end_virtual(this_page); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 628 | |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 629 | /* likewise, 3 data lengths */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 630 | 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] | 631 | |
| 632 | /* now fix the start locations & lengths according to the cursor's |
| 633 | * position (ie: our page) */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 634 | if (pre_data_len < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 635 | pre_data_len = 0; |
| 636 | else |
| 637 | pre_data_len -= this_page_start; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 638 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 639 | if (begin < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 640 | begin = this_page_start; |
| 641 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 642 | if (end < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 643 | end = this_page_start; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 644 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 645 | if (begin > this_page_end) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 646 | begin = this_page_end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 647 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 648 | if (end > this_page_end) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 649 | end = this_page_end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 650 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 651 | /* Now calculate the lengths */ |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 652 | sel_data_len = end - begin; |
| 653 | post_data_len = this_page_end - end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 654 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 655 | /* Paint this line! */ |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 656 | mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 657 | wattron(edit, A_REVERSE); |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 658 | mvwaddnstr(edit, y, begin - this_page_start, |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 659 | &fileptr->data[begin], sel_data_len); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 660 | wattroff(edit, A_REVERSE); |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 661 | mvwaddnstr(edit, y, end - this_page_start, |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 662 | &fileptr->data[end], post_data_len); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 663 | } |
| 664 | #endif |
| 665 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 666 | /* edit_add takes care of the job of actually painting a line into the |
| 667 | * edit window. |
| 668 | * |
| 669 | * Called only from update_line. Expects a converted-to-not-have-tabs |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 670 | * line */ |
| 671 | 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] | 672 | int virt_mark_beginx, int this_page) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 673 | { |
| 674 | #ifndef NANO_SMALL |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 675 | /* There are quite a few cases that could take place, we'll deal |
| 676 | * with them each in turn */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 677 | if (ISSET(MARK_ISSET) |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 678 | && !((fileptr->lineno > mark_beginbuf->lineno |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 679 | && fileptr->lineno > current->lineno) |
| 680 | || (fileptr->lineno < mark_beginbuf->lineno |
| 681 | && fileptr->lineno < current->lineno))) { |
| 682 | /* If we get here we are on a line that is atleast |
| 683 | * partially selected. The lineno checks above determined |
| 684 | * that */ |
| 685 | if (fileptr != mark_beginbuf && fileptr != current) { |
| 686 | /* We are on a completely marked line, paint it all |
| 687 | * inverse */ |
| 688 | wattron(edit, A_REVERSE); |
| 689 | mvwaddnstr(edit, yval, 0, fileptr->data, COLS); |
| 690 | wattroff(edit, A_REVERSE); |
| 691 | } else if (fileptr == mark_beginbuf && fileptr == current) { |
| 692 | /* Special case, we're still on the same line we started |
| 693 | * marking -- so we call our helper function */ |
| 694 | if (virt_cur_x < virt_mark_beginx) { |
| 695 | /* To the right of us is marked */ |
| 696 | add_marked_sameline(virt_cur_x, virt_mark_beginx, |
| 697 | fileptr, yval, virt_cur_x, this_page); |
| 698 | } else { |
| 699 | /* To the left of us is marked */ |
| 700 | add_marked_sameline(virt_mark_beginx, virt_cur_x, |
| 701 | fileptr, yval, virt_cur_x, this_page); |
| 702 | } |
| 703 | } else if (fileptr == mark_beginbuf) { |
| 704 | /* |
| 705 | * we're updating the line that was first marked |
| 706 | * but we're not currently on it. So we want to |
| 707 | * figur out which half to invert based on our |
| 708 | * relative line numbers. |
| 709 | * |
| 710 | * i.e. If we're above the "beginbuf" line, we want to |
| 711 | * mark the left side. Otherwise we're below, so we |
| 712 | * mark the right |
| 713 | */ |
| 714 | int target; |
| 715 | |
| 716 | if (mark_beginbuf->lineno > current->lineno) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 717 | wattron(edit, A_REVERSE); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 718 | |
| 719 | target = |
| 720 | (virt_mark_beginx < |
| 721 | COLS - 1) ? virt_mark_beginx : COLS - 1; |
| 722 | |
| 723 | mvwaddnstr(edit, yval, 0, fileptr->data, target); |
| 724 | |
| 725 | if (mark_beginbuf->lineno < current->lineno) |
| 726 | wattron(edit, A_REVERSE); |
| 727 | else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 728 | wattroff(edit, A_REVERSE); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 729 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 730 | target = (COLS - 1) - virt_mark_beginx; |
| 731 | if (target < 0) |
| 732 | target = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 733 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 734 | mvwaddnstr(edit, yval, virt_mark_beginx, |
| 735 | &fileptr->data[virt_mark_beginx], target); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 736 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 737 | if (mark_beginbuf->lineno < current->lineno) |
| 738 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 739 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 740 | } else if (fileptr == current) { |
| 741 | /* we're on the cursors line, but it's not the first |
| 742 | * one we marked. Similar to the previous logic. */ |
| 743 | int this_page_start = get_page_start_virtual(this_page), |
| 744 | this_page_end = get_page_end_virtual(this_page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 745 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 746 | if (mark_beginbuf->lineno < current->lineno) |
| 747 | wattron(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 748 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 749 | if (virt_cur_x > COLS - 2) { |
| 750 | mvwaddnstr(edit, yval, 0, |
| 751 | &fileptr->data[this_page_start], |
| 752 | virt_cur_x - this_page_start); |
| 753 | } else { |
| 754 | mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x); |
| 755 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 756 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 757 | if (mark_beginbuf->lineno > current->lineno) |
| 758 | wattron(edit, A_REVERSE); |
| 759 | else |
| 760 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 761 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 762 | if (virt_cur_x > COLS - 2) |
| 763 | mvwaddnstr(edit, yval, virt_cur_x - this_page_start, |
| 764 | &fileptr->data[virt_cur_x], |
| 765 | this_page_end - virt_cur_x); |
| 766 | else |
| 767 | mvwaddnstr(edit, yval, virt_cur_x, |
| 768 | &fileptr->data[virt_cur_x], COLS - virt_cur_x); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 769 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 770 | if (mark_beginbuf->lineno > current->lineno) |
| 771 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | } else |
| 775 | #endif |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 776 | /* Just paint the string (no mark on this line) */ |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 777 | mvwaddnstr(edit, yval, 0, &fileptr->data[start], |
Chris Allegretta | 908805a | 2000-12-04 04:42:56 +0000 | [diff] [blame] | 778 | get_page_end_virtual(this_page) - start + 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /* |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 782 | * Just update one line in the edit buffer. Basically a wrapper for |
| 783 | * edit_add |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 784 | * |
| 785 | * index gives is a place in the string to update starting from. |
| 786 | * Likely args are current_x or 0. |
| 787 | */ |
| 788 | void update_line(filestruct * fileptr, int index) |
| 789 | { |
| 790 | filestruct *filetmp; |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 791 | int line = 0, col = 0; |
| 792 | int virt_cur_x = current_x, virt_mark_beginx = mark_beginx; |
| 793 | char *realdata, *tmp; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 794 | int i, pos, len, page; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 795 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 796 | if (!fileptr) |
| 797 | return; |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 798 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 799 | /* First, blank out the line (at a minimum) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 800 | for (filetmp = edittop; filetmp != fileptr && filetmp != editbot; |
| 801 | filetmp = filetmp->next) |
| 802 | line++; |
| 803 | |
| 804 | mvwaddstr(edit, line, 0, hblank); |
| 805 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 806 | /* Next, convert all the tabs to spaces so everything else is easy */ |
| 807 | index = xpt(fileptr, index); |
| 808 | |
| 809 | realdata = fileptr->data; |
| 810 | len = strlen(realdata); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 811 | fileptr->data = nmalloc(xpt(fileptr, len) + 1); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 812 | |
| 813 | pos = 0; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 814 | for (i = 0; i < len; i++) { |
| 815 | if (realdata[i] == '\t') { |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 816 | do { |
| 817 | fileptr->data[pos++] = ' '; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 818 | if (i < current_x) |
| 819 | virt_cur_x++; |
| 820 | if (i < mark_beginx) |
| 821 | virt_mark_beginx++; |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 822 | } while (pos % tabsize); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 823 | /* must decrement once to account for tab-is-one-character */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 824 | if (i < current_x) |
| 825 | virt_cur_x--; |
| 826 | if (i < mark_beginx) |
| 827 | virt_mark_beginx--; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 828 | } else if (realdata[i] >= 1 && realdata[i] <= 26) { |
| 829 | /* Treat control characters as ^letter */ |
Chris Allegretta | 6306a11 | 2000-09-02 07:55:41 +0000 | [diff] [blame] | 830 | fileptr->data[pos++] = '^'; |
| 831 | fileptr->data[pos++] = realdata[i] + 64; |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 832 | } else { |
| 833 | fileptr->data[pos++] = realdata[i]; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | fileptr->data[pos] = '\0'; |
| 838 | |
| 839 | /* Now, Paint the line */ |
| 840 | if (current == fileptr && index > COLS - 2) { |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 841 | /* This handles when the current line is beyond COLS */ |
| 842 | /* It requires figureing out what page we're at */ |
| 843 | page = get_page_from_virtual(index); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 844 | col = get_page_start_virtual(page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 845 | |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 846 | edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 847 | mvwaddch(edit, line, 0, '$'); |
| 848 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 849 | if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 850 | mvwaddch(edit, line, COLS - 1, '$'); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 851 | } else { |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 852 | /* It's not the current line means that it's at x=0 and page=1 */ |
| 853 | /* If it is the current line, then we're in the same boat */ |
| 854 | edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 855 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 856 | if (strlenpt(&filetmp->data[col]) > COLS) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 857 | mvwaddch(edit, line, COLS - 1, '$'); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 858 | } |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 859 | |
| 860 | /* Clean up our mess */ |
| 861 | tmp = fileptr->data; |
| 862 | fileptr->data = realdata; |
| 863 | free(tmp); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | void center_cursor(void) |
| 867 | { |
| 868 | current_y = editwinrows / 2; |
| 869 | wmove(edit, current_y, current_x); |
| 870 | } |
| 871 | |
| 872 | /* Refresh the screen without changing the position of lines */ |
| 873 | void edit_refresh(void) |
| 874 | { |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 875 | static int noloop = 0; |
Chris Allegretta | 95b0b52 | 2000-07-28 02:58:06 +0000 | [diff] [blame] | 876 | int lines = 0, i = 0, currentcheck = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 877 | filestruct *temp, *hold = current; |
| 878 | |
| 879 | if (current == NULL) |
| 880 | return; |
| 881 | |
| 882 | temp = edittop; |
| 883 | |
| 884 | while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) { |
| 885 | hold = temp; |
| 886 | update_line(temp, current_x); |
Chris Allegretta | 95b0b52 | 2000-07-28 02:58:06 +0000 | [diff] [blame] | 887 | if (temp == current) |
| 888 | currentcheck = 1; |
| 889 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 890 | temp = temp->next; |
| 891 | lines++; |
| 892 | } |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 893 | /* If noloop == 1, then we already did an edit_update without finishing |
| 894 | this function. So we don't run edit_update again */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 895 | if (!currentcheck && !noloop) { /* Then current has run off the screen... */ |
Chris Allegretta | da721be | 2000-07-31 01:26:42 +0000 | [diff] [blame] | 896 | edit_update(current, CENTER); |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 897 | noloop = 1; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 898 | } else if (noloop) |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 899 | noloop = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 900 | |
| 901 | if (lines <= editwinrows - 1) |
| 902 | while (lines <= editwinrows - 1) { |
| 903 | mvwaddstr(edit, lines, i, hblank); |
| 904 | lines++; |
| 905 | } |
| 906 | if (temp == NULL) |
| 907 | editbot = hold; |
| 908 | else |
| 909 | editbot = temp; |
| 910 | } |
| 911 | |
| 912 | /* |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 913 | * Same as above, but touch the window first so everything is redrawn. |
| 914 | */ |
| 915 | void edit_refresh_clearok(void) |
| 916 | { |
| 917 | clearok(edit, TRUE); |
| 918 | edit_refresh(); |
| 919 | clearok(edit, FALSE); |
| 920 | } |
| 921 | |
| 922 | /* |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 923 | * Nice generic routine to update the edit buffer given a pointer to the |
| 924 | * file struct =) |
| 925 | */ |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 926 | void edit_update(filestruct * fileptr, int topmidbot) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 927 | { |
Robert Siemborski | 29e9a76 | 2000-07-05 03:16:04 +0000 | [diff] [blame] | 928 | int i = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 929 | filestruct *temp; |
| 930 | |
| 931 | if (fileptr == NULL) |
| 932 | return; |
| 933 | |
| 934 | temp = fileptr; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 935 | if (topmidbot == 2); |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 936 | else if (topmidbot == 0) |
| 937 | for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++) |
| 938 | temp = temp->prev; |
| 939 | else |
| 940 | for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++) |
| 941 | temp = temp->prev; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 942 | |
Robert Siemborski | 29e9a76 | 2000-07-05 03:16:04 +0000 | [diff] [blame] | 943 | edittop = temp; |
| 944 | fix_editbot(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 945 | |
| 946 | edit_refresh(); |
| 947 | } |
| 948 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 949 | /* This function updates current based on where current_y is, reset_cursor |
| 950 | does the opposite */ |
| 951 | void update_cursor(void) |
| 952 | { |
| 953 | int i = 0; |
| 954 | |
| 955 | #ifdef DEBUG |
| 956 | fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y, |
| 957 | current_x); |
| 958 | #endif |
| 959 | |
| 960 | current = edittop; |
| 961 | while (i <= current_y - 1 && current->next != NULL) { |
| 962 | current = current->next; |
| 963 | i++; |
| 964 | } |
| 965 | |
| 966 | #ifdef DEBUG |
| 967 | fprintf(stderr, _("current->data = \"%s\"\n"), current->data); |
| 968 | #endif |
| 969 | |
| 970 | } |
| 971 | |
| 972 | /* |
| 973 | * Ask a question on the statusbar. Answer will be stored in answer |
| 974 | * global. Returns -1 on aborted enter, -2 on a blank string, and 0 |
| 975 | * otherwise, the valid shortcut key caught, Def is any editable text we |
| 976 | * want to put up by default. |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 977 | * |
| 978 | * New arg tabs tells whether or not to allow tab completion. |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 979 | */ |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 980 | int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 981 | { |
| 982 | va_list ap; |
| 983 | char foo[133]; |
| 984 | int ret; |
| 985 | |
| 986 | bottombars(s, slen); |
| 987 | |
| 988 | va_start(ap, msg); |
| 989 | vsnprintf(foo, 132, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 990 | va_end(ap); |
Chris Allegretta | a4d2162 | 2000-07-08 23:57:03 +0000 | [diff] [blame] | 991 | strncat(foo, ": ", 132); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 992 | |
| 993 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 994 | ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 995 | wattroff(bottomwin, A_REVERSE); |
| 996 | |
| 997 | switch (ret) { |
| 998 | |
| 999 | case NANO_FIRSTLINE_KEY: |
| 1000 | do_first_line(); |
| 1001 | break; |
| 1002 | case NANO_LASTLINE_KEY: |
| 1003 | do_last_line(); |
| 1004 | break; |
| 1005 | case NANO_CANCEL_KEY: |
| 1006 | return -1; |
| 1007 | default: |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 1008 | blank_statusbar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | #ifdef DEBUG |
| 1012 | fprintf(stderr, _("I got \"%s\"\n"), answer); |
| 1013 | #endif |
| 1014 | |
| 1015 | return ret; |
| 1016 | } |
| 1017 | |
| 1018 | /* |
| 1019 | * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for |
| 1020 | * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C) |
| 1021 | */ |
| 1022 | int do_yesno(int all, int leavecursor, char *msg, ...) |
| 1023 | { |
| 1024 | va_list ap; |
| 1025 | char foo[133]; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1026 | int kbinput, ok = -1, i; |
| 1027 | char *yesstr; /* String of yes characters accepted */ |
| 1028 | char *nostr; /* Same for no */ |
| 1029 | char *allstr; /* And all, surprise! */ |
| 1030 | char shortstr[5]; /* Temp string for above */ |
| 1031 | |
| 1032 | /* Yes, no and all are strings of any length. Each string consists of |
| 1033 | all characters accepted as a valid character for that value. |
| 1034 | The first value will be the one displayed in the shortcuts. */ |
| 1035 | yesstr = _("Yy"); |
| 1036 | nostr = _("Nn"); |
| 1037 | allstr = _("Aa"); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1038 | |
| 1039 | /* Write the bottom of the screen */ |
| 1040 | clear_bottomwin(); |
| 1041 | wattron(bottomwin, A_REVERSE); |
| 1042 | blank_statusbar_refresh(); |
| 1043 | wattroff(bottomwin, A_REVERSE); |
| 1044 | |
Jordi Mallach | 0b0fc49 | 2000-06-23 01:00:13 +0000 | [diff] [blame] | 1045 | /* Remove gettext call for keybindings until we clear the thing up */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1046 | if (!ISSET(NO_HELP)) { |
| 1047 | wmove(bottomwin, 1, 0); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1048 | |
| 1049 | snprintf(shortstr, 3, " %c", yesstr[0]); |
| 1050 | onekey(shortstr, _("Yes")); |
| 1051 | |
| 1052 | if (all) { |
| 1053 | snprintf(shortstr, 3, " %c", allstr[0]); |
| 1054 | onekey(shortstr, _("All")); |
| 1055 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1056 | wmove(bottomwin, 2, 0); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1057 | |
| 1058 | snprintf(shortstr, 3, " %c", nostr[0]); |
| 1059 | onekey(shortstr, _("No")); |
| 1060 | |
Jordi Mallach | 0b0fc49 | 2000-06-23 01:00:13 +0000 | [diff] [blame] | 1061 | onekey("^C", _("Cancel")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1062 | } |
| 1063 | va_start(ap, msg); |
| 1064 | vsnprintf(foo, 132, msg, ap); |
| 1065 | va_end(ap); |
| 1066 | wattron(bottomwin, A_REVERSE); |
| 1067 | mvwaddstr(bottomwin, 0, 0, foo); |
| 1068 | wattroff(bottomwin, A_REVERSE); |
| 1069 | wrefresh(bottomwin); |
| 1070 | |
| 1071 | if (leavecursor == 1) |
| 1072 | reset_cursor(); |
| 1073 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1074 | while (ok == -1) { |
| 1075 | kbinput = wgetch(edit); |
| 1076 | |
| 1077 | switch (kbinput) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1078 | case NANO_CONTROL_C: |
| 1079 | ok = -2; |
| 1080 | break; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1081 | default: |
| 1082 | |
| 1083 | /* Look for the kbinput in the yes, no and (optinally) all str */ |
| 1084 | for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++) |
| 1085 | ; |
| 1086 | if (yesstr[i] != 0) { |
Chris Allegretta | ea620fe | 2001-02-18 05:39:41 +0000 | [diff] [blame] | 1087 | ok = 1; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1088 | break; |
| 1089 | } |
| 1090 | |
| 1091 | for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++) |
| 1092 | ; |
| 1093 | if (nostr[i] != 0) { |
| 1094 | ok = 0; |
| 1095 | break; |
| 1096 | } |
| 1097 | |
| 1098 | if (all) { |
| 1099 | for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++) |
| 1100 | ; |
| 1101 | if (allstr[i] != 0) { |
| 1102 | ok = 2; |
| 1103 | break; |
| 1104 | } |
| 1105 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1108 | |
| 1109 | /* Then blank the screen */ |
| 1110 | blank_statusbar_refresh(); |
| 1111 | |
| 1112 | if (ok == -2) |
| 1113 | return -1; |
| 1114 | else |
| 1115 | return ok; |
| 1116 | } |
| 1117 | |
| 1118 | void statusbar(char *msg, ...) |
| 1119 | { |
| 1120 | va_list ap; |
| 1121 | char foo[133]; |
| 1122 | int start_x = 0; |
| 1123 | |
| 1124 | va_start(ap, msg); |
| 1125 | vsnprintf(foo, 132, msg, ap); |
| 1126 | va_end(ap); |
| 1127 | |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 1128 | start_x = COLS / 2 - strlen(foo) / 2 - 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1129 | |
| 1130 | /* Blank out line */ |
| 1131 | blank_statusbar(); |
| 1132 | |
| 1133 | wmove(bottomwin, 0, start_x); |
| 1134 | |
| 1135 | wattron(bottomwin, A_REVERSE); |
| 1136 | |
| 1137 | waddstr(bottomwin, "[ "); |
| 1138 | waddstr(bottomwin, foo); |
| 1139 | waddstr(bottomwin, " ]"); |
| 1140 | wattroff(bottomwin, A_REVERSE); |
| 1141 | wrefresh(bottomwin); |
| 1142 | |
| 1143 | if (ISSET(CONSTUPDATE)) |
| 1144 | statblank = 1; |
| 1145 | else |
| 1146 | statblank = 25; |
| 1147 | } |
| 1148 | |
| 1149 | void display_main_list(void) |
| 1150 | { |
| 1151 | bottombars(main_list, MAIN_VISIBLE); |
| 1152 | } |
| 1153 | |
| 1154 | int total_refresh(void) |
| 1155 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1156 | clearok(edit, TRUE); |
| 1157 | clearok(topwin, TRUE); |
| 1158 | clearok(bottomwin, TRUE); |
| 1159 | wnoutrefresh(edit); |
| 1160 | wnoutrefresh(topwin); |
| 1161 | wnoutrefresh(bottomwin); |
| 1162 | doupdate(); |
| 1163 | clearok(edit, FALSE); |
| 1164 | clearok(topwin, FALSE); |
| 1165 | clearok(bottomwin, FALSE); |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 1166 | edit_refresh(); |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 1167 | titlebar(NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1168 | return 1; |
| 1169 | } |
| 1170 | |
| 1171 | void previous_line(void) |
| 1172 | { |
| 1173 | if (current_y > 0) |
| 1174 | current_y--; |
| 1175 | } |
| 1176 | |
| 1177 | int do_cursorpos(void) |
| 1178 | { |
| 1179 | filestruct *fileptr; |
Chris Allegretta | 66795ec | 2000-12-27 04:47:28 +0000 | [diff] [blame] | 1180 | float linepct = 0.0, bytepct = 0.0; |
| 1181 | int i = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1182 | |
| 1183 | if (current == NULL || fileage == NULL) |
| 1184 | return 0; |
| 1185 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1186 | for (fileptr = fileage; fileptr != current && fileptr != NULL; |
| 1187 | fileptr = fileptr->next) |
Chris Allegretta | 66795ec | 2000-12-27 04:47:28 +0000 | [diff] [blame] | 1188 | i += strlen(fileptr->data) + 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1189 | |
| 1190 | if (fileptr == NULL) |
| 1191 | return -1; |
| 1192 | |
Chris Allegretta | 66795ec | 2000-12-27 04:47:28 +0000 | [diff] [blame] | 1193 | i += current_x; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1194 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1195 | if (totlines > 0) |
| 1196 | linepct = 100 * current->lineno / totlines; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1197 | |
| 1198 | if (totsize > 0) |
| 1199 | bytepct = 100 * i / totsize; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1200 | |
| 1201 | #ifdef DEBUG |
| 1202 | fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"), |
| 1203 | linepct, bytepct); |
| 1204 | #endif |
| 1205 | |
| 1206 | statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"), |
| 1207 | current->lineno, totlines, linepct, i, totsize, bytepct); |
| 1208 | reset_cursor(); |
| 1209 | return 1; |
| 1210 | } |
| 1211 | |
| 1212 | /* Our broken, non-shortcut list compliant help function. |
| 1213 | But hey, it's better than nothing, and it's dynamic! */ |
| 1214 | int do_help(void) |
| 1215 | { |
Rocco Corsi | af5c302 | 2001-01-12 07:51:05 +0000 | [diff] [blame] | 1216 | #ifndef DISABLE_HELP |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1217 | char *ptr = help_text, *end; |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1218 | int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1219 | int no_help_flag = 0; |
| 1220 | |
| 1221 | blank_edit(); |
| 1222 | curs_set(0); |
| 1223 | blank_statusbar(); |
| 1224 | |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1225 | kp = keypad_on(edit, 1); |
| 1226 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1227 | if (ISSET(NO_HELP)) { |
| 1228 | |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1229 | /* Well if we're going to do this, we should at least |
| 1230 | do it the right way */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1231 | no_help_flag = 1; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1232 | UNSET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1233 | window_init(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1234 | bottombars(help_list, HELP_LIST_LEN); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1235 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1236 | } else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1237 | bottombars(help_list, HELP_LIST_LEN); |
| 1238 | |
| 1239 | do { |
| 1240 | ptr = help_text; |
| 1241 | switch (kbinput) { |
| 1242 | case NANO_NEXTPAGE_KEY: |
| 1243 | case NANO_NEXTPAGE_FKEY: |
| 1244 | case KEY_NPAGE: |
| 1245 | if (!no_more) { |
| 1246 | blank_edit(); |
| 1247 | page++; |
| 1248 | } |
| 1249 | break; |
| 1250 | case NANO_PREVPAGE_KEY: |
| 1251 | case NANO_PREVPAGE_FKEY: |
| 1252 | case KEY_PPAGE: |
| 1253 | if (page > 1) { |
| 1254 | no_more = 0; |
| 1255 | blank_edit(); |
| 1256 | page--; |
| 1257 | } |
| 1258 | break; |
| 1259 | } |
| 1260 | |
| 1261 | /* Calculate where in the text we should be based on the page */ |
| 1262 | for (i = 1; i < page; i++) { |
| 1263 | row = 0; |
| 1264 | j = 0; |
Chris Allegretta | 44e73df | 2000-09-07 03:37:38 +0000 | [diff] [blame] | 1265 | |
| 1266 | while (row < editwinrows - 2 && *ptr != '\0') { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1267 | if (*ptr == '\n' || j == COLS - 5) { |
| 1268 | j = 0; |
| 1269 | row++; |
| 1270 | } |
| 1271 | ptr++; |
| 1272 | j++; |
| 1273 | } |
| 1274 | } |
| 1275 | |
Chris Allegretta | 44e73df | 2000-09-07 03:37:38 +0000 | [diff] [blame] | 1276 | if (i > 1) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1277 | |
Chris Allegretta | 44e73df | 2000-09-07 03:37:38 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1280 | i = 0; |
| 1281 | j = 0; |
| 1282 | while (i < editwinrows && *ptr != '\0') { |
| 1283 | end = ptr; |
| 1284 | while (*end != '\n' && *end != '\0' && j != COLS - 5) { |
| 1285 | end++; |
| 1286 | j++; |
| 1287 | } |
| 1288 | if (j == COLS - 5) { |
| 1289 | |
| 1290 | /* Don't print half a word if we've run of of space */ |
| 1291 | while (*end != ' ' && *end != '\0') { |
| 1292 | end--; |
| 1293 | j--; |
| 1294 | } |
| 1295 | } |
| 1296 | mvwaddnstr(edit, i, 0, ptr, j); |
| 1297 | j = 0; |
| 1298 | i++; |
| 1299 | if (*end == '\n') |
| 1300 | end++; |
| 1301 | ptr = end; |
| 1302 | } |
| 1303 | if (*ptr == '\0') { |
| 1304 | no_more = 1; |
| 1305 | continue; |
| 1306 | } |
Chris Allegretta | d1627cf | 2000-12-18 05:03:16 +0000 | [diff] [blame] | 1307 | } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY && |
| 1308 | kbinput != NANO_EXIT_FKEY); |
| 1309 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1310 | if (no_help_flag) { |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1311 | blank_bottombars(); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1312 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1313 | SET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1314 | window_init(); |
| 1315 | } |
| 1316 | display_main_list(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1317 | |
| 1318 | curs_set(1); |
| 1319 | edit_refresh(); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1320 | kp = keypad_on(edit, kp); |
| 1321 | |
Chris Allegretta | 3bc8c72 | 2000-12-10 17:03:25 +0000 | [diff] [blame] | 1322 | #elif defined(DISABLE_HELP) |
| 1323 | nano_disabled_msg(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1324 | #endif |
| 1325 | |
| 1326 | return 1; |
| 1327 | } |
| 1328 | |
| 1329 | /* Dump the current file structure to stderr */ |
| 1330 | void dump_buffer(filestruct * inptr) |
| 1331 | { |
| 1332 | #ifdef DEBUG |
| 1333 | filestruct *fileptr; |
| 1334 | |
| 1335 | if (inptr == fileage) |
| 1336 | fprintf(stderr, _("Dumping file buffer to stderr...\n")); |
| 1337 | else if (inptr == cutbuffer) |
| 1338 | fprintf(stderr, _("Dumping cutbuffer to stderr...\n")); |
| 1339 | else |
| 1340 | fprintf(stderr, _("Dumping a buffer to stderr...\n")); |
| 1341 | |
| 1342 | fileptr = inptr; |
| 1343 | while (fileptr != NULL) { |
| 1344 | fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data); |
| 1345 | fflush(stderr); |
| 1346 | fileptr = fileptr->next; |
| 1347 | } |
| 1348 | #endif /* DEBUG */ |
| 1349 | } |
| 1350 | |
| 1351 | void dump_buffer_reverse(filestruct * inptr) |
| 1352 | { |
| 1353 | #ifdef DEBUG |
| 1354 | filestruct *fileptr; |
| 1355 | |
| 1356 | fileptr = filebot; |
| 1357 | while (fileptr != NULL) { |
| 1358 | fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data); |
| 1359 | fflush(stderr); |
| 1360 | fileptr = fileptr->prev; |
| 1361 | } |
| 1362 | #endif /* DEBUG */ |
| 1363 | } |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1364 | |
| 1365 | /* Fix editbot based on the assumption that edittop is correct */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1366 | void fix_editbot(void) |
| 1367 | { |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1368 | int i; |
| 1369 | editbot = edittop; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1370 | for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL) |
| 1371 | && (editbot != filebot); i++, editbot = editbot->next); |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1372 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1373 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1374 | /* highlight the current word being replaced or spell checked */ |
| 1375 | void do_replace_highlight(int highlight_flag, char *word) |
| 1376 | { |
| 1377 | char *highlight_word = NULL; |
| 1378 | int x, y; |
| 1379 | |
| 1380 | highlight_word = mallocstrcpy(highlight_word, ¤t->data[current_x]); |
| 1381 | highlight_word[strlen(word)] = '\0'; |
| 1382 | |
| 1383 | /* adjust output when word extends beyond screen*/ |
| 1384 | |
| 1385 | x = xplustabs(); |
| 1386 | y = get_page_end_virtual(get_page_from_virtual(x)) + 1; |
| 1387 | |
| 1388 | if ((COLS - (y - x) + strlen(word)) > COLS) { |
| 1389 | highlight_word[y - x - 1] = '$'; |
| 1390 | highlight_word[y - x] = '\0'; |
| 1391 | } |
| 1392 | |
| 1393 | /* OK display the output */ |
| 1394 | |
| 1395 | reset_cursor(); |
| 1396 | |
| 1397 | if (highlight_flag) |
| 1398 | wattron(edit, A_REVERSE); |
| 1399 | |
| 1400 | waddstr(edit, highlight_word); |
| 1401 | |
| 1402 | if (highlight_flag) |
| 1403 | wattroff(edit, A_REVERSE); |
| 1404 | |
| 1405 | free(highlight_word); |
| 1406 | } |
| 1407 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1408 | #ifdef NANO_EXTRA |
Chris Allegretta | 7cd9f74 | 2000-11-25 20:17:28 +0000 | [diff] [blame] | 1409 | #define CREDIT_LEN 45 |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1410 | void do_credits(void) |
| 1411 | { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1412 | int i, j = 0, k, place = 0, start_x; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1413 | char *what; |
| 1414 | |
| 1415 | char *nanotext = _("The nano text editor"); |
| 1416 | char *version = _("version "); |
| 1417 | char *brought = _("Brought to you by:"); |
| 1418 | char *specialthx = _("Special thanks to:"); |
| 1419 | char *fsf = _("The Free Software Foundation"); |
| 1420 | char *ncurses = _("Pavel Curtis, Zeyd Ben-Halim and Eric S. Raymond for ncurses"); |
| 1421 | char *anyonelse = _("and anyone else we forgot..."); |
| 1422 | char *thankyou = _("Thank you for using nano!\n"); |
| 1423 | |
| 1424 | char *credits[CREDIT_LEN] = {nanotext, |
| 1425 | version, |
| 1426 | VERSION, |
| 1427 | "", |
| 1428 | brought, |
| 1429 | "Chris Allegretta", |
| 1430 | "Jordi Mallach", |
| 1431 | "Adam Rogoyski", |
| 1432 | "Rob Siemborski", |
| 1433 | "Rocco Corsi", |
| 1434 | "Ken Tyler", |
| 1435 | "Sven Guckes", |
| 1436 | "Florian König", |
| 1437 | "Pauli Virtanen", |
| 1438 | "Daniele Medri", |
| 1439 | "Clement Laforet", |
| 1440 | "Tedi Heriyanto", |
Chris Allegretta | a131c7c | 2000-11-25 19:59:41 +0000 | [diff] [blame] | 1441 | "Bill Soudan", |
Chris Allegretta | 7cd9f74 | 2000-11-25 20:17:28 +0000 | [diff] [blame] | 1442 | "Christian Weisgerber", |
Chris Allegretta | 827b15f | 2001-01-03 02:09:04 +0000 | [diff] [blame] | 1443 | "Erik Andersen", |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1444 | "Big Gaute", |
| 1445 | "Joshua Jensen", |
Chris Allegretta | 0d471de | 2001-03-15 14:40:42 +0000 | [diff] [blame] | 1446 | "Ryan Krebs", |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1447 | "", |
| 1448 | specialthx, |
| 1449 | "Plattsburgh State University", |
| 1450 | "Benet Laboratories", |
| 1451 | "Amy Allegretta", |
| 1452 | "Linda Young", |
| 1453 | "Jeremy Robichaud", |
| 1454 | "Richard Kolb II", |
| 1455 | fsf, |
| 1456 | "Linus Torvalds", |
| 1457 | ncurses, |
| 1458 | anyonelse, |
| 1459 | thankyou, |
| 1460 | "", "", "", "", |
| 1461 | "(c) 2000 Chris Allegretta", |
| 1462 | "", "", "", "", |
| 1463 | "www.nano-editor.org" |
| 1464 | }; |
| 1465 | |
| 1466 | curs_set(0); |
| 1467 | nodelay(edit, TRUE); |
| 1468 | blank_bottombars(); |
| 1469 | mvwaddstr(topwin, 0, 0, hblank); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1470 | blank_edit(); |
| 1471 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1472 | wrefresh(bottomwin); |
| 1473 | wrefresh(topwin); |
| 1474 | |
| 1475 | while (wgetch(edit) == ERR) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1476 | for (k = 0; k <= 1; k++) { |
| 1477 | blank_edit(); |
| 1478 | for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); i--) { |
| 1479 | mvwaddstr(edit, i * 2 - k, 0, hblank); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1480 | |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1481 | if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN) |
| 1482 | what = credits[place - (editwinrows / 2 - 1 - i)]; |
| 1483 | else |
| 1484 | what = ""; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1485 | |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 1486 | start_x = COLS / 2 - strlen(what) / 2 - 1; |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1487 | mvwaddstr(edit, i * 2 - k, start_x, what); |
| 1488 | } |
| 1489 | usleep(700000); |
| 1490 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1491 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1492 | if (j < editwinrows / 2 - 1) |
| 1493 | j++; |
| 1494 | |
| 1495 | place++; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1496 | |
| 1497 | if (place >= CREDIT_LEN + editwinrows / 2) |
| 1498 | break; |
| 1499 | } |
| 1500 | |
| 1501 | nodelay(edit, FALSE); |
| 1502 | curs_set(1); |
| 1503 | display_main_list(); |
| 1504 | total_refresh(); |
| 1505 | } |
| 1506 | #endif |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1507 | |
| 1508 | int keypad_on(WINDOW * win, int new) |
| 1509 | { |
| 1510 | |
| 1511 | /* This is taken right from aumix. Don't sue me */ |
| 1512 | #ifdef HAVE_USEKEYPAD |
| 1513 | int old; |
| 1514 | |
| 1515 | old = win->_use_keypad; |
| 1516 | keypad(win, new); |
| 1517 | return old; |
| 1518 | #else |
| 1519 | keypad(win, new); |
| 1520 | return 1; |
| 1521 | #endif /* HAVE_USEKEYPAD */ |
| 1522 | |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | |