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 | * * |
David Lawrence Ramsey | f28f50e | 2004-01-09 23:04:55 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 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 | |
Jordi Mallach | 55381aa | 2004-11-17 23:17:05 +0000 | [diff] [blame] | 22 | #ifdef HAVE_CONFIG_H |
| 23 | #include <config.h> |
| 24 | #endif |
David Lawrence Ramsey | e21adfa | 2002-09-13 18:14:04 +0000 | [diff] [blame] | 25 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 26 | #include <stdarg.h> |
| 27 | #include <string.h> |
Chris Allegretta | dba37ae | 2000-07-07 05:13:09 +0000 | [diff] [blame] | 28 | #include <stdlib.h> |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 29 | #include <unistd.h> |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 30 | #include <ctype.h> |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 31 | #include <assert.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 32 | #include "proto.h" |
| 33 | #include "nano.h" |
| 34 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 35 | static buffer *key_buffer = NULL; |
| 36 | /* The default keystroke buffer, |
| 37 | * containing all the keystrokes we have |
| 38 | * at a given point. */ |
| 39 | static size_t key_buffer_len = 0; |
| 40 | /* The length of the default keystroke |
| 41 | * buffer. */ |
| 42 | static int statusblank = 0; /* The number of keystrokes left after |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 43 | * we call statusbar(), before we |
| 44 | * actually blank the statusbar. */ |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 45 | static bool resetstatuspos = FALSE; |
| 46 | /* Should we reset the cursor position |
| 47 | * at the statusbar prompt? */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 48 | |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 49 | /* Control character compatibility: |
| 50 | * |
| 51 | * - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI, |
| 52 | * VT100, and VT220. |
| 53 | * - NANO_TAB_KEY is Ctrl-I, which is Tab under ASCII, ANSI, VT100, |
| 54 | * VT220, and VT320. |
| 55 | * - NANO_ENTER_KEY is Ctrl-M, which is Enter under ASCII, ANSI, VT100, |
| 56 | * VT220, and VT320. |
| 57 | * - NANO_XON_KEY is Ctrl-Q, which is XON under ASCII, ANSI, VT100, |
| 58 | * VT220, and VT320. |
| 59 | * - NANO_XOFF_KEY is Ctrl-S, which is XOFF under ASCII, ANSI, VT100, |
| 60 | * VT220, and VT320. |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 61 | * - NANO_CONTROL_8 is Ctrl-8 (Ctrl-?), which is Delete under ASCII, |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 62 | * ANSI, VT100, and VT220, and which is Backspace under VT320. |
| 63 | * |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 64 | * Note: VT220 and VT320 also generate Esc [ 3 ~ for Delete. By |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 65 | * default, xterm assumes it's running on a VT320 and generates Ctrl-8 |
| 66 | * (Ctrl-?) for Backspace and Esc [ 3 ~ for Delete. This causes |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 67 | * problems for VT100-derived terminals such as the FreeBSD console, |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 68 | * which expect Ctrl-H for Backspace and Ctrl-8 (Ctrl-?) for Delete, and |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 69 | * on which the VT320 sequences are translated by the keypad to KEY_DC |
| 70 | * and [nothing]. We work around this conflict via the REBIND_DELETE |
| 71 | * flag: if it's not set, we assume VT320 compatibility, and if it is, |
| 72 | * we assume VT100 compatibility. Thanks to Lee Nelson and Wouter van |
| 73 | * Hemel for helping work this conflict out. |
| 74 | * |
| 75 | * Escape sequence compatibility: |
| 76 | * |
| 77 | * We support escape sequences for ANSI, VT100, VT220, VT320, the Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 78 | * console, the FreeBSD console, the Mach console (a.k.a. the Hurd |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 79 | * console), xterm, rxvt, and Eterm. Among these, there are several |
| 80 | * conflicts and omissions, outlined as follows: |
| 81 | * |
| 82 | * - Tab on ANSI == PageUp on FreeBSD console; the former is omitted. |
| 83 | * (Ctrl-I is also Tab on ANSI, which we already support.) |
| 84 | * - PageDown on FreeBSD console == Center (5) on numeric keypad with |
| 85 | * NumLock off on Linux console; the latter is omitted. (The editing |
| 86 | * keypad key is more important to have working than the numeric |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 87 | * keypad key, because the latter has no value when NumLock is off.) |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 88 | * - F1 on FreeBSD console == the mouse key on xterm/rxvt/Eterm; the |
| 89 | * latter is omitted. (Mouse input will only work properly if the |
| 90 | * extended keypad value KEY_MOUSE is generated on mouse events |
| 91 | * instead of the escape sequence.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 92 | * - F9 on FreeBSD console == PageDown on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 93 | * omitted. (The editing keypad is more important to have working |
| 94 | * than the function keys, because the functions of the former are not |
| 95 | * arbitrary and the functions of the latter are.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 96 | * - F10 on FreeBSD console == PageUp on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 97 | * omitted. (Same as above.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 98 | * - F13 on FreeBSD console == End on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 99 | * omitted. (Same as above.) |
David Lawrence Ramsey | 8381fdd | 2004-11-01 22:40:02 +0000 | [diff] [blame] | 100 | * - F15 on FreeBSD console == Shift-Up on rxvt/Eterm; the former is |
| 101 | * omitted. (The arrow keys, with or without modifiers, are more |
| 102 | * important to have working than the function keys, because the |
| 103 | * functions of the former are not arbitrary and the functions of the |
| 104 | * latter are.) |
| 105 | * - F16 on FreeBSD console == Shift-Down on rxvt/Eterm; the former is |
| 106 | * omitted. (Same as above.) |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 107 | * |
| 108 | * Note that Center (5) on the numeric keypad with NumLock off can also |
| 109 | * be the Begin key. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 110 | |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 111 | #ifndef NANO_SMALL |
| 112 | /* Reset all the input routines that rely on character sequences. */ |
| 113 | void reset_kbinput(void) |
| 114 | { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 115 | #ifdef NANO_WIDE |
| 116 | /* Reset the multibyte and wide character interpreter states. */ |
| 117 | if (!ISSET(NO_UTF8)) { |
| 118 | mbtowc(NULL, NULL, 0); |
| 119 | wctomb(NULL, 0); |
| 120 | } |
| 121 | #endif |
| 122 | parse_kbinput(NULL, NULL, NULL, TRUE); |
| 123 | get_word_kbinput(0, TRUE); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 124 | } |
| 125 | #endif |
| 126 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 127 | /* Read in a sequence of keystrokes from win and save them in the |
| 128 | * default keystroke buffer. This should only be called when the |
| 129 | * default keystroke buffer is empty. */ |
| 130 | void get_buffer(WINDOW *win) |
David Lawrence Ramsey | dfca1c4 | 2004-08-25 16:37:06 +0000 | [diff] [blame] | 131 | { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 132 | int input; |
| 133 | size_t i = 0; |
David Lawrence Ramsey | dfca1c4 | 2004-08-25 16:37:06 +0000 | [diff] [blame] | 134 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 135 | #ifdef NANO_WIDE |
| 136 | size_t wide_key_buffer_len = 0; |
| 137 | buffer *wide_key_buffer = NULL; |
| 138 | #endif |
| 139 | |
| 140 | /* If the keystroke buffer isn't empty, get out. */ |
| 141 | if (key_buffer != NULL) |
| 142 | return; |
| 143 | |
| 144 | /* Read in the first character using blocking input. */ |
| 145 | nodelay(win, FALSE); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 146 | |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 147 | #ifndef NANO_SMALL |
| 148 | allow_pending_sigwinch(TRUE); |
| 149 | #endif |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 150 | input = wgetch(win); |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 151 | #ifndef NANO_SMALL |
| 152 | allow_pending_sigwinch(FALSE); |
| 153 | #endif |
| 154 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 155 | /* Increment the length of the keystroke buffer, save the value of |
| 156 | * the keystroke in key, and set key_code to TRUE if the keystroke |
| 157 | * is an extended keypad value and hence shouldn't be treated as a |
| 158 | * multibyte character. */ |
| 159 | key_buffer_len++; |
| 160 | key_buffer = (buffer *)nmalloc(sizeof(buffer)); |
| 161 | key_buffer[0].key = input; |
| 162 | key_buffer[0].key_code = !is_byte_char(input); |
| 163 | |
| 164 | /* Read in the remaining characters using non-blocking input. */ |
| 165 | nodelay(win, TRUE); |
| 166 | |
| 167 | while (TRUE) { |
| 168 | #ifndef NANO_SMALL |
| 169 | allow_pending_sigwinch(TRUE); |
| 170 | #endif |
| 171 | input = wgetch(win); |
| 172 | #ifndef NANO_SMALL |
| 173 | allow_pending_sigwinch(FALSE); |
| 174 | #endif |
| 175 | |
| 176 | /* If there aren't any more characters, stop reading. */ |
| 177 | if (input == ERR) |
| 178 | break; |
| 179 | |
| 180 | /* Otherwise, increment the length of the keystroke buffer, save |
| 181 | * the value of the keystroke in key, and set key_code to TRUE |
| 182 | * if the keystroke is an extended keypad value and hence |
| 183 | * shouldn't be treated as a multibyte character. */ |
| 184 | key_buffer_len++; |
| 185 | key_buffer = (buffer *)nrealloc(key_buffer, key_buffer_len * |
| 186 | sizeof(buffer)); |
| 187 | key_buffer[key_buffer_len - 1].key = input; |
| 188 | key_buffer[key_buffer_len - 1].key_code = !is_byte_char(input); |
| 189 | } |
| 190 | |
| 191 | /* Switch back to non-blocking input. */ |
| 192 | nodelay(win, FALSE); |
| 193 | |
| 194 | #ifdef NANO_WIDE |
| 195 | if (!ISSET(NO_UTF8)) { |
| 196 | /* Change all incomplete or invalid multibyte keystrokes to -1, |
| 197 | * and change all complete and valid multibyte keystrokes to |
| 198 | * their wide character value. */ |
| 199 | for (i = 0; i < key_buffer_len; i++) { |
| 200 | wchar_t wide_key; |
| 201 | |
| 202 | if (!key_buffer[i].key_code) { |
| 203 | key_buffer[i].key = mbtowc(&wide_key, |
| 204 | (const char *)&key_buffer[i].key, 1); |
| 205 | if (key_buffer[i].key != -1) |
| 206 | key_buffer[i].key = wide_key; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /* Save all of the non-(-1) keystrokes in another buffer. */ |
| 211 | for (i = 0; i < key_buffer_len; i++) { |
| 212 | if (key_buffer[i].key != -1) { |
| 213 | wide_key_buffer_len++; |
| 214 | wide_key_buffer = (buffer *)nrealloc(wide_key_buffer, |
| 215 | wide_key_buffer_len * sizeof(buffer)); |
| 216 | |
| 217 | wide_key_buffer[wide_key_buffer_len - 1].key = |
| 218 | key_buffer[i].key; |
| 219 | wide_key_buffer[wide_key_buffer_len - 1].key_code = |
| 220 | key_buffer[i].key_code; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /* Replace the default keystroke buffer with the non-(-1) |
| 225 | * keystroke buffer. */ |
| 226 | key_buffer_len = wide_key_buffer_len; |
| 227 | free(key_buffer); |
| 228 | key_buffer = wide_key_buffer; |
| 229 | } |
| 230 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 231 | } |
| 232 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 233 | /* Return the length of the default keystroke buffer. */ |
| 234 | size_t get_buffer_len(void) |
| 235 | { |
| 236 | return key_buffer_len; |
| 237 | } |
| 238 | |
| 239 | /* Return the key values stored in the keystroke buffer input, |
| 240 | * discarding the key_code values in it. */ |
| 241 | int *buffer_to_keys(buffer *input, size_t input_len) |
| 242 | { |
| 243 | int *sequence = (int *)nmalloc(input_len * sizeof(int)); |
| 244 | size_t i; |
| 245 | |
| 246 | for (i = 0; i < input_len; i++) |
| 247 | sequence[i] = input[i].key; |
| 248 | |
| 249 | return sequence; |
| 250 | } |
| 251 | |
| 252 | /* Add the contents of the keystroke buffer input to the default |
| 253 | * keystroke buffer. */ |
| 254 | void unget_input(buffer *input, size_t input_len) |
| 255 | { |
| 256 | #ifndef NANO_SMALL |
| 257 | allow_pending_sigwinch(TRUE); |
| 258 | allow_pending_sigwinch(FALSE); |
| 259 | #endif |
| 260 | |
| 261 | /* If input is empty, get out. */ |
| 262 | if (input_len == 0) |
| 263 | return; |
| 264 | |
| 265 | /* If adding input would put the default keystroke buffer beyond |
| 266 | * maximum capacity, only add enough of input to put it at maximum |
| 267 | * capacity. */ |
| 268 | if (key_buffer_len + input_len < key_buffer_len) |
| 269 | input_len = (size_t)-1 - key_buffer_len; |
| 270 | |
| 271 | /* Add the length of input to the length of the default keystroke |
| 272 | * buffer, and reallocate the default keystroke buffer so that it |
| 273 | * has enough room for input. */ |
| 274 | key_buffer_len += input_len; |
| 275 | key_buffer = (buffer *)nrealloc(key_buffer, key_buffer_len * |
| 276 | sizeof(buffer)); |
| 277 | |
| 278 | /* If the default keystroke buffer wasn't empty before, move its |
| 279 | * beginning forward far enough so that we can add input to its |
| 280 | * beginning. */ |
| 281 | if (key_buffer_len > input_len) |
| 282 | memmove(key_buffer + input_len, key_buffer, |
| 283 | (key_buffer_len - input_len) * sizeof(buffer)); |
| 284 | |
| 285 | /* Copy input to the beginning of the default keystroke buffer. */ |
| 286 | memcpy(key_buffer, input, input_len * sizeof(buffer)); |
| 287 | } |
| 288 | |
| 289 | /* Put back the character stored in kbinput. If func_key is TRUE and |
| 290 | * the character is out of byte range, interpret it as an extended |
| 291 | * keypad value. If meta_key is TRUE, put back the Escape character |
| 292 | * after putting back kbinput. */ |
| 293 | void unget_kbinput(int kbinput, bool meta_key, bool func_key) |
| 294 | { |
| 295 | buffer input; |
| 296 | |
| 297 | input.key = kbinput; |
| 298 | input.key_code = (func_key && !is_byte_char(kbinput)); |
| 299 | |
| 300 | unget_input(&input, 1); |
| 301 | |
| 302 | if (meta_key) { |
| 303 | input.key = NANO_CONTROL_3; |
| 304 | input.key_code = FALSE; |
| 305 | unget_input(&input, 1); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /* Try to read input_len characters from the default keystroke buffer. |
| 310 | * If the default keystroke buffer is empty and win isn't NULL, try to |
| 311 | * read in more characters from win and add them to the default |
| 312 | * keystroke buffer before doing anything else. If the default |
| 313 | * keystroke buffer is empty and win is NULL, return NULL. */ |
| 314 | buffer *get_input(WINDOW *win, size_t input_len) |
| 315 | { |
| 316 | buffer *input; |
| 317 | |
| 318 | #ifndef NANO_SMALL |
| 319 | allow_pending_sigwinch(TRUE); |
| 320 | allow_pending_sigwinch(FALSE); |
| 321 | #endif |
| 322 | |
| 323 | if (key_buffer_len == 0) { |
| 324 | if (win != NULL) |
| 325 | get_buffer(win); |
| 326 | |
| 327 | if (key_buffer_len == 0) |
| 328 | return NULL; |
| 329 | } |
| 330 | |
| 331 | /* If input_len is greater than the length of the default keystroke |
| 332 | * buffer, only read the number of characters in the default |
| 333 | * keystroke buffer. */ |
| 334 | if (input_len > key_buffer_len) |
| 335 | input_len = key_buffer_len; |
| 336 | |
| 337 | /* Subtract input_len from the length of the default keystroke |
| 338 | * buffer, and allocate the keystroke buffer input so that it |
| 339 | * has enough room for input_len keystrokes. */ |
| 340 | key_buffer_len -= input_len; |
| 341 | input = (buffer *)nmalloc(input_len * sizeof(buffer)); |
| 342 | |
| 343 | /* Copy input_len characters from the beginning of the default |
| 344 | * keystroke buffer into input. */ |
| 345 | memcpy(input, key_buffer, input_len * sizeof(buffer)); |
| 346 | |
| 347 | /* If the default keystroke buffer is empty, mark it as such. */ |
| 348 | if (key_buffer_len == 0) { |
| 349 | free(key_buffer); |
| 350 | key_buffer = NULL; |
| 351 | /* If the default keystroke buffer isn't empty, move its |
| 352 | * beginning forward far enough back so that the keystrokes in input |
| 353 | * are no longer at its beginning. */ |
| 354 | } else { |
| 355 | memmove(key_buffer, key_buffer + input_len, key_buffer_len * |
| 356 | sizeof(buffer)); |
| 357 | key_buffer = (buffer *)nrealloc(key_buffer, key_buffer_len * |
| 358 | sizeof(buffer)); |
| 359 | } |
| 360 | |
| 361 | return input; |
| 362 | } |
| 363 | |
| 364 | /* Read in a single character. If it's ignored, swallow it and go on. |
| 365 | * Otherwise, try to translate it from ASCII, meta key sequences, escape |
| 366 | * sequences, and/or extended keypad values. Set meta_key to TRUE when |
| 367 | * we get a meta key sequence, and set func_key to TRUE when we get an |
| 368 | * extended keypad value. Supported extended keypad values consist of |
| 369 | * [arrow key], Ctrl-[arrow key], Shift-[arrow key], Enter, Backspace, |
| 370 | * the editing keypad (Insert, Delete, Home, End, PageUp, and PageDown), |
| 371 | * the function keypad (F1-F16), and the numeric keypad with NumLock |
| 372 | * off. Assume nodelay(win) is FALSE. */ |
| 373 | int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key) |
| 374 | { |
| 375 | int kbinput; |
| 376 | |
| 377 | /* Read in a character and interpret it. Continue doing this until |
| 378 | * we get a recognized value or sequence. */ |
| 379 | while ((kbinput = parse_kbinput(win, meta_key, func_key |
| 380 | #ifndef NANO_SMALL |
| 381 | , FALSE |
| 382 | #endif |
| 383 | )) == ERR); |
| 384 | |
| 385 | return kbinput; |
| 386 | } |
| 387 | |
| 388 | /* Translate ASCII characters, extended keypad values, and escape |
| 389 | * sequences into their corresponding key values. Set meta_key to TRUE |
| 390 | * when we get a meta key sequence, and set func_key to TRUE when we get |
| 391 | * a function key. Assume nodelay(win) is FALSE. */ |
| 392 | int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 393 | #ifndef NANO_SMALL |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 394 | , bool reset |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 395 | #endif |
| 396 | ) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 397 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 398 | { |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 399 | static int escapes = 0; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 400 | static int word_digits = 0; |
| 401 | buffer *kbinput; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 402 | int retval = ERR; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 403 | bool no_func_key = FALSE; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 404 | |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 405 | if (reset) { |
| 406 | escapes = 0; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 407 | word_digits = 0; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 408 | return ERR; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 409 | } |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 410 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 411 | *meta_key = FALSE; |
| 412 | *func_key = FALSE; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 413 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 414 | /* Read in a character. */ |
| 415 | while ((kbinput = get_input(win, 1)) == NULL); |
| 416 | |
| 417 | /* If we got an extended keypad value or an ASCII character, |
| 418 | * translate it. */ |
| 419 | if (kbinput->key_code || is_byte_char(kbinput->key)) { |
| 420 | switch (kbinput->key) { |
| 421 | case ERR: |
| 422 | break; |
| 423 | case NANO_CONTROL_3: |
| 424 | /* Increment the escape counter. */ |
| 425 | escapes++; |
| 426 | switch (escapes) { |
| 427 | case 1: |
| 428 | /* One escape: wait for more input. */ |
| 429 | case 2: |
| 430 | /* Two escapes: wait for more input. */ |
| 431 | break; |
| 432 | default: |
| 433 | /* More than two escapes: reset the escape |
| 434 | * counter and wait for more input. */ |
| 435 | escapes = 0; |
| 436 | } |
| 437 | break; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 438 | #if !defined(NANO_SMALL) && defined(KEY_RESIZE) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 439 | /* Since we don't change the default SIGWINCH handler when |
| 440 | * NANO_SMALL is defined, KEY_RESIZE is never generated. |
| 441 | * Also, Slang and SunOS 5.7-5.9 don't support |
| 442 | * KEY_RESIZE. */ |
| 443 | case KEY_RESIZE: |
| 444 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 445 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 446 | #ifdef PDCURSES |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 447 | case KEY_SHIFT_L: |
| 448 | case KEY_SHIFT_R: |
| 449 | case KEY_CONTROL_L: |
| 450 | case KEY_CONTROL_R: |
| 451 | case KEY_ALT_L: |
| 452 | case KEY_ALT_R: |
| 453 | break; |
David Lawrence Ramsey | d897445 | 2004-06-04 22:28:55 +0000 | [diff] [blame] | 454 | #endif |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 455 | default: |
| 456 | switch (escapes) { |
| 457 | case 0: |
| 458 | switch (kbinput->key) { |
| 459 | case NANO_CONTROL_8: |
| 460 | retval = ISSET(REBIND_DELETE) ? |
| 461 | NANO_DELETE_KEY : |
| 462 | NANO_BACKSPACE_KEY; |
| 463 | break; |
| 464 | case KEY_DOWN: |
| 465 | retval = NANO_NEXTLINE_KEY; |
| 466 | break; |
| 467 | case KEY_UP: |
| 468 | retval = NANO_PREVLINE_KEY; |
| 469 | break; |
| 470 | case KEY_LEFT: |
| 471 | retval = NANO_BACK_KEY; |
| 472 | break; |
| 473 | case KEY_RIGHT: |
| 474 | retval = NANO_FORWARD_KEY; |
| 475 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 476 | #ifdef KEY_HOME |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 477 | /* HP-UX 10 and 11 don't support |
| 478 | * KEY_HOME. */ |
| 479 | case KEY_HOME: |
| 480 | retval = NANO_HOME_KEY; |
| 481 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 482 | #endif |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 483 | case KEY_BACKSPACE: |
| 484 | retval = NANO_BACKSPACE_KEY; |
| 485 | break; |
| 486 | case KEY_DC: |
| 487 | retval = ISSET(REBIND_DELETE) ? |
| 488 | NANO_BACKSPACE_KEY : |
| 489 | NANO_DELETE_KEY; |
| 490 | break; |
| 491 | case KEY_IC: |
| 492 | retval = NANO_INSERTFILE_KEY; |
| 493 | break; |
| 494 | case KEY_NPAGE: |
| 495 | retval = NANO_NEXTPAGE_KEY; |
| 496 | break; |
| 497 | case KEY_PPAGE: |
| 498 | retval = NANO_PREVPAGE_KEY; |
| 499 | break; |
| 500 | case KEY_ENTER: |
| 501 | retval = NANO_ENTER_KEY; |
| 502 | break; |
| 503 | case KEY_A1: /* Home (7) on numeric |
| 504 | * keypad with NumLock |
| 505 | * off. */ |
| 506 | retval = NANO_HOME_KEY; |
| 507 | break; |
| 508 | case KEY_A3: /* PageUp (9) on numeric |
| 509 | * keypad with NumLock |
| 510 | * off. */ |
| 511 | retval = NANO_PREVPAGE_KEY; |
| 512 | break; |
| 513 | case KEY_B2: /* Center (5) on numeric |
| 514 | * keypad with NumLock |
| 515 | * off. */ |
| 516 | break; |
| 517 | case KEY_C1: /* End (1) on numeric |
| 518 | * keypad with NumLock |
| 519 | * off. */ |
| 520 | retval = NANO_END_KEY; |
| 521 | break; |
| 522 | case KEY_C3: /* PageDown (4) on |
| 523 | * numeric keypad with |
| 524 | * NumLock off. */ |
| 525 | retval = NANO_NEXTPAGE_KEY; |
| 526 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 527 | #ifdef KEY_BEG |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 528 | /* Slang doesn't support KEY_BEG. */ |
| 529 | case KEY_BEG: /* Center (5) on numeric |
| 530 | * keypad with NumLock |
| 531 | * off. */ |
| 532 | break; |
David Lawrence Ramsey | 16eb518 | 2004-06-03 20:26:12 +0000 | [diff] [blame] | 533 | #endif |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 534 | #ifdef KEY_END |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 535 | /* HP-UX 10 and 11 don't support KEY_END. */ |
| 536 | case KEY_END: |
| 537 | retval = NANO_END_KEY; |
| 538 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 539 | #endif |
| 540 | #ifdef KEY_SUSPEND |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 541 | /* Slang doesn't support KEY_SUSPEND. */ |
| 542 | case KEY_SUSPEND: |
| 543 | retval = NANO_SUSPEND_KEY; |
| 544 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 545 | #endif |
| 546 | #ifdef KEY_SLEFT |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 547 | /* Slang doesn't support KEY_SLEFT. */ |
| 548 | case KEY_SLEFT: |
| 549 | retval = NANO_BACK_KEY; |
| 550 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 551 | #endif |
| 552 | #ifdef KEY_SRIGHT |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 553 | /* Slang doesn't support KEY_SRIGHT. */ |
| 554 | case KEY_SRIGHT: |
| 555 | retval = NANO_FORWARD_KEY; |
| 556 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 557 | #endif |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 558 | default: |
| 559 | retval = kbinput->key; |
| 560 | break; |
| 561 | } |
| 562 | break; |
| 563 | case 1: |
| 564 | /* One escape followed by a non-escape: escape |
| 565 | * sequence mode. Reset the escape counter. If |
| 566 | * there aren't any other keys waiting, we have |
| 567 | * a meta key sequence, so set meta_key to TRUE |
| 568 | * and save the lowercase version of the |
| 569 | * non-escape character as the result. If there |
| 570 | * are other keys waiting, we have a true escape |
| 571 | * sequence, so interpret it. */ |
| 572 | escapes = 0; |
| 573 | if (get_buffer_len() == 0) { |
| 574 | *meta_key = TRUE; |
| 575 | retval = tolower(kbinput->key); |
| 576 | } else { |
| 577 | buffer *escape_kbinput; |
| 578 | int *sequence; |
| 579 | size_t seq_len; |
| 580 | bool ignore_seq; |
| 581 | |
| 582 | /* Put back the non-escape character, get |
| 583 | * the complete escape sequence, translate |
| 584 | * its key values into the corresponding key |
| 585 | * value, and save that as the result. */ |
| 586 | unget_input(kbinput, 1); |
| 587 | seq_len = get_buffer_len(); |
| 588 | escape_kbinput = get_input(NULL, seq_len); |
| 589 | sequence = buffer_to_keys(escape_kbinput, |
| 590 | seq_len); |
| 591 | retval = get_escape_seq_kbinput(sequence, |
| 592 | seq_len, &ignore_seq); |
| 593 | |
| 594 | /* If the escape sequence is unrecognized |
| 595 | * and not ignored, put back all of its |
| 596 | * characters except for the initial |
| 597 | * escape. */ |
| 598 | if (retval == ERR && !ignore_seq) |
| 599 | unget_input(escape_kbinput, seq_len); |
| 600 | |
| 601 | free(escape_kbinput); |
| 602 | } |
| 603 | break; |
| 604 | case 2: |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 605 | /* Two escapes followed by one or more decimal |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 606 | * digits: word sequence mode. If the word |
| 607 | * sequence's range is limited to 6XXXX (the |
| 608 | * first digit is in the '0' to '6' range and |
| 609 | * it's the first digit, or it's in the '0' to |
| 610 | * '9' range and it's not the first digit), |
| 611 | * increment the word sequence counter, |
| 612 | * interpret the digit, and save the |
| 613 | * corresponding word value as the result. If |
| 614 | * the word sequence's range is not limited to |
| 615 | * 6XXXX, fall through. */ |
| 616 | if (('0' <= kbinput->key && kbinput->key <= '6' |
| 617 | && word_digits == 0) || |
| 618 | ('0' <= kbinput->key && kbinput->key <= '9' |
| 619 | && word_digits > 0)) { |
| 620 | word_digits++; |
| 621 | retval = get_word_kbinput(kbinput->key |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 622 | #ifndef NANO_SMALL |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 623 | , FALSE |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 624 | #endif |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 625 | ); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 626 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 627 | if (retval != ERR) { |
| 628 | /* If we've read in a complete word |
| 629 | * sequence, reset the word sequence |
| 630 | * counter and the escape counter, and |
| 631 | * mark it so that it isn't interpreted |
| 632 | * as an extended keypad value. */ |
| 633 | word_digits = 0; |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 634 | escapes = 0; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 635 | no_func_key = TRUE; |
| 636 | } |
| 637 | } else { |
| 638 | /* Reset the escape counter. */ |
| 639 | escapes = 0; |
| 640 | if (word_digits == 0) |
| 641 | /* Two escapes followed by a non-decimal |
| 642 | * digit or a decimal digit that would |
| 643 | * create a word sequence greater than |
| 644 | * 6XXXX, and we're not in the middle of |
| 645 | * a word sequence: control character |
| 646 | * sequence mode. Interpret the control |
| 647 | * sequence and save the corresponding |
| 648 | * control character as the result. */ |
| 649 | retval = get_control_kbinput(kbinput->key); |
| 650 | else { |
| 651 | /* If we're in the middle of a word |
| 652 | * sequence, reset the word sequence |
| 653 | * counter and save the character we got |
| 654 | * as the result. */ |
| 655 | word_digits = 0; |
| 656 | retval = kbinput->key; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 657 | } |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 658 | } |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 659 | break; |
| 660 | } |
| 661 | } |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 662 | } |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 663 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 664 | /* If we have a result and it's an extended keypad value, set |
| 665 | * func_key to TRUE. */ |
| 666 | if (retval != ERR) |
| 667 | *func_key = !is_byte_char(retval); |
| 668 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 669 | #ifdef DEBUG |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 670 | fprintf(stderr, "parse_kbinput(): kbinput->key = %d, meta_key = %d, func_key = %d, escapes = %d, word_digits = %d, retval = %d\n", kbinput->key, (int)*meta_key, (int)*func_key, escapes, word_digits, retval); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 671 | #endif |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 672 | |
| 673 | /* Return the result. */ |
| 674 | return retval; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 675 | } |
| 676 | |
David Lawrence Ramsey | 58f6d83 | 2004-01-27 07:12:47 +0000 | [diff] [blame] | 677 | /* Translate escape sequences, most of which correspond to extended |
David Lawrence Ramsey | 832db76 | 2004-11-27 23:28:39 +0000 | [diff] [blame] | 678 | * keypad values, into their corresponding key values. These sequences |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 679 | * are generated when the keypad doesn't support the needed keys. If |
| 680 | * the escape sequence is recognized but we want to ignore it, return |
| 681 | * ERR and set ignore_seq to TRUE; if it's unrecognized, return ERR and |
| 682 | * set ignore_seq to FALSE. Assume that Escape has already been read |
| 683 | * in. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 684 | int get_escape_seq_kbinput(const int *sequence, size_t seq_len, bool |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 685 | *ignore_seq) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 686 | { |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 687 | int retval = ERR; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 688 | |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 689 | *ignore_seq = FALSE; |
| 690 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 691 | if (seq_len > 1) { |
| 692 | switch (sequence[0]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 693 | case 'O': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 694 | switch (sequence[1]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 695 | case '2': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 696 | if (seq_len >= 3) { |
| 697 | switch (sequence[2]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 698 | case 'P': /* Esc O 2 P == F13 on |
| 699 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 700 | retval = KEY_F(13); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 701 | break; |
| 702 | case 'Q': /* Esc O 2 Q == F14 on |
| 703 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 704 | retval = KEY_F(14); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 705 | break; |
David Lawrence Ramsey | 8381fdd | 2004-11-01 22:40:02 +0000 | [diff] [blame] | 706 | case 'R': /* Esc O 2 R == F15 on |
| 707 | * xterm. */ |
| 708 | retval = KEY_F(15); |
| 709 | break; |
| 710 | case 'S': /* Esc O 2 S == F16 on |
| 711 | * xterm. */ |
| 712 | retval = KEY_F(16); |
| 713 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 717 | case 'A': /* Esc O A == Up on VT100/VT320/xterm. */ |
| 718 | case 'B': /* Esc O B == Down on |
| 719 | * VT100/VT320/xterm. */ |
| 720 | case 'C': /* Esc O C == Right on |
| 721 | * VT100/VT320/xterm. */ |
| 722 | case 'D': /* Esc O D == Left on |
| 723 | * VT100/VT320/xterm. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 724 | retval = get_escape_seq_abcd(sequence[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 725 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 726 | case 'E': /* Esc O E == Center (5) on numeric keypad |
| 727 | * with NumLock off on xterm. */ |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 728 | *ignore_seq = TRUE; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 729 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 730 | case 'F': /* Esc O F == End on xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 731 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 732 | break; |
| 733 | case 'H': /* Esc O H == Home on xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 734 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 735 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 736 | case 'M': /* Esc O M == Enter on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 737 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 738 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 739 | retval = NANO_ENTER_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 740 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 741 | case 'P': /* Esc O P == F1 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 742 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 743 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 744 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 745 | case 'Q': /* Esc O Q == F2 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 746 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 747 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 748 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 749 | case 'R': /* Esc O R == F3 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 750 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 751 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 752 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 753 | case 'S': /* Esc O S == F4 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 754 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 755 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 756 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 757 | case 'T': /* Esc O T == F5 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 758 | retval = KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 759 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 760 | case 'U': /* Esc O U == F6 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 761 | retval = KEY_F(6); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 762 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 763 | case 'V': /* Esc O V == F7 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 764 | retval = KEY_F(7); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 765 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 766 | case 'W': /* Esc O W == F8 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 767 | retval = KEY_F(8); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 768 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 769 | case 'X': /* Esc O X == F9 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 770 | retval = KEY_F(9); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 771 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 772 | case 'Y': /* Esc O Y == F10 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 773 | retval = KEY_F(10); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 774 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 775 | case 'a': /* Esc O a == Ctrl-Up on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 776 | case 'b': /* Esc O b == Ctrl-Down on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 777 | case 'c': /* Esc O c == Ctrl-Right on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 778 | case 'd': /* Esc O d == Ctrl-Left on rxvt. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 779 | retval = get_escape_seq_abcd(sequence[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 780 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 781 | case 'j': /* Esc O j == '*' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 782 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 783 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 784 | retval = '*'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 785 | break; |
| 786 | case 'k': /* Esc O k == '+' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 787 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 788 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 789 | retval = '+'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 790 | break; |
| 791 | case 'l': /* Esc O l == ',' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 792 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 793 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 794 | retval = '+'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 795 | break; |
| 796 | case 'm': /* Esc O m == '-' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 797 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 798 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 799 | retval = '-'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 800 | break; |
| 801 | case 'n': /* Esc O n == Delete (.) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 802 | * with NumLock off on VT100/VT220/VT320/ |
| 803 | * xterm/rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 804 | retval = NANO_DELETE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 805 | break; |
| 806 | case 'o': /* Esc O o == '/' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 807 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 808 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 809 | retval = '/'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 810 | break; |
| 811 | case 'p': /* Esc O p == Insert (0) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 812 | * with NumLock off on VT100/VT220/VT320/ |
| 813 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 814 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 815 | break; |
| 816 | case 'q': /* Esc O q == End (1) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 817 | * with NumLock off on VT100/VT220/VT320/ |
| 818 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 819 | retval = NANO_END_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 820 | break; |
| 821 | case 'r': /* Esc O r == Down (2) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 822 | * with NumLock off on VT100/VT220/VT320/ |
| 823 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 824 | retval = NANO_NEXTLINE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 825 | break; |
| 826 | case 's': /* Esc O s == PageDown (3) on numeric |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 827 | * keypad with NumLock off on VT100/VT220/ |
| 828 | * VT320/rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 829 | retval = NANO_NEXTPAGE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 830 | break; |
| 831 | case 't': /* Esc O t == Left (4) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 832 | * with NumLock off on VT100/VT220/VT320/ |
| 833 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 834 | retval = NANO_BACK_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 835 | break; |
| 836 | case 'u': /* Esc O u == Center (5) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 837 | * with NumLock off on VT100/VT220/VT320/ |
| 838 | * rxvt/Eterm. */ |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 839 | *ignore_seq = TRUE; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 840 | break; |
| 841 | case 'v': /* Esc O v == Right (6) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 842 | * with NumLock off on VT100/VT220/VT320/ |
| 843 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 844 | retval = NANO_FORWARD_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 845 | break; |
| 846 | case 'w': /* Esc O w == Home (7) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 847 | * with NumLock off on VT100/VT220/VT320/ |
| 848 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 849 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 850 | break; |
| 851 | case 'x': /* Esc O x == Up (8) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 852 | * with NumLock off on VT100/VT220/VT320/ |
| 853 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 854 | retval = NANO_PREVLINE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 855 | break; |
| 856 | case 'y': /* Esc O y == PageUp (9) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 857 | * with NumLock off on VT100/VT220/VT320/ |
| 858 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 859 | retval = NANO_PREVPAGE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 860 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 861 | } |
| 862 | break; |
| 863 | case 'o': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 864 | switch (sequence[1]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 865 | case 'a': /* Esc o a == Ctrl-Up on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 866 | case 'b': /* Esc o b == Ctrl-Down on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 867 | case 'c': /* Esc o c == Ctrl-Right on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 868 | case 'd': /* Esc o d == Ctrl-Left on Eterm. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 869 | retval = get_escape_seq_abcd(sequence[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 870 | break; |
| 871 | } |
| 872 | break; |
| 873 | case '[': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 874 | switch (sequence[1]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 875 | case '1': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 876 | if (seq_len >= 3) { |
| 877 | switch (sequence[2]) { |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 878 | case '1': /* Esc [ 1 1 ~ == F1 on rxvt/ |
| 879 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 880 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 881 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 882 | case '2': /* Esc [ 1 2 ~ == F2 on rxvt/ |
| 883 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 884 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 885 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 886 | case '3': /* Esc [ 1 3 ~ == F3 on rxvt/ |
| 887 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 888 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 889 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 890 | case '4': /* Esc [ 1 4 ~ == F4 on rxvt/ |
| 891 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 892 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 893 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 894 | case '5': /* Esc [ 1 5 ~ == F5 on xterm/ |
| 895 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 896 | retval = KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 897 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 898 | case '7': /* Esc [ 1 7 ~ == F6 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 899 | * VT220/VT320/Linux console/ |
| 900 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 901 | retval = KEY_F(6); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 902 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 903 | case '8': /* Esc [ 1 8 ~ == F7 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 904 | * VT220/VT320/Linux console/ |
| 905 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 906 | retval = KEY_F(7); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 907 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 908 | case '9': /* Esc [ 1 9 ~ == F8 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 909 | * VT220/VT320/Linux console/ |
| 910 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 911 | retval = KEY_F(8); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 912 | break; |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 913 | case ';': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 914 | if (seq_len >= 4) { |
| 915 | switch (sequence[3]) { |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 916 | case '2': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 917 | if (seq_len >= 5) { |
| 918 | switch (sequence[4]) { |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 919 | case 'A': /* Esc [ 1 ; 2 A == Shift-Up on |
| 920 | * xterm. */ |
| 921 | case 'B': /* Esc [ 1 ; 2 B == Shift-Down on |
| 922 | * xterm. */ |
| 923 | case 'C': /* Esc [ 1 ; 2 C == Shift-Right on |
| 924 | * xterm. */ |
| 925 | case 'D': /* Esc [ 1 ; 2 D == Shift-Left on |
| 926 | * xterm. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 927 | retval = get_escape_seq_abcd(sequence[4]); |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 928 | break; |
| 929 | } |
| 930 | } |
| 931 | break; |
| 932 | case '5': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 933 | if (seq_len >= 5) { |
| 934 | switch (sequence[4]) { |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 935 | case 'A': /* Esc [ 1 ; 5 A == Ctrl-Up on |
| 936 | * xterm. */ |
| 937 | case 'B': /* Esc [ 1 ; 5 B == Ctrl-Down on |
| 938 | * xterm. */ |
| 939 | case 'C': /* Esc [ 1 ; 5 C == Ctrl-Right on |
| 940 | * xterm. */ |
| 941 | case 'D': /* Esc [ 1 ; 5 D == Ctrl-Left on |
| 942 | * xterm. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 943 | retval = get_escape_seq_abcd(sequence[4]); |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 944 | break; |
| 945 | } |
| 946 | } |
| 947 | break; |
| 948 | } |
| 949 | } |
| 950 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 951 | default: /* Esc [ 1 ~ == Home on |
| 952 | * VT320/Linux console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 953 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 954 | break; |
| 955 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 956 | } |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 957 | break; |
| 958 | case '2': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 959 | if (seq_len >= 3) { |
| 960 | switch (sequence[2]) { |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 961 | case '0': /* Esc [ 2 0 ~ == F9 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 962 | * VT220/VT320/Linux console/ |
| 963 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 964 | retval = KEY_F(9); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 965 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 966 | case '1': /* Esc [ 2 1 ~ == F10 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 967 | * VT220/VT320/Linux console/ |
| 968 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 969 | retval = KEY_F(10); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 970 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 971 | case '3': /* Esc [ 2 3 ~ == F11 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 972 | * VT220/VT320/Linux console/ |
| 973 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 974 | retval = KEY_F(11); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 975 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 976 | case '4': /* Esc [ 2 4 ~ == F12 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 977 | * VT220/VT320/Linux console/ |
| 978 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 979 | retval = KEY_F(12); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 980 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 981 | case '5': /* Esc [ 2 5 ~ == F13 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 982 | * VT220/VT320/Linux console/ |
| 983 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 984 | retval = KEY_F(13); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 985 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 986 | case '6': /* Esc [ 2 6 ~ == F14 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 987 | * VT220/VT320/Linux console/ |
| 988 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 989 | retval = KEY_F(14); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 990 | break; |
David Lawrence Ramsey | 8381fdd | 2004-11-01 22:40:02 +0000 | [diff] [blame] | 991 | case '8': /* Esc [ 2 8 ~ == F15 on |
| 992 | * VT220/VT320/Linux console/ |
| 993 | * rxvt/Eterm. */ |
| 994 | retval = KEY_F(15); |
| 995 | break; |
| 996 | case '9': /* Esc [ 2 9 ~ == F16 on |
| 997 | * VT220/VT320/Linux console/ |
| 998 | * rxvt/Eterm. */ |
| 999 | retval = KEY_F(16); |
| 1000 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1001 | default: /* Esc [ 2 ~ == Insert on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1002 | * VT220/VT320/Linux console/ |
| 1003 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1004 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1005 | break; |
| 1006 | } |
| 1007 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1008 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1009 | case '3': /* Esc [ 3 ~ == Delete on VT220/VT320/ |
| 1010 | * Linux console/xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1011 | retval = NANO_DELETE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1012 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1013 | case '4': /* Esc [ 4 ~ == End on VT220/VT320/Linux |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1014 | * console/xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1015 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1016 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1017 | case '5': /* Esc [ 5 ~ == PageUp on VT220/VT320/ |
| 1018 | * Linux console/xterm; Esc [ 5 ^ == |
| 1019 | * PageUp on Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1020 | retval = NANO_PREVPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1021 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1022 | case '6': /* Esc [ 6 ~ == PageDown on VT220/VT320/ |
| 1023 | * Linux console/xterm; Esc [ 6 ^ == |
| 1024 | * PageDown on Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1025 | retval = NANO_NEXTPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1026 | break; |
| 1027 | case '7': /* Esc [ 7 ~ == Home on rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1028 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1029 | break; |
| 1030 | case '8': /* Esc [ 8 ~ == End on rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1031 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1032 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1033 | case '9': /* Esc [ 9 == Delete on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1034 | retval = NANO_DELETE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1035 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1036 | case '@': /* Esc [ @ == Insert on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1037 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1038 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1039 | case 'A': /* Esc [ A == Up on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1040 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1041 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1042 | case 'B': /* Esc [ B == Down on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1043 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1044 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1045 | case 'C': /* Esc [ C == Right on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1046 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1047 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1048 | case 'D': /* Esc [ D == Left on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1049 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1050 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1051 | retval = get_escape_seq_abcd(sequence[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1052 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 1053 | case 'E': /* Esc [ E == Center (5) on numeric keypad |
| 1054 | * with NumLock off on FreeBSD console. */ |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 1055 | *ignore_seq = TRUE; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 1056 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1057 | case 'F': /* Esc [ F == End on FreeBSD |
| 1058 | * console/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1059 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | case 'G': /* Esc [ G == PageDown on FreeBSD |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 1062 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1063 | retval = NANO_NEXTPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1064 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1065 | case 'H': /* Esc [ H == Home on ANSI/VT220/FreeBSD |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1066 | * console/Mach console/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1067 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1068 | break; |
| 1069 | case 'I': /* Esc [ I == PageUp on FreeBSD |
| 1070 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1071 | retval = NANO_PREVPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1072 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1073 | case 'L': /* Esc [ L == Insert on ANSI/FreeBSD |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1074 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1075 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1076 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1077 | case 'M': /* Esc [ M == F1 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1078 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1079 | break; |
| 1080 | case 'N': /* Esc [ N == F2 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1081 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1082 | break; |
| 1083 | case 'O': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1084 | if (seq_len >= 3) { |
| 1085 | switch (sequence[2]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1086 | case 'P': /* Esc [ O P == F1 on |
| 1087 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1088 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1089 | break; |
| 1090 | case 'Q': /* Esc [ O Q == F2 on |
| 1091 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1092 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1093 | break; |
| 1094 | case 'R': /* Esc [ O R == F3 on |
| 1095 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1096 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1097 | break; |
| 1098 | case 'S': /* Esc [ O S == F4 on |
| 1099 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1100 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1101 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1102 | } |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1103 | } else { |
| 1104 | /* Esc [ O == F3 on FreeBSD console. */ |
| 1105 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1106 | } |
| 1107 | break; |
| 1108 | case 'P': /* Esc [ P == F4 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1109 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1110 | break; |
| 1111 | case 'Q': /* Esc [ Q == F5 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1112 | retval = KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1113 | break; |
| 1114 | case 'R': /* Esc [ R == F6 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1115 | retval = KEY_F(6); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1116 | break; |
| 1117 | case 'S': /* Esc [ S == F7 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1118 | retval = KEY_F(7); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1119 | break; |
| 1120 | case 'T': /* Esc [ T == F8 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1121 | retval = KEY_F(8); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1122 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1123 | case 'U': /* Esc [ U == PageDown on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1124 | retval = NANO_NEXTPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1125 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1126 | case 'V': /* Esc [ V == PageUp on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1127 | retval = NANO_PREVPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1128 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1129 | case 'W': /* Esc [ W == F11 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1130 | retval = KEY_F(11); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1131 | break; |
| 1132 | case 'X': /* Esc [ X == F12 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1133 | retval = KEY_F(12); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1134 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1135 | case 'Y': /* Esc [ Y == End on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1136 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1137 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1138 | case 'Z': /* Esc [ Z == F14 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1139 | retval = KEY_F(14); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1140 | break; |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1141 | case 'a': /* Esc [ a == Shift-Up on rxvt/Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1142 | case 'b': /* Esc [ b == Shift-Down on rxvt/Eterm. */ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1143 | case 'c': /* Esc [ c == Shift-Right on rxvt/ |
| 1144 | * Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1145 | case 'd': /* Esc [ d == Shift-Left on rxvt/Eterm. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1146 | retval = get_escape_seq_abcd(sequence[1]); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1147 | break; |
| 1148 | case '[': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1149 | if (seq_len >= 3) { |
| 1150 | switch (sequence[2]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1151 | case 'A': /* Esc [ [ A == F1 on Linux |
| 1152 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1153 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1154 | break; |
| 1155 | case 'B': /* Esc [ [ B == F2 on Linux |
| 1156 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1157 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1158 | break; |
| 1159 | case 'C': /* Esc [ [ C == F3 on Linux |
| 1160 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1161 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1162 | break; |
| 1163 | case 'D': /* Esc [ [ D == F4 on Linux |
| 1164 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1165 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1166 | break; |
| 1167 | case 'E': /* Esc [ [ E == F5 on Linux |
| 1168 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1169 | retval = KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1170 | break; |
| 1171 | } |
| 1172 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1173 | break; |
| 1174 | } |
| 1175 | break; |
| 1176 | } |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1177 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1178 | |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1179 | #ifdef DEBUG |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1180 | fprintf(stderr, "get_escape_seq_kbinput(): retval = %d, ignore_seq = %d\n", retval, (int)*ignore_seq); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1181 | #endif |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1182 | |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1183 | return retval; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1186 | /* Return the equivalent arrow key value for the case-insensitive |
David Lawrence Ramsey | b7e5cf6 | 2004-02-07 03:39:48 +0000 | [diff] [blame] | 1187 | * letters A (up), B (down), C (right), and D (left). These are common |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1188 | * to many escape sequences. */ |
| 1189 | int get_escape_seq_abcd(int kbinput) |
| 1190 | { |
| 1191 | switch (tolower(kbinput)) { |
| 1192 | case 'a': |
| 1193 | return NANO_PREVLINE_KEY; |
| 1194 | case 'b': |
| 1195 | return NANO_NEXTLINE_KEY; |
| 1196 | case 'c': |
| 1197 | return NANO_FORWARD_KEY; |
| 1198 | case 'd': |
| 1199 | return NANO_BACK_KEY; |
| 1200 | default: |
| 1201 | return ERR; |
| 1202 | } |
| 1203 | } |
| 1204 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1205 | /* Translate a word sequence: turn a three-digit decimal number from |
| 1206 | * 000 to 255 into its corresponding word value. */ |
| 1207 | int get_word_kbinput(int kbinput |
| 1208 | #ifndef NANO_SMALL |
| 1209 | , bool reset |
| 1210 | #endif |
| 1211 | ) |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1212 | { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1213 | static int word_digits = 0; |
| 1214 | static int word_kbinput = 0; |
| 1215 | int retval = ERR; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1216 | |
| 1217 | #ifndef NANO_SMALL |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1218 | if (reset) { |
| 1219 | word_digits = 0; |
| 1220 | word_kbinput = 0; |
| 1221 | return ERR; |
| 1222 | } |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1223 | #endif |
| 1224 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1225 | /* Increment the word digit counter. */ |
| 1226 | word_digits++; |
| 1227 | |
| 1228 | switch (word_digits) { |
| 1229 | case 1: |
| 1230 | /* One digit: reset the word sequence holder and add the |
| 1231 | * digit we got to the 10000's position of the word sequence |
| 1232 | * holder. */ |
| 1233 | word_kbinput = 0; |
| 1234 | if ('0' <= kbinput && kbinput <= '6') |
| 1235 | word_kbinput += (kbinput - '0') * 10000; |
| 1236 | else |
| 1237 | /* If the character we got isn't a decimal digit, or if |
| 1238 | * it is and it would put the word sequence out of word |
| 1239 | * range, save it as the result. */ |
| 1240 | retval = kbinput; |
| 1241 | break; |
| 1242 | case 2: |
| 1243 | /* Two digits: add the digit we got to the 1000's position |
| 1244 | * of the word sequence holder. */ |
| 1245 | if (('0' <= kbinput && kbinput <= '5') || |
| 1246 | (word_kbinput < 60000 && '6' <= kbinput && |
| 1247 | kbinput <= '9')) |
| 1248 | word_kbinput += (kbinput - '0') * 1000; |
| 1249 | else |
| 1250 | /* If the character we got isn't a decimal digit, or if |
| 1251 | * it is and it would put the word sequence out of word |
| 1252 | * range, save it as the result. */ |
| 1253 | retval = kbinput; |
| 1254 | break; |
| 1255 | case 3: |
| 1256 | /* Three digits: add the digit we got to the 100's position |
| 1257 | * of the word sequence holder. */ |
| 1258 | if (('0' <= kbinput && kbinput <= '5') || |
| 1259 | (word_kbinput < 65000 && '6' <= kbinput && |
| 1260 | kbinput <= '9')) |
| 1261 | word_kbinput += (kbinput - '0') * 100; |
| 1262 | else |
| 1263 | /* If the character we got isn't a decimal digit, or if |
| 1264 | * it is and it would put the word sequence out of word |
| 1265 | * range, save it as the result. */ |
| 1266 | retval = kbinput; |
| 1267 | break; |
| 1268 | case 4: |
| 1269 | /* Four digits: add the digit we got to the 10's position of |
| 1270 | * the word sequence holder. */ |
| 1271 | if (('0' <= kbinput && kbinput <= '3') || |
| 1272 | (word_kbinput < 65500 && '4' <= kbinput && |
| 1273 | kbinput <= '9')) |
| 1274 | word_kbinput += (kbinput - '0') * 10; |
| 1275 | else |
| 1276 | /* If the character we got isn't a decimal digit, or if |
| 1277 | * it is and it would put the word sequence out of word |
| 1278 | * range, save it as the result. */ |
| 1279 | retval = kbinput; |
| 1280 | break; |
| 1281 | case 5: |
| 1282 | /* Five digits: add the digit we got to the 1's position of |
| 1283 | * the word sequence holder, and save the corresponding word |
| 1284 | * value as the result. */ |
| 1285 | if (('0' <= kbinput && kbinput <= '5') || |
| 1286 | (word_kbinput < 65530 && '6' <= kbinput && |
| 1287 | kbinput <= '9')) { |
| 1288 | word_kbinput += (kbinput - '0'); |
| 1289 | retval = word_kbinput; |
| 1290 | } else |
| 1291 | /* If the character we got isn't a decimal digit, or if |
| 1292 | * it is and it would put the word sequence out of word |
| 1293 | * range, save it as the result. */ |
| 1294 | retval = kbinput; |
| 1295 | break; |
| 1296 | default: |
| 1297 | /* More than three digits: save the character we got as the |
| 1298 | * result. */ |
| 1299 | retval = kbinput; |
| 1300 | break; |
| 1301 | } |
| 1302 | |
| 1303 | /* If we have a result, reset the word digit counter and the word |
| 1304 | * sequence holder. */ |
| 1305 | if (retval != ERR) { |
| 1306 | word_digits = 0; |
| 1307 | word_kbinput = 0; |
| 1308 | } |
| 1309 | |
| 1310 | #ifdef DEBUG |
| 1311 | fprintf(stderr, "get_word_kbinput(): kbinput = %d, word_digits = %d, word_kbinput = %d, retval = %d\n", kbinput, word_digits, word_kbinput, retval); |
| 1312 | #endif |
| 1313 | |
| 1314 | return retval; |
| 1315 | } |
| 1316 | |
| 1317 | /* Translate a control character sequence: turn an ASCII non-control |
| 1318 | * character into its corresponding control character. */ |
| 1319 | int get_control_kbinput(int kbinput) |
| 1320 | { |
| 1321 | int retval; |
| 1322 | |
| 1323 | /* Ctrl-2 (Ctrl-Space, Ctrl-@, Ctrl-`) */ |
| 1324 | if (kbinput == '2' || kbinput == ' ' || kbinput == '@' || |
| 1325 | kbinput == '`') |
| 1326 | retval = NANO_CONTROL_SPACE; |
| 1327 | /* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-_) */ |
| 1328 | else if ('3' <= kbinput && kbinput <= '7') |
| 1329 | retval = kbinput - 24; |
| 1330 | /* Ctrl-8 (Ctrl-?) */ |
| 1331 | else if (kbinput == '8' || kbinput == '?') |
| 1332 | retval = NANO_CONTROL_8; |
| 1333 | /* Ctrl-A to Ctrl-_ */ |
| 1334 | else if ('A' <= kbinput && kbinput <= '_') |
| 1335 | retval = kbinput - 64; |
| 1336 | /* Ctrl-a to Ctrl-~ */ |
| 1337 | else if ('a' <= kbinput && kbinput <= '~') |
| 1338 | retval = kbinput - 96; |
| 1339 | else |
| 1340 | retval = kbinput; |
| 1341 | |
| 1342 | #ifdef DEBUG |
| 1343 | fprintf(stderr, "get_control_kbinput(): kbinput = %d, retval = %d\n", kbinput, retval); |
| 1344 | #endif |
| 1345 | |
| 1346 | return retval; |
| 1347 | } |
| 1348 | |
| 1349 | /* Read in a string of characters verbatim, and return the length of the |
| 1350 | * string in kbinput_len. Assume nodelay(win) is FALSE. */ |
| 1351 | int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) |
| 1352 | { |
| 1353 | int *retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1354 | |
| 1355 | /* Turn off flow control characters if necessary so that we can type |
| 1356 | * them in verbatim, and turn the keypad off so that we don't get |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1357 | * extended keypad values. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1358 | if (ISSET(PRESERVE)) |
| 1359 | disable_flow_control(); |
| 1360 | keypad(win, FALSE); |
| 1361 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1362 | /* Read in a stream of characters and interpret it if possible. */ |
| 1363 | retval = parse_verbatim_kbinput(win, kbinput_len); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1364 | |
| 1365 | /* Turn flow control characters back on if necessary and turn the |
| 1366 | * keypad back on now that we're done. */ |
| 1367 | if (ISSET(PRESERVE)) |
| 1368 | enable_flow_control(); |
| 1369 | keypad(win, TRUE); |
| 1370 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1371 | return retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1374 | /* Read in a stream of all available characters. Translate the first |
| 1375 | * few characters of the input into the corresponding word value if |
| 1376 | * possible. After that, leave the input as-is. */ |
| 1377 | int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1378 | { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1379 | buffer *kbinput, *sequence; |
| 1380 | int word, *retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1381 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1382 | /* Read in the first keystroke. */ |
| 1383 | while ((kbinput = get_input(win, 1)) == NULL); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1384 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1385 | /* Check whether the first keystroke is a decimal digit. */ |
| 1386 | word = get_word_kbinput(kbinput->key |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1387 | #ifndef NANO_SMALL |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1388 | , FALSE |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1389 | #endif |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1390 | ); |
| 1391 | |
| 1392 | /* If the first keystroke isn't a decimal digit, put back the first |
| 1393 | * keystroke. */ |
| 1394 | if (word != ERR) |
| 1395 | unget_input(kbinput, 1); |
| 1396 | /* Otherwise, read in keystrokes until we have a complete word |
| 1397 | * sequence, and put back the corresponding word value. */ |
| 1398 | else { |
| 1399 | buffer word_kbinput; |
| 1400 | |
| 1401 | while (word == ERR) { |
| 1402 | while ((kbinput = get_input(win, 1)) == NULL); |
| 1403 | word = get_word_kbinput(kbinput->key |
| 1404 | #ifndef NANO_SMALL |
| 1405 | , FALSE |
| 1406 | #endif |
| 1407 | ); |
| 1408 | } |
| 1409 | |
| 1410 | word_kbinput.key = word; |
| 1411 | word_kbinput.key_code = FALSE; |
| 1412 | |
| 1413 | unget_input(&word_kbinput, 1); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1416 | /* Get the complete sequence, and save the key values in it as the |
| 1417 | * result. */ |
| 1418 | *kbinput_len = get_buffer_len(); |
| 1419 | sequence = get_input(NULL, *kbinput_len); |
| 1420 | retval = buffer_to_keys(sequence, *kbinput_len); |
| 1421 | free(sequence); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1422 | |
| 1423 | return retval; |
| 1424 | } |
| 1425 | |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1426 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1427 | /* Check for a mouse event, and if one's taken place, save the |
| 1428 | * coordinates where it took place in mouse_x and mouse_y. After that, |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1429 | * assuming allow_shortcuts is FALSE, if the shortcut list on the |
| 1430 | * bottom two lines of the screen is visible and the mouse event took |
David Lawrence Ramsey | dfca1c4 | 2004-08-25 16:37:06 +0000 | [diff] [blame] | 1431 | * place on it, figure out which shortcut was clicked and put back the |
| 1432 | * equivalent keystroke(s). Return FALSE if no keystrokes were |
| 1433 | * put back, or TRUE if at least one was. Assume that KEY_MOUSE has |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1434 | * already been read in. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1435 | bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts) |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1436 | { |
| 1437 | MEVENT mevent; |
| 1438 | |
| 1439 | *mouse_x = -1; |
| 1440 | *mouse_y = -1; |
| 1441 | |
| 1442 | /* First, get the actual mouse event. */ |
| 1443 | if (getmouse(&mevent) == ERR) |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1444 | return FALSE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1445 | |
| 1446 | /* Save the screen coordinates where the mouse event took place. */ |
| 1447 | *mouse_x = mevent.x; |
| 1448 | *mouse_y = mevent.y; |
| 1449 | |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1450 | /* If we're allowing shortcuts, the current shortcut list is being |
| 1451 | * displayed on the last two lines of the screen, and the mouse |
| 1452 | * event took place inside it, we need to figure out which shortcut |
David Lawrence Ramsey | dfca1c4 | 2004-08-25 16:37:06 +0000 | [diff] [blame] | 1453 | * was clicked and put back the equivalent keystroke(s) for it. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1454 | if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin, |
| 1455 | *mouse_y, *mouse_x)) { |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1456 | int i, j; |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1457 | size_t currslen; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1458 | /* The number of shortcuts in the current shortcut list. */ |
| 1459 | const shortcut *s = currshortcut; |
| 1460 | /* The actual shortcut we clicked on, starting at the first |
| 1461 | * one in the current shortcut list. */ |
| 1462 | |
| 1463 | /* Get the shortcut lists' length. */ |
| 1464 | if (currshortcut == main_list) |
| 1465 | currslen = MAIN_VISIBLE; |
David Lawrence Ramsey | fe0d366 | 2004-08-26 01:43:16 +0000 | [diff] [blame] | 1466 | else { |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1467 | currslen = length_of_list(currshortcut); |
| 1468 | |
David Lawrence Ramsey | fe0d366 | 2004-08-26 01:43:16 +0000 | [diff] [blame] | 1469 | /* We don't show any more shortcuts than the main list |
| 1470 | * does. */ |
| 1471 | if (currslen > MAIN_VISIBLE) |
| 1472 | currslen = MAIN_VISIBLE; |
| 1473 | } |
| 1474 | |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1475 | /* Calculate the width of each shortcut in the list (it's the |
| 1476 | * same for all of them). */ |
| 1477 | if (currslen < 2) |
| 1478 | i = COLS / 6; |
| 1479 | else |
| 1480 | i = COLS / ((currslen / 2) + (currslen % 2)); |
| 1481 | |
| 1482 | /* Calculate the y-coordinates relative to the beginning of |
| 1483 | * bottomwin, i.e, the bottom three lines of the screen. */ |
| 1484 | j = *mouse_y - (editwinrows + 3); |
| 1485 | |
| 1486 | /* If we're on the statusbar, beyond the end of the shortcut |
| 1487 | * list, or beyond the end of a shortcut on the right side of |
| 1488 | * the screen, don't do anything. */ |
| 1489 | if (j < 0 || (*mouse_x / i) >= currslen) |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1490 | return FALSE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1491 | j = (*mouse_x / i) * 2 + j; |
| 1492 | if (j >= currslen) |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1493 | return FALSE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1494 | |
| 1495 | /* Go through the shortcut list to determine which shortcut was |
| 1496 | * clicked. */ |
| 1497 | for (; j > 0; j--) |
| 1498 | s = s->next; |
| 1499 | |
David Lawrence Ramsey | db6015c | 2004-09-11 21:41:13 +0000 | [diff] [blame] | 1500 | /* And put back the equivalent key. Assume that each shortcut |
| 1501 | * has, at the very least, an equivalent control key, an |
| 1502 | * equivalent primary meta key sequence, or both. */ |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1503 | if (s->ctrlval != NANO_NO_KEY) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1504 | unget_kbinput(s->ctrlval, FALSE, FALSE); |
David Lawrence Ramsey | fe0d366 | 2004-08-26 01:43:16 +0000 | [diff] [blame] | 1505 | else if (s->metaval != NANO_NO_KEY) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1506 | unget_kbinput(s->metaval, TRUE, FALSE); |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1507 | |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1508 | return TRUE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1509 | } |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1510 | return FALSE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1511 | } |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1512 | #endif /* !DISABLE_MOUSE */ |
| 1513 | |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1514 | const shortcut *get_shortcut(const shortcut *s_list, int *kbinput, bool |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 1515 | *meta_key, bool *func_key) |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1516 | { |
| 1517 | const shortcut *s = s_list; |
| 1518 | size_t slen = length_of_list(s_list); |
| 1519 | |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1520 | #ifdef DEBUG |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1521 | fprintf(stderr, "get_shortcut(): kbinput = %d, meta_key = %d, func_key = %d\n", *kbinput, (int)*meta_key, (int)*func_key); |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1522 | #endif |
| 1523 | |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1524 | /* Check for shortcuts. */ |
| 1525 | for (; slen > 0; slen--) { |
| 1526 | /* We've found a shortcut if: |
| 1527 | * |
| 1528 | * 1. The key exists. |
| 1529 | * 2. The key is a control key in the shortcut list. |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 1530 | * 3. meta_key is TRUE and the key is the primary or |
| 1531 | * miscellaneous meta sequence in the shortcut list. |
| 1532 | * 4. func_key is TRUE and the key is a function key in the |
| 1533 | * shortcut list. */ |
| 1534 | |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1535 | if (*kbinput != NANO_NO_KEY && (*kbinput == s->ctrlval || |
| 1536 | (*meta_key == TRUE && (*kbinput == s->metaval || |
| 1537 | *kbinput == s->miscval)) || (*func_key == TRUE && |
| 1538 | *kbinput == s->funcval))) { |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1539 | break; |
| 1540 | } |
| 1541 | |
| 1542 | s = s->next; |
| 1543 | } |
| 1544 | |
| 1545 | /* Translate the shortcut to either its control key or its meta key |
| 1546 | * equivalent. Assume that the shortcut has an equivalent control |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 1547 | * key, an equivalent primary meta key sequence, or both. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1548 | if (slen > 0) { |
| 1549 | if (s->ctrlval != NANO_NO_KEY) { |
| 1550 | *meta_key = FALSE; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1551 | *func_key = FALSE; |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1552 | *kbinput = s->ctrlval; |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1553 | } else if (s->metaval != NANO_NO_KEY) { |
| 1554 | *meta_key = TRUE; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1555 | *func_key = FALSE; |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1556 | *kbinput = s->metaval; |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1557 | } |
| 1558 | return s; |
| 1559 | } |
| 1560 | |
| 1561 | return NULL; |
| 1562 | } |
| 1563 | |
| 1564 | #ifndef NANO_SMALL |
| 1565 | const toggle *get_toggle(int kbinput, bool meta_key) |
| 1566 | { |
| 1567 | const toggle *t = toggles; |
| 1568 | |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1569 | #ifdef DEBUG |
| 1570 | fprintf(stderr, "get_toggle(): kbinput = %d, meta_key = %d\n", kbinput, (int)meta_key); |
| 1571 | #endif |
| 1572 | |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1573 | /* Check for toggles. */ |
| 1574 | for (; t != NULL; t = t->next) { |
| 1575 | /* We've found a toggle if meta_key is TRUE and the key is in |
| 1576 | * the meta toggle list. */ |
| 1577 | if (meta_key && kbinput == t->val) |
| 1578 | break; |
| 1579 | } |
| 1580 | |
| 1581 | return t; |
| 1582 | } |
| 1583 | #endif /* !NANO_SMALL */ |
| 1584 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1585 | /* Return the placewewant associated with current_x. That is, xplustabs |
| 1586 | * is the zero-based column position of the cursor. Value is no smaller |
| 1587 | * than current_x. */ |
| 1588 | size_t xplustabs(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1589 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1590 | return strnlenpt(current->data, current_x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1593 | /* actual_x() gives the index in str of the character displayed at |
| 1594 | * column xplus. That is, actual_x() is the largest value such that |
| 1595 | * strnlenpt(str, actual_x(str, xplus)) <= xplus. */ |
| 1596 | size_t actual_x(const char *str, size_t xplus) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1597 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1598 | size_t i = 0; |
David Lawrence Ramsey | 09b34ed | 2004-09-24 21:48:40 +0000 | [diff] [blame] | 1599 | /* The position in str, returned. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1600 | size_t length = 0; |
David Lawrence Ramsey | 09b34ed | 2004-09-24 21:48:40 +0000 | [diff] [blame] | 1601 | /* The screen display width to str[i]. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1602 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1603 | assert(str != NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1604 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1605 | for (; length < xplus && *str != '\0'; i++, str++) { |
| 1606 | if (*str == '\t') |
David Lawrence Ramsey | 0362c58 | 2003-09-30 03:31:56 +0000 | [diff] [blame] | 1607 | length += tabsize - (length % tabsize); |
David Lawrence Ramsey | 1601c28 | 2004-10-21 22:06:40 +0000 | [diff] [blame] | 1608 | else if (is_cntrl_char(*str)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1609 | length += 2; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1610 | else |
| 1611 | length++; |
| 1612 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1613 | assert(length == strnlenpt(str - i, i)); |
| 1614 | assert(i <= strlen(str - i)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1615 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1616 | if (length > xplus) |
| 1617 | i--; |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1618 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1619 | return i; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
David Lawrence Ramsey | a3370c4 | 2004-04-05 01:08:14 +0000 | [diff] [blame] | 1622 | /* A strlen() with tabs factored in, similar to xplustabs(). How many |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame] | 1623 | * columns wide are the first size characters of buf? */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1624 | size_t strnlenpt(const char *buf, size_t size) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1625 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1626 | size_t length = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1627 | |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame] | 1628 | assert(buf != NULL); |
| 1629 | for (; *buf != '\0' && size != 0; size--, buf++) { |
| 1630 | if (*buf == '\t') |
| 1631 | length += tabsize - (length % tabsize); |
David Lawrence Ramsey | 1601c28 | 2004-10-21 22:06:40 +0000 | [diff] [blame] | 1632 | else if (is_cntrl_char(*buf)) |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame] | 1633 | length += 2; |
| 1634 | else |
| 1635 | length++; |
| 1636 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1637 | return length; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame] | 1640 | /* How many columns wide is buf? */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1641 | size_t strlenpt(const char *buf) |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 1642 | { |
David Lawrence Ramsey | 0b047c5 | 2004-03-29 23:09:08 +0000 | [diff] [blame] | 1643 | return strnlenpt(buf, (size_t)-1); |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1646 | void blank_titlebar(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1647 | { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1648 | mvwaddstr(topwin, 0, 0, hblank); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1651 | void blank_edit(void) |
| 1652 | { |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 1653 | int i; |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 1654 | for (i = 0; i < editwinrows; i++) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1655 | mvwaddstr(edit, i, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1658 | void blank_statusbar(void) |
| 1659 | { |
| 1660 | mvwaddstr(bottomwin, 0, 0, hblank); |
| 1661 | } |
| 1662 | |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 1663 | void check_statusblank(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1664 | { |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 1665 | if (statusblank > 1) |
| 1666 | statusblank--; |
| 1667 | else if (statusblank == 1 && !ISSET(CONSTUPDATE)) { |
| 1668 | statusblank = 0; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1669 | blank_statusbar(); |
| 1670 | wnoutrefresh(bottomwin); |
| 1671 | reset_cursor(); |
| 1672 | wrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1673 | } |
| 1674 | } |
| 1675 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1676 | void blank_bottombars(void) |
| 1677 | { |
| 1678 | if (!ISSET(NO_HELP)) { |
| 1679 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 1680 | mvwaddstr(bottomwin, 2, 0, hblank); |
| 1681 | } |
| 1682 | } |
| 1683 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1684 | /* Convert buf into a string that can be displayed on screen. The |
| 1685 | * caller wants to display buf starting with column start_col, and |
| 1686 | * extending for at most len columns. start_col is zero-based. len is |
| 1687 | * one-based, so len == 0 means you get "" returned. The returned |
| 1688 | * string is dynamically allocated, and should be freed. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1689 | char *display_string(const char *buf, size_t start_col, size_t len) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1690 | { |
| 1691 | size_t start_index; |
| 1692 | /* Index in buf of first character shown in return value. */ |
| 1693 | size_t column; |
| 1694 | /* Screen column start_index corresponds to. */ |
| 1695 | size_t end_index; |
| 1696 | /* Index in buf of last character shown in return value. */ |
| 1697 | size_t alloc_len; |
| 1698 | /* The length of memory allocated for converted. */ |
| 1699 | char *converted; |
| 1700 | /* The string we return. */ |
| 1701 | size_t index; |
| 1702 | /* Current position in converted. */ |
| 1703 | |
| 1704 | if (len == 0) |
| 1705 | return mallocstrcpy(NULL, ""); |
| 1706 | |
| 1707 | start_index = actual_x(buf, start_col); |
| 1708 | column = strnlenpt(buf, start_index); |
| 1709 | assert(column <= start_col); |
| 1710 | end_index = actual_x(buf, start_col + len - 1); |
| 1711 | alloc_len = strnlenpt(buf, end_index + 1) - column; |
| 1712 | if (len > alloc_len + column - start_col) |
| 1713 | len = alloc_len + column - start_col; |
| 1714 | converted = charalloc(alloc_len + 1); |
| 1715 | buf += start_index; |
| 1716 | index = 0; |
| 1717 | |
| 1718 | for (; index < alloc_len; buf++) { |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 1719 | if (*buf == '\t') { |
| 1720 | converted[index++] = |
| 1721 | #if !defined(NANO_SMALL) && defined(ENABLE_NANORC) |
| 1722 | ISSET(WHITESPACE_DISPLAY) ? whitespace[0] : |
| 1723 | #endif |
| 1724 | ' '; |
| 1725 | while ((column + index) % tabsize) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1726 | converted[index++] = ' '; |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 1727 | } else if (is_cntrl_char(*buf)) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1728 | converted[index++] = '^'; |
| 1729 | if (*buf == '\n') |
| 1730 | /* Treat newlines embedded in a line as encoded nulls; |
| 1731 | * the line in question should be run through unsunder() |
| 1732 | * before reaching here. */ |
| 1733 | converted[index++] = '@'; |
| 1734 | else if (*buf == NANO_CONTROL_8) |
| 1735 | converted[index++] = '?'; |
| 1736 | else |
| 1737 | converted[index++] = *buf + 64; |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 1738 | } else if (*buf == ' ') |
| 1739 | converted[index++] = |
| 1740 | #if !defined(NANO_SMALL) && defined(ENABLE_NANORC) |
| 1741 | ISSET(WHITESPACE_DISPLAY) ? whitespace[1] : |
| 1742 | #endif |
| 1743 | ' '; |
| 1744 | else |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1745 | converted[index++] = *buf; |
| 1746 | } |
| 1747 | assert(len <= alloc_len + column - start_col); |
| 1748 | charmove(converted, converted + start_col - column, len); |
| 1749 | null_at(&converted, len); |
| 1750 | |
| 1751 | return charealloc(converted, len + 1); |
| 1752 | } |
| 1753 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1754 | /* Repaint the statusbar when getting a character in nanogetstr(). buf |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1755 | * should be no longer than max(0, COLS - 4). |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1756 | * |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1757 | * 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] | 1758 | * off! */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1759 | void nanoget_repaint(const char *buf, const char *inputbuf, size_t x) |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 1760 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1761 | size_t x_real = strnlenpt(inputbuf, x); |
| 1762 | int wid = COLS - strlen(buf) - 2; |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 1763 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1764 | assert(0 <= x && x <= strlen(inputbuf)); |
| 1765 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1766 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 1767 | blank_statusbar(); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1768 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1769 | mvwaddstr(bottomwin, 0, 0, buf); |
| 1770 | waddch(bottomwin, ':'); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1771 | |
| 1772 | if (COLS > 1) |
| 1773 | waddch(bottomwin, x_real < wid ? ' ' : '$'); |
| 1774 | if (COLS > 2) { |
| 1775 | size_t page_start = x_real - x_real % wid; |
| 1776 | char *expanded = display_string(inputbuf, page_start, wid); |
| 1777 | |
| 1778 | assert(wid > 0); |
| 1779 | assert(strlen(expanded) <= wid); |
| 1780 | waddstr(bottomwin, expanded); |
| 1781 | free(expanded); |
| 1782 | wmove(bottomwin, 0, COLS - wid + x_real - page_start); |
| 1783 | } else |
| 1784 | wmove(bottomwin, 0, COLS - 1); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1785 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
David Lawrence Ramsey | 6aec4b8 | 2004-03-15 20:26:30 +0000 | [diff] [blame] | 1788 | /* Get the input from the keyboard; this should only be called from |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1789 | * statusq(). */ |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 1790 | int nanogetstr(bool allow_tabs, const char *buf, const char *def, |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1791 | #ifndef NANO_SMALL |
| 1792 | historyheadtype *history_list, |
| 1793 | #endif |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 1794 | const shortcut *s |
Rocco Corsi | 06aca1c | 2001-01-11 05:30:31 +0000 | [diff] [blame] | 1795 | #ifndef DISABLE_TABCOMP |
David Lawrence Ramsey | 4d44d2d | 2004-08-01 22:35:31 +0000 | [diff] [blame] | 1796 | , bool *list |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 1797 | #endif |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 1798 | ) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1799 | { |
| 1800 | int kbinput; |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 1801 | bool meta_key, func_key; |
David Lawrence Ramsey | 7a97e18 | 2004-10-30 01:03:15 +0000 | [diff] [blame] | 1802 | static size_t x = (size_t)-1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1803 | /* the cursor position in 'answer' */ |
David Lawrence Ramsey | 7a97e18 | 2004-10-30 01:03:15 +0000 | [diff] [blame] | 1804 | size_t xend; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1805 | /* length of 'answer', the status bar text */ |
David Lawrence Ramsey | 4d44d2d | 2004-08-01 22:35:31 +0000 | [diff] [blame] | 1806 | bool tabbed = FALSE; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1807 | /* used by input_tab() */ |
| 1808 | const shortcut *t; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1809 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1810 | #ifndef NANO_SMALL |
| 1811 | /* for history */ |
| 1812 | char *history = NULL; |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 1813 | char *currentbuf = NULL; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1814 | char *complete = NULL; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1815 | int last_kbinput = 0; |
| 1816 | |
| 1817 | /* This variable is used in the search history code. use_cb == 0 |
| 1818 | means that we're using the existing history and ignoring |
| 1819 | currentbuf. use_cb == 1 means that the entry in answer should be |
| 1820 | moved to currentbuf or restored from currentbuf to answer. |
| 1821 | use_cb == 2 means that the entry in currentbuf should be moved to |
| 1822 | answer or restored from answer to currentbuf. */ |
| 1823 | int use_cb = 0; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1824 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1825 | xend = strlen(def); |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1826 | |
David Lawrence Ramsey | 4dd723a | 2004-10-05 02:29:52 +0000 | [diff] [blame] | 1827 | /* Only put x at the end of the string if it's uninitialized, if it |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 1828 | would be past the end of the string as it is, or if |
| 1829 | resetstatuspos is TRUE. Otherwise, leave it alone. This is so |
| 1830 | the cursor position stays at the same place if a prompt-changing |
| 1831 | toggle is pressed. */ |
David Lawrence Ramsey | 7a97e18 | 2004-10-30 01:03:15 +0000 | [diff] [blame] | 1832 | if (x == (size_t)-1 || x > xend || resetstatuspos) |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1833 | x = xend; |
| 1834 | |
Chris Allegretta | e1e0fd6 | 2003-04-15 01:15:09 +0000 | [diff] [blame] | 1835 | answer = charealloc(answer, xend + 1); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1836 | if (xend > 0) |
| 1837 | strcpy(answer, def); |
| 1838 | else |
| 1839 | answer[0] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1840 | |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 1841 | #if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE) |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1842 | currshortcut = s; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 1843 | #endif |
| 1844 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1845 | /* Get the input! */ |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 1846 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1847 | nanoget_repaint(buf, answer, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1848 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1849 | /* Make sure any editor screen updates are displayed before getting |
| 1850 | input */ |
David Lawrence Ramsey | 0fb841a | 2004-07-01 17:04:23 +0000 | [diff] [blame] | 1851 | wnoutrefresh(edit); |
| 1852 | wrefresh(bottomwin); |
Chris Allegretta | 022b96f | 2000-11-14 17:47:58 +0000 | [diff] [blame] | 1853 | |
David Lawrence Ramsey | 32e3b88 | 2004-05-29 01:20:17 +0000 | [diff] [blame] | 1854 | /* If we're using restricted mode, we aren't allowed to change the |
| 1855 | * name of a file once it has one because that would allow writing |
| 1856 | * to files not specified on the command line. In this case, |
| 1857 | * disable all keys that would change the text if the filename isn't |
| 1858 | * blank and we're at the "Write File" prompt. */ |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 1859 | while ((kbinput = get_kbinput(bottomwin, &meta_key, &func_key)) != |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 1860 | NANO_CANCEL_KEY && kbinput != NANO_ENTER_KEY) { |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1861 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1862 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1863 | fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput); |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1864 | #endif |
| 1865 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1866 | /* Temporary hack to interpret NANO_HELP_FKEY correctly. */ |
| 1867 | if (kbinput == t->funcval) |
| 1868 | kbinput = t->ctrlval; |
David Lawrence Ramsey | d7f5ad9 | 2004-03-04 19:30:53 +0000 | [diff] [blame] | 1869 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1870 | if (kbinput == t->ctrlval && is_cntrl_char(kbinput)) { |
Chris Allegretta | 5bf51d3 | 2000-11-16 06:01:10 +0000 | [diff] [blame] | 1871 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1872 | #ifndef DISABLE_HELP |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1873 | /* Have to do this here, it would be too late to do it |
| 1874 | in statusq() */ |
David Lawrence Ramsey | d7f5ad9 | 2004-03-04 19:30:53 +0000 | [diff] [blame] | 1875 | if (kbinput == NANO_HELP_KEY) { |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1876 | do_help(); |
| 1877 | break; |
| 1878 | } |
| 1879 | #endif |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1880 | #ifndef NANO_SMALL |
| 1881 | /* Have to handle these here too, for the time being */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1882 | if (kbinput == NANO_PREVLINE_KEY || kbinput == NANO_NEXTLINE_KEY) |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1883 | break; |
| 1884 | #endif |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 1885 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1886 | return t->ctrlval; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1887 | } |
| 1888 | } |
David Lawrence Ramsey | 7a97e18 | 2004-10-30 01:03:15 +0000 | [diff] [blame] | 1889 | assert(x <= xend && xend == strlen(answer)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1890 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1891 | if (kbinput != '\t') |
David Lawrence Ramsey | 4d44d2d | 2004-08-01 22:35:31 +0000 | [diff] [blame] | 1892 | tabbed = FALSE; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1893 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1894 | switch (kbinput) { |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 1895 | #ifndef DISABLE_MOUSE |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1896 | case KEY_MOUSE: |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1897 | { |
| 1898 | int mouse_x, mouse_y; |
| 1899 | get_mouseinput(&mouse_x, &mouse_y, TRUE); |
| 1900 | } |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1901 | break; |
| 1902 | #endif |
David Lawrence Ramsey | 72d8e54 | 2004-09-25 00:45:07 +0000 | [diff] [blame] | 1903 | case NANO_REFRESH_KEY: |
| 1904 | total_refresh(); |
| 1905 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1906 | case NANO_HOME_KEY: |
David Lawrence Ramsey | c7acf69 | 2004-05-22 20:15:20 +0000 | [diff] [blame] | 1907 | #ifndef NANO_SMALL |
| 1908 | if (ISSET(SMART_HOME)) { |
David Lawrence Ramsey | 7a97e18 | 2004-10-30 01:03:15 +0000 | [diff] [blame] | 1909 | size_t old_x = x; |
David Lawrence Ramsey | c7acf69 | 2004-05-22 20:15:20 +0000 | [diff] [blame] | 1910 | |
| 1911 | for (x = 0; isblank(answer[x]) && x < xend; x++) |
| 1912 | ; |
| 1913 | |
| 1914 | if (x == old_x || x == xend) |
| 1915 | x = 0; |
| 1916 | } else |
| 1917 | #endif |
| 1918 | x = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1919 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1920 | case NANO_END_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1921 | x = xend; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1922 | break; |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 1923 | case NANO_FORWARD_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1924 | if (x < xend) |
| 1925 | x++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1926 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1927 | case NANO_DELETE_KEY: |
David Lawrence Ramsey | 32e3b88 | 2004-05-29 01:20:17 +0000 | [diff] [blame] | 1928 | /* If we're using restricted mode, the filename isn't blank, |
| 1929 | * and we're at the "Write File" prompt, disable Delete. */ |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 1930 | if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) { |
| 1931 | if (x < xend) { |
| 1932 | charmove(answer + x, answer + x + 1, xend - x); |
| 1933 | xend--; |
| 1934 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1935 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1936 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1937 | case NANO_CUT_KEY: |
David Lawrence Ramsey | 32e3b88 | 2004-05-29 01:20:17 +0000 | [diff] [blame] | 1938 | /* If we're using restricted mode, the filename isn't blank, |
David Lawrence Ramsey | 8037fe0 | 2004-07-23 12:30:40 +0000 | [diff] [blame] | 1939 | * and we're at the "Write File" prompt, disable Cut. */ |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 1940 | if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) { |
| 1941 | null_at(&answer, 0); |
| 1942 | xend = 0; |
| 1943 | x = 0; |
| 1944 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1945 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1946 | case NANO_BACKSPACE_KEY: |
David Lawrence Ramsey | 32e3b88 | 2004-05-29 01:20:17 +0000 | [diff] [blame] | 1947 | /* If we're using restricted mode, the filename isn't blank, |
| 1948 | * and we're at the "Write File" prompt, disable |
| 1949 | * Backspace. */ |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 1950 | if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) { |
| 1951 | if (x > 0) { |
| 1952 | charmove(answer + x - 1, answer + x, xend - x + 1); |
| 1953 | x--; |
| 1954 | xend--; |
| 1955 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1956 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1957 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1958 | case NANO_TAB_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1959 | #ifndef NANO_SMALL |
| 1960 | /* tab history completion */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1961 | if (history_list != NULL) { |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1962 | if (!complete || last_kbinput != NANO_TAB_KEY) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1963 | history_list->current = (historytype *)history_list; |
| 1964 | history_list->len = strlen(answer); |
| 1965 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1966 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1967 | if (history_list->len > 0) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1968 | complete = get_history_completion(history_list, answer); |
| 1969 | xend = strlen(complete); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1970 | x = xend; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1971 | answer = mallocstrcpy(answer, complete); |
| 1972 | } |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 1973 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1974 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 1975 | else |
| 1976 | #endif |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 1977 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1978 | #ifndef DISABLE_TABCOMP |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 1979 | if (allow_tabs) { |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 1980 | int shift = 0; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1981 | |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 1982 | answer = input_tab(answer, x, &tabbed, &shift, list); |
| 1983 | xend = strlen(answer); |
| 1984 | x += shift; |
| 1985 | if (x > xend) |
| 1986 | x = xend; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1987 | } |
| 1988 | #endif |
| 1989 | break; |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 1990 | case NANO_BACK_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1991 | if (x > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1992 | x--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1993 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1994 | case NANO_PREVLINE_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1995 | #ifndef NANO_SMALL |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1996 | if (history_list != NULL) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 1997 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1998 | /* if currentbuf is NULL, or if use_cb is 1, currentbuf |
| 1999 | isn't NULL, and currentbuf is different from answer, |
| 2000 | it means that we're scrolling up at the top of the |
| 2001 | search history, and we need to save the current |
| 2002 | answer in currentbuf; do this and reset use_cb to |
| 2003 | 0 */ |
David Lawrence Ramsey | b8c479a | 2004-07-31 14:10:23 +0000 | [diff] [blame] | 2004 | if (currentbuf == NULL || (use_cb == 1 && |
| 2005 | strcmp(currentbuf, answer) != 0)) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 2006 | currentbuf = mallocstrcpy(currentbuf, answer); |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2007 | use_cb = 0; |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2010 | /* if currentbuf isn't NULL, use_cb is 2, and currentbuf |
| 2011 | is different from answer, it means that we're |
| 2012 | scrolling up at the bottom of the search history, and |
| 2013 | we need to make the string in currentbuf the current |
| 2014 | answer; do this, blow away currentbuf since we don't |
| 2015 | need it anymore, and reset use_cb to 0 */ |
David Lawrence Ramsey | b8c479a | 2004-07-31 14:10:23 +0000 | [diff] [blame] | 2016 | if (currentbuf != NULL && use_cb == 2 && |
| 2017 | strcmp(currentbuf, answer) != 0) { |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2018 | answer = mallocstrcpy(answer, currentbuf); |
| 2019 | free(currentbuf); |
| 2020 | currentbuf = NULL; |
| 2021 | xend = strlen(answer); |
| 2022 | use_cb = 0; |
| 2023 | |
| 2024 | /* else get older search from the history list and save |
| 2025 | it in answer; if there is no older search, blank out |
| 2026 | answer */ |
| 2027 | } else if ((history = get_history_older(history_list)) != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2028 | answer = mallocstrcpy(answer, history); |
| 2029 | xend = strlen(history); |
| 2030 | } else { |
| 2031 | answer = mallocstrcpy(answer, ""); |
| 2032 | xend = 0; |
| 2033 | } |
| 2034 | x = xend; |
| 2035 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2036 | #endif |
Chris Allegretta | 54abd94 | 2003-01-09 23:43:12 +0000 | [diff] [blame] | 2037 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 2038 | case NANO_NEXTLINE_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2039 | #ifndef NANO_SMALL |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 2040 | if (history_list != NULL) { |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2041 | |
| 2042 | /* get newer search from the history list and save it |
| 2043 | in answer */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 2044 | if ((history = get_history_newer(history_list)) != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2045 | answer = mallocstrcpy(answer, history); |
| 2046 | xend = strlen(history); |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 2047 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2048 | /* if there is no newer search, we're here */ |
| 2049 | |
| 2050 | /* if currentbuf isn't NULL and use_cb isn't 2, it means |
| 2051 | that we're scrolling down at the bottom of the search |
| 2052 | history and we need to make the string in currentbuf |
| 2053 | the current answer; do this, blow away currentbuf |
| 2054 | since we don't need it anymore, and set use_cb to |
| 2055 | 1 */ |
| 2056 | } else if (currentbuf != NULL && use_cb != 2) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 2057 | answer = mallocstrcpy(answer, currentbuf); |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 2058 | free(currentbuf); |
| 2059 | currentbuf = NULL; |
| 2060 | xend = strlen(answer); |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2061 | use_cb = 1; |
| 2062 | |
| 2063 | /* otherwise, if currentbuf is NULL and use_cb isn't 2, |
| 2064 | it means that we're scrolling down at the bottom of |
Chris Allegretta | c30fc24 | 2003-08-11 00:32:45 +0000 | [diff] [blame] | 2065 | the search history and the current answer (if it's |
| 2066 | not blank) needs to be saved in currentbuf; do this, |
| 2067 | blank out answer (if necessary), and set use_cb to |
| 2068 | 2 */ |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2069 | } else if (use_cb != 2) { |
Chris Allegretta | c30fc24 | 2003-08-11 00:32:45 +0000 | [diff] [blame] | 2070 | if (answer[0] != '\0') { |
| 2071 | currentbuf = mallocstrcpy(currentbuf, answer); |
| 2072 | answer = mallocstrcpy(answer, ""); |
| 2073 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2074 | xend = 0; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2075 | use_cb = 2; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2076 | } |
| 2077 | x = xend; |
| 2078 | } |
| 2079 | #endif |
| 2080 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2081 | default: |
| 2082 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2083 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2084 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 2085 | fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2086 | kbinput); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2087 | #endif |
David Lawrence Ramsey | 4d44d2d | 2004-08-01 22:35:31 +0000 | [diff] [blame] | 2088 | if (meta_key && (kbinput == t->metaval || kbinput == t->miscval)) |
David Lawrence Ramsey | 32613fa | 2004-05-24 18:40:41 +0000 | [diff] [blame] | 2089 | /* We hit a meta key. Do like above. We don't |
David Lawrence Ramsey | dfca1c4 | 2004-08-25 16:37:06 +0000 | [diff] [blame] | 2090 | * just put back the letter and let it get |
David Lawrence Ramsey | 8213850 | 2003-12-24 08:03:54 +0000 | [diff] [blame] | 2091 | * caught above cause that screws the |
| 2092 | * keypad... */ |
| 2093 | return kbinput; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2094 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2095 | |
David Lawrence Ramsey | 32e3b88 | 2004-05-29 01:20:17 +0000 | [diff] [blame] | 2096 | /* If we're using restricted mode, the filename isn't blank, |
| 2097 | * and we're at the "Write File" prompt, act as though the |
| 2098 | * unhandled character we got is a control character and |
| 2099 | * throw it away. */ |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 2100 | if (is_cntrl_char(kbinput) || (ISSET(RESTRICTED) && filename[0] != '\0' && s == writefile_list)) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2101 | break; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 2102 | answer = charealloc(answer, xend + 2); |
David Lawrence Ramsey | 9eff746 | 2003-09-16 02:04:00 +0000 | [diff] [blame] | 2103 | charmove(answer + x + 1, answer + x, xend - x + 1); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2104 | xend++; |
| 2105 | answer[x] = kbinput; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2106 | x++; |
| 2107 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2108 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 2109 | fprintf(stderr, "input \'%c\' (%d)\n", kbinput, kbinput); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2110 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2111 | } /* switch (kbinput) */ |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 2112 | #ifndef NANO_SMALL |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2113 | last_kbinput = kbinput; |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 2114 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2115 | nanoget_repaint(buf, answer, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2116 | wrefresh(bottomwin); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2117 | } /* while (kbinput ...) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2118 | |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 2119 | /* We finished putting in an answer; reset x */ |
David Lawrence Ramsey | 7a97e18 | 2004-10-30 01:03:15 +0000 | [diff] [blame] | 2120 | x = (size_t)-1; |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 2121 | |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 2122 | return kbinput; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 2125 | /* Ask a question on the statusbar. Answer will be stored in answer |
| 2126 | * global. Returns -1 on aborted enter, -2 on a blank string, and 0 |
| 2127 | * otherwise, the valid shortcut key caught. def is any editable text |
| 2128 | * we want to put up by default. |
| 2129 | * |
| 2130 | * New arg tabs tells whether or not to allow tab completion. */ |
| 2131 | int statusq(bool allow_tabs, const shortcut *s, const char *def, |
| 2132 | #ifndef NANO_SMALL |
| 2133 | historyheadtype *which_history, |
| 2134 | #endif |
| 2135 | const char *msg, ...) |
| 2136 | { |
| 2137 | va_list ap; |
| 2138 | char *foo = charalloc(COLS - 3); |
| 2139 | int ret; |
| 2140 | #ifndef DISABLE_TABCOMP |
| 2141 | bool list = FALSE; |
| 2142 | #endif |
| 2143 | |
| 2144 | bottombars(s); |
| 2145 | |
| 2146 | va_start(ap, msg); |
| 2147 | vsnprintf(foo, COLS - 4, msg, ap); |
| 2148 | va_end(ap); |
| 2149 | foo[COLS - 4] = '\0'; |
| 2150 | |
| 2151 | ret = nanogetstr(allow_tabs, foo, def, |
| 2152 | #ifndef NANO_SMALL |
| 2153 | which_history, |
| 2154 | #endif |
| 2155 | s |
| 2156 | #ifndef DISABLE_TABCOMP |
| 2157 | , &list |
| 2158 | #endif |
| 2159 | ); |
| 2160 | free(foo); |
| 2161 | resetstatuspos = FALSE; |
| 2162 | |
| 2163 | switch (ret) { |
David Lawrence Ramsey | 1f204c0 | 2004-10-15 01:39:46 +0000 | [diff] [blame] | 2164 | case NANO_FIRSTLINE_KEY: |
| 2165 | case NANO_FIRSTLINE_FKEY: |
| 2166 | do_first_line(); |
| 2167 | resetstatuspos = TRUE; |
| 2168 | break; |
| 2169 | case NANO_LASTLINE_KEY: |
| 2170 | case NANO_LASTLINE_FKEY: |
| 2171 | do_last_line(); |
| 2172 | resetstatuspos = TRUE; |
| 2173 | break; |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 2174 | #ifndef DISABLE_JUSTIFY |
David Lawrence Ramsey | 1f204c0 | 2004-10-15 01:39:46 +0000 | [diff] [blame] | 2175 | case NANO_PARABEGIN_KEY: |
| 2176 | case NANO_PARABEGIN_ALTKEY1: |
| 2177 | case NANO_PARABEGIN_ALTKEY2: |
| 2178 | do_para_begin(); |
| 2179 | resetstatuspos = TRUE; |
| 2180 | break; |
| 2181 | case NANO_PARAEND_KEY: |
| 2182 | case NANO_PARAEND_ALTKEY1: |
| 2183 | case NANO_PARAEND_ALTKEY2: |
| 2184 | do_para_end(); |
| 2185 | resetstatuspos = TRUE; |
| 2186 | break; |
| 2187 | case NANO_FULLJUSTIFY_KEY: |
| 2188 | case NANO_FULLJUSTIFY_ALTKEY: |
| 2189 | if (!ISSET(VIEW_MODE)) |
| 2190 | do_full_justify(); |
| 2191 | resetstatuspos = TRUE; |
| 2192 | break; |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 2193 | #endif |
David Lawrence Ramsey | 1f204c0 | 2004-10-15 01:39:46 +0000 | [diff] [blame] | 2194 | case NANO_CANCEL_KEY: |
| 2195 | ret = -1; |
| 2196 | resetstatuspos = TRUE; |
| 2197 | break; |
| 2198 | case NANO_ENTER_KEY: |
| 2199 | ret = (answer[0] == '\0') ? -2 : 0; |
| 2200 | resetstatuspos = TRUE; |
| 2201 | break; |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 2202 | } |
| 2203 | blank_statusbar(); |
| 2204 | |
| 2205 | #ifdef DEBUG |
| 2206 | fprintf(stderr, "I got \"%s\"\n", answer); |
| 2207 | #endif |
| 2208 | |
| 2209 | #ifndef DISABLE_TABCOMP |
| 2210 | /* if we've done tab completion, there might be a list of |
| 2211 | filename matches on the edit window at this point; make sure |
| 2212 | they're cleared off. */ |
| 2213 | if (list) |
| 2214 | edit_refresh(); |
| 2215 | #endif |
| 2216 | |
| 2217 | return ret; |
| 2218 | } |
| 2219 | |
| 2220 | void statusq_abort(void) |
| 2221 | { |
| 2222 | resetstatuspos = TRUE; |
| 2223 | } |
| 2224 | |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 2225 | void titlebar(const char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2226 | { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2227 | size_t space; |
| 2228 | /* The space we have available for display. */ |
| 2229 | size_t verlen = strlen(VERMSG) + 1; |
| 2230 | /* The length of the version message. */ |
| 2231 | const char *prefix; |
| 2232 | /* "File:", "Dir:", or "New Buffer". Goes before filename. */ |
| 2233 | size_t prefixlen; |
| 2234 | /* strlen(prefix) + 1. */ |
| 2235 | const char *state; |
| 2236 | /* "Modified", "View", or spaces the length of "Modified". |
| 2237 | * Tells the state of this buffer. */ |
| 2238 | size_t statelen = 0; |
| 2239 | /* strlen(state) + 1. */ |
| 2240 | char *exppath = NULL; |
| 2241 | /* The file name, expanded for display. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2242 | size_t exppathlen = 0; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2243 | /* strlen(exppath) + 1. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2244 | bool newfie = FALSE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2245 | /* Do we say "New Buffer"? */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2246 | bool dots = FALSE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2247 | /* Do we put an ellipsis before the path? */ |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 2248 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2249 | assert(path != NULL || filename != NULL); |
| 2250 | assert(COLS >= 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2251 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2252 | wattron(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2253 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2254 | blank_titlebar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2255 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2256 | if (COLS <= 5 || COLS - 5 < verlen) |
| 2257 | space = 0; |
| 2258 | else { |
| 2259 | space = COLS - 5 - verlen; |
David Lawrence Ramsey | 8328fc2 | 2004-05-25 23:34:43 +0000 | [diff] [blame] | 2260 | /* Reserve 2/3 of the screen plus one column for after the |
| 2261 | * version message. */ |
| 2262 | if (space < COLS - (COLS / 3) + 1) |
| 2263 | space = COLS - (COLS / 3) + 1; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2264 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2265 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2266 | if (COLS > 4) { |
David Lawrence Ramsey | 8328fc2 | 2004-05-25 23:34:43 +0000 | [diff] [blame] | 2267 | /* The version message should only take up 1/3 of the screen |
| 2268 | * minus one column. */ |
| 2269 | mvwaddnstr(topwin, 0, 2, VERMSG, (COLS / 3) - 3); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2270 | waddstr(topwin, " "); |
| 2271 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2272 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2273 | if (ISSET(MODIFIED)) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2274 | state = _("Modified"); |
| 2275 | else if (path == NULL && ISSET(VIEW_MODE)) |
| 2276 | state = _("View"); |
| 2277 | else { |
| 2278 | if (space > 0) |
| 2279 | statelen = strnlen(_("Modified"), space - 1) + 1; |
| 2280 | state = &hblank[COLS - statelen]; |
| 2281 | } |
| 2282 | statelen = strnlen(state, COLS); |
| 2283 | /* We need a space before state. */ |
| 2284 | if ((ISSET(MODIFIED) || ISSET(VIEW_MODE)) && statelen < COLS) |
| 2285 | statelen++; |
| 2286 | |
| 2287 | assert(space >= 0); |
| 2288 | if (space == 0 || statelen >= space) |
| 2289 | goto the_end; |
| 2290 | |
| 2291 | #ifndef DISABLE_BROWSER |
| 2292 | if (path != NULL) |
| 2293 | prefix = _("DIR:"); |
| 2294 | else |
| 2295 | #endif |
| 2296 | if (filename[0] == '\0') { |
| 2297 | prefix = _("New Buffer"); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2298 | newfie = TRUE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2299 | } else |
| 2300 | prefix = _("File:"); |
| 2301 | assert(statelen < space); |
| 2302 | prefixlen = strnlen(prefix, space - statelen); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2303 | /* If newfie is FALSE, we need a space after prefix. */ |
| 2304 | if (!newfie && prefixlen + statelen < space) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2305 | prefixlen++; |
| 2306 | |
| 2307 | if (path == NULL) |
| 2308 | path = filename; |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2309 | if (space >= prefixlen + statelen) |
| 2310 | space -= prefixlen + statelen; |
| 2311 | else |
| 2312 | space = 0; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2313 | /* space is now the room we have for the file name. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2314 | if (!newfie) { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2315 | size_t lenpt = strlenpt(path), start_col; |
| 2316 | |
| 2317 | if (lenpt > space) |
| 2318 | start_col = actual_x(path, lenpt - space); |
| 2319 | else |
| 2320 | start_col = 0; |
| 2321 | exppath = display_string(path, start_col, space); |
| 2322 | dots = (lenpt > space); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2323 | exppathlen = strlen(exppath); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | if (!dots) { |
| 2327 | /* There is room for the whole filename, so we center it. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2328 | waddnstr(topwin, hblank, (space - exppathlen) / 3); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2329 | waddnstr(topwin, prefix, prefixlen); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2330 | if (!newfie) { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2331 | assert(strlen(prefix) + 1 == prefixlen); |
| 2332 | waddch(topwin, ' '); |
| 2333 | waddstr(topwin, exppath); |
| 2334 | } |
| 2335 | } else { |
| 2336 | /* We will say something like "File: ...ename". */ |
| 2337 | waddnstr(topwin, prefix, prefixlen); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2338 | if (space == 0 || newfie) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2339 | goto the_end; |
| 2340 | waddch(topwin, ' '); |
| 2341 | waddnstr(topwin, "...", space); |
| 2342 | if (space <= 3) |
| 2343 | goto the_end; |
| 2344 | space -= 3; |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame^] | 2345 | assert(exppathlen == space + 3); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2346 | waddnstr(topwin, exppath + 3, space); |
| 2347 | } |
| 2348 | |
| 2349 | the_end: |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2350 | free(exppath); |
| 2351 | |
| 2352 | if (COLS <= 1 || statelen >= COLS - 1) |
| 2353 | mvwaddnstr(topwin, 0, 0, state, COLS); |
| 2354 | else { |
| 2355 | assert(COLS - statelen - 2 >= 0); |
| 2356 | mvwaddch(topwin, 0, COLS - statelen - 2, ' '); |
| 2357 | mvwaddnstr(topwin, 0, COLS - statelen - 1, state, statelen); |
| 2358 | } |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2359 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2360 | wattroff(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2361 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2362 | wnoutrefresh(topwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2363 | reset_cursor(); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2364 | wrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2367 | /* If modified is not already set, set it and update titlebar. */ |
| 2368 | void set_modified(void) |
| 2369 | { |
| 2370 | if (!ISSET(MODIFIED)) { |
| 2371 | SET(MODIFIED); |
| 2372 | titlebar(NULL); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | void statusbar(const char *msg, ...) |
| 2377 | { |
| 2378 | va_list ap; |
| 2379 | |
| 2380 | va_start(ap, msg); |
| 2381 | |
| 2382 | /* Curses mode is turned off. If we use wmove() now, it will muck |
| 2383 | * up the terminal settings. So we just use vfprintf(). */ |
| 2384 | if (curses_ended) { |
| 2385 | vfprintf(stderr, msg, ap); |
| 2386 | va_end(ap); |
| 2387 | return; |
| 2388 | } |
| 2389 | |
| 2390 | /* Blank out the line. */ |
| 2391 | blank_statusbar(); |
| 2392 | |
| 2393 | if (COLS >= 4) { |
| 2394 | char *bar; |
| 2395 | char *foo; |
| 2396 | size_t start_x = 0, foo_len; |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2397 | #if !defined(NANO_SMALL) && defined(ENABLE_NANORC) |
David Lawrence Ramsey | 846658e | 2004-12-05 04:18:26 +0000 | [diff] [blame] | 2398 | bool old_whitespace = ISSET(WHITESPACE_DISPLAY); |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2399 | UNSET(WHITESPACE_DISPLAY); |
| 2400 | #endif |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2401 | bar = charalloc(COLS - 3); |
| 2402 | vsnprintf(bar, COLS - 3, msg, ap); |
| 2403 | va_end(ap); |
| 2404 | foo = display_string(bar, 0, COLS - 4); |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2405 | #if !defined(NANO_SMALL) && defined(ENABLE_NANORC) |
| 2406 | if (old_whitespace) |
| 2407 | SET(WHITESPACE_DISPLAY); |
| 2408 | #endif |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2409 | free(bar); |
| 2410 | foo_len = strlen(foo); |
| 2411 | start_x = (COLS - foo_len - 4) / 2; |
| 2412 | |
| 2413 | wmove(bottomwin, 0, start_x); |
| 2414 | wattron(bottomwin, A_REVERSE); |
| 2415 | |
| 2416 | waddstr(bottomwin, "[ "); |
| 2417 | waddstr(bottomwin, foo); |
| 2418 | free(foo); |
| 2419 | waddstr(bottomwin, " ]"); |
| 2420 | wattroff(bottomwin, A_REVERSE); |
| 2421 | wnoutrefresh(bottomwin); |
| 2422 | reset_cursor(); |
| 2423 | wrefresh(edit); |
| 2424 | /* Leave the cursor at its position in the edit window, not |
| 2425 | * in the statusbar. */ |
| 2426 | } |
| 2427 | |
| 2428 | SET(DISABLE_CURPOS); |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 2429 | statusblank = 26; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2432 | void bottombars(const shortcut *s) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2433 | { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2434 | size_t i, colwidth, slen; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2435 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2436 | if (ISSET(NO_HELP)) |
| 2437 | return; |
| 2438 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2439 | if (s == main_list) { |
| 2440 | slen = MAIN_VISIBLE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2441 | assert(slen <= length_of_list(s)); |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 2442 | } else { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2443 | slen = length_of_list(s); |
| 2444 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2445 | /* Don't show any more shortcuts than the main list does. */ |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 2446 | if (slen > MAIN_VISIBLE) |
| 2447 | slen = MAIN_VISIBLE; |
| 2448 | } |
| 2449 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2450 | /* There will be this many characters per column. We need at least |
| 2451 | * 3 to display anything properly.*/ |
| 2452 | colwidth = COLS / ((slen / 2) + (slen % 2)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2453 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2454 | blank_bottombars(); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2455 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2456 | for (i = 0; i < slen; i++, s = s->next) { |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2457 | const char *keystr; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2458 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2459 | /* Yucky sentinel values we can't handle a better way. */ |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 2460 | #ifndef NANO_SMALL |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2461 | if (s->ctrlval == NANO_HISTORY_KEY) |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2462 | keystr = _("Up"); |
| 2463 | else { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2464 | #endif |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2465 | char foo[4]; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2466 | |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2467 | if (s->ctrlval == NANO_CONTROL_SPACE) |
| 2468 | strcpy(foo, "^ "); |
| 2469 | else if (s->ctrlval == NANO_CONTROL_8) |
| 2470 | strcpy(foo, "^?"); |
| 2471 | /* Normal values. Assume that the shortcut has an |
| 2472 | * equivalent control key, meta key sequence, or both. */ |
| 2473 | else if (s->ctrlval != NANO_NO_KEY) |
| 2474 | sprintf(foo, "^%c", s->ctrlval + 64); |
| 2475 | else if (s->metaval != NANO_NO_KEY) |
| 2476 | sprintf(foo, "M-%c", toupper(s->metaval)); |
| 2477 | |
| 2478 | keystr = foo; |
| 2479 | #ifndef NANO_SMALL |
| 2480 | } |
| 2481 | #endif |
| 2482 | |
| 2483 | wmove(bottomwin, 1 + i % 2, (i / 2) * colwidth); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2484 | onekey(keystr, s->desc, colwidth); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2487 | wnoutrefresh(bottomwin); |
| 2488 | reset_cursor(); |
| 2489 | wrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2492 | /* Write a shortcut key to the help area at the bottom of the window. |
| 2493 | * keystroke is e.g. "^G" and desc is e.g. "Get Help". We are careful |
| 2494 | * to write at most len characters, even if len is very small and |
| 2495 | * keystroke and desc are long. Note that waddnstr(,,(size_t)-1) adds |
| 2496 | * the whole string! We do not bother padding the entry with blanks. */ |
| 2497 | void onekey(const char *keystroke, const char *desc, size_t len) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2498 | { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2499 | assert(keystroke != NULL && desc != NULL && len >= 0); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2500 | wattron(bottomwin, A_REVERSE); |
| 2501 | waddnstr(bottomwin, keystroke, len); |
| 2502 | wattroff(bottomwin, A_REVERSE); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2503 | len -= strlen(keystroke) + 1; |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2504 | if (len > 0) { |
| 2505 | waddch(bottomwin, ' '); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2506 | waddnstr(bottomwin, desc, len); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2507 | } |
| 2508 | } |
| 2509 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2510 | /* And so start the display update routines. */ |
| 2511 | |
| 2512 | #ifndef NDEBUG |
| 2513 | int check_linenumbers(const filestruct *fileptr) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 2514 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2515 | int check_line = 0; |
| 2516 | const filestruct *filetmp; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 2517 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2518 | for (filetmp = edittop; filetmp != fileptr; filetmp = filetmp->next) |
| 2519 | check_line++; |
| 2520 | return check_line; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 2521 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2522 | #endif |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 2523 | |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 2524 | /* nano scrolls horizontally within a line in chunks. This function |
| 2525 | * returns the column number of the first character displayed in the |
| 2526 | * window when the cursor is at the given column. Note that |
| 2527 | * 0 <= column - get_page_start(column) < COLS. */ |
| 2528 | size_t get_page_start(size_t column) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2529 | { |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 2530 | assert(COLS > 0); |
| 2531 | if (column == 0 || column < COLS - 1) |
| 2532 | return 0; |
| 2533 | else if (COLS > 9) |
David Lawrence Ramsey | 66081d4 | 2004-01-22 07:25:31 +0000 | [diff] [blame] | 2534 | return column - 7 - (column - 7) % (COLS - 8); |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 2535 | else if (COLS > 2) |
| 2536 | return column - (COLS - 2); |
| 2537 | else |
| 2538 | return column - (COLS - 1); |
| 2539 | /* The parentheses are necessary to avoid overflow. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2542 | /* Resets current_y, based on the position of current, and puts the |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2543 | * cursor in the edit window at (current_y, current_x). */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2544 | void reset_cursor(void) |
| 2545 | { |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2546 | /* If we haven't opened any files yet, put the cursor in the top |
| 2547 | * left corner of the edit window and get out. */ |
| 2548 | if (edittop == NULL || current == NULL) { |
| 2549 | wmove(edit, 0, 0); |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2550 | return; |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2551 | } |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2552 | |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2553 | current_y = current->lineno - edittop->lineno; |
| 2554 | if (current_y < editwinrows) { |
| 2555 | size_t x = xplustabs(); |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2556 | wmove(edit, current_y, x - get_page_start(x)); |
| 2557 | } |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2558 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2559 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2560 | /* edit_add() takes care of the job of actually painting a line into the |
| 2561 | * edit window. fileptr is the line to be painted, at row yval of the |
| 2562 | * window. converted is the actual string to be written to the window, |
| 2563 | * with tabs and control characters replaced by strings of regular |
David Lawrence Ramsey | 4178db0 | 2004-05-23 21:23:23 +0000 | [diff] [blame] | 2564 | * characters. start is the column number of the first character of |
| 2565 | * this page. That is, the first character of converted corresponds to |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2566 | * character number actual_x(fileptr->data, start) of the line. */ |
David Lawrence Ramsey | 07d3feb | 2004-04-16 05:15:11 +0000 | [diff] [blame] | 2567 | void edit_add(const filestruct *fileptr, const char *converted, int |
| 2568 | yval, size_t start) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2569 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2570 | #if defined(ENABLE_COLOR) || !defined(NANO_SMALL) |
| 2571 | size_t startpos = actual_x(fileptr->data, start); |
| 2572 | /* The position in fileptr->data of the leftmost character |
| 2573 | * that displays at least partially on the window. */ |
| 2574 | size_t endpos = actual_x(fileptr->data, start + COLS - 1) + 1; |
| 2575 | /* The position in fileptr->data of the first character that is |
| 2576 | * completely off the window to the right. |
| 2577 | * |
| 2578 | * Note that endpos might be beyond the null terminator of the |
| 2579 | * string. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2580 | #endif |
| 2581 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2582 | assert(fileptr != NULL && converted != NULL); |
| 2583 | assert(strlen(converted) <= COLS); |
| 2584 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2585 | /* 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] | 2586 | * just the text that needs it). */ |
| 2587 | mvwaddstr(edit, yval, 0, converted); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2588 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 2589 | #ifdef ENABLE_COLOR |
Chris Allegretta | 1dd0bc9 | 2002-10-13 18:43:45 +0000 | [diff] [blame] | 2590 | if (colorstrings != NULL && ISSET(COLOR_SYNTAX)) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2591 | const colortype *tmpcolor = colorstrings; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2592 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2593 | for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { |
| 2594 | int x_start; |
| 2595 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 2596 | int paintlen; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2597 | /* Number of chars to paint on this line. There are COLS |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2598 | * characters on a whole line. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2599 | regmatch_t startmatch; /* match position for start_regexp */ |
| 2600 | regmatch_t endmatch; /* match position for end_regexp */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2601 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2602 | if (tmpcolor->bright) |
| 2603 | wattron(edit, A_BOLD); |
| 2604 | wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2605 | /* Two notes about regexec(). Return value 0 means there is |
| 2606 | * a match. Also, rm_eo is the first non-matching character |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2607 | * after the match. */ |
| 2608 | |
| 2609 | /* First case, tmpcolor is a single-line expression. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2610 | if (tmpcolor->end == NULL) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2611 | size_t k = 0; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2612 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2613 | /* 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] | 2614 | * last match. Even though two matches may overlap, we |
| 2615 | * want to ignore them, so that we can highlight |
| 2616 | * C-strings correctly. */ |
| 2617 | while (k < endpos) { |
| 2618 | /* Note the fifth parameter to regexec(). It says |
| 2619 | * not to match the beginning-of-line character |
| 2620 | * unless k is 0. If regexec() returns REG_NOMATCH, |
| 2621 | * there are no more matches in the line. */ |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 2622 | if (regexec(&tmpcolor->start, &fileptr->data[k], 1, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2623 | &startmatch, k == 0 ? 0 : REG_NOTBOL) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2624 | break; |
| 2625 | /* Translate the match to the beginning of the line. */ |
| 2626 | startmatch.rm_so += k; |
| 2627 | startmatch.rm_eo += k; |
David Lawrence Ramsey | 2ab03f6 | 2002-10-17 02:19:31 +0000 | [diff] [blame] | 2628 | if (startmatch.rm_so == startmatch.rm_eo) { |
| 2629 | startmatch.rm_eo++; |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 2630 | statusbar(_("Refusing 0 length regex match")); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2631 | } else if (startmatch.rm_so < endpos && |
| 2632 | startmatch.rm_eo > startpos) { |
| 2633 | if (startmatch.rm_so <= startpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2634 | x_start = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2635 | else |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2636 | x_start = strnlenpt(fileptr->data, |
| 2637 | startmatch.rm_so) - start; |
| 2638 | paintlen = strnlenpt(fileptr->data, |
| 2639 | startmatch.rm_eo) - start - x_start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2640 | if (paintlen > COLS - x_start) |
| 2641 | paintlen = COLS - x_start; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2642 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2643 | assert(0 <= x_start && 0 < paintlen && |
| 2644 | x_start + paintlen <= COLS); |
| 2645 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2646 | converted + x_start, paintlen); |
| 2647 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2648 | k = startmatch.rm_eo; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2649 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2650 | } else { |
| 2651 | /* This is a multi-line regexp. There are two steps. |
| 2652 | * First, we have to see if the beginning of the line is |
| 2653 | * colored by a start on an earlier line, and an end on |
| 2654 | * this line or later. |
| 2655 | * |
| 2656 | * We find the first line before fileptr matching the |
| 2657 | * start. If every match on that line is followed by an |
| 2658 | * end, then go to step two. Otherwise, find the next line |
| 2659 | * after start_line matching the end. If that line is not |
| 2660 | * before fileptr, then paint the beginning of this line. */ |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 2661 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2662 | const filestruct *start_line = fileptr->prev; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2663 | /* the first line before fileptr matching start */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2664 | regoff_t start_col; |
| 2665 | /* where it starts in that line */ |
| 2666 | const filestruct *end_line; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2667 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2668 | while (start_line != NULL && |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 2669 | regexec(&tmpcolor->start, start_line->data, 1, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2670 | &startmatch, 0) == REG_NOMATCH) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2671 | /* If there is an end on this line, there is no need |
| 2672 | * to look for starts on earlier lines. */ |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2673 | if (regexec(tmpcolor->end, start_line->data, 0, |
| 2674 | NULL, 0) == 0) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2675 | goto step_two; |
| 2676 | start_line = start_line->prev; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2677 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2678 | /* No start found, so skip to the next step. */ |
| 2679 | if (start_line == NULL) |
| 2680 | goto step_two; |
| 2681 | /* Now start_line is the first line before fileptr |
| 2682 | * containing a start match. Is there a start on this |
| 2683 | * line not followed by an end on this line? */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2684 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2685 | start_col = 0; |
David Lawrence Ramsey | 6aec4b8 | 2004-03-15 20:26:30 +0000 | [diff] [blame] | 2686 | while (TRUE) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2687 | start_col += startmatch.rm_so; |
| 2688 | startmatch.rm_eo -= startmatch.rm_so; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2689 | if (regexec(tmpcolor->end, |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2690 | start_line->data + start_col + startmatch.rm_eo, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2691 | 0, NULL, start_col + startmatch.rm_eo == 0 ? 0 : |
| 2692 | REG_NOTBOL) == REG_NOMATCH) |
| 2693 | /* No end found after this start. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2694 | break; |
| 2695 | start_col++; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 2696 | if (regexec(&tmpcolor->start, |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2697 | start_line->data + start_col, 1, |
| 2698 | &startmatch, REG_NOTBOL) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2699 | /* No later start on this line. */ |
| 2700 | goto step_two; |
| 2701 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2702 | /* Indeed, there is a start not followed on this line by |
| 2703 | * an end. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2704 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2705 | /* We have already checked that there is no end before |
| 2706 | * fileptr and after the start. Is there an end after |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2707 | * the start at all? We don't paint unterminated |
| 2708 | * starts. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2709 | end_line = fileptr; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 2710 | while (end_line != NULL && |
David Lawrence Ramsey | 537a880 | 2004-06-24 22:39:24 +0000 | [diff] [blame] | 2711 | regexec(tmpcolor->end, end_line->data, 1, |
| 2712 | &endmatch, 0) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2713 | end_line = end_line->next; |
| 2714 | |
| 2715 | /* No end found, or it is too early. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2716 | if (end_line == NULL || |
| 2717 | (end_line == fileptr && endmatch.rm_eo <= startpos)) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2718 | goto step_two; |
| 2719 | |
| 2720 | /* Now paint the start of fileptr. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2721 | paintlen = end_line != fileptr ? COLS : |
| 2722 | strnlenpt(fileptr->data, endmatch.rm_eo) - start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2723 | if (paintlen > COLS) |
| 2724 | paintlen = COLS; |
| 2725 | |
| 2726 | assert(0 < paintlen && paintlen <= COLS); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2727 | mvwaddnstr(edit, yval, 0, converted, paintlen); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2728 | |
| 2729 | /* We have already painted the whole line. */ |
| 2730 | if (paintlen == COLS) |
| 2731 | goto skip_step_two; |
| 2732 | |
David Lawrence Ramsey | 94e7094 | 2004-05-13 18:04:31 +0000 | [diff] [blame] | 2733 | step_two: |
| 2734 | /* Second step, we look for starts on this line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2735 | start_col = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2736 | while (start_col < endpos) { |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2737 | if (regexec(&tmpcolor->start, |
| 2738 | fileptr->data + start_col, 1, &startmatch, |
| 2739 | start_col == 0 ? 0 : REG_NOTBOL) == REG_NOMATCH || |
| 2740 | start_col + startmatch.rm_so >= endpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2741 | /* No more starts on this line. */ |
| 2742 | break; |
| 2743 | /* Translate the match to be relative to the |
| 2744 | * beginning of the line. */ |
| 2745 | startmatch.rm_so += start_col; |
| 2746 | startmatch.rm_eo += start_col; |
| 2747 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2748 | if (startmatch.rm_so <= startpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2749 | x_start = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2750 | else |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2751 | x_start = strnlenpt(fileptr->data, |
| 2752 | startmatch.rm_so) - start; |
| 2753 | if (regexec(tmpcolor->end, |
| 2754 | fileptr->data + startmatch.rm_eo, 1, &endmatch, |
| 2755 | startmatch.rm_eo == 0 ? 0 : REG_NOTBOL) == 0) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2756 | /* Translate the end match to be relative to the |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2757 | * beginning of the line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2758 | endmatch.rm_so += startmatch.rm_eo; |
| 2759 | endmatch.rm_eo += startmatch.rm_eo; |
| 2760 | /* There is an end on this line. But does it |
David Lawrence Ramsey | 94e7094 | 2004-05-13 18:04:31 +0000 | [diff] [blame] | 2761 | * appear on this page, and is the match more |
| 2762 | * than zero characters long? */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2763 | if (endmatch.rm_eo > startpos && |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2764 | endmatch.rm_eo > startmatch.rm_so) { |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2765 | paintlen = strnlenpt(fileptr->data, |
| 2766 | endmatch.rm_eo) - start - x_start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2767 | if (x_start + paintlen > COLS) |
| 2768 | paintlen = COLS - x_start; |
| 2769 | |
| 2770 | assert(0 <= x_start && 0 < paintlen && |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2771 | x_start + paintlen <= COLS); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2772 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2773 | converted + x_start, paintlen); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2774 | } |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2775 | } else { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2776 | /* There is no end on this line. But we haven't |
| 2777 | * yet looked for one on later lines. */ |
| 2778 | end_line = fileptr->next; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2779 | while (end_line != NULL && |
| 2780 | regexec(tmpcolor->end, end_line->data, 0, |
| 2781 | NULL, 0) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2782 | end_line = end_line->next; |
| 2783 | if (end_line != NULL) { |
| 2784 | assert(0 <= x_start && x_start < COLS); |
| 2785 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2786 | converted + x_start, COLS - x_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2787 | /* We painted to the end of the line, so |
| 2788 | * don't bother checking any more starts. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2789 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 2790 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2791 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2792 | start_col = startmatch.rm_so + 1; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2793 | } /* while start_col < endpos */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2794 | } /* if (tmp_color->end != NULL) */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2795 | |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 2796 | skip_step_two: |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2797 | wattroff(edit, A_BOLD); |
| 2798 | wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); |
| 2799 | } /* for tmpcolor in colorstrings */ |
| 2800 | } |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2801 | #endif /* ENABLE_COLOR */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2802 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 2803 | #ifndef NANO_SMALL |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2804 | if (ISSET(MARK_ISSET) |
| 2805 | && (fileptr->lineno <= mark_beginbuf->lineno |
| 2806 | || fileptr->lineno <= current->lineno) |
| 2807 | && (fileptr->lineno >= mark_beginbuf->lineno |
| 2808 | || fileptr->lineno >= current->lineno)) { |
| 2809 | /* fileptr is at least partially selected. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2810 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2811 | const filestruct *top; |
| 2812 | /* Either current or mark_beginbuf, whichever is first. */ |
| 2813 | size_t top_x; |
| 2814 | /* current_x or mark_beginx, corresponding to top. */ |
| 2815 | const filestruct *bot; |
| 2816 | size_t bot_x; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2817 | int x_start; |
| 2818 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 2819 | int paintlen; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2820 | /* Number of chars to paint on this line. There are COLS |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2821 | * characters on a whole line. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2822 | |
David Lawrence Ramsey | 90e59c1 | 2004-11-05 23:03:03 +0000 | [diff] [blame] | 2823 | mark_order(&top, &top_x, &bot, &bot_x, NULL); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2824 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2825 | if (top->lineno < fileptr->lineno || top_x < startpos) |
| 2826 | top_x = startpos; |
| 2827 | if (bot->lineno > fileptr->lineno || bot_x > endpos) |
| 2828 | bot_x = endpos; |
| 2829 | |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2830 | /* The selected bit of fileptr is on this page. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2831 | if (top_x < endpos && bot_x > startpos) { |
| 2832 | assert(startpos <= top_x); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2833 | |
| 2834 | /* x_start is the expanded location of the beginning of the |
| 2835 | * mark minus the beginning of the page. */ |
| 2836 | x_start = strnlenpt(fileptr->data, top_x) - start; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2837 | |
| 2838 | if (bot_x >= endpos) |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2839 | /* If the end of the mark is off the page, paintlen is |
| 2840 | * -1, meaning that everything on the line gets |
| 2841 | * painted. */ |
| 2842 | paintlen = -1; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2843 | else |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2844 | /* Otherwise, paintlen is the expanded location of the |
| 2845 | * end of the mark minus the expanded location of the |
| 2846 | * beginning of the mark. */ |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2847 | paintlen = strnlenpt(fileptr->data, bot_x) |
| 2848 | - (x_start + start); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2849 | |
| 2850 | /* If x_start is before the beginning of the page, shift |
| 2851 | * paintlen x_start characters to compensate, and put |
| 2852 | * x_start at the beginning of the page. */ |
| 2853 | if (x_start < 0) { |
| 2854 | paintlen += x_start; |
| 2855 | x_start = 0; |
| 2856 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2857 | |
| 2858 | assert(x_start >= 0 && x_start <= strlen(converted)); |
| 2859 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2860 | wattron(edit, A_REVERSE); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2861 | mvwaddnstr(edit, yval, x_start, converted + x_start, paintlen); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2862 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2863 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 2864 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2865 | #endif /* !NANO_SMALL */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2866 | } |
| 2867 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2868 | /* 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] | 2869 | * edit_add(). |
| 2870 | * |
David Lawrence Ramsey | 07d3feb | 2004-04-16 05:15:11 +0000 | [diff] [blame] | 2871 | * If fileptr != current, then index is considered 0. The line will be |
| 2872 | * displayed starting with fileptr->data[index]. Likely args are |
| 2873 | * current_x or 0. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2874 | void update_line(const filestruct *fileptr, size_t index) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2875 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2876 | int line; |
| 2877 | /* line in the edit window for CURSES calls */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2878 | char *converted; |
| 2879 | /* fileptr->data converted to have tabs and control characters |
| 2880 | * expanded. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2881 | size_t page_start; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2882 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2883 | assert(fileptr != NULL); |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 2884 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2885 | line = fileptr->lineno - edittop->lineno; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2886 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2887 | /* We assume the line numbers are valid. Is that really true? */ |
| 2888 | assert(line < 0 || line == check_linenumbers(fileptr)); |
| 2889 | |
| 2890 | if (line < 0 || line >= editwinrows) |
| 2891 | return; |
| 2892 | |
| 2893 | /* First, blank out the line (at a minimum) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2894 | mvwaddstr(edit, line, 0, hblank); |
| 2895 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2896 | /* Next, convert variables that index the line to their equivalent |
| 2897 | * positions in the expanded line. */ |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 2898 | index = (fileptr == current) ? strnlenpt(fileptr->data, index) : 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2899 | page_start = get_page_start(index); |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2900 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2901 | /* Expand the line, replacing Tab by spaces, and control characters |
| 2902 | * by their display form. */ |
| 2903 | converted = display_string(fileptr->data, page_start, COLS); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 2904 | |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 2905 | /* Now, paint the line */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2906 | edit_add(fileptr, converted, line, page_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2907 | free(converted); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2908 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2909 | if (page_start > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2910 | mvwaddch(edit, line, 0, '$'); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2911 | if (strlenpt(fileptr->data) > page_start + COLS) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2912 | mvwaddch(edit, line, COLS - 1, '$'); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2913 | } |
| 2914 | |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2915 | /* Return a nonzero value if we need an update after moving |
| 2916 | * horizontally. We need one if the mark is on or if old_pww and |
David Lawrence Ramsey | 684b193 | 2004-05-31 14:47:12 +0000 | [diff] [blame] | 2917 | * placewewant are on different pages. */ |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 2918 | int need_horizontal_update(size_t old_pww) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2919 | { |
| 2920 | return |
| 2921 | #ifndef NANO_SMALL |
| 2922 | ISSET(MARK_ISSET) || |
| 2923 | #endif |
| 2924 | get_page_start(old_pww) != get_page_start(placewewant); |
| 2925 | } |
| 2926 | |
| 2927 | /* Return a nonzero value if we need an update after moving vertically. |
| 2928 | * We need one if the mark is on or if old_pww and placewewant |
David Lawrence Ramsey | 684b193 | 2004-05-31 14:47:12 +0000 | [diff] [blame] | 2929 | * are on different pages. */ |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 2930 | int need_vertical_update(size_t old_pww) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2931 | { |
| 2932 | return |
| 2933 | #ifndef NANO_SMALL |
| 2934 | ISSET(MARK_ISSET) || |
| 2935 | #endif |
| 2936 | get_page_start(old_pww) != get_page_start(placewewant); |
| 2937 | } |
| 2938 | |
| 2939 | /* Scroll the edit window in the given direction and the given number |
| 2940 | * of lines, and draw new lines on the blank lines left after the |
| 2941 | * scrolling. direction is the direction to scroll, either UP or DOWN, |
| 2942 | * and nlines is the number of lines to scroll. Don't redraw the old |
| 2943 | * topmost or bottommost line (where we assume current is) before |
| 2944 | * scrolling or draw the new topmost or bottommost line after scrolling |
| 2945 | * (where we assume current will be), since we don't know where we are |
David Lawrence Ramsey | 684b193 | 2004-05-31 14:47:12 +0000 | [diff] [blame] | 2946 | * on the page or whether we'll stay there. */ |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2947 | void edit_scroll(updown direction, int nlines) |
| 2948 | { |
| 2949 | filestruct *foo; |
| 2950 | int i, scroll_rows = 0; |
| 2951 | |
| 2952 | /* Scrolling less than one line or more than editwinrows lines is |
| 2953 | * redundant, so don't allow it. */ |
| 2954 | if (nlines < 1 || nlines > editwinrows) |
| 2955 | return; |
| 2956 | |
| 2957 | /* Move the top line of the edit window up or down (depending on the |
| 2958 | * value of direction) nlines lines. If there are fewer lines of |
| 2959 | * text than that left, move it to the top or bottom line of the |
| 2960 | * file (depending on the value of direction). Keep track of |
| 2961 | * how many lines we moved in scroll_rows. */ |
| 2962 | for (i = nlines; i > 0; i--) { |
| 2963 | if (direction == UP) { |
| 2964 | if (edittop->prev == NULL) |
| 2965 | break; |
| 2966 | edittop = edittop->prev; |
| 2967 | scroll_rows--; |
| 2968 | } else { |
| 2969 | if (edittop->next == NULL) |
| 2970 | break; |
| 2971 | edittop = edittop->next; |
| 2972 | scroll_rows++; |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | /* Scroll the text on the screen up or down scroll_rows lines, |
| 2977 | * depending on the value of direction. */ |
| 2978 | scrollok(edit, TRUE); |
| 2979 | wscrl(edit, scroll_rows); |
| 2980 | scrollok(edit, FALSE); |
| 2981 | |
| 2982 | foo = edittop; |
| 2983 | if (direction != UP) { |
| 2984 | int slines = editwinrows - nlines; |
| 2985 | for (; slines > 0 && foo != NULL; slines--) |
| 2986 | foo = foo->next; |
| 2987 | } |
| 2988 | |
| 2989 | /* And draw new lines on the blank top or bottom lines of the edit |
| 2990 | * window, depending on the value of direction. Don't draw the new |
| 2991 | * topmost or new bottommost line. */ |
| 2992 | while (scroll_rows != 0 && foo != NULL) { |
| 2993 | if (foo->next != NULL) |
| 2994 | update_line(foo, 0); |
| 2995 | if (direction == UP) |
| 2996 | scroll_rows++; |
| 2997 | else |
| 2998 | scroll_rows--; |
| 2999 | foo = foo->next; |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | /* Update any lines between old_current and current that need to be |
David Lawrence Ramsey | 684b193 | 2004-05-31 14:47:12 +0000 | [diff] [blame] | 3004 | * updated. */ |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 3005 | void edit_redraw(const filestruct *old_current, size_t old_pww) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3006 | { |
David Lawrence Ramsey | ce1d765 | 2004-06-01 18:32:36 +0000 | [diff] [blame] | 3007 | int do_refresh = need_vertical_update(0) || |
| 3008 | need_vertical_update(old_pww); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3009 | const filestruct *foo; |
| 3010 | |
| 3011 | /* If either old_current or current is offscreen, refresh the screen |
| 3012 | * and get out. */ |
| 3013 | if (old_current->lineno < edittop->lineno || old_current->lineno >= |
| 3014 | edittop->lineno + editwinrows || current->lineno < |
| 3015 | edittop->lineno || current->lineno >= edittop->lineno + |
| 3016 | editwinrows) { |
| 3017 | edit_refresh(); |
| 3018 | return; |
| 3019 | } |
| 3020 | |
David Lawrence Ramsey | ce1d765 | 2004-06-01 18:32:36 +0000 | [diff] [blame] | 3021 | /* Update old_current and current if we're not on the first page |
| 3022 | * and/or we're not on the same page as before. If the mark is on, |
| 3023 | * update all the lines between old_current and current too. */ |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3024 | foo = old_current; |
| 3025 | while (foo != current) { |
| 3026 | if (do_refresh) |
| 3027 | update_line(foo, 0); |
| 3028 | #ifndef NANO_SMALL |
| 3029 | if (!ISSET(MARK_ISSET)) |
| 3030 | #endif |
| 3031 | break; |
| 3032 | if (foo->lineno > current->lineno) |
| 3033 | foo = foo->prev; |
| 3034 | else |
| 3035 | foo = foo->next; |
| 3036 | } |
| 3037 | if (do_refresh) |
| 3038 | update_line(current, current_x); |
| 3039 | } |
| 3040 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 3041 | /* Refresh the screen without changing the position of lines. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3042 | void edit_refresh(void) |
| 3043 | { |
Chris Allegretta | 63d0b48 | 2003-01-26 19:47:10 +0000 | [diff] [blame] | 3044 | if (current->lineno < edittop->lineno || |
| 3045 | current->lineno >= edittop->lineno + editwinrows) |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 3046 | /* Note that edit_update() changes edittop so that it's in range |
| 3047 | * of current. Thus, when it then calls edit_refresh(), there |
| 3048 | * is no danger of getting an infinite loop. */ |
| 3049 | edit_update( |
| 3050 | #ifndef NANO_SMALL |
| 3051 | ISSET(SMOOTHSCROLL) ? NONE : |
| 3052 | #endif |
| 3053 | CENTER); |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 3054 | else { |
| 3055 | int nlines = 0; |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 3056 | const filestruct *foo = edittop; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3057 | |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 3058 | #ifdef DEBUG |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 3059 | fprintf(stderr, "edit_refresh(): edittop->lineno = %d\n", edittop->lineno); |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 3060 | #endif |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 3061 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 3062 | while (nlines < editwinrows) { |
David Lawrence Ramsey | 9d325a0 | 2004-05-29 03:03:52 +0000 | [diff] [blame] | 3063 | update_line(foo, foo == current ? current_x : 0); |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 3064 | nlines++; |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 3065 | if (foo->next == NULL) |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 3066 | break; |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 3067 | foo = foo->next; |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 3068 | } |
| 3069 | while (nlines < editwinrows) { |
| 3070 | mvwaddstr(edit, nlines, 0, hblank); |
| 3071 | nlines++; |
| 3072 | } |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 3073 | reset_cursor(); |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 3074 | wrefresh(edit); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 3075 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 3078 | /* A nice generic routine to update the edit buffer. We keep current in |
| 3079 | * the same place and move edittop to put it in range of current. */ |
David Lawrence Ramsey | 20b8350 | 2004-08-26 18:07:58 +0000 | [diff] [blame] | 3080 | void edit_update(topmidnone location) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3081 | { |
David Lawrence Ramsey | 20b8350 | 2004-08-26 18:07:58 +0000 | [diff] [blame] | 3082 | filestruct *foo = current; |
| 3083 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 3084 | if (location != TOP) { |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 3085 | /* If location is CENTER, we move edittop up (editwinrows / 2) |
| 3086 | * lines. This puts current at the center of the screen. If |
| 3087 | * location is NONE, we move edittop up current_y lines if |
| 3088 | * current_y is in range of the screen, 0 lines if current_y is |
| 3089 | * less than 0, or (editwinrows - 1) lines if current_y is |
| 3090 | * greater than (editwinrows - 1). This puts current at the |
| 3091 | * same place on the screen as before, or at the top or bottom |
| 3092 | * of the screen if edittop is beyond either. */ |
| 3093 | int goal; |
| 3094 | |
| 3095 | if (location == CENTER) |
| 3096 | goal = editwinrows / 2; |
| 3097 | else { |
| 3098 | goal = current_y; |
| 3099 | |
| 3100 | /* Limit goal to (editwinrows - 1) lines maximum. */ |
| 3101 | if (goal > editwinrows - 1) |
| 3102 | goal = editwinrows - 1; |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 3103 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3104 | |
David Lawrence Ramsey | 20b8350 | 2004-08-26 18:07:58 +0000 | [diff] [blame] | 3105 | for (; goal > 0 && foo->prev != NULL; goal--) |
| 3106 | foo = foo->prev; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 3107 | } |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 3108 | |
David Lawrence Ramsey | 20b8350 | 2004-08-26 18:07:58 +0000 | [diff] [blame] | 3109 | edittop = foo; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3110 | edit_refresh(); |
| 3111 | } |
| 3112 | |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3113 | /* Ask a simple yes/no question, specified in msg, on the statusbar. |
| 3114 | * Return 1 for Y, 0 for N, 2 for All (if all is TRUE when passed in) |
| 3115 | * and -1 for abort (^C). */ |
David Lawrence Ramsey | 045883a | 2004-10-05 20:11:31 +0000 | [diff] [blame] | 3116 | int do_yesno(bool all, const char *msg) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3117 | { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3118 | int ok = -2, width = 16; |
David Lawrence Ramsey | 45eda52 | 2004-06-12 21:20:33 +0000 | [diff] [blame] | 3119 | const char *yesstr; /* String of yes characters accepted. */ |
| 3120 | const char *nostr; /* Same for no. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 3121 | const char *allstr; /* And all, surprise! */ |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 3122 | |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3123 | /* yesstr, nostr, and allstr are strings of any length. Each string |
| 3124 | * consists of all characters accepted as a valid character for that |
| 3125 | * value. The first value will be the one displayed in the |
| 3126 | * shortcuts. Translators: if possible, specify both the shortcuts |
| 3127 | * for your language and English. For example, in French: "OoYy" |
| 3128 | * for "Oui". */ |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 3129 | yesstr = _("Yy"); |
| 3130 | nostr = _("Nn"); |
| 3131 | allstr = _("Aa"); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3132 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3133 | if (!ISSET(NO_HELP)) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3134 | char shortstr[3]; /* Temp string for Y, N, A. */ |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 3135 | |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3136 | if (COLS < 32) |
| 3137 | width = COLS / 2; |
| 3138 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3139 | /* Write the bottom of the screen. */ |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3140 | blank_bottombars(); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 3141 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 3142 | sprintf(shortstr, " %c", yesstr[0]); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3143 | wmove(bottomwin, 1, 0); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3144 | onekey(shortstr, _("Yes"), width); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 3145 | |
| 3146 | if (all) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3147 | wmove(bottomwin, 1, width); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 3148 | shortstr[1] = allstr[0]; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3149 | onekey(shortstr, _("All"), width); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 3150 | } |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 3151 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3152 | wmove(bottomwin, 2, 0); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 3153 | shortstr[1] = nostr[0]; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3154 | onekey(shortstr, _("No"), width); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 3155 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3156 | wmove(bottomwin, 2, 16); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3157 | onekey("^C", _("Cancel"), width); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3158 | } |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3159 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3160 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 3161 | |
| 3162 | blank_statusbar(); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3163 | mvwaddnstr(bottomwin, 0, 0, msg, COLS - 1); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 3164 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3165 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 3166 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3167 | wrefresh(bottomwin); |
| 3168 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3169 | do { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3170 | int kbinput; |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 3171 | bool meta_key, func_key; |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 3172 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3173 | int mouse_x, mouse_y; |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 3174 | #endif |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 3175 | |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 3176 | kbinput = get_kbinput(edit, &meta_key, &func_key); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3177 | |
| 3178 | if (kbinput == NANO_CANCEL_KEY) |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3179 | ok = -1; |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 3180 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 3181 | /* Look, ma! We get to duplicate lots of code from |
| 3182 | * do_mouse()!! */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3183 | else if (kbinput == KEY_MOUSE) { |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 3184 | get_mouseinput(&mouse_x, &mouse_y, FALSE); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 3185 | |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3186 | if (mouse_x != -1 && mouse_y != -1 && !ISSET(NO_HELP) && |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 3187 | wenclose(bottomwin, mouse_y, mouse_x) && |
| 3188 | mouse_x < (width * 2) && mouse_y >= editwinrows + 3) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 3189 | int x = mouse_x / width; |
| 3190 | /* Did we click in the first column of shortcuts, or |
| 3191 | * the second? */ |
| 3192 | int y = mouse_y - editwinrows - 3; |
| 3193 | /* Did we click in the first row of shortcuts? */ |
| 3194 | |
| 3195 | assert(0 <= x && x <= 1 && 0 <= y && y <= 1); |
| 3196 | |
| 3197 | /* x = 0 means they clicked Yes or No. |
| 3198 | * y = 0 means Yes or All. */ |
| 3199 | ok = -2 * x * y + x - y + 1; |
| 3200 | |
| 3201 | if (ok == 2 && !all) |
| 3202 | ok = -2; |
| 3203 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3204 | } |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3205 | #endif |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3206 | /* Look for the kbinput in the yes, no and (optionally) all |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3207 | * strings. */ |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3208 | else if (strchr(yesstr, kbinput) != NULL) |
| 3209 | ok = 1; |
| 3210 | else if (strchr(nostr, kbinput) != NULL) |
| 3211 | ok = 0; |
| 3212 | else if (all && strchr(allstr, kbinput) != NULL) |
| 3213 | ok = 2; |
| 3214 | } while (ok == -2); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3215 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 3216 | return ok; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3219 | void total_refresh(void) |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3220 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3221 | clearok(topwin, TRUE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3222 | clearok(edit, TRUE); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3223 | clearok(bottomwin, TRUE); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3224 | wnoutrefresh(topwin); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3225 | wnoutrefresh(edit); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3226 | wnoutrefresh(bottomwin); |
| 3227 | doupdate(); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3228 | clearok(topwin, FALSE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3229 | clearok(edit, FALSE); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3230 | clearok(bottomwin, FALSE); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3231 | titlebar(NULL); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 3232 | edit_refresh(); |
| 3233 | /* FIXME: bottomwin needs to be refreshed too. */ |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | void display_main_list(void) |
| 3237 | { |
| 3238 | bottombars(main_list); |
| 3239 | } |
| 3240 | |
David Lawrence Ramsey | 576bf33 | 2004-07-12 03:10:30 +0000 | [diff] [blame] | 3241 | /* If constant is FALSE, the user typed Ctrl-C, so we unconditionally |
| 3242 | * display the cursor position. Otherwise, we display it only if the |
| 3243 | * character position changed and DISABLE_CURPOS is not set. |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3244 | * |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3245 | * If constant is TRUE and DISABLE_CURPOS is set, we unset it and update |
| 3246 | * old_i and old_totsize. That way, we leave the current statusbar |
| 3247 | * alone, but next time we will display. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 3248 | void do_cursorpos(bool constant) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3249 | { |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3250 | const filestruct *fileptr; |
David Lawrence Ramsey | 7a97e18 | 2004-10-30 01:03:15 +0000 | [diff] [blame] | 3251 | size_t i = 0; |
| 3252 | static size_t old_i = 0; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3253 | static long old_totsize = -1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3254 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3255 | assert(current != NULL && fileage != NULL && totlines != 0); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3256 | |
| 3257 | if (old_totsize == -1) |
| 3258 | old_totsize = totsize; |
| 3259 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3260 | for (fileptr = fileage; fileptr != current; fileptr = fileptr->next) { |
| 3261 | assert(fileptr != NULL); |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 3262 | i += strlen(fileptr->data) + 1; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3263 | } |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 3264 | i += current_x; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 3265 | |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 3266 | /* Check whether totsize is correct. Else there is a bug |
| 3267 | * somewhere. */ |
| 3268 | assert(current != filebot || i == totsize); |
| 3269 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3270 | if (constant && ISSET(DISABLE_CURPOS)) { |
| 3271 | UNSET(DISABLE_CURPOS); |
| 3272 | old_i = i; |
| 3273 | old_totsize = totsize; |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3274 | return; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3275 | } |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 3276 | |
David Lawrence Ramsey | 4178db0 | 2004-05-23 21:23:23 +0000 | [diff] [blame] | 3277 | /* If constant is FALSE, display the position on the statusbar |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3278 | * unconditionally; otherwise, only display the position when the |
| 3279 | * character values have changed. */ |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3280 | if (!constant || old_i != i || old_totsize != totsize) { |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 3281 | size_t xpt = xplustabs() + 1; |
| 3282 | size_t cur_len = strlenpt(current->data) + 1; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3283 | int linepct = 100 * current->lineno / totlines; |
| 3284 | int colpct = 100 * xpt / cur_len; |
| 3285 | int bytepct = totsize == 0 ? 0 : 100 * i / totsize; |
| 3286 | |
| 3287 | statusbar( |
| 3288 | _("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%ld (%d%%)"), |
| 3289 | current->lineno, totlines, linepct, |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 3290 | (unsigned long)xpt, (unsigned long)cur_len, colpct, |
David Lawrence Ramsey | 7a97e18 | 2004-10-30 01:03:15 +0000 | [diff] [blame] | 3291 | (unsigned long)i, totsize, bytepct); |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3292 | UNSET(DISABLE_CURPOS); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | old_i = i; |
| 3296 | old_totsize = totsize; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3299 | void do_cursorpos_void(void) |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3300 | { |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3301 | do_cursorpos(FALSE); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
David Lawrence Ramsey | 8037fe0 | 2004-07-23 12:30:40 +0000 | [diff] [blame] | 3304 | #ifndef DISABLE_HELP |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 3305 | /* Calculate the next line of help_text, starting at ptr. */ |
David Lawrence Ramsey | 8037fe0 | 2004-07-23 12:30:40 +0000 | [diff] [blame] | 3306 | int help_line_len(const char *ptr) |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 3307 | { |
David Lawrence Ramsey | 8037fe0 | 2004-07-23 12:30:40 +0000 | [diff] [blame] | 3308 | int j = 0; |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 3309 | |
| 3310 | while (*ptr != '\n' && *ptr != '\0' && j < COLS - 5) { |
| 3311 | ptr++; |
| 3312 | j++; |
| 3313 | } |
| 3314 | if (j == COLS - 5) { |
| 3315 | /* Don't wrap at the first of two spaces following a period. */ |
| 3316 | if (*ptr == ' ' && *(ptr + 1) == ' ') |
| 3317 | j++; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3318 | /* 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] | 3319 | while (*ptr != ' ' && j > 0) { |
| 3320 | ptr--; |
| 3321 | j--; |
| 3322 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3323 | /* Word longer than COLS - 5 chars just gets broken. */ |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 3324 | if (j == 0) |
| 3325 | j = COLS - 5; |
| 3326 | } |
| 3327 | assert(j >= 0 && j <= COLS - 4 && (j > 0 || *ptr == '\n')); |
| 3328 | return j; |
| 3329 | } |
| 3330 | |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3331 | /* Our dynamic, shortcut-list-compliant help function. */ |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3332 | void do_help(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3333 | { |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3334 | int line = 0; |
| 3335 | /* The line number in help_text of the first displayed help line. |
| 3336 | * This variable is zero-based. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 3337 | bool no_more = FALSE; |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3338 | /* no_more means the end of the help text is shown, so don't go |
| 3339 | * down any more. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 3340 | int kbinput = ERR; |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 3341 | bool meta_key, func_key; |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3342 | |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 3343 | bool old_no_help = ISSET(NO_HELP); |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3344 | #ifndef DISABLE_MOUSE |
| 3345 | const shortcut *oldshortcut = currshortcut; |
| 3346 | /* We will set currshortcut to allow clicking on the help |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3347 | * screen's shortcut list. */ |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3348 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3349 | |
David Lawrence Ramsey | ae064bf | 2004-06-01 20:38:00 +0000 | [diff] [blame] | 3350 | curs_set(0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3351 | blank_edit(); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 3352 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3353 | blank_statusbar(); |
| 3354 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3355 | /* Set help_text as the string to display. */ |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 3356 | help_init(); |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 3357 | assert(help_text != NULL); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 3358 | |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3359 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3360 | /* Set currshortcut to allow clicking on the help screen's shortcut |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3361 | * list, AFTER help_init(). */ |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 3362 | currshortcut = help_list; |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3363 | #endif |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 3364 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3365 | if (ISSET(NO_HELP)) { |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3366 | /* Make sure that the help screen's shortcut list will actually |
| 3367 | * be displayed. */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 3368 | UNSET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 3369 | window_init(); |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3370 | } |
| 3371 | bottombars(help_list); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3372 | |
| 3373 | do { |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3374 | int i; |
| 3375 | int old_line = line; |
| 3376 | /* We redisplay the help only if it moved. */ |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 3377 | const char *ptr = help_text; |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 3378 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3379 | switch (kbinput) { |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 3380 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3381 | case KEY_MOUSE: |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 3382 | { |
| 3383 | int mouse_x, mouse_y; |
| 3384 | get_mouseinput(&mouse_x, &mouse_y, TRUE); |
| 3385 | } |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3386 | break; |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 3387 | #endif |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3388 | case NANO_NEXTPAGE_KEY: |
| 3389 | case NANO_NEXTPAGE_FKEY: |
| 3390 | if (!no_more) |
| 3391 | line += editwinrows - 2; |
| 3392 | break; |
| 3393 | case NANO_PREVPAGE_KEY: |
| 3394 | case NANO_PREVPAGE_FKEY: |
| 3395 | if (line > 0) { |
| 3396 | line -= editwinrows - 2; |
| 3397 | if (line < 0) |
| 3398 | line = 0; |
| 3399 | } |
| 3400 | break; |
| 3401 | case NANO_PREVLINE_KEY: |
| 3402 | if (line > 0) |
| 3403 | line--; |
| 3404 | break; |
| 3405 | case NANO_NEXTLINE_KEY: |
| 3406 | if (!no_more) |
| 3407 | line++; |
| 3408 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3409 | } |
| 3410 | |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3411 | if (line == old_line && kbinput != ERR) |
| 3412 | goto skip_redisplay; |
| 3413 | |
| 3414 | blank_edit(); |
| 3415 | |
| 3416 | assert(COLS > 5); |
| 3417 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3418 | /* Calculate where in the text we should be, based on the |
| 3419 | * page. */ |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3420 | for (i = 0; i < line; i++) { |
David Lawrence Ramsey | 8037fe0 | 2004-07-23 12:30:40 +0000 | [diff] [blame] | 3421 | ptr += help_line_len(ptr); |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 3422 | if (*ptr == '\n') |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3423 | ptr++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 3426 | for (i = 0; i < editwinrows && *ptr != '\0'; i++) { |
David Lawrence Ramsey | 8037fe0 | 2004-07-23 12:30:40 +0000 | [diff] [blame] | 3427 | int j = help_line_len(ptr); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3428 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3429 | mvwaddnstr(edit, i, 0, ptr, j); |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 3430 | ptr += j; |
| 3431 | if (*ptr == '\n') |
| 3432 | ptr++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3433 | } |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3434 | no_more = (*ptr == '\0'); |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 3435 | |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3436 | skip_redisplay: |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 3437 | kbinput = get_kbinput(edit, &meta_key, &func_key); |
David Lawrence Ramsey | 8037fe0 | 2004-07-23 12:30:40 +0000 | [diff] [blame] | 3438 | } while (kbinput != NANO_CANCEL_KEY && kbinput != NANO_EXIT_KEY && |
| 3439 | kbinput != NANO_EXIT_FKEY); |
Chris Allegretta | d1627cf | 2000-12-18 05:03:16 +0000 | [diff] [blame] | 3440 | |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3441 | #ifndef DISABLE_MOUSE |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 3442 | currshortcut = oldshortcut; |
David Lawrence Ramsey | be26561 | 2004-05-29 20:38:08 +0000 | [diff] [blame] | 3443 | #endif |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 3444 | |
David Lawrence Ramsey | e7638ea | 2004-06-01 19:49:38 +0000 | [diff] [blame] | 3445 | if (old_no_help) { |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 3446 | blank_bottombars(); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 3447 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3448 | SET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 3449 | window_init(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3450 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 3451 | bottombars(currshortcut); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3452 | |
David Lawrence Ramsey | ae064bf | 2004-06-01 20:38:00 +0000 | [diff] [blame] | 3453 | curs_set(1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3454 | edit_refresh(); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 3455 | |
David Lawrence Ramsey | 5245344 | 2004-06-26 15:24:16 +0000 | [diff] [blame] | 3456 | /* The help_init() at the beginning allocated help_text. Since |
| 3457 | * help_text has now been written to the screen, we don't need it |
| 3458 | * anymore. */ |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 3459 | free(help_text); |
| 3460 | help_text = NULL; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3461 | } |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 3462 | #endif /* !DISABLE_HELP */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3463 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3464 | /* Highlight the current word being replaced or spell checked. We |
| 3465 | * expect word to have tabs and control characters expanded. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 3466 | void do_replace_highlight(int highlight_flag, const char *word) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3467 | { |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 3468 | size_t y = xplustabs(); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3469 | size_t word_len = strlen(word); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3470 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3471 | y = get_page_start(y) + COLS - y; |
| 3472 | /* Now y is the number of characters we can display on this |
| 3473 | * line. */ |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3474 | |
| 3475 | reset_cursor(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3476 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3477 | if (highlight_flag) |
| 3478 | wattron(edit, A_REVERSE); |
| 3479 | |
David Lawrence Ramsey | 2a4ab6d | 2003-12-24 08:29:49 +0000 | [diff] [blame] | 3480 | #ifdef HAVE_REGEX_H |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 3481 | /* This is so we can show zero-length regexes. */ |
| 3482 | if (word_len == 0) |
| 3483 | waddstr(edit, " "); |
| 3484 | else |
David Lawrence Ramsey | 2a4ab6d | 2003-12-24 08:29:49 +0000 | [diff] [blame] | 3485 | #endif |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 3486 | waddnstr(edit, word, y - 1); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3487 | |
| 3488 | if (word_len > y) |
| 3489 | waddch(edit, '$'); |
| 3490 | else if (word_len == y) |
| 3491 | waddch(edit, word[word_len - 1]); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3492 | |
| 3493 | if (highlight_flag) |
| 3494 | wattroff(edit, A_REVERSE); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3497 | #ifdef DEBUG |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3498 | /* Dump the passed-in file structure to stderr. */ |
| 3499 | void dump_buffer(const filestruct *inptr) |
| 3500 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3501 | if (inptr == fileage) |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 3502 | fprintf(stderr, "Dumping file buffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3503 | else if (inptr == cutbuffer) |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 3504 | fprintf(stderr, "Dumping cutbuffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3505 | else |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 3506 | fprintf(stderr, "Dumping a buffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3507 | |
| 3508 | while (inptr != NULL) { |
| 3509 | fprintf(stderr, "(%d) %s\n", inptr->lineno, inptr->data); |
| 3510 | inptr = inptr->next; |
| 3511 | } |
| 3512 | } |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3513 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3514 | /* Dump the file structure to stderr in reverse. */ |
David Lawrence Ramsey | aaad3af | 2003-08-31 16:44:10 +0000 | [diff] [blame] | 3515 | void dump_buffer_reverse(void) |
| 3516 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3517 | const filestruct *fileptr = filebot; |
| 3518 | |
| 3519 | while (fileptr != NULL) { |
David Lawrence Ramsey | 24f10c3 | 2004-07-17 20:01:45 +0000 | [diff] [blame] | 3520 | fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3521 | fileptr = fileptr->prev; |
| 3522 | } |
| 3523 | } |
| 3524 | #endif /* DEBUG */ |
| 3525 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3526 | #ifdef NANO_EXTRA |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 3527 | #define CREDIT_LEN 53 |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 3528 | #define XLCREDIT_LEN 8 |
| 3529 | |
David Lawrence Ramsey | fdece46 | 2004-01-19 18:15:03 +0000 | [diff] [blame] | 3530 | /* Easter egg: Display credits. Assume nodelay(edit) is FALSE. */ |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3531 | void do_credits(void) |
| 3532 | { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3533 | int crpos = 0, xlpos = 0; |
| 3534 | const char *credits[CREDIT_LEN] = { |
| 3535 | NULL, /* "The nano text editor" */ |
| 3536 | NULL, /* "version" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3537 | VERSION, |
| 3538 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3539 | NULL, /* "Brought to you by:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3540 | "Chris Allegretta", |
| 3541 | "Jordi Mallach", |
| 3542 | "Adam Rogoyski", |
| 3543 | "Rob Siemborski", |
| 3544 | "Rocco Corsi", |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 3545 | "David Lawrence Ramsey", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 3546 | "David Benbennick", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3547 | "Ken Tyler", |
| 3548 | "Sven Guckes", |
| 3549 | "Florian König", |
| 3550 | "Pauli Virtanen", |
| 3551 | "Daniele Medri", |
| 3552 | "Clement Laforet", |
| 3553 | "Tedi Heriyanto", |
| 3554 | "Bill Soudan", |
| 3555 | "Christian Weisgerber", |
| 3556 | "Erik Andersen", |
| 3557 | "Big Gaute", |
| 3558 | "Joshua Jensen", |
| 3559 | "Ryan Krebs", |
| 3560 | "Albert Chin", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3561 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3562 | NULL, /* "Special thanks to:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3563 | "Plattsburgh State University", |
| 3564 | "Benet Laboratories", |
| 3565 | "Amy Allegretta", |
| 3566 | "Linda Young", |
| 3567 | "Jeremy Robichaud", |
| 3568 | "Richard Kolb II", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3569 | NULL, /* "The Free Software Foundation" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3570 | "Linus Torvalds", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3571 | NULL, /* "For ncurses:" */ |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 3572 | "Thomas Dickey", |
| 3573 | "Pavel Curtis", |
| 3574 | "Zeyd Ben-Halim", |
| 3575 | "Eric S. Raymond", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3576 | NULL, /* "and anyone else we forgot..." */ |
| 3577 | NULL, /* "Thank you for using nano!" */ |
| 3578 | "", |
| 3579 | "", |
| 3580 | "", |
| 3581 | "", |
David Lawrence Ramsey | 6481c3f | 2004-01-09 23:06:54 +0000 | [diff] [blame] | 3582 | "(c) 1999-2004 Chris Allegretta", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3583 | "", |
| 3584 | "", |
| 3585 | "", |
| 3586 | "", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 3587 | "http://www.nano-editor.org/" |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3588 | }; |
| 3589 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3590 | const char *xlcredits[XLCREDIT_LEN] = { |
David Lawrence Ramsey | 576bf33 | 2004-07-12 03:10:30 +0000 | [diff] [blame] | 3591 | N_("The nano text editor"), |
| 3592 | N_("version"), |
| 3593 | N_("Brought to you by:"), |
| 3594 | N_("Special thanks to:"), |
| 3595 | N_("The Free Software Foundation"), |
| 3596 | N_("For ncurses:"), |
| 3597 | N_("and anyone else we forgot..."), |
| 3598 | N_("Thank you for using nano!") |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3599 | }; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 3600 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3601 | curs_set(0); |
| 3602 | nodelay(edit, TRUE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3603 | scrollok(edit, TRUE); |
| 3604 | blank_titlebar(); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 3605 | blank_edit(); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3606 | blank_statusbar(); |
| 3607 | blank_bottombars(); |
| 3608 | wrefresh(topwin); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 3609 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3610 | wrefresh(bottomwin); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3611 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3612 | for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) { |
| 3613 | if (wgetch(edit) != ERR) |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3614 | break; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3615 | if (crpos < CREDIT_LEN) { |
| 3616 | const char *what = credits[crpos]; |
| 3617 | size_t start_x; |
| 3618 | |
| 3619 | if (what == NULL) { |
| 3620 | assert(0 <= xlpos && xlpos < XLCREDIT_LEN); |
David Lawrence Ramsey | 837a02b | 2004-05-18 15:23:31 +0000 | [diff] [blame] | 3621 | what = _(xlcredits[xlpos]); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3622 | xlpos++; |
| 3623 | } |
| 3624 | start_x = COLS / 2 - strlen(what) / 2 - 1; |
| 3625 | mvwaddstr(edit, editwinrows - 1 - editwinrows % 2, start_x, what); |
| 3626 | } |
| 3627 | napms(700); |
| 3628 | scroll(edit); |
| 3629 | wrefresh(edit); |
| 3630 | if (wgetch(edit) != ERR) |
| 3631 | break; |
| 3632 | napms(700); |
| 3633 | scroll(edit); |
| 3634 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3637 | scrollok(edit, FALSE); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3638 | nodelay(edit, FALSE); |
| 3639 | curs_set(1); |
| 3640 | display_main_list(); |
| 3641 | total_refresh(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3642 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3643 | #endif |