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