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