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