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