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 | * * |
Chris Allegretta | d757e25 | 2003-01-15 19:33:27 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2003 Chris Allegretta * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 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 | |
David Lawrence Ramsey | e21adfa | 2002-09-13 18:14:04 +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> |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 28 | #include <ctype.h> |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 29 | #include <assert.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 30 | #include "proto.h" |
| 31 | #include "nano.h" |
| 32 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 33 | static int statblank = 0; /* Number of keystrokes left after |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 34 | we call statusbar(), before we |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 35 | actually blank the statusbar */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 36 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 37 | /* Read in a single input character. If it's ignored, swallow it and go |
| 38 | * on. Otherwise, try to translate it from ASCII and extended (keypad) |
| 39 | * input. Assume nodelay(win) is FALSE. */ |
| 40 | int get_kbinput(WINDOW *win, int *meta, int rebind_delete) |
| 41 | { |
| 42 | int kbinput, retval; |
| 43 | |
| 44 | kbinput = get_ignored_kbinput(win); |
| 45 | retval = get_accepted_kbinput(win, kbinput, meta, rebind_delete); |
| 46 | |
| 47 | return retval; |
| 48 | } |
| 49 | |
| 50 | /* Read in a string of input characters (e. g. an escape sequence) |
| 51 | * verbatim, and return the length of the string in kbinput_len. Assume |
| 52 | * nodelay(win) is FALSE. */ |
| 53 | char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len) |
| 54 | { |
| 55 | char *verbatim_kbinput; |
| 56 | int kbinput = wgetch(win); |
| 57 | |
| 58 | verbatim_kbinput = charalloc(1); |
| 59 | verbatim_kbinput[0] = kbinput; |
| 60 | *kbinput_len = 1; |
| 61 | |
| 62 | if (kbinput >= '0' && kbinput <= '2') |
| 63 | /* Entering a three-digit decimal ASCII code from 000-255 in |
| 64 | * verbatim mode will produce the corresponding ASCII |
| 65 | * character. */ |
| 66 | verbatim_kbinput[0] = (char)get_ascii_kbinput(win, kbinput); |
| 67 | else { |
| 68 | nodelay(win, TRUE); |
| 69 | while ((kbinput = wgetch(win)) != ERR) { |
David Lawrence Ramsey | da8fd8f | 2003-09-16 01:22:31 +0000 | [diff] [blame] | 70 | (*kbinput_len)++; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 71 | verbatim_kbinput = charealloc(verbatim_kbinput, *kbinput_len); |
| 72 | verbatim_kbinput[*kbinput_len - 1] = (char)kbinput; |
| 73 | } |
| 74 | nodelay(win, FALSE); |
| 75 | } |
| 76 | |
| 77 | #ifdef DEBUG |
| 78 | fprintf(stderr, "get_verbatim_kbinput(): verbatim_kbinput = %s\n", verbatim_kbinput); |
| 79 | #endif |
| 80 | return verbatim_kbinput; |
| 81 | } |
| 82 | |
| 83 | /* Swallow input characters that should be quietly ignored, and return |
| 84 | * the first input character that shouldn't be. */ |
| 85 | int get_ignored_kbinput(WINDOW *win) |
| 86 | { |
| 87 | int kbinput; |
| 88 | |
| 89 | while (1) { |
| 90 | kbinput = wgetch(win); |
| 91 | switch (kbinput) { |
| 92 | case ERR: |
| 93 | case KEY_RESIZE: |
| 94 | #ifdef PDCURSES |
| 95 | case KEY_SHIFT_L: |
| 96 | case KEY_SHIFT_R: |
| 97 | case KEY_CONTROL_L: |
| 98 | case KEY_CONTROL_R: |
| 99 | case KEY_ALT_L: |
| 100 | case KEY_ALT_R: |
| 101 | #endif |
| 102 | #ifdef DEBUG |
| 103 | fprintf(stderr, "get_ignored_kbinput(): kbinput = %d\n", kbinput); |
| 104 | #endif |
| 105 | break; |
| 106 | default: |
| 107 | return kbinput; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /* Translate acceptable ASCII and extended (keypad) input. Set meta to |
| 113 | * 1 if we get a Meta sequence. Assume nodelay(win) is FALSE. */ |
| 114 | int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta, |
| 115 | int rebind_delete) |
| 116 | { |
| 117 | *meta = 0; |
| 118 | |
| 119 | switch (kbinput) { |
| 120 | case NANO_CONTROL_3: /* Escape */ |
| 121 | switch (kbinput = wgetch(win)) { |
| 122 | case NANO_CONTROL_3: /* Escape */ |
| 123 | kbinput = wgetch(win); |
| 124 | /* Esc Esc [three-digit decimal ASCII code from |
| 125 | * 000-255] == [corresponding ASCII character]; |
| 126 | Esc Esc 2 obviously can't be Ctrl-2 here */ |
| 127 | if (kbinput >= '0' && kbinput <= '2') |
| 128 | kbinput = get_ascii_kbinput(win, kbinput); |
| 129 | /* Esc Esc [character] == Ctrl-[character]; |
| 130 | * Ctrl-Space (Ctrl-2) == Ctrl-@ == Ctrl-` */ |
| 131 | else if (kbinput == ' ' || kbinput == '@' || kbinput == '`') |
| 132 | kbinput = NANO_CONTROL_SPACE; |
| 133 | /* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-_) */ |
| 134 | else if (kbinput >= '3' && kbinput <= '7') |
| 135 | kbinput -= 24; |
| 136 | /* Ctrl-8 (Ctrl-?) */ |
| 137 | else if (kbinput == '8' || kbinput == '?') |
| 138 | kbinput = NANO_CONTROL_8; |
| 139 | /* Ctrl-A to Ctrl-_ */ |
| 140 | else if (kbinput >= 'A' && kbinput <= '_') |
| 141 | kbinput -= 64; |
David Lawrence Ramsey | da8fd8f | 2003-09-16 01:22:31 +0000 | [diff] [blame] | 142 | /* Ctrl-A to Ctrl-~ */ |
| 143 | else if (kbinput >= 'a' && kbinput <= '~') |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 144 | kbinput -= 96; |
| 145 | break; |
| 146 | /* Terminal breakage, part 1: We shouldn't get an escape |
| 147 | * sequence here for terminals that support Delete, but |
| 148 | * we do sometimes on FreeBSD. Thank you, Wouter van |
| 149 | * Hemel. */ |
| 150 | case '[': |
| 151 | nodelay(win, TRUE); |
| 152 | kbinput = wgetch(win); |
| 153 | switch (kbinput) { |
| 154 | case ERR: |
| 155 | kbinput = '['; |
| 156 | *meta = 1; |
| 157 | break; |
| 158 | default: |
| 159 | kbinput = get_escape_seq_kbinput(win, kbinput); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 160 | } |
| 161 | nodelay(win, FALSE); |
| 162 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 163 | default: |
| 164 | /* Esc [character] == Meta-[character] */ |
David Lawrence Ramsey | da8fd8f | 2003-09-16 01:22:31 +0000 | [diff] [blame] | 165 | kbinput = tolower(kbinput); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 166 | *meta = 1; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 167 | } |
| 168 | break; |
| 169 | case KEY_DOWN: |
| 170 | kbinput = NANO_DOWN_KEY; |
| 171 | break; |
| 172 | case KEY_UP: |
| 173 | kbinput = NANO_UP_KEY; |
| 174 | break; |
| 175 | case KEY_LEFT: |
| 176 | kbinput = NANO_BACK_KEY; |
| 177 | break; |
| 178 | case KEY_RIGHT: |
| 179 | kbinput = NANO_FORWARD_KEY; |
| 180 | break; |
| 181 | case KEY_HOME: |
| 182 | kbinput = NANO_HOME_KEY; |
| 183 | break; |
| 184 | case KEY_BACKSPACE: |
| 185 | kbinput = NANO_BACKSPACE_KEY; |
| 186 | break; |
| 187 | case KEY_DC: |
| 188 | /* Terminal breakage, part 2: We should only get KEY_DC when |
| 189 | * hitting Delete, but we get it when hitting Backspace |
| 190 | * sometimes on FreeBSD. Thank you, Lee Nelson. */ |
| 191 | kbinput = (rebind_delete) ? NANO_BACKSPACE_KEY : NANO_DELETE_KEY; |
| 192 | break; |
| 193 | case KEY_IC: |
| 194 | kbinput = NANO_INSERTFILE_KEY; |
| 195 | break; |
| 196 | case KEY_NPAGE: |
| 197 | kbinput = NANO_NEXTPAGE_KEY; |
| 198 | break; |
| 199 | case KEY_PPAGE: |
| 200 | kbinput = NANO_PREVPAGE_KEY; |
| 201 | break; |
| 202 | case KEY_ENTER: |
| 203 | kbinput = NANO_ENTER_KEY; |
| 204 | break; |
| 205 | case KEY_END: |
| 206 | kbinput = NANO_END_KEY; |
| 207 | break; |
| 208 | case KEY_SUSPEND: |
| 209 | kbinput = NANO_SUSPEND_KEY; |
| 210 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 211 | } |
| 212 | #ifdef DEBUG |
| 213 | fprintf(stderr, "get_accepted_kbinput(): kbinput = %d, meta = %d\n", kbinput, *meta); |
| 214 | #endif |
| 215 | return kbinput; |
| 216 | } |
| 217 | |
| 218 | /* Translate a three-digit decimal ASCII code from 000-255 into the |
| 219 | * corresponding ASCII character. */ |
| 220 | int get_ascii_kbinput(WINDOW *win, int kbinput) |
| 221 | { |
| 222 | int retval; |
| 223 | |
| 224 | switch (kbinput) { |
| 225 | case '0': |
| 226 | case '1': |
| 227 | case '2': |
| 228 | retval = (kbinput - 48) * 100; |
| 229 | break; |
| 230 | default: |
| 231 | return kbinput; |
| 232 | } |
| 233 | |
| 234 | kbinput = wgetch(win); |
| 235 | switch (kbinput) { |
| 236 | case '0': |
| 237 | case '1': |
| 238 | case '2': |
| 239 | case '3': |
| 240 | case '4': |
| 241 | case '5': |
| 242 | retval += (kbinput - 48) * 10; |
| 243 | break; |
| 244 | case '6': |
| 245 | case '7': |
| 246 | case '8': |
| 247 | case '9': |
| 248 | if (retval < 200) { |
| 249 | retval += (kbinput - 48) * 10; |
| 250 | break; |
| 251 | } |
| 252 | default: |
| 253 | return kbinput; |
| 254 | } |
| 255 | |
| 256 | kbinput = wgetch(win); |
| 257 | switch (kbinput) { |
| 258 | case '0': |
| 259 | case '1': |
| 260 | case '2': |
| 261 | case '3': |
| 262 | case '4': |
| 263 | case '5': |
| 264 | retval += kbinput - 48; |
| 265 | break; |
| 266 | case '6': |
| 267 | case '7': |
| 268 | case '8': |
| 269 | case '9': |
| 270 | if (retval < 250) { |
| 271 | retval += kbinput - 48; |
| 272 | break; |
| 273 | } |
| 274 | default: |
| 275 | return kbinput; |
| 276 | } |
| 277 | |
| 278 | #ifdef DEBUG |
| 279 | fprintf(stderr, "get_ascii_kbinput(): kbinput = %d\n", kbinput); |
| 280 | #endif |
| 281 | return retval; |
| 282 | } |
| 283 | |
| 284 | /* Translate common escape sequences for some keys. These are generated |
| 285 | * when the terminal doesn't support those keys. Assume nodelay(win) is |
| 286 | * TRUE. */ |
| 287 | int get_escape_seq_kbinput(WINDOW *win, int kbinput) |
| 288 | { |
| 289 | switch (kbinput) { |
| 290 | case '3': |
| 291 | /* Esc [ 3 ~ == kdch1 on many terminals. */ |
| 292 | kbinput = get_skip_tilde_kbinput(win, kbinput, NANO_DELETE_KEY); |
| 293 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 294 | } |
| 295 | return kbinput; |
| 296 | } |
| 297 | |
| 298 | /* If there is no next character, return the passed-in error value. If |
| 299 | * the next character's a tilde, eat it and return the passed-in |
| 300 | * return value. Otherwise, return the next character. Assume |
| 301 | * nodelay(win) is TRUE. */ |
| 302 | int get_skip_tilde_kbinput(WINDOW *win, int errval, int retval) |
| 303 | { |
| 304 | int kbinput = wgetch(win); |
| 305 | switch (kbinput) { |
| 306 | case ERR: |
| 307 | return errval; |
| 308 | case '~': |
| 309 | return retval; |
| 310 | default: |
| 311 | return kbinput; |
| 312 | } |
| 313 | } |
| 314 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 315 | int do_first_line(void) |
| 316 | { |
| 317 | current = fileage; |
| 318 | placewewant = 0; |
| 319 | current_x = 0; |
David Lawrence Ramsey | d91ab6e | 2003-09-07 23:57:24 +0000 | [diff] [blame] | 320 | edit_update(current, TOP); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 321 | return 1; |
| 322 | } |
| 323 | |
| 324 | int do_last_line(void) |
| 325 | { |
| 326 | current = filebot; |
| 327 | placewewant = 0; |
| 328 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 329 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 330 | return 1; |
| 331 | } |
| 332 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 333 | /* Return the placewewant associated with current_x. That is, xplustabs |
| 334 | * is the zero-based column position of the cursor. Value is no smaller |
| 335 | * than current_x. */ |
| 336 | size_t xplustabs(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 337 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 338 | return strnlenpt(current->data, current_x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 339 | } |
| 340 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 341 | /* actual_x() gives the index in str of the character displayed at |
| 342 | * column xplus. That is, actual_x() is the largest value such that |
| 343 | * strnlenpt(str, actual_x(str, xplus)) <= xplus. */ |
| 344 | size_t actual_x(const char *str, size_t xplus) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 345 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 346 | size_t i = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 347 | /* the position in str, returned */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 348 | size_t length = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 349 | /* the screen display width to str[i] */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 350 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 351 | assert(str != NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 352 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 353 | for (; length < xplus && *str != '\0'; i++, str++) { |
| 354 | if (*str == '\t') |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 355 | length += tabsize - length % tabsize; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 356 | else if (is_cntrl_char((int)*str)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 357 | length += 2; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 358 | else |
| 359 | length++; |
| 360 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 361 | assert(length == strnlenpt(str - i, i)); |
| 362 | assert(i <= strlen(str - i)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 363 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 364 | if (length > xplus) |
| 365 | i--; |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 366 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 367 | return i; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 368 | } |
| 369 | |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame^] | 370 | /* A strlen with tabs factored in, similar to xplustabs(). How many |
| 371 | * columns wide are the first size characters of buf? */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 372 | size_t strnlenpt(const char *buf, size_t size) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 373 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 374 | size_t length = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 375 | |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame^] | 376 | assert(buf != NULL); |
| 377 | for (; *buf != '\0' && size != 0; size--, buf++) { |
| 378 | if (*buf == '\t') |
| 379 | length += tabsize - (length % tabsize); |
| 380 | else if (is_cntrl_char((int)*buf)) |
| 381 | length += 2; |
| 382 | else |
| 383 | length++; |
| 384 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 385 | return length; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 386 | } |
| 387 | |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame^] | 388 | /* How many columns wide is buf? */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 389 | size_t strlenpt(const char *buf) |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 390 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 391 | return strnlenpt(buf, -1); |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 394 | void blank_bottombars(void) |
| 395 | { |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame^] | 396 | if (!ISSET(NO_HELP)) { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 397 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 398 | mvwaddstr(bottomwin, 2, 0, hblank); |
| 399 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 400 | } |
| 401 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 402 | void blank_bottomwin(void) |
| 403 | { |
| 404 | if (ISSET(NO_HELP)) |
| 405 | return; |
| 406 | |
| 407 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 408 | mvwaddstr(bottomwin, 2, 0, hblank); |
| 409 | } |
| 410 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 411 | void blank_edit(void) |
| 412 | { |
| 413 | int i; |
| 414 | for (i = 0; i <= editwinrows - 1; i++) |
| 415 | mvwaddstr(edit, i, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 418 | void blank_statusbar(void) |
| 419 | { |
| 420 | mvwaddstr(bottomwin, 0, 0, hblank); |
| 421 | } |
| 422 | |
| 423 | void blank_statusbar_refresh(void) |
| 424 | { |
| 425 | blank_statusbar(); |
| 426 | wrefresh(bottomwin); |
| 427 | } |
| 428 | |
| 429 | void check_statblank(void) |
| 430 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 431 | if (statblank > 1) |
| 432 | statblank--; |
| 433 | else if (statblank == 1 && !ISSET(CONSTUPDATE)) { |
| 434 | statblank--; |
| 435 | blank_statusbar_refresh(); |
| 436 | } |
| 437 | } |
| 438 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 439 | /* Convert buf into a string that can be displayed on screen. The |
| 440 | * caller wants to display buf starting with column start_col, and |
| 441 | * extending for at most len columns. start_col is zero-based. len is |
| 442 | * one-based, so len == 0 means you get "" returned. The returned |
| 443 | * string is dynamically allocated, and should be freed. */ |
| 444 | char *display_string(const char *buf, size_t start_col, int len) |
| 445 | { |
| 446 | size_t start_index; |
| 447 | /* Index in buf of first character shown in return value. */ |
| 448 | size_t column; |
| 449 | /* Screen column start_index corresponds to. */ |
| 450 | size_t end_index; |
| 451 | /* Index in buf of last character shown in return value. */ |
| 452 | size_t alloc_len; |
| 453 | /* The length of memory allocated for converted. */ |
| 454 | char *converted; |
| 455 | /* The string we return. */ |
| 456 | size_t index; |
| 457 | /* Current position in converted. */ |
| 458 | |
| 459 | if (len == 0) |
| 460 | return mallocstrcpy(NULL, ""); |
| 461 | |
| 462 | start_index = actual_x(buf, start_col); |
| 463 | column = strnlenpt(buf, start_index); |
| 464 | assert(column <= start_col); |
| 465 | end_index = actual_x(buf, start_col + len - 1); |
| 466 | alloc_len = strnlenpt(buf, end_index + 1) - column; |
| 467 | if (len > alloc_len + column - start_col) |
| 468 | len = alloc_len + column - start_col; |
| 469 | converted = charalloc(alloc_len + 1); |
| 470 | buf += start_index; |
| 471 | index = 0; |
| 472 | |
| 473 | for (; index < alloc_len; buf++) { |
| 474 | if (*buf == '\t') |
| 475 | do { |
| 476 | converted[index++] = ' '; |
| 477 | } while ((column + index) % tabsize); |
| 478 | else if (is_cntrl_char(*buf)) { |
| 479 | converted[index++] = '^'; |
| 480 | if (*buf == '\n') |
| 481 | /* Treat newlines embedded in a line as encoded nulls; |
| 482 | * the line in question should be run through unsunder() |
| 483 | * before reaching here. */ |
| 484 | converted[index++] = '@'; |
| 485 | else if (*buf == NANO_CONTROL_8) |
| 486 | converted[index++] = '?'; |
| 487 | else |
| 488 | converted[index++] = *buf + 64; |
| 489 | } else |
| 490 | converted[index++] = *buf; |
| 491 | } |
| 492 | assert(len <= alloc_len + column - start_col); |
| 493 | charmove(converted, converted + start_col - column, len); |
| 494 | null_at(&converted, len); |
| 495 | |
| 496 | return charealloc(converted, len + 1); |
| 497 | } |
| 498 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 499 | /* Repaint the statusbar when getting a character in nanogetstr(). buf |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 500 | * should be no longer than max(0, COLS - 4). |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 501 | * |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 502 | * Note that we must turn on A_REVERSE here, since do_help() turns it |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 503 | * off! */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 504 | void nanoget_repaint(const char *buf, const char *inputbuf, size_t x) |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 505 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 506 | size_t x_real = strnlenpt(inputbuf, x); |
| 507 | int wid = COLS - strlen(buf) - 2; |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 508 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 509 | assert(0 <= x && x <= strlen(inputbuf)); |
| 510 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 511 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 512 | blank_statusbar(); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 513 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 514 | mvwaddstr(bottomwin, 0, 0, buf); |
| 515 | waddch(bottomwin, ':'); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 516 | |
| 517 | if (COLS > 1) |
| 518 | waddch(bottomwin, x_real < wid ? ' ' : '$'); |
| 519 | if (COLS > 2) { |
| 520 | size_t page_start = x_real - x_real % wid; |
| 521 | char *expanded = display_string(inputbuf, page_start, wid); |
| 522 | |
| 523 | assert(wid > 0); |
| 524 | assert(strlen(expanded) <= wid); |
| 525 | waddstr(bottomwin, expanded); |
| 526 | free(expanded); |
| 527 | wmove(bottomwin, 0, COLS - wid + x_real - page_start); |
| 528 | } else |
| 529 | wmove(bottomwin, 0, COLS - 1); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 530 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 533 | /* Get the input from the kb; this should only be called from |
| 534 | * statusq(). */ |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 535 | int nanogetstr(int allowtabs, const char *buf, const char *def, |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 536 | #ifndef NANO_SMALL |
| 537 | historyheadtype *history_list, |
| 538 | #endif |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 539 | const shortcut *s |
Rocco Corsi | 06aca1c | 2001-01-11 05:30:31 +0000 | [diff] [blame] | 540 | #ifndef DISABLE_TABCOMP |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 541 | , int *list |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 542 | #endif |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 543 | ) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 544 | { |
| 545 | int kbinput; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 546 | int meta; |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 547 | static int x = -1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 548 | /* the cursor position in 'answer' */ |
| 549 | int xend; |
| 550 | /* length of 'answer', the status bar text */ |
| 551 | int tabbed = 0; |
| 552 | /* used by input_tab() */ |
| 553 | const shortcut *t; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 554 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 555 | #ifndef NANO_SMALL |
| 556 | /* for history */ |
| 557 | char *history = NULL; |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 558 | char *currentbuf = NULL; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 559 | char *complete = NULL; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 560 | int last_kbinput = 0; |
| 561 | |
| 562 | /* This variable is used in the search history code. use_cb == 0 |
| 563 | means that we're using the existing history and ignoring |
| 564 | currentbuf. use_cb == 1 means that the entry in answer should be |
| 565 | moved to currentbuf or restored from currentbuf to answer. |
| 566 | use_cb == 2 means that the entry in currentbuf should be moved to |
| 567 | answer or restored from answer to currentbuf. */ |
| 568 | int use_cb = 0; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 569 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 570 | xend = strlen(def); |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 571 | |
| 572 | /* Only put x at the end of the string if it's uninitialized or if |
| 573 | it would be past the end of the string as it is. Otherwise, |
| 574 | leave it alone. This is so the cursor position stays at the same |
| 575 | place if a prompt-changing toggle is pressed. */ |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 576 | if (x == -1 || x > xend || resetstatuspos) |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 577 | x = xend; |
| 578 | |
Chris Allegretta | e1e0fd6 | 2003-04-15 01:15:09 +0000 | [diff] [blame] | 579 | answer = charealloc(answer, xend + 1); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 580 | if (xend > 0) |
| 581 | strcpy(answer, def); |
| 582 | else |
| 583 | answer[0] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 584 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 585 | #if !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)) |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 586 | currshortcut = s; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 587 | #endif |
| 588 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 589 | /* Get the input! */ |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 590 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 591 | nanoget_repaint(buf, answer, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 592 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 593 | /* Make sure any editor screen updates are displayed before getting |
| 594 | input */ |
Chris Allegretta | 022b96f | 2000-11-14 17:47:58 +0000 | [diff] [blame] | 595 | wrefresh(edit); |
| 596 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 597 | while ((kbinput = get_kbinput(bottomwin, &meta, ISSET(REBIND_DELETE))) != NANO_ENTER_KEY) { |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 598 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 599 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 600 | fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput); |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 601 | #endif |
| 602 | |
David Lawrence Ramsey | 7f47d42 | 2003-09-08 18:01:49 +0000 | [diff] [blame] | 603 | if (kbinput == t->val && (kbinput < 32 || kbinput == 127)) { |
Chris Allegretta | 5bf51d3 | 2000-11-16 06:01:10 +0000 | [diff] [blame] | 604 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 605 | #ifndef DISABLE_HELP |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 606 | /* Have to do this here, it would be too late to do it |
| 607 | in statusq() */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 608 | if (kbinput == NANO_HELP_KEY || kbinput == NANO_HELP_FKEY) { |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 609 | do_help(); |
| 610 | break; |
| 611 | } |
| 612 | #endif |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 613 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 614 | return t->val; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 615 | } |
| 616 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 617 | assert(0 <= x && x <= xend && xend == strlen(answer)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 618 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 619 | if (kbinput != '\t') |
| 620 | tabbed = 0; |
| 621 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 622 | switch (kbinput) { |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 623 | #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION) |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 624 | case KEY_MOUSE: |
| 625 | do_mouse(); |
| 626 | break; |
| 627 | #endif |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 628 | case NANO_HOME_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 629 | x = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 630 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 631 | case NANO_END_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 632 | x = xend; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 633 | break; |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 634 | case NANO_FORWARD_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 635 | if (x < xend) |
| 636 | x++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 637 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 638 | case NANO_DELETE_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 639 | if (x < xend) { |
David Lawrence Ramsey | 9eff746 | 2003-09-16 02:04:00 +0000 | [diff] [blame] | 640 | charmove(answer + x, answer + x + 1, xend - x); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 641 | xend--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 642 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 643 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 644 | case NANO_CUT_KEY: |
| 645 | case NANO_UNCUT_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 646 | null_at(&answer, 0); |
| 647 | xend = 0; |
| 648 | x = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 649 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 650 | case NANO_BACKSPACE_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 651 | if (x > 0) { |
David Lawrence Ramsey | 9eff746 | 2003-09-16 02:04:00 +0000 | [diff] [blame] | 652 | charmove(answer + x - 1, answer + x, xend - x + 1); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 653 | x--; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 654 | xend--; |
| 655 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 656 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 657 | case NANO_TAB_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 658 | #ifndef NANO_SMALL |
| 659 | /* tab history completion */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 660 | if (history_list != NULL) { |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 661 | if (!complete || last_kbinput != NANO_TAB_KEY) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 662 | history_list->current = (historytype *)history_list; |
| 663 | history_list->len = strlen(answer); |
| 664 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 665 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 666 | if (history_list->len > 0) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 667 | complete = get_history_completion(history_list, answer); |
| 668 | xend = strlen(complete); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 669 | x = xend; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 670 | answer = mallocstrcpy(answer, complete); |
| 671 | } |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 672 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 673 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 674 | else |
| 675 | #endif |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 676 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 677 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 678 | if (allowtabs) { |
| 679 | int shift = 0; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 680 | |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 681 | answer = input_tab(answer, x, &tabbed, &shift, list); |
| 682 | xend = strlen(answer); |
| 683 | x += shift; |
| 684 | if (x > xend) |
| 685 | x = xend; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 686 | } |
| 687 | #endif |
| 688 | break; |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 689 | case NANO_BACK_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 690 | if (x > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 691 | x--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 692 | break; |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 693 | case NANO_UP_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 694 | #ifndef NANO_SMALL |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 695 | if (history_list != NULL) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 696 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 697 | /* if currentbuf is NULL, or if use_cb is 1, currentbuf |
| 698 | isn't NULL, and currentbuf is different from answer, |
| 699 | it means that we're scrolling up at the top of the |
| 700 | search history, and we need to save the current |
| 701 | answer in currentbuf; do this and reset use_cb to |
| 702 | 0 */ |
| 703 | if (currentbuf == NULL || (use_cb == 1 && strcmp(currentbuf, answer))) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 704 | currentbuf = mallocstrcpy(currentbuf, answer); |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 705 | use_cb = 0; |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 706 | } |
| 707 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 708 | /* if currentbuf isn't NULL, use_cb is 2, and currentbuf |
| 709 | is different from answer, it means that we're |
| 710 | scrolling up at the bottom of the search history, and |
| 711 | we need to make the string in currentbuf the current |
| 712 | answer; do this, blow away currentbuf since we don't |
| 713 | need it anymore, and reset use_cb to 0 */ |
| 714 | if (currentbuf != NULL && use_cb == 2 && strcmp(currentbuf, answer)) { |
| 715 | answer = mallocstrcpy(answer, currentbuf); |
| 716 | free(currentbuf); |
| 717 | currentbuf = NULL; |
| 718 | xend = strlen(answer); |
| 719 | use_cb = 0; |
| 720 | |
| 721 | /* else get older search from the history list and save |
| 722 | it in answer; if there is no older search, blank out |
| 723 | answer */ |
| 724 | } else if ((history = get_history_older(history_list)) != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 725 | answer = mallocstrcpy(answer, history); |
| 726 | xend = strlen(history); |
| 727 | } else { |
| 728 | answer = mallocstrcpy(answer, ""); |
| 729 | xend = 0; |
| 730 | } |
| 731 | x = xend; |
| 732 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 733 | #endif |
Chris Allegretta | 54abd94 | 2003-01-09 23:43:12 +0000 | [diff] [blame] | 734 | break; |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 735 | case NANO_DOWN_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 736 | #ifndef NANO_SMALL |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 737 | if (history_list != NULL) { |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 738 | |
| 739 | /* get newer search from the history list and save it |
| 740 | in answer */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 741 | if ((history = get_history_newer(history_list)) != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 742 | answer = mallocstrcpy(answer, history); |
| 743 | xend = strlen(history); |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 744 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 745 | /* if there is no newer search, we're here */ |
| 746 | |
| 747 | /* if currentbuf isn't NULL and use_cb isn't 2, it means |
| 748 | that we're scrolling down at the bottom of the search |
| 749 | history and we need to make the string in currentbuf |
| 750 | the current answer; do this, blow away currentbuf |
| 751 | since we don't need it anymore, and set use_cb to |
| 752 | 1 */ |
| 753 | } else if (currentbuf != NULL && use_cb != 2) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 754 | answer = mallocstrcpy(answer, currentbuf); |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 755 | free(currentbuf); |
| 756 | currentbuf = NULL; |
| 757 | xend = strlen(answer); |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 758 | use_cb = 1; |
| 759 | |
| 760 | /* otherwise, if currentbuf is NULL and use_cb isn't 2, |
| 761 | it means that we're scrolling down at the bottom of |
Chris Allegretta | c30fc24 | 2003-08-11 00:32:45 +0000 | [diff] [blame] | 762 | the search history and the current answer (if it's |
| 763 | not blank) needs to be saved in currentbuf; do this, |
| 764 | blank out answer (if necessary), and set use_cb to |
| 765 | 2 */ |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 766 | } else if (use_cb != 2) { |
Chris Allegretta | c30fc24 | 2003-08-11 00:32:45 +0000 | [diff] [blame] | 767 | if (answer[0] != '\0') { |
| 768 | currentbuf = mallocstrcpy(currentbuf, answer); |
| 769 | answer = mallocstrcpy(answer, ""); |
| 770 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 771 | xend = 0; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 772 | use_cb = 2; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 773 | } |
| 774 | x = xend; |
| 775 | } |
| 776 | #endif |
| 777 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 778 | default: |
| 779 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 780 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 781 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 782 | fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 783 | kbinput); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 784 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 785 | if (meta == 1 && (kbinput == t->val || kbinput == t->val - 32)) |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 786 | /* We hit an Alt key. Do like above. We don't |
| 787 | just ungetch() the letter and let it get |
| 788 | caught above cause that screws the |
| 789 | keypad... */ |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 790 | return t->val; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 791 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 792 | |
David Lawrence Ramsey | 7f47d42 | 2003-09-08 18:01:49 +0000 | [diff] [blame] | 793 | if (kbinput < 32 || kbinput == 127) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 794 | break; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 795 | answer = charealloc(answer, xend + 2); |
David Lawrence Ramsey | 9eff746 | 2003-09-16 02:04:00 +0000 | [diff] [blame] | 796 | charmove(answer + x + 1, answer + x, xend - x + 1); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 797 | xend++; |
| 798 | answer[x] = kbinput; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 799 | x++; |
| 800 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 801 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 802 | fprintf(stderr, "input \'%c\' (%d)\n", kbinput, kbinput); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 803 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 804 | } /* switch (kbinput) */ |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 805 | #ifndef NANO_SMALL |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 806 | last_kbinput = kbinput; |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 807 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 808 | nanoget_repaint(buf, answer, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 809 | wrefresh(bottomwin); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 810 | } /* while (kbinput ...) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 811 | |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 812 | /* We finished putting in an answer; reset x */ |
| 813 | x = -1; |
| 814 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 815 | /* Just check for a blank answer here */ |
Chris Allegretta | 15c28f8 | 2003-01-05 21:47:06 +0000 | [diff] [blame] | 816 | if (answer[0] == '\0') |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 817 | return -2; |
| 818 | else |
| 819 | return 0; |
| 820 | } |
| 821 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 822 | /* If modified is not already set, set it and update titlebar. */ |
| 823 | void set_modified(void) |
| 824 | { |
| 825 | if (!ISSET(MODIFIED)) { |
| 826 | SET(MODIFIED); |
| 827 | titlebar(NULL); |
| 828 | wrefresh(topwin); |
| 829 | } |
| 830 | } |
| 831 | |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 832 | void titlebar(const char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 833 | { |
| 834 | int namelen, space; |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 835 | const char *what = path; |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 836 | |
| 837 | if (path == NULL) |
| 838 | what = filename; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 839 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 840 | wattron(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 841 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 842 | mvwaddstr(topwin, 0, 0, hblank); |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 843 | mvwaddnstr(topwin, 0, 2, VERMSG, COLS - 3); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 844 | |
David Lawrence Ramsey | ec290f2 | 2003-08-30 19:05:40 +0000 | [diff] [blame] | 845 | space = COLS - sizeof(VERMSG) - 23; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 846 | |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 847 | namelen = strlen(what); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 848 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 849 | if (space > 0) { |
| 850 | if (what[0] == '\0') |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 851 | mvwaddnstr(topwin, 0, COLS / 2 - 6, _("New Buffer"), |
| 852 | COLS / 2 + COLS % 2 - 6); |
| 853 | else if (namelen > space) { |
| 854 | if (path == NULL) |
| 855 | waddstr(topwin, _(" File: ...")); |
| 856 | else |
| 857 | waddstr(topwin, _(" DIR: ...")); |
| 858 | waddstr(topwin, &what[namelen - space]); |
| 859 | } else { |
| 860 | if (path == NULL) |
| 861 | mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), |
| 862 | _("File: ")); |
| 863 | else |
| 864 | mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), |
| 865 | _(" DIR: ")); |
| 866 | waddstr(topwin, what); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 867 | } |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 868 | } /* If we don't have space, we shouldn't bother */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 869 | if (ISSET(MODIFIED)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 870 | mvwaddnstr(topwin, 0, COLS - 11, _(" Modified "), 11); |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 871 | else if (ISSET(VIEW_MODE)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 872 | mvwaddnstr(topwin, 0, COLS - 11, _(" View "), 11); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 873 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 874 | wattroff(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 875 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 876 | wrefresh(topwin); |
| 877 | reset_cursor(); |
| 878 | } |
| 879 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 880 | void bottombars(const shortcut *s) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 881 | { |
Chris Allegretta | bc72e36 | 2002-02-16 20:03:44 +0000 | [diff] [blame] | 882 | int i, j, numcols; |
Chris Allegretta | 3bbc416 | 2003-01-23 00:46:12 +0000 | [diff] [blame] | 883 | char keystr[9]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 884 | int slen; |
| 885 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 886 | if (ISSET(NO_HELP)) |
| 887 | return; |
| 888 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 889 | if (s == main_list) { |
| 890 | slen = MAIN_VISIBLE; |
| 891 | assert(MAIN_VISIBLE <= length_of_list(s)); |
| 892 | } else |
| 893 | slen = length_of_list(s); |
| 894 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 895 | /* There will be this many columns of shortcuts */ |
| 896 | numcols = (slen + (slen % 2)) / 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 897 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 898 | blank_bottomwin(); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 899 | |
Chris Allegretta | bc72e36 | 2002-02-16 20:03:44 +0000 | [diff] [blame] | 900 | for (i = 0; i < numcols; i++) { |
| 901 | for (j = 0; j <= 1; j++) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 902 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 903 | wmove(bottomwin, 1 + j, i * (COLS / numcols)); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 904 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 905 | /* Yucky sentinel values we can't handle a better way */ |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 906 | if (s->val == NANO_CONTROL_SPACE) |
| 907 | strcpy(keystr, "^ "); |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 908 | #ifndef NANO_SMALL |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 909 | else if (s->val == KEY_UP) |
Chris Allegretta | 3bbc416 | 2003-01-23 00:46:12 +0000 | [diff] [blame] | 910 | strncpy(keystr, _("Up"), 8); |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 911 | #endif /* NANO_SMALL */ |
| 912 | else if (s->val > 0) { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 913 | if (s->val < 64) |
| 914 | sprintf(keystr, "^%c", s->val + 64); |
| 915 | else |
| 916 | sprintf(keystr, "M-%c", s->val - 32); |
| 917 | } else if (s->altval > 0) |
| 918 | sprintf(keystr, "M-%c", s->altval); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 919 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 920 | onekey(keystr, s->desc, COLS / numcols); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 921 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 922 | s = s->next; |
| 923 | if (s == NULL) |
| 924 | goto break_completely_out; |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 925 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 928 | break_completely_out: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 929 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 930 | } |
| 931 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 932 | /* Write a shortcut key to the help area at the bottom of the window. |
| 933 | * keystroke is e.g. "^G" and desc is e.g. "Get Help". |
| 934 | * We are careful to write exactly len characters, even if len is |
| 935 | * very small and keystroke and desc are long. */ |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 936 | void onekey(const char *keystroke, const char *desc, int len) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 937 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 938 | wattron(bottomwin, A_REVERSE); |
| 939 | waddnstr(bottomwin, keystroke, len); |
| 940 | wattroff(bottomwin, A_REVERSE); |
| 941 | len -= strlen(keystroke); |
| 942 | if (len > 0) { |
| 943 | waddch(bottomwin, ' '); |
| 944 | len--; |
| 945 | waddnstr(bottomwin, desc, len); |
| 946 | len -= strlen(desc); |
| 947 | for (; len > 0; len--) |
| 948 | waddch(bottomwin, ' '); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 952 | /* And so start the display update routines. */ |
| 953 | |
| 954 | #ifndef NDEBUG |
| 955 | int check_linenumbers(const filestruct *fileptr) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 956 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 957 | int check_line = 0; |
| 958 | const filestruct *filetmp; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 959 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 960 | for (filetmp = edittop; filetmp != fileptr; filetmp = filetmp->next) |
| 961 | check_line++; |
| 962 | return check_line; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 963 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 964 | #endif |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 965 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 966 | /* nano scrolls horizontally within a line in chunks. This function |
| 967 | * returns the column number of the first character displayed in the |
| 968 | * window when the cursor is at the given column. */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 969 | int get_page_start(int column) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 970 | { |
| 971 | assert(COLS > 9); |
| 972 | return column < COLS - 1 ? 0 : column - 7 - (column - 8) % (COLS - 9); |
| 973 | } |
| 974 | |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 975 | /* Resets current_y, based on the position of current, and puts the |
| 976 | * cursor at (current_y, current_x). */ |
| 977 | void reset_cursor(void) |
| 978 | { |
| 979 | const filestruct *ptr = edittop; |
| 980 | size_t x; |
| 981 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 982 | /* Yuck. This condition can be true after open_file() when opening |
| 983 | * the first file. */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 984 | if (edittop == NULL) |
| 985 | return; |
| 986 | |
| 987 | current_y = 0; |
| 988 | |
| 989 | while (ptr != current && ptr != editbot && ptr->next != NULL) { |
| 990 | ptr = ptr->next; |
| 991 | current_y++; |
| 992 | } |
| 993 | |
| 994 | x = xplustabs(); |
| 995 | wmove(edit, current_y, x - get_page_start(x)); |
| 996 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 997 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 998 | /* edit_add() takes care of the job of actually painting a line into the |
| 999 | * edit window. fileptr is the line to be painted, at row yval of the |
| 1000 | * window. converted is the actual string to be written to the window, |
| 1001 | * with tabs and control characters replaced by strings of regular |
| 1002 | * characters. start is the column number of the first character |
| 1003 | * of this page. That is, the first character of converted corresponds to |
| 1004 | * character number actual_x(fileptr->data, start) of the line. */ |
| 1005 | void edit_add(const filestruct *fileptr, const char *converted, |
| 1006 | int yval, size_t start) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1007 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1008 | #if defined(ENABLE_COLOR) || !defined(NANO_SMALL) |
| 1009 | size_t startpos = actual_x(fileptr->data, start); |
| 1010 | /* The position in fileptr->data of the leftmost character |
| 1011 | * that displays at least partially on the window. */ |
| 1012 | size_t endpos = actual_x(fileptr->data, start + COLS - 1) + 1; |
| 1013 | /* The position in fileptr->data of the first character that is |
| 1014 | * completely off the window to the right. |
| 1015 | * |
| 1016 | * Note that endpos might be beyond the null terminator of the |
| 1017 | * string. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1018 | #endif |
| 1019 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1020 | assert(fileptr != NULL && converted != NULL); |
| 1021 | assert(strlen(converted) <= COLS); |
| 1022 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1023 | /* Just paint the string in any case (we'll add color or reverse on |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1024 | * just the text that needs it). */ |
| 1025 | mvwaddstr(edit, yval, 0, converted); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1026 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 1027 | #ifdef ENABLE_COLOR |
Chris Allegretta | 1dd0bc9 | 2002-10-13 18:43:45 +0000 | [diff] [blame] | 1028 | if (colorstrings != NULL && ISSET(COLOR_SYNTAX)) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1029 | const colortype *tmpcolor = colorstrings; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1030 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1031 | for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { |
| 1032 | int x_start; |
| 1033 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 1034 | int paintlen; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1035 | /* Number of chars to paint on this line. There are COLS |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1036 | * characters on a whole line. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1037 | regmatch_t startmatch; /* match position for start_regexp */ |
| 1038 | regmatch_t endmatch; /* match position for end_regexp */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1039 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1040 | if (tmpcolor->bright) |
| 1041 | wattron(edit, A_BOLD); |
| 1042 | wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1043 | /* Two notes about regexec(). Return value 0 means there is |
| 1044 | * a match. Also, rm_eo is the first non-matching character |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1045 | * after the match. */ |
| 1046 | |
| 1047 | /* First case, tmpcolor is a single-line expression. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1048 | if (tmpcolor->end == NULL) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1049 | size_t k = 0; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1050 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1051 | /* We increment k by rm_eo, to move past the end of the |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1052 | * last match. Even though two matches may overlap, we |
| 1053 | * want to ignore them, so that we can highlight |
| 1054 | * C-strings correctly. */ |
| 1055 | while (k < endpos) { |
| 1056 | /* Note the fifth parameter to regexec(). It says |
| 1057 | * not to match the beginning-of-line character |
| 1058 | * unless k is 0. If regexec() returns REG_NOMATCH, |
| 1059 | * there are no more matches in the line. */ |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1060 | if (regexec(&tmpcolor->start, &fileptr->data[k], 1, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1061 | &startmatch, k == 0 ? 0 : REG_NOTBOL) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1062 | break; |
| 1063 | /* Translate the match to the beginning of the line. */ |
| 1064 | startmatch.rm_so += k; |
| 1065 | startmatch.rm_eo += k; |
David Lawrence Ramsey | 2ab03f6 | 2002-10-17 02:19:31 +0000 | [diff] [blame] | 1066 | if (startmatch.rm_so == startmatch.rm_eo) { |
| 1067 | startmatch.rm_eo++; |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 1068 | statusbar(_("Refusing 0 length regex match")); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1069 | } else if (startmatch.rm_so < endpos && |
| 1070 | startmatch.rm_eo > startpos) { |
| 1071 | if (startmatch.rm_so <= startpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1072 | x_start = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1073 | else |
| 1074 | x_start = strnlenpt(fileptr->data, startmatch.rm_so) |
| 1075 | - start; |
| 1076 | paintlen = strnlenpt(fileptr->data, startmatch.rm_eo) |
| 1077 | - start - x_start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1078 | if (paintlen > COLS - x_start) |
| 1079 | paintlen = COLS - x_start; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1080 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1081 | assert(0 <= x_start && 0 < paintlen && |
| 1082 | x_start + paintlen <= COLS); |
| 1083 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1084 | converted + x_start, paintlen); |
| 1085 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1086 | k = startmatch.rm_eo; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1087 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1088 | } else { |
| 1089 | /* This is a multi-line regexp. There are two steps. |
| 1090 | * First, we have to see if the beginning of the line is |
| 1091 | * colored by a start on an earlier line, and an end on |
| 1092 | * this line or later. |
| 1093 | * |
| 1094 | * We find the first line before fileptr matching the |
| 1095 | * start. If every match on that line is followed by an |
| 1096 | * end, then go to step two. Otherwise, find the next line |
| 1097 | * after start_line matching the end. If that line is not |
| 1098 | * before fileptr, then paint the beginning of this line. */ |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 1099 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1100 | const filestruct *start_line = fileptr->prev; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1101 | /* the first line before fileptr matching start */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1102 | regoff_t start_col; |
| 1103 | /* where it starts in that line */ |
| 1104 | const filestruct *end_line; |
| 1105 | int searched_later_lines = 0; |
| 1106 | /* Used in step 2. Have we looked for an end on |
| 1107 | * lines after fileptr? */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1108 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1109 | while (start_line != NULL && |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1110 | regexec(&tmpcolor->start, start_line->data, 1, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1111 | &startmatch, 0) == REG_NOMATCH) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1112 | /* If there is an end on this line, there is no need |
| 1113 | * to look for starts on earlier lines. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1114 | if (regexec(tmpcolor->end, start_line->data, 0, NULL, 0) |
| 1115 | == 0) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1116 | goto step_two; |
| 1117 | start_line = start_line->prev; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1118 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1119 | /* No start found, so skip to the next step. */ |
| 1120 | if (start_line == NULL) |
| 1121 | goto step_two; |
| 1122 | /* Now start_line is the first line before fileptr |
| 1123 | * containing a start match. Is there a start on this |
| 1124 | * line not followed by an end on this line? */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1125 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1126 | start_col = 0; |
| 1127 | while (1) { |
| 1128 | start_col += startmatch.rm_so; |
| 1129 | startmatch.rm_eo -= startmatch.rm_so; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1130 | if (regexec(tmpcolor->end, |
| 1131 | start_line->data + start_col + startmatch.rm_eo, |
| 1132 | 0, NULL, start_col + startmatch.rm_eo == 0 ? 0 : |
| 1133 | REG_NOTBOL) == REG_NOMATCH) |
| 1134 | /* No end found after this start. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1135 | break; |
| 1136 | start_col++; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1137 | if (regexec(&tmpcolor->start, |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1138 | start_line->data + start_col, 1, &startmatch, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1139 | REG_NOTBOL) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1140 | /* No later start on this line. */ |
| 1141 | goto step_two; |
| 1142 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1143 | /* Indeed, there is a start not followed on this line by |
| 1144 | * an end. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1145 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1146 | /* We have already checked that there is no end before |
| 1147 | * fileptr and after the start. Is there an end after |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1148 | * the start at all? We don't paint unterminated |
| 1149 | * starts. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1150 | end_line = fileptr; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1151 | while (end_line != NULL && |
| 1152 | regexec(tmpcolor->end, end_line->data, 1, &endmatch, 0)) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1153 | end_line = end_line->next; |
| 1154 | |
| 1155 | /* No end found, or it is too early. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1156 | if (end_line == NULL || |
| 1157 | (end_line == fileptr && endmatch.rm_eo <= startpos)) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1158 | goto step_two; |
| 1159 | |
| 1160 | /* Now paint the start of fileptr. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1161 | paintlen = end_line != fileptr ? COLS : |
| 1162 | strnlenpt(fileptr->data, endmatch.rm_eo) - start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1163 | if (paintlen > COLS) |
| 1164 | paintlen = COLS; |
| 1165 | |
| 1166 | assert(0 < paintlen && paintlen <= COLS); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1167 | mvwaddnstr(edit, yval, 0, converted, paintlen); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1168 | |
| 1169 | /* We have already painted the whole line. */ |
| 1170 | if (paintlen == COLS) |
| 1171 | goto skip_step_two; |
| 1172 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1173 | step_two: /* Second step, we look for starts on this line. */ |
| 1174 | start_col = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1175 | while (start_col < endpos) { |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1176 | if (regexec(&tmpcolor->start, fileptr->data + start_col, 1, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1177 | &startmatch, start_col == 0 ? 0 : REG_NOTBOL) |
| 1178 | == REG_NOMATCH || start_col + startmatch.rm_so >= |
| 1179 | endpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1180 | /* No more starts on this line. */ |
| 1181 | break; |
| 1182 | /* Translate the match to be relative to the |
| 1183 | * beginning of the line. */ |
| 1184 | startmatch.rm_so += start_col; |
| 1185 | startmatch.rm_eo += start_col; |
| 1186 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1187 | if (startmatch.rm_so <= startpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1188 | x_start = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1189 | else |
| 1190 | x_start = strnlenpt(fileptr->data, startmatch.rm_so) |
| 1191 | - start; |
| 1192 | if (regexec(tmpcolor->end, fileptr->data + startmatch.rm_eo, |
| 1193 | 1, &endmatch, startmatch.rm_eo == 0 ? 0 : |
| 1194 | REG_NOTBOL) == 0) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1195 | /* Translate the end match to be relative to the |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1196 | * beginning of the line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1197 | endmatch.rm_so += startmatch.rm_eo; |
| 1198 | endmatch.rm_eo += startmatch.rm_eo; |
| 1199 | /* There is an end on this line. But does it |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1200 | * appear on this page, and is the match more than |
| 1201 | * zero characters long? */ |
| 1202 | if (endmatch.rm_eo > startpos && |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1203 | endmatch.rm_eo > startmatch.rm_so) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1204 | paintlen = strnlenpt(fileptr->data, endmatch.rm_eo) |
| 1205 | - start - x_start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1206 | if (x_start + paintlen > COLS) |
| 1207 | paintlen = COLS - x_start; |
| 1208 | |
| 1209 | assert(0 <= x_start && 0 < paintlen && |
| 1210 | x_start + paintlen <= COLS); |
| 1211 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1212 | converted + x_start, paintlen); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1213 | } |
| 1214 | } else if (!searched_later_lines) { |
| 1215 | searched_later_lines = 1; |
| 1216 | /* There is no end on this line. But we haven't |
| 1217 | * yet looked for one on later lines. */ |
| 1218 | end_line = fileptr->next; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1219 | while (end_line != NULL && |
| 1220 | regexec(tmpcolor->end, end_line->data, 0, |
| 1221 | NULL, 0) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1222 | end_line = end_line->next; |
| 1223 | if (end_line != NULL) { |
| 1224 | assert(0 <= x_start && x_start < COLS); |
| 1225 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1226 | converted + x_start, |
| 1227 | COLS - x_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1228 | /* We painted to the end of the line, so |
| 1229 | * don't bother checking any more starts. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1230 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 1231 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1232 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1233 | start_col = startmatch.rm_so + 1; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1234 | } /* while start_col < endpos */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1235 | } /* if (tmp_color->end != NULL) */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1236 | |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1237 | skip_step_two: |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1238 | wattroff(edit, A_BOLD); |
| 1239 | wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); |
| 1240 | } /* for tmpcolor in colorstrings */ |
| 1241 | } |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1242 | #endif /* ENABLE_COLOR */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1243 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 1244 | #ifndef NANO_SMALL |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1245 | if (ISSET(MARK_ISSET) |
| 1246 | && (fileptr->lineno <= mark_beginbuf->lineno |
| 1247 | || fileptr->lineno <= current->lineno) |
| 1248 | && (fileptr->lineno >= mark_beginbuf->lineno |
| 1249 | || fileptr->lineno >= current->lineno)) { |
| 1250 | /* fileptr is at least partially selected. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1251 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1252 | const filestruct *top; |
| 1253 | /* Either current or mark_beginbuf, whichever is first. */ |
| 1254 | size_t top_x; |
| 1255 | /* current_x or mark_beginx, corresponding to top. */ |
| 1256 | const filestruct *bot; |
| 1257 | size_t bot_x; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1258 | int x_start; |
| 1259 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 1260 | int paintlen; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1261 | /* Number of chars to paint on this line. There are COLS |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1262 | * characters on a whole line. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1263 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1264 | mark_order(&top, &top_x, &bot, &bot_x); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1265 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1266 | if (top->lineno < fileptr->lineno || top_x < startpos) |
| 1267 | top_x = startpos; |
| 1268 | if (bot->lineno > fileptr->lineno || bot_x > endpos) |
| 1269 | bot_x = endpos; |
| 1270 | |
| 1271 | /* the selected bit of fileptr is on this page */ |
| 1272 | if (top_x < endpos && bot_x > startpos) { |
| 1273 | assert(startpos <= top_x); |
| 1274 | x_start = strnlenpt(fileptr->data + startpos, top_x - startpos); |
| 1275 | |
| 1276 | if (bot_x >= endpos) |
| 1277 | paintlen = -1; /* Paint everything. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1278 | else |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1279 | paintlen = strnlenpt(fileptr->data + top_x, bot_x - top_x); |
| 1280 | |
| 1281 | assert(x_start >= 0 && x_start <= strlen(converted)); |
| 1282 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1283 | wattron(edit, A_REVERSE); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1284 | mvwaddnstr(edit, yval, x_start, converted + x_start, paintlen); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1285 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1286 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 1287 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1288 | #endif /* !NANO_SMALL */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1291 | /* Just update one line in the edit buffer. Basically a wrapper for |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1292 | * edit_add(). |
| 1293 | * |
| 1294 | * If fileptr != current, then index is considered 0. |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1295 | * The line will be displayed starting with fileptr->data[index]. |
| 1296 | * Likely args are current_x or 0. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1297 | void update_line(const filestruct *fileptr, size_t index) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1298 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1299 | int line; |
| 1300 | /* line in the edit window for CURSES calls */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1301 | char *converted; |
| 1302 | /* fileptr->data converted to have tabs and control characters |
| 1303 | * expanded. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1304 | size_t page_start; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1305 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1306 | assert(fileptr != NULL); |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 1307 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1308 | line = fileptr->lineno - edittop->lineno; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1309 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1310 | /* We assume the line numbers are valid. Is that really true? */ |
| 1311 | assert(line < 0 || line == check_linenumbers(fileptr)); |
| 1312 | |
| 1313 | if (line < 0 || line >= editwinrows) |
| 1314 | return; |
| 1315 | |
| 1316 | /* First, blank out the line (at a minimum) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1317 | mvwaddstr(edit, line, 0, hblank); |
| 1318 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1319 | /* Next, convert variables that index the line to their equivalent |
| 1320 | * positions in the expanded line. */ |
| 1321 | index = fileptr == current ? strnlenpt(fileptr->data, index) : 0; |
| 1322 | page_start = get_page_start(index); |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1323 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1324 | /* Expand the line, replacing Tab by spaces, and control characters |
| 1325 | * by their display form. */ |
| 1326 | converted = display_string(fileptr->data, page_start, COLS); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1327 | |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 1328 | /* Now, paint the line */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1329 | edit_add(fileptr, converted, line, page_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1330 | free(converted); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1331 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1332 | if (page_start > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1333 | mvwaddch(edit, line, 0, '$'); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1334 | if (strlenpt(fileptr->data) > page_start + COLS) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1335 | mvwaddch(edit, line, COLS - 1, '$'); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1338 | /* This function updates current, based on where current_y is; |
| 1339 | * reset_cursor() does the opposite. */ |
| 1340 | void update_cursor(void) |
| 1341 | { |
| 1342 | int i = 0; |
| 1343 | |
| 1344 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1345 | fprintf(stderr, "Moved to (%d, %d) in edit buffer\n", current_y, |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1346 | current_x); |
| 1347 | #endif |
| 1348 | |
| 1349 | current = edittop; |
| 1350 | while (i < current_y && current->next != NULL) { |
| 1351 | current = current->next; |
| 1352 | i++; |
| 1353 | } |
| 1354 | |
| 1355 | #ifdef DEBUG |
Chris Allegretta | 0e86e60 | 2003-01-23 04:27:23 +0000 | [diff] [blame] | 1356 | fprintf(stderr, "current->data = \"%s\"\n", current->data); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1357 | #endif |
| 1358 | } |
| 1359 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1360 | void center_cursor(void) |
| 1361 | { |
| 1362 | current_y = editwinrows / 2; |
| 1363 | wmove(edit, current_y, current_x); |
| 1364 | } |
| 1365 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1366 | /* Refresh the screen without changing the position of lines. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1367 | void edit_refresh(void) |
| 1368 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1369 | /* Neither of these conditions should occur, but they do. edittop |
| 1370 | * is NULL when you open an existing file on the command line, and |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1371 | * ENABLE_COLOR is defined. Yuck. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1372 | if (current == NULL) |
| 1373 | return; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1374 | if (edittop == NULL) |
| 1375 | edittop = current; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1376 | |
Chris Allegretta | 63d0b48 | 2003-01-26 19:47:10 +0000 | [diff] [blame] | 1377 | if (current->lineno < edittop->lineno || |
| 1378 | current->lineno >= edittop->lineno + editwinrows) |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1379 | /* Note that edit_update() changes edittop so that |
| 1380 | * current->lineno = edittop->lineno + editwinrows / 2. Thus |
| 1381 | * when it then calls edit_refresh(), there is no danger of |
| 1382 | * getting an infinite loop. */ |
Chris Allegretta | da721be | 2000-07-31 01:26:42 +0000 | [diff] [blame] | 1383 | edit_update(current, CENTER); |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1384 | else { |
| 1385 | int nlines = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1386 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1387 | /* Don't make the cursor jump around the screen whilst |
| 1388 | * updating. */ |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1389 | leaveok(edit, TRUE); |
| 1390 | |
| 1391 | editbot = edittop; |
| 1392 | while (nlines < editwinrows) { |
| 1393 | update_line(editbot, current_x); |
| 1394 | nlines++; |
| 1395 | if (editbot->next == NULL) |
| 1396 | break; |
| 1397 | editbot = editbot->next; |
| 1398 | } |
| 1399 | while (nlines < editwinrows) { |
| 1400 | mvwaddstr(edit, nlines, 0, hblank); |
| 1401 | nlines++; |
| 1402 | } |
| 1403 | /* What the hell are we expecting to update the screen if this |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1404 | * isn't here? Luck? */ |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1405 | wrefresh(edit); |
| 1406 | leaveok(edit, FALSE); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1407 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1410 | /* Same as above, but touch the window first, so everything is |
| 1411 | * redrawn. */ |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 1412 | void edit_refresh_clearok(void) |
| 1413 | { |
| 1414 | clearok(edit, TRUE); |
| 1415 | edit_refresh(); |
| 1416 | clearok(edit, FALSE); |
| 1417 | } |
| 1418 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1419 | /* Nice generic routine to update the edit buffer, given a pointer to the |
| 1420 | * file struct =) */ |
David Lawrence Ramsey | 1356a0a | 2003-09-10 20:31:02 +0000 | [diff] [blame] | 1421 | void edit_update(filestruct *fileptr, topmidnone location) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1422 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1423 | if (fileptr == NULL) |
| 1424 | return; |
| 1425 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1426 | if (location != TOP) { |
David Lawrence Ramsey | d91ab6e | 2003-09-07 23:57:24 +0000 | [diff] [blame] | 1427 | int goal = location == NONE ? current_y : editwinrows / 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1428 | |
David Lawrence Ramsey | d91ab6e | 2003-09-07 23:57:24 +0000 | [diff] [blame] | 1429 | for (; goal > 0 && fileptr->prev != NULL; goal--) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1430 | fileptr = fileptr->prev; |
| 1431 | } |
| 1432 | edittop = fileptr; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1433 | edit_refresh(); |
| 1434 | } |
| 1435 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1436 | /* Ask a question on the statusbar. Answer will be stored in answer |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1437 | * 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] | 1438 | * otherwise, the valid shortcut key caught. Def is any editable text we |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1439 | * want to put up by default. |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 1440 | * |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1441 | * New arg tabs tells whether or not to allow tab completion. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1442 | int statusq(int tabs, const shortcut *s, const char *def, |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1443 | #ifndef NANO_SMALL |
| 1444 | historyheadtype *which_history, |
| 1445 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1446 | const char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1447 | { |
| 1448 | va_list ap; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1449 | char *foo = charalloc(COLS - 3); |
Chris Allegretta | 9caa193 | 2002-02-15 20:08:05 +0000 | [diff] [blame] | 1450 | int ret; |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1451 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | a16e4e9 | 2002-01-05 18:59:54 +0000 | [diff] [blame] | 1452 | int list = 0; |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1453 | #endif |
| 1454 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1455 | bottombars(s); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1456 | |
| 1457 | va_start(ap, msg); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1458 | vsnprintf(foo, COLS - 4, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1459 | va_end(ap); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1460 | foo[COLS - 4] = '\0'; |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1461 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1462 | ret = nanogetstr(tabs, foo, def, |
| 1463 | #ifndef NANO_SMALL |
| 1464 | which_history, |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1465 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1466 | s |
| 1467 | #ifndef DISABLE_TABCOMP |
| 1468 | , &list |
| 1469 | #endif |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 1470 | ); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1471 | free(foo); |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 1472 | resetstatuspos = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1473 | |
| 1474 | switch (ret) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1475 | case NANO_FIRSTLINE_KEY: |
| 1476 | do_first_line(); |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 1477 | resetstatuspos = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1478 | break; |
| 1479 | case NANO_LASTLINE_KEY: |
| 1480 | do_last_line(); |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 1481 | resetstatuspos = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1482 | break; |
David Lawrence Ramsey | 8faf305 | 2003-09-04 20:25:29 +0000 | [diff] [blame] | 1483 | #ifndef DISABLE_JUSTIFY |
| 1484 | case NANO_PARABEGIN_KEY: |
| 1485 | do_para_begin(); |
| 1486 | resetstatuspos = 1; |
| 1487 | break; |
| 1488 | case NANO_PARAEND_KEY: |
| 1489 | do_para_end(); |
| 1490 | resetstatuspos = 1; |
| 1491 | break; |
| 1492 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1493 | case NANO_CANCEL_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1494 | ret = -1; |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 1495 | resetstatuspos = 1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1496 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1497 | } |
Chris Allegretta | a90d0cf | 2003-02-10 02:55:03 +0000 | [diff] [blame] | 1498 | blank_statusbar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1499 | |
| 1500 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1501 | fprintf(stderr, "I got \"%s\"\n", answer); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1502 | #endif |
| 1503 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1504 | #ifndef DISABLE_TABCOMP |
| 1505 | /* if we've done tab completion, there might be a list of |
| 1506 | filename matches on the edit window at this point; make sure |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1507 | they're cleared off. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1508 | if (list) |
| 1509 | edit_refresh(); |
| 1510 | #endif |
| 1511 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1512 | return ret; |
| 1513 | } |
| 1514 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1515 | /* Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1516 | * for N, 2 for All (if all is nonzero when passed in) and -1 for abort |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1517 | * (^C). */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1518 | int do_yesno(int all, int leavecursor, const char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1519 | { |
| 1520 | va_list ap; |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1521 | char *foo; |
| 1522 | int ok = -2; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1523 | const char *yesstr; /* String of yes characters accepted */ |
| 1524 | const char *nostr; /* Same for no */ |
| 1525 | const char *allstr; /* And all, surprise! */ |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1526 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1527 | /* Yes, no and all are strings of any length. Each string consists |
| 1528 | * of all characters accepted as a valid character for that value. |
| 1529 | * The first value will be the one displayed in the shortcuts. */ |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1530 | yesstr = _("Yy"); |
| 1531 | nostr = _("Nn"); |
| 1532 | allstr = _("Aa"); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1533 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1534 | /* Remove gettext call for keybindings until we clear the thing |
| 1535 | * up. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1536 | if (!ISSET(NO_HELP)) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1537 | char shortstr[3]; /* Temp string for Y, N, A. */ |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1538 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1539 | /* Write the bottom of the screen. */ |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1540 | blank_bottombars(); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1541 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1542 | sprintf(shortstr, " %c", yesstr[0]); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1543 | wmove(bottomwin, 1, 0); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1544 | onekey(shortstr, _("Yes"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1545 | |
| 1546 | if (all) { |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1547 | wmove(bottomwin, 1, 16); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1548 | shortstr[1] = allstr[0]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1549 | onekey(shortstr, _("All"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1550 | } |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1551 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1552 | wmove(bottomwin, 2, 0); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1553 | shortstr[1] = nostr[0]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1554 | onekey(shortstr, _("No"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1555 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1556 | wmove(bottomwin, 2, 16); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1557 | onekey("^C", _("Cancel"), 16); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1558 | } |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1559 | |
| 1560 | foo = charalloc(COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1561 | va_start(ap, msg); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1562 | vsnprintf(foo, COLS, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1563 | va_end(ap); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1564 | foo[COLS - 1] = '\0'; |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1565 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1566 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1567 | |
| 1568 | blank_statusbar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1569 | mvwaddstr(bottomwin, 0, 0, foo); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1570 | free(foo); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1571 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1572 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1573 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1574 | wrefresh(bottomwin); |
| 1575 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1576 | do { |
| 1577 | int kbinput = wgetch(edit); |
Chris Allegretta | b2cd248 | 2003-02-12 23:18:19 +0000 | [diff] [blame] | 1578 | #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION) |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1579 | MEVENT mevent; |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1580 | #endif |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1581 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1582 | if (kbinput == NANO_CONTROL_C) |
| 1583 | ok = -1; |
Chris Allegretta | b2cd248 | 2003-02-12 23:18:19 +0000 | [diff] [blame] | 1584 | #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION) |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1585 | /* Look ma! We get to duplicate lots of code from do_mouse!! */ |
| 1586 | else if (kbinput == KEY_MOUSE && getmouse(&mevent) != ERR && |
| 1587 | wenclose(bottomwin, mevent.y, mevent.x) && |
| 1588 | !ISSET(NO_HELP) && mevent.x < 32 && |
| 1589 | mevent.y >= editwinrows + 3) { |
| 1590 | int x = mevent.x /= 16; |
| 1591 | /* Did we click in the first column of shortcuts, or the |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1592 | * second? */ |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1593 | int y = mevent.y - editwinrows - 3; |
| 1594 | /* Did we click in the first row of shortcuts? */ |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1595 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1596 | assert(0 <= x && x <= 1 && 0 <= y && y <= 1); |
| 1597 | /* x = 0 means they clicked Yes or No. |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1598 | * y = 0 means Yes or All. */ |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1599 | ok = -2 * x * y + x - y + 1; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1600 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1601 | if (ok == 2 && !all) |
| 1602 | ok = -2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1603 | } |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1604 | #endif |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1605 | /* Look for the kbinput in the yes, no and (optionally) all |
| 1606 | * str. */ |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1607 | else if (strchr(yesstr, kbinput) != NULL) |
| 1608 | ok = 1; |
| 1609 | else if (strchr(nostr, kbinput) != NULL) |
| 1610 | ok = 0; |
| 1611 | else if (all && strchr(allstr, kbinput) != NULL) |
| 1612 | ok = 2; |
| 1613 | } while (ok == -2); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1614 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1615 | /* Then blank the statusbar. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1616 | blank_statusbar_refresh(); |
| 1617 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1618 | return ok; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1621 | int total_refresh(void) |
| 1622 | { |
| 1623 | clearok(edit, TRUE); |
| 1624 | clearok(topwin, TRUE); |
| 1625 | clearok(bottomwin, TRUE); |
| 1626 | wnoutrefresh(edit); |
| 1627 | wnoutrefresh(topwin); |
| 1628 | wnoutrefresh(bottomwin); |
| 1629 | doupdate(); |
| 1630 | clearok(edit, FALSE); |
| 1631 | clearok(topwin, FALSE); |
| 1632 | clearok(bottomwin, FALSE); |
| 1633 | edit_refresh(); |
| 1634 | titlebar(NULL); |
| 1635 | return 1; |
| 1636 | } |
| 1637 | |
| 1638 | void display_main_list(void) |
| 1639 | { |
| 1640 | bottombars(main_list); |
| 1641 | } |
| 1642 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1643 | void statusbar(const char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1644 | { |
| 1645 | va_list ap; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1646 | |
Chris Allegretta | a0d8997 | 2003-02-03 03:32:08 +0000 | [diff] [blame] | 1647 | va_start(ap, msg); |
| 1648 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1649 | /* Curses mode is turned off. If we use wmove() now, it will muck |
| 1650 | * up the terminal settings. So we just use vfprintf(). */ |
Chris Allegretta | a0d8997 | 2003-02-03 03:32:08 +0000 | [diff] [blame] | 1651 | if (curses_ended) { |
| 1652 | vfprintf(stderr, msg, ap); |
| 1653 | va_end(ap); |
| 1654 | return; |
| 1655 | } |
| 1656 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1657 | /* Blank out the line. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1658 | blank_statusbar(); |
| 1659 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1660 | if (COLS >= 4) { |
| 1661 | char *bar; |
| 1662 | char *foo; |
| 1663 | int start_x = 0; |
| 1664 | size_t foo_len; |
| 1665 | bar = charalloc(COLS - 3); |
| 1666 | vsnprintf(bar, COLS - 3, msg, ap); |
| 1667 | va_end(ap); |
| 1668 | foo = display_string(bar, 0, COLS - 4); |
| 1669 | free(bar); |
| 1670 | foo_len = strlen(foo); |
| 1671 | start_x = (COLS - foo_len - 4) / 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1672 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1673 | wmove(bottomwin, 0, start_x); |
| 1674 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1675 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1676 | waddstr(bottomwin, "[ "); |
| 1677 | waddstr(bottomwin, foo); |
| 1678 | free(foo); |
| 1679 | waddstr(bottomwin, " ]"); |
| 1680 | wattroff(bottomwin, A_REVERSE); |
| 1681 | wnoutrefresh(bottomwin); |
| 1682 | wrefresh(edit); |
| 1683 | /* Leave the cursor at its position in the edit window, not |
| 1684 | * in the statusbar. */ |
| 1685 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1686 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1687 | SET(DISABLE_CURPOS); |
| 1688 | statblank = 26; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1691 | /* If constant is false, the user typed ^C so we unconditionally display |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1692 | * the cursor position. Otherwise, we display it only if the character |
| 1693 | * position changed, and DISABLE_CURPOS is not set. |
| 1694 | * |
| 1695 | * If constant and DISABLE_CURPOS is set, we unset it and update old_i and |
| 1696 | * old_totsize. That way, we leave the current statusbar alone, but next |
| 1697 | * time we will display. */ |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1698 | int do_cursorpos(int constant) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1699 | { |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1700 | const filestruct *fileptr; |
| 1701 | unsigned long i = 0; |
| 1702 | static unsigned long old_i = 0; |
| 1703 | static long old_totsize = -1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1704 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1705 | assert(current != NULL && fileage != NULL && totlines != 0); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1706 | |
| 1707 | if (old_totsize == -1) |
| 1708 | old_totsize = totsize; |
| 1709 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1710 | for (fileptr = fileage; fileptr != current; fileptr = fileptr->next) { |
| 1711 | assert(fileptr != NULL); |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1712 | i += strlen(fileptr->data) + 1; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1713 | } |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1714 | i += current_x; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1715 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1716 | if (constant && ISSET(DISABLE_CURPOS)) { |
| 1717 | UNSET(DISABLE_CURPOS); |
| 1718 | old_i = i; |
| 1719 | old_totsize = totsize; |
| 1720 | return 0; |
| 1721 | } |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1722 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1723 | /* If constant is false, display the position on the statusbar |
| 1724 | * unconditionally; otherwise, only display the position when the |
| 1725 | * character values have changed. */ |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1726 | if (!constant || old_i != i || old_totsize != totsize) { |
| 1727 | unsigned long xpt = xplustabs() + 1; |
| 1728 | unsigned long cur_len = strlenpt(current->data) + 1; |
| 1729 | int linepct = 100 * current->lineno / totlines; |
| 1730 | int colpct = 100 * xpt / cur_len; |
| 1731 | int bytepct = totsize == 0 ? 0 : 100 * i / totsize; |
| 1732 | |
| 1733 | statusbar( |
| 1734 | _("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%ld (%d%%)"), |
| 1735 | current->lineno, totlines, linepct, |
| 1736 | xpt, cur_len, colpct, |
| 1737 | i, totsize, bytepct); |
| 1738 | UNSET(DISABLE_CURPOS); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | old_i = i; |
| 1742 | old_totsize = totsize; |
| 1743 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1744 | reset_cursor(); |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1745 | return 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1748 | int do_cursorpos_void(void) |
| 1749 | { |
| 1750 | return do_cursorpos(0); |
| 1751 | } |
| 1752 | |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 1753 | /* Calculate the next line of help_text, starting at ptr. */ |
| 1754 | int line_len(const char *ptr) |
| 1755 | { |
| 1756 | int j = 0; |
| 1757 | |
| 1758 | while (*ptr != '\n' && *ptr != '\0' && j < COLS - 5) { |
| 1759 | ptr++; |
| 1760 | j++; |
| 1761 | } |
| 1762 | if (j == COLS - 5) { |
| 1763 | /* Don't wrap at the first of two spaces following a period. */ |
| 1764 | if (*ptr == ' ' && *(ptr + 1) == ' ') |
| 1765 | j++; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1766 | /* Don't print half a word if we've run out of space. */ |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 1767 | while (*ptr != ' ' && j > 0) { |
| 1768 | ptr--; |
| 1769 | j--; |
| 1770 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1771 | /* Word longer than COLS - 5 chars just gets broken. */ |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 1772 | if (j == 0) |
| 1773 | j = COLS - 5; |
| 1774 | } |
| 1775 | assert(j >= 0 && j <= COLS - 4 && (j > 0 || *ptr == '\n')); |
| 1776 | return j; |
| 1777 | } |
| 1778 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1779 | /* Our shortcut-list-compliant help function, which is better than |
| 1780 | * nothing, and dynamic! */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1781 | int do_help(void) |
| 1782 | { |
Rocco Corsi | af5c302 | 2001-01-12 07:51:05 +0000 | [diff] [blame] | 1783 | #ifndef DISABLE_HELP |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1784 | int i, page = 0, kbinput = -1, meta, no_more = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1785 | int no_help_flag = 0; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1786 | const shortcut *oldshortcut; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1787 | |
| 1788 | blank_edit(); |
| 1789 | curs_set(0); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1790 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1791 | blank_statusbar(); |
| 1792 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1793 | /* Set help_text as the string to display. */ |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1794 | help_init(); |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1795 | assert(help_text != NULL); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1796 | |
| 1797 | oldshortcut = currshortcut; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1798 | |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1799 | currshortcut = help_list; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 1800 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1801 | if (ISSET(NO_HELP)) { |
| 1802 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1803 | /* Well, if we're going to do this, we should at least do it the |
| 1804 | * right way. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1805 | no_help_flag = 1; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1806 | UNSET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1807 | window_init(); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1808 | bottombars(help_list); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1809 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1810 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1811 | bottombars(help_list); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1812 | |
| 1813 | do { |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 1814 | const char *ptr = help_text; |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1815 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1816 | switch (kbinput) { |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1817 | #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION) |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1818 | case KEY_MOUSE: |
| 1819 | do_mouse(); |
| 1820 | break; |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1821 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1822 | case NANO_NEXTPAGE_KEY: |
| 1823 | case NANO_NEXTPAGE_FKEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1824 | if (!no_more) { |
| 1825 | blank_edit(); |
| 1826 | page++; |
| 1827 | } |
| 1828 | break; |
| 1829 | case NANO_PREVPAGE_KEY: |
| 1830 | case NANO_PREVPAGE_FKEY: |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 1831 | if (page > 0) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1832 | no_more = 0; |
| 1833 | blank_edit(); |
| 1834 | page--; |
| 1835 | } |
| 1836 | break; |
| 1837 | } |
| 1838 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1839 | /* Calculate where in the text we should be, based on the |
| 1840 | * page. */ |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 1841 | for (i = 1; i < page * (editwinrows - 1); i++) { |
| 1842 | ptr += line_len(ptr); |
| 1843 | if (*ptr == '\n') |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1844 | ptr++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1845 | } |
| 1846 | |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 1847 | for (i = 0; i < editwinrows && *ptr != '\0'; i++) { |
| 1848 | int j = line_len(ptr); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1849 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1850 | mvwaddnstr(edit, i, 0, ptr, j); |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 1851 | ptr += j; |
| 1852 | if (*ptr == '\n') |
| 1853 | ptr++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1854 | } |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 1855 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1856 | if (*ptr == '\0') { |
| 1857 | no_more = 1; |
| 1858 | continue; |
| 1859 | } |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1860 | } while ((kbinput = get_kbinput(edit, &meta, ISSET(REBIND_DELETE))) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY); |
Chris Allegretta | d1627cf | 2000-12-18 05:03:16 +0000 | [diff] [blame] | 1861 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1862 | currshortcut = oldshortcut; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1863 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1864 | if (no_help_flag) { |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1865 | blank_bottombars(); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1866 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1867 | SET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1868 | window_init(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1869 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1870 | bottombars(currshortcut); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1871 | |
| 1872 | curs_set(1); |
| 1873 | edit_refresh(); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1874 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1875 | /* The help_init() at the beginning allocated help_text, which has |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1876 | * now been written to the screen. */ |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1877 | free(help_text); |
| 1878 | help_text = NULL; |
| 1879 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1880 | #elif defined(DISABLE_HELP) |
| 1881 | nano_disabled_msg(); |
| 1882 | #endif |
| 1883 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1884 | return 1; |
| 1885 | } |
| 1886 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1887 | /* Highlight the current word being replaced or spell checked. We |
| 1888 | * expect word to have tabs and control characters expanded. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1889 | void do_replace_highlight(int highlight_flag, const char *word) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1890 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1891 | int y = xplustabs(); |
| 1892 | size_t word_len = strlen(word); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1893 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1894 | y = get_page_start(y) + COLS - y; |
| 1895 | /* Now y is the number of characters we can display on this |
| 1896 | * line. */ |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1897 | |
| 1898 | reset_cursor(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1899 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1900 | if (highlight_flag) |
| 1901 | wattron(edit, A_REVERSE); |
| 1902 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1903 | waddnstr(edit, word, y - 1); |
| 1904 | |
| 1905 | if (word_len > y) |
| 1906 | waddch(edit, '$'); |
| 1907 | else if (word_len == y) |
| 1908 | waddch(edit, word[word_len - 1]); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1909 | |
| 1910 | if (highlight_flag) |
| 1911 | wattroff(edit, A_REVERSE); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1914 | /* Fix editbot, based on the assumption that edittop is correct. */ |
| 1915 | void fix_editbot(void) |
| 1916 | { |
| 1917 | int i; |
| 1918 | |
| 1919 | editbot = edittop; |
| 1920 | for (i = 0; i < editwinrows && editbot->next != NULL; i++) |
| 1921 | editbot = editbot->next; |
| 1922 | } |
| 1923 | |
| 1924 | #ifdef DEBUG |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1925 | /* Dump the passed-in file structure to stderr. */ |
| 1926 | void dump_buffer(const filestruct *inptr) |
| 1927 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1928 | if (inptr == fileage) |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1929 | fprintf(stderr, "Dumping file buffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1930 | else if (inptr == cutbuffer) |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1931 | fprintf(stderr, "Dumping cutbuffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1932 | else |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1933 | fprintf(stderr, "Dumping a buffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1934 | |
| 1935 | while (inptr != NULL) { |
| 1936 | fprintf(stderr, "(%d) %s\n", inptr->lineno, inptr->data); |
| 1937 | inptr = inptr->next; |
| 1938 | } |
| 1939 | } |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1940 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1941 | /* Dump the file structure to stderr in reverse. */ |
David Lawrence Ramsey | aaad3af | 2003-08-31 16:44:10 +0000 | [diff] [blame] | 1942 | void dump_buffer_reverse(void) |
| 1943 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1944 | const filestruct *fileptr = filebot; |
| 1945 | |
| 1946 | while (fileptr != NULL) { |
| 1947 | fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data); |
| 1948 | fileptr = fileptr->prev; |
| 1949 | } |
| 1950 | } |
| 1951 | #endif /* DEBUG */ |
| 1952 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1953 | #ifdef NANO_EXTRA |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 1954 | #define CREDIT_LEN 53 |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1955 | #define XLCREDIT_LEN 8 |
| 1956 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1957 | void do_credits(void) |
| 1958 | { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1959 | int i, j = 0, k, place = 0, start_x; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1960 | |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 1961 | const char *what; |
| 1962 | const char *xlcredits[XLCREDIT_LEN]; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1963 | |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 1964 | const char *credits[CREDIT_LEN] = { |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1965 | "0", /* "The nano text editor" */ |
| 1966 | "1", /* "version" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1967 | VERSION, |
| 1968 | "", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1969 | "2", /* "Brought to you by:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1970 | "Chris Allegretta", |
| 1971 | "Jordi Mallach", |
| 1972 | "Adam Rogoyski", |
| 1973 | "Rob Siemborski", |
| 1974 | "Rocco Corsi", |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1975 | "David Lawrence Ramsey", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 1976 | "David Benbennick", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1977 | "Ken Tyler", |
| 1978 | "Sven Guckes", |
| 1979 | "Florian König", |
| 1980 | "Pauli Virtanen", |
| 1981 | "Daniele Medri", |
| 1982 | "Clement Laforet", |
| 1983 | "Tedi Heriyanto", |
| 1984 | "Bill Soudan", |
| 1985 | "Christian Weisgerber", |
| 1986 | "Erik Andersen", |
| 1987 | "Big Gaute", |
| 1988 | "Joshua Jensen", |
| 1989 | "Ryan Krebs", |
| 1990 | "Albert Chin", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1991 | "", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1992 | "3", /* "Special thanks to:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1993 | "Plattsburgh State University", |
| 1994 | "Benet Laboratories", |
| 1995 | "Amy Allegretta", |
| 1996 | "Linda Young", |
| 1997 | "Jeremy Robichaud", |
| 1998 | "Richard Kolb II", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1999 | "4", /* "The Free Software Foundation" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2000 | "Linus Torvalds", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 2001 | "5", /* "For ncurses:" */ |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 2002 | "Thomas Dickey", |
| 2003 | "Pavel Curtis", |
| 2004 | "Zeyd Ben-Halim", |
| 2005 | "Eric S. Raymond", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 2006 | "6", /* "and anyone else we forgot..." */ |
| 2007 | "7", /* "Thank you for using nano!\n" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2008 | "", "", "", "", |
David Lawrence Ramsey | aaad3af | 2003-08-31 16:44:10 +0000 | [diff] [blame] | 2009 | "(c) 1999-2003 Chris Allegretta", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2010 | "", "", "", "", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 2011 | "http://www.nano-editor.org/" |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2012 | }; |
| 2013 | |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 2014 | xlcredits[0] = _("The nano text editor"); |
| 2015 | xlcredits[1] = _("version "); |
| 2016 | xlcredits[2] = _("Brought to you by:"); |
| 2017 | xlcredits[3] = _("Special thanks to:"); |
| 2018 | xlcredits[4] = _("The Free Software Foundation"); |
| 2019 | xlcredits[5] = _("For ncurses:"); |
| 2020 | xlcredits[6] = _("and anyone else we forgot..."); |
| 2021 | xlcredits[7] = _("Thank you for using nano!\n"); |
| 2022 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2023 | curs_set(0); |
| 2024 | nodelay(edit, TRUE); |
| 2025 | blank_bottombars(); |
| 2026 | mvwaddstr(topwin, 0, 0, hblank); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2027 | blank_edit(); |
| 2028 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2029 | wrefresh(bottomwin); |
| 2030 | wrefresh(topwin); |
| 2031 | |
| 2032 | while (wgetch(edit) == ERR) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2033 | for (k = 0; k <= 1; k++) { |
| 2034 | blank_edit(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2035 | for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); |
| 2036 | i--) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2037 | mvwaddstr(edit, i * 2 - k, 0, hblank); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2038 | |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 2039 | if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2040 | what = credits[place - (editwinrows / 2 - 1 - i)]; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 2041 | |
| 2042 | /* God I've missed hacking. If what is exactly |
| 2043 | 1 char long, it's a sentinel for a translated |
| 2044 | string, so use that instead. This means no |
| 2045 | thanking people with 1 character long names ;-) */ |
| 2046 | if (strlen(what) == 1) |
| 2047 | what = xlcredits[atoi(what)]; |
| 2048 | } else |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2049 | what = ""; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2050 | |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 2051 | start_x = COLS / 2 - strlen(what) / 2 - 1; |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2052 | mvwaddstr(edit, i * 2 - k, start_x, what); |
| 2053 | } |
| 2054 | usleep(700000); |
| 2055 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2056 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2057 | if (j < editwinrows / 2 - 1) |
| 2058 | j++; |
| 2059 | |
| 2060 | place++; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2061 | |
| 2062 | if (place >= CREDIT_LEN + editwinrows / 2) |
| 2063 | break; |
| 2064 | } |
| 2065 | |
| 2066 | nodelay(edit, FALSE); |
| 2067 | curs_set(1); |
| 2068 | display_main_list(); |
| 2069 | total_refresh(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2070 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2071 | #endif |