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