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