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