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