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