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