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