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