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 | 315eb32 | 2005-11-28 19:35:29 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 Chris Allegretta * |
David Lawrence Ramsey | 47cfd19 | 2006-01-02 04:30:33 +0000 | [diff] [blame] | 6 | * Copyright (C) 2005-2006 David Lawrence Ramsey * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or modify * |
| 8 | * 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] | 9 | * the Free Software Foundation; either version 2, or (at your option) * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 10 | * any later version. * |
| 11 | * * |
David Lawrence Ramsey | 6e925cf | 2005-05-15 19:57:17 +0000 | [diff] [blame] | 12 | * This program is distributed in the hope that it will be useful, but * |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 15 | * General Public License for more details. * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 16 | * * |
| 17 | * You should have received a copy of the GNU General Public License * |
| 18 | * along with this program; if not, write to the Free Software * |
David Lawrence Ramsey | 6e925cf | 2005-05-15 19:57:17 +0000 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * |
| 20 | * 02110-1301, USA. * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 21 | * * |
| 22 | **************************************************************************/ |
| 23 | |
David Lawrence Ramsey | 034b994 | 2005-12-08 02:47:10 +0000 | [diff] [blame] | 24 | #include "proto.h" |
David Lawrence Ramsey | e21adfa | 2002-09-13 18:14:04 +0000 | [diff] [blame] | 25 | |
David Lawrence Ramsey | 143b8c7 | 2005-11-01 18:35:47 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 27 | #include <stdarg.h> |
| 28 | #include <string.h> |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 29 | #include <unistd.h> |
David Lawrence Ramsey | 6f5de42 | 2005-10-06 05:28:37 +0000 | [diff] [blame] | 30 | #include <errno.h> |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 31 | #include <ctype.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 32 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 33 | static int *key_buffer = NULL; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 34 | /* The default keystroke buffer, |
| 35 | * containing all the keystrokes we have |
| 36 | * at a given point. */ |
| 37 | static size_t key_buffer_len = 0; |
| 38 | /* The length of the default keystroke |
| 39 | * buffer. */ |
David Lawrence Ramsey | fe7d53e | 2005-06-25 20:56:36 +0000 | [diff] [blame] | 40 | static int statusblank = 0; |
| 41 | /* The number of keystrokes left after |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 42 | * we call statusbar(), before we |
| 43 | * actually blank the statusbar. */ |
David Lawrence Ramsey | ea01474 | 2005-06-17 18:27:00 +0000 | [diff] [blame] | 44 | static bool disable_cursorpos = FALSE; |
| 45 | /* Should we temporarily disable |
| 46 | * constant cursor position display? */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 47 | |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 48 | /* Control character compatibility: |
| 49 | * |
| 50 | * - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI, |
| 51 | * VT100, and VT220. |
| 52 | * - NANO_TAB_KEY is Ctrl-I, which is Tab under ASCII, ANSI, VT100, |
| 53 | * VT220, and VT320. |
| 54 | * - NANO_ENTER_KEY is Ctrl-M, which is Enter under ASCII, ANSI, VT100, |
| 55 | * VT220, and VT320. |
| 56 | * - NANO_XON_KEY is Ctrl-Q, which is XON under ASCII, ANSI, VT100, |
| 57 | * VT220, and VT320. |
| 58 | * - NANO_XOFF_KEY is Ctrl-S, which is XOFF under ASCII, ANSI, VT100, |
| 59 | * VT220, and VT320. |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 60 | * - 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] | 61 | * ANSI, VT100, and VT220, and which is Backspace under VT320. |
| 62 | * |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 63 | * Note: VT220 and VT320 also generate Esc [ 3 ~ for Delete. By |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 64 | * default, xterm assumes it's running on a VT320 and generates Ctrl-8 |
| 65 | * (Ctrl-?) for Backspace and Esc [ 3 ~ for Delete. This causes |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 66 | * problems for VT100-derived terminals such as the FreeBSD console, |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 67 | * 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] | 68 | * on which the VT320 sequences are translated by the keypad to KEY_DC |
| 69 | * and [nothing]. We work around this conflict via the REBIND_DELETE |
| 70 | * flag: if it's not set, we assume VT320 compatibility, and if it is, |
| 71 | * we assume VT100 compatibility. Thanks to Lee Nelson and Wouter van |
| 72 | * Hemel for helping work this conflict out. |
| 73 | * |
| 74 | * Escape sequence compatibility: |
| 75 | * |
| 76 | * We support escape sequences for ANSI, VT100, VT220, VT320, the Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 77 | * 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] | 78 | * console), xterm, rxvt, and Eterm. Among these, there are several |
| 79 | * conflicts and omissions, outlined as follows: |
| 80 | * |
| 81 | * - Tab on ANSI == PageUp on FreeBSD console; the former is omitted. |
| 82 | * (Ctrl-I is also Tab on ANSI, which we already support.) |
| 83 | * - PageDown on FreeBSD console == Center (5) on numeric keypad with |
| 84 | * NumLock off on Linux console; the latter is omitted. (The editing |
| 85 | * keypad key is more important to have working than the numeric |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 86 | * 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] | 87 | * - F1 on FreeBSD console == the mouse key on xterm/rxvt/Eterm; the |
| 88 | * latter is omitted. (Mouse input will only work properly if the |
| 89 | * extended keypad value KEY_MOUSE is generated on mouse events |
| 90 | * instead of the escape sequence.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 91 | * - F9 on FreeBSD console == PageDown on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 92 | * omitted. (The editing keypad is more important to have working |
| 93 | * than the function keys, because the functions of the former are not |
| 94 | * arbitrary and the functions of the latter are.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 95 | * - F10 on FreeBSD console == PageUp on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 96 | * omitted. (Same as above.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 97 | * - F13 on FreeBSD console == End on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 98 | * omitted. (Same as above.) |
David Lawrence Ramsey | 8381fdd | 2004-11-01 22:40:02 +0000 | [diff] [blame] | 99 | * - F15 on FreeBSD console == Shift-Up on rxvt/Eterm; the former is |
| 100 | * omitted. (The arrow keys, with or without modifiers, are more |
| 101 | * important to have working than the function keys, because the |
| 102 | * functions of the former are not arbitrary and the functions of the |
| 103 | * latter are.) |
| 104 | * - F16 on FreeBSD console == Shift-Down on rxvt/Eterm; the former is |
| 105 | * omitted. (Same as above.) |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 106 | * |
| 107 | * Note that Center (5) on the numeric keypad with NumLock off can also |
| 108 | * be the Begin key. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 109 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 110 | #ifndef NANO_TINY |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 111 | /* Reset all the input routines that rely on character sequences. */ |
| 112 | void reset_kbinput(void) |
| 113 | { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 114 | parse_kbinput(NULL, NULL, NULL, TRUE); |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 115 | get_byte_kbinput(0, TRUE); |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 116 | get_unicode_kbinput(0, TRUE); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 117 | } |
| 118 | #endif |
| 119 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 120 | /* Read in a sequence of keystrokes from win and save them in the |
| 121 | * default keystroke buffer. This should only be called when the |
| 122 | * default keystroke buffer is empty. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 123 | void get_key_buffer(WINDOW *win) |
David Lawrence Ramsey | dfca1c4 | 2004-08-25 16:37:06 +0000 | [diff] [blame] | 124 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 125 | int input; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 126 | |
| 127 | /* If the keystroke buffer isn't empty, get out. */ |
| 128 | if (key_buffer != NULL) |
| 129 | return; |
| 130 | |
| 131 | /* Read in the first character using blocking input. */ |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 132 | #ifndef NANO_TINY |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 133 | allow_pending_sigwinch(TRUE); |
| 134 | #endif |
David Lawrence Ramsey | 78ea5e4 | 2004-12-12 19:04:56 +0000 | [diff] [blame] | 135 | |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 136 | /* Just before reading in the first character, display any pending |
| 137 | * screen updates. */ |
| 138 | doupdate(); |
| 139 | |
David Lawrence Ramsey | 6f5de42 | 2005-10-06 05:28:37 +0000 | [diff] [blame] | 140 | while ((input = wgetch(win)) == ERR) { |
| 141 | /* If errno is EIO, it means that the input source that we were |
| 142 | * using is gone, so die gracefully. */ |
| 143 | if (errno == EIO) |
| 144 | handle_hupterm(0); |
| 145 | } |
David Lawrence Ramsey | 78ea5e4 | 2004-12-12 19:04:56 +0000 | [diff] [blame] | 146 | |
David Lawrence Ramsey | c275dc5 | 2005-03-08 17:45:36 +0000 | [diff] [blame] | 147 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 148 | #ifndef NANO_TINY |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 149 | allow_pending_sigwinch(FALSE); |
| 150 | #endif |
| 151 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 152 | /* Increment the length of the keystroke buffer, save the value of |
| 153 | * 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] | 154 | * is an extended keypad value or FALSE if it isn't. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 155 | key_buffer_len++; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 156 | key_buffer = (int *)nmalloc(sizeof(int)); |
| 157 | key_buffer[0] = input; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 158 | |
| 159 | /* Read in the remaining characters using non-blocking input. */ |
| 160 | nodelay(win, TRUE); |
| 161 | |
| 162 | while (TRUE) { |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 163 | #ifndef NANO_TINY |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 164 | allow_pending_sigwinch(TRUE); |
| 165 | #endif |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 166 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 167 | input = wgetch(win); |
David Lawrence Ramsey | 78ea5e4 | 2004-12-12 19:04:56 +0000 | [diff] [blame] | 168 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 169 | /* If there aren't any more characters, stop reading. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 170 | if (input == ERR) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 171 | break; |
| 172 | |
| 173 | /* Otherwise, increment the length of the keystroke buffer, save |
| 174 | * 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] | 175 | * if the keystroke is an extended keypad value or FALSE if it |
| 176 | * isn't. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 177 | key_buffer_len++; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 178 | key_buffer = (int *)nrealloc(key_buffer, key_buffer_len * |
| 179 | sizeof(int)); |
| 180 | key_buffer[key_buffer_len - 1] = input; |
David Lawrence Ramsey | 78ea5e4 | 2004-12-12 19:04:56 +0000 | [diff] [blame] | 181 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 182 | #ifndef NANO_TINY |
David Lawrence Ramsey | 78ea5e4 | 2004-12-12 19:04:56 +0000 | [diff] [blame] | 183 | allow_pending_sigwinch(FALSE); |
| 184 | #endif |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* Switch back to non-blocking input. */ |
| 188 | nodelay(win, FALSE); |
David Lawrence Ramsey | a17a130 | 2005-03-16 14:39:42 +0000 | [diff] [blame] | 189 | |
| 190 | #ifdef DEBUG |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 191 | 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] | 192 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 193 | } |
| 194 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 195 | /* Return the length of the default keystroke buffer. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 196 | size_t get_key_buffer_len(void) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 197 | { |
| 198 | return key_buffer_len; |
| 199 | } |
| 200 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 201 | /* Add the contents of the keystroke buffer input to the default |
| 202 | * keystroke buffer. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 203 | void unget_input(int *input, size_t input_len) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 204 | { |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 205 | #ifndef NANO_TINY |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 206 | allow_pending_sigwinch(TRUE); |
| 207 | allow_pending_sigwinch(FALSE); |
| 208 | #endif |
| 209 | |
| 210 | /* If input is empty, get out. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 211 | if (input_len == 0) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 212 | return; |
| 213 | |
| 214 | /* If adding input would put the default keystroke buffer beyond |
| 215 | * maximum capacity, only add enough of input to put it at maximum |
| 216 | * capacity. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 217 | if (key_buffer_len + input_len < key_buffer_len) |
| 218 | input_len = (size_t)-1 - key_buffer_len; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 219 | |
| 220 | /* Add the length of input to the length of the default keystroke |
| 221 | * buffer, and reallocate the default keystroke buffer so that it |
| 222 | * has enough room for input. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 223 | key_buffer_len += input_len; |
| 224 | key_buffer = (int *)nrealloc(key_buffer, key_buffer_len * |
| 225 | sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 226 | |
| 227 | /* If the default keystroke buffer wasn't empty before, move its |
| 228 | * beginning forward far enough so that we can add input to its |
| 229 | * beginning. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 230 | if (key_buffer_len > input_len) |
| 231 | memmove(key_buffer + input_len, key_buffer, |
| 232 | (key_buffer_len - input_len) * sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 233 | |
| 234 | /* Copy input to the beginning of the default keystroke buffer. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 235 | memcpy(key_buffer, input, input_len * sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 236 | } |
| 237 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 238 | /* Put back the character stored in kbinput, putting it in byte range |
| 239 | * beforehand. If meta_key is TRUE, put back the Escape character after |
| 240 | * putting back kbinput. If func_key is TRUE, put back the function key |
| 241 | * (a value outside byte range) without putting it in byte range. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 242 | void unget_kbinput(int kbinput, bool meta_key, bool func_key) |
| 243 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 244 | if (!func_key) |
| 245 | kbinput = (char)kbinput; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 246 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 247 | unget_input(&kbinput, 1); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 248 | |
| 249 | if (meta_key) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 250 | kbinput = NANO_CONTROL_3; |
| 251 | unget_input(&kbinput, 1); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
| 255 | /* Try to read input_len characters from the default keystroke buffer. |
| 256 | * If the default keystroke buffer is empty and win isn't NULL, try to |
| 257 | * read in more characters from win and add them to the default |
| 258 | * keystroke buffer before doing anything else. If the default |
| 259 | * keystroke buffer is empty and win is NULL, return NULL. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 260 | int *get_input(WINDOW *win, size_t input_len) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 261 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 262 | int *input; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 263 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 264 | #ifndef NANO_TINY |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 265 | allow_pending_sigwinch(TRUE); |
| 266 | allow_pending_sigwinch(FALSE); |
| 267 | #endif |
| 268 | |
| 269 | if (key_buffer_len == 0) { |
| 270 | if (win != NULL) |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 271 | get_key_buffer(win); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 272 | |
| 273 | if (key_buffer_len == 0) |
| 274 | return NULL; |
| 275 | } |
| 276 | |
| 277 | /* If input_len is greater than the length of the default keystroke |
| 278 | * buffer, only read the number of characters in the default |
| 279 | * keystroke buffer. */ |
| 280 | if (input_len > key_buffer_len) |
| 281 | input_len = key_buffer_len; |
| 282 | |
| 283 | /* Subtract input_len from the length of the default keystroke |
| 284 | * buffer, and allocate the keystroke buffer input so that it |
| 285 | * has enough room for input_len keystrokes. */ |
| 286 | key_buffer_len -= input_len; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 287 | input = (int *)nmalloc(input_len * sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 288 | |
| 289 | /* Copy input_len characters from the beginning of the default |
| 290 | * keystroke buffer into input. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 291 | memcpy(input, key_buffer, input_len * sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 292 | |
| 293 | /* If the default keystroke buffer is empty, mark it as such. */ |
| 294 | if (key_buffer_len == 0) { |
| 295 | free(key_buffer); |
| 296 | key_buffer = NULL; |
| 297 | /* If the default keystroke buffer isn't empty, move its |
David Lawrence Ramsey | 1c367b6 | 2005-09-04 03:29:47 +0000 | [diff] [blame] | 298 | * beginning forward far enough so that the keystrokes in input are |
| 299 | * no longer at its beginning. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 300 | } else { |
| 301 | memmove(key_buffer, key_buffer + input_len, key_buffer_len * |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 302 | sizeof(int)); |
| 303 | key_buffer = (int *)nrealloc(key_buffer, key_buffer_len * |
| 304 | sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | return input; |
| 308 | } |
| 309 | |
| 310 | /* Read in a single character. If it's ignored, swallow it and go on. |
| 311 | * Otherwise, try to translate it from ASCII, meta key sequences, escape |
| 312 | * sequences, and/or extended keypad values. Set meta_key to TRUE when |
| 313 | * we get a meta key sequence, and set func_key to TRUE when we get an |
| 314 | * extended keypad value. Supported extended keypad values consist of |
| 315 | * [arrow key], Ctrl-[arrow key], Shift-[arrow key], Enter, Backspace, |
| 316 | * the editing keypad (Insert, Delete, Home, End, PageUp, and PageDown), |
| 317 | * the function keypad (F1-F16), and the numeric keypad with NumLock |
| 318 | * off. Assume nodelay(win) is FALSE. */ |
| 319 | int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key) |
| 320 | { |
| 321 | int kbinput; |
| 322 | |
| 323 | /* Read in a character and interpret it. Continue doing this until |
| 324 | * we get a recognized value or sequence. */ |
| 325 | while ((kbinput = parse_kbinput(win, meta_key, func_key |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 326 | #ifndef NANO_TINY |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 327 | , FALSE |
| 328 | #endif |
| 329 | )) == ERR); |
| 330 | |
| 331 | return kbinput; |
| 332 | } |
| 333 | |
| 334 | /* Translate ASCII characters, extended keypad values, and escape |
| 335 | * sequences into their corresponding key values. Set meta_key to TRUE |
| 336 | * when we get a meta key sequence, and set func_key to TRUE when we get |
| 337 | * a function key. Assume nodelay(win) is FALSE. */ |
| 338 | int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 339 | #ifndef NANO_TINY |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 340 | , bool reset |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 341 | #endif |
| 342 | ) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 343 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 344 | { |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 345 | static int escapes = 0, byte_digits = 0; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 346 | int *kbinput, retval = ERR; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 347 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 348 | #ifndef NANO_TINY |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 349 | if (reset) { |
| 350 | escapes = 0; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 351 | byte_digits = 0; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 352 | return ERR; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 353 | } |
David Lawrence Ramsey | 1b1e8b6 | 2005-01-02 23:35:19 +0000 | [diff] [blame] | 354 | #endif |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 355 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 356 | *meta_key = FALSE; |
| 357 | *func_key = FALSE; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 358 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 359 | /* Read in a character. */ |
| 360 | while ((kbinput = get_input(win, 1)) == NULL); |
| 361 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 362 | switch (*kbinput) { |
| 363 | case ERR: |
| 364 | break; |
| 365 | case NANO_CONTROL_3: |
| 366 | /* Increment the escape counter. */ |
| 367 | escapes++; |
| 368 | switch (escapes) { |
| 369 | case 1: |
| 370 | /* One escape: wait for more input. */ |
| 371 | case 2: |
| 372 | /* Two escapes: wait for more input. */ |
| 373 | break; |
| 374 | default: |
| 375 | /* More than two escapes: reset the escape counter |
| 376 | * and wait for more input. */ |
| 377 | escapes = 0; |
| 378 | } |
| 379 | break; |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 380 | #if !defined(NANO_TINY) && defined(KEY_RESIZE) |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 381 | /* Since we don't change the default SIGWINCH handler when |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 382 | * NANO_TINY is defined, KEY_RESIZE is never generated. Also, |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 383 | * Slang and SunOS 5.7-5.9 don't support KEY_RESIZE. */ |
| 384 | case KEY_RESIZE: |
| 385 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 386 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 387 | #ifdef PDCURSES |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 388 | case KEY_SHIFT_L: |
| 389 | case KEY_SHIFT_R: |
| 390 | case KEY_CONTROL_L: |
| 391 | case KEY_CONTROL_R: |
| 392 | case KEY_ALT_L: |
| 393 | case KEY_ALT_R: |
| 394 | break; |
David Lawrence Ramsey | d897445 | 2004-06-04 22:28:55 +0000 | [diff] [blame] | 395 | #endif |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 396 | default: |
| 397 | switch (escapes) { |
| 398 | case 0: |
| 399 | switch (*kbinput) { |
| 400 | case NANO_CONTROL_8: |
| 401 | retval = ISSET(REBIND_DELETE) ? |
| 402 | NANO_DELETE_KEY : NANO_BACKSPACE_KEY; |
| 403 | break; |
| 404 | case KEY_DOWN: |
| 405 | retval = NANO_NEXTLINE_KEY; |
| 406 | break; |
| 407 | case KEY_UP: |
| 408 | retval = NANO_PREVLINE_KEY; |
| 409 | break; |
| 410 | case KEY_LEFT: |
| 411 | retval = NANO_BACK_KEY; |
| 412 | break; |
| 413 | case KEY_RIGHT: |
| 414 | retval = NANO_FORWARD_KEY; |
| 415 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 416 | #ifdef KEY_HOME |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 417 | /* HP-UX 10 and 11 don't support KEY_HOME. */ |
| 418 | case KEY_HOME: |
| 419 | retval = NANO_HOME_KEY; |
| 420 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 421 | #endif |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 422 | case KEY_BACKSPACE: |
| 423 | retval = NANO_BACKSPACE_KEY; |
| 424 | break; |
| 425 | case KEY_DC: |
| 426 | retval = ISSET(REBIND_DELETE) ? |
| 427 | NANO_BACKSPACE_KEY : NANO_DELETE_KEY; |
| 428 | break; |
| 429 | case KEY_IC: |
| 430 | retval = NANO_INSERTFILE_KEY; |
| 431 | break; |
| 432 | case KEY_NPAGE: |
| 433 | retval = NANO_NEXTPAGE_KEY; |
| 434 | break; |
| 435 | case KEY_PPAGE: |
| 436 | retval = NANO_PREVPAGE_KEY; |
| 437 | break; |
| 438 | case KEY_ENTER: |
| 439 | retval = NANO_ENTER_KEY; |
| 440 | break; |
| 441 | case KEY_A1: /* Home (7) on numeric keypad |
| 442 | * with NumLock off. */ |
| 443 | retval = NANO_HOME_KEY; |
| 444 | break; |
| 445 | case KEY_A3: /* PageUp (9) on numeric keypad |
| 446 | * with NumLock off. */ |
| 447 | retval = NANO_PREVPAGE_KEY; |
| 448 | break; |
| 449 | case KEY_B2: /* Center (5) on numeric keypad |
| 450 | * with NumLock off. */ |
| 451 | break; |
| 452 | case KEY_C1: /* End (1) on numeric keypad |
| 453 | * with NumLock off. */ |
| 454 | retval = NANO_END_KEY; |
| 455 | break; |
| 456 | case KEY_C3: /* PageDown (4) on numeric |
| 457 | * keypad with NumLock off. */ |
| 458 | retval = NANO_NEXTPAGE_KEY; |
| 459 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 460 | #ifdef KEY_BEG |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 461 | /* Slang doesn't support KEY_BEG. */ |
| 462 | case KEY_BEG: /* Center (5) on numeric keypad |
| 463 | * with NumLock off. */ |
| 464 | break; |
David Lawrence Ramsey | 16eb518 | 2004-06-03 20:26:12 +0000 | [diff] [blame] | 465 | #endif |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 466 | #ifdef KEY_END |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 467 | /* HP-UX 10 and 11 don't support KEY_END. */ |
| 468 | case KEY_END: |
| 469 | retval = NANO_END_KEY; |
| 470 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 471 | #endif |
David Lawrence Ramsey | 475c402 | 2006-01-30 01:32:41 +0000 | [diff] [blame^] | 472 | #ifdef KEY_SBEG |
| 473 | /* Slang doesn't support KEY_SBEG. */ |
| 474 | case KEY_SBEG: /* Center (5) on numeric keypad |
| 475 | * with NumLock off. */ |
| 476 | break; |
| 477 | #endif |
| 478 | #ifdef KEY_SDC |
| 479 | /* Slang doesn't support KEY_SDC. */ |
| 480 | case KEY_SDC: |
| 481 | retval = NANO_DELETE_KEY; |
| 482 | break; |
| 483 | #endif |
| 484 | #ifdef KEY_SEND |
| 485 | /* HP-UX 10 and 11 don't support KEY_SEND. */ |
| 486 | case KEY_SEND: |
| 487 | retval = NANO_END_KEY; |
| 488 | break; |
| 489 | #endif |
| 490 | #ifdef KEY_SHOME |
| 491 | /* HP-UX 10 and 11 and Slang don't support |
| 492 | * KEY_SHOME. */ |
| 493 | case KEY_SHOME: |
| 494 | retval = NANO_HOME_KEY; |
| 495 | break; |
| 496 | #endif |
| 497 | #ifdef KEY_SIC |
| 498 | /* Slang doesn't support KEY_SIC. */ |
| 499 | case KEY_SIC: |
| 500 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 501 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 502 | #endif |
| 503 | #ifdef KEY_SLEFT |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 504 | /* Slang doesn't support KEY_SLEFT. */ |
| 505 | case KEY_SLEFT: |
| 506 | retval = NANO_BACK_KEY; |
| 507 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 508 | #endif |
| 509 | #ifdef KEY_SRIGHT |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 510 | /* Slang doesn't support KEY_SRIGHT. */ |
| 511 | case KEY_SRIGHT: |
| 512 | retval = NANO_FORWARD_KEY; |
| 513 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 514 | #endif |
David Lawrence Ramsey | 475c402 | 2006-01-30 01:32:41 +0000 | [diff] [blame^] | 515 | #ifdef KEY_SSUSPEND |
| 516 | /* Slang doesn't support KEY_SSUSPEND. */ |
| 517 | case KEY_SSUSPEND: |
| 518 | retval = NANO_SUSPEND_KEY; |
| 519 | break; |
| 520 | #endif |
| 521 | #ifdef KEY_SUSPEND |
| 522 | /* Slang doesn't support KEY_SUSPEND. */ |
| 523 | case KEY_SUSPEND: |
| 524 | retval = NANO_SUSPEND_KEY; |
| 525 | break; |
| 526 | #endif |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 527 | default: |
| 528 | retval = *kbinput; |
| 529 | break; |
| 530 | } |
| 531 | break; |
| 532 | case 1: |
| 533 | /* One escape followed by a non-escape: escape |
| 534 | * sequence mode. Reset the escape counter. If |
| 535 | * there aren't any other keys waiting, we have a |
| 536 | * meta key sequence, so set meta_key to TRUE and |
| 537 | * save the lowercase version of the non-escape |
| 538 | * character as the result. If there are other keys |
| 539 | * waiting, we have a true escape sequence, so |
| 540 | * interpret it. */ |
| 541 | escapes = 0; |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 542 | if (get_key_buffer_len() == 0) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 543 | *meta_key = TRUE; |
| 544 | retval = tolower(*kbinput); |
| 545 | } else { |
| 546 | int *seq; |
| 547 | size_t seq_len; |
| 548 | bool ignore_seq; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 549 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 550 | /* Put back the non-escape character, get the |
| 551 | * complete escape sequence, translate the |
| 552 | * sequence into its corresponding key value, |
| 553 | * and save that as the result. */ |
| 554 | unget_input(kbinput, 1); |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 555 | seq_len = get_key_buffer_len(); |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 556 | seq = get_input(NULL, seq_len); |
| 557 | retval = get_escape_seq_kbinput(seq, seq_len, |
| 558 | &ignore_seq); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 559 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 560 | /* If the escape sequence is unrecognized and |
| 561 | * not ignored, put back all of its characters |
| 562 | * except for the initial escape. */ |
| 563 | if (retval == ERR && !ignore_seq) |
| 564 | unget_input(seq, seq_len); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 565 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 566 | free(seq); |
| 567 | } |
| 568 | break; |
| 569 | case 2: |
| 570 | /* Two escapes followed by one or more decimal |
David Lawrence Ramsey | 38f70a5 | 2005-07-19 18:46:02 +0000 | [diff] [blame] | 571 | * digits: byte sequence mode. If the byte |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 572 | * sequence's range is limited to 2XX (the first |
| 573 | * digit is in the '0' to '2' range and it's the |
| 574 | * first digit, or it's in the '0' to '9' range and |
| 575 | * it's not the first digit), increment the byte |
| 576 | * sequence counter and interpret the digit. If the |
| 577 | * byte sequence's range is not limited to 2XX, fall |
| 578 | * through. */ |
| 579 | if (('0' <= *kbinput && *kbinput <= '6' && |
| 580 | byte_digits == 0) || ('0' <= *kbinput && |
| 581 | *kbinput <= '9' && byte_digits > 0)) { |
| 582 | int byte; |
David Lawrence Ramsey | 95a0224 | 2004-12-06 04:14:42 +0000 | [diff] [blame] | 583 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 584 | byte_digits++; |
| 585 | byte = get_byte_kbinput(*kbinput |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 586 | #ifndef NANO_TINY |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 587 | , FALSE |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 588 | #endif |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 589 | ); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 590 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 591 | if (byte != ERR) { |
David Lawrence Ramsey | ce9d299 | 2005-06-14 23:38:08 +0000 | [diff] [blame] | 592 | char *byte_mb; |
| 593 | int byte_mb_len, *seq, i; |
| 594 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 595 | /* If we've read in a complete byte |
| 596 | * sequence, reset the byte sequence counter |
| 597 | * and the escape counter, and put back the |
| 598 | * corresponding byte value. */ |
| 599 | byte_digits = 0; |
| 600 | escapes = 0; |
| 601 | |
David Lawrence Ramsey | ce9d299 | 2005-06-14 23:38:08 +0000 | [diff] [blame] | 602 | /* Put back the multibyte equivalent of the |
| 603 | * byte value. */ |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 604 | byte_mb = make_mbchar((long)byte, |
| 605 | &byte_mb_len); |
David Lawrence Ramsey | ce9d299 | 2005-06-14 23:38:08 +0000 | [diff] [blame] | 606 | |
| 607 | seq = (int *)nmalloc(byte_mb_len * |
| 608 | sizeof(int)); |
| 609 | |
| 610 | for (i = 0; i < byte_mb_len; i++) |
| 611 | seq[i] = (unsigned char)byte_mb[i]; |
| 612 | |
| 613 | unget_input(seq, byte_mb_len); |
| 614 | |
| 615 | free(byte_mb); |
| 616 | free(seq); |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 617 | } |
| 618 | } else { |
| 619 | /* Reset the escape counter. */ |
| 620 | escapes = 0; |
| 621 | if (byte_digits == 0) |
| 622 | /* Two escapes followed by a non-decimal |
| 623 | * digit or a decimal digit that would |
| 624 | * create a byte sequence greater than 2XX, |
| 625 | * and we're not in the middle of a byte |
| 626 | * sequence: control character sequence |
| 627 | * mode. Interpret the control sequence and |
| 628 | * save the corresponding control character |
| 629 | * as the result. */ |
| 630 | retval = get_control_kbinput(*kbinput); |
| 631 | else { |
| 632 | /* If we're in the middle of a byte |
| 633 | * sequence, reset the byte sequence counter |
| 634 | * and save the character we got as the |
| 635 | * result. */ |
| 636 | byte_digits = 0; |
| 637 | retval = *kbinput; |
| 638 | } |
| 639 | } |
| 640 | break; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /* If we have a result and it's an extended keypad value (i.e, a |
| 645 | * value outside of byte range), set func_key to TRUE. */ |
| 646 | if (retval != ERR) |
| 647 | *func_key = !is_byte(retval); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 648 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 649 | #ifdef DEBUG |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 650 | 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] | 651 | #endif |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 652 | |
| 653 | /* Return the result. */ |
| 654 | return retval; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 655 | } |
| 656 | |
David Lawrence Ramsey | 58f6d83 | 2004-01-27 07:12:47 +0000 | [diff] [blame] | 657 | /* Translate escape sequences, most of which correspond to extended |
David Lawrence Ramsey | 832db76 | 2004-11-27 23:28:39 +0000 | [diff] [blame] | 658 | * keypad values, into their corresponding key values. These sequences |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 659 | * are generated when the keypad doesn't support the needed keys. If |
| 660 | * the escape sequence is recognized but we want to ignore it, return |
| 661 | * ERR and set ignore_seq to TRUE; if it's unrecognized, return ERR and |
| 662 | * set ignore_seq to FALSE. Assume that Escape has already been read |
| 663 | * in. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 664 | 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] | 665 | *ignore_seq) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 666 | { |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 667 | int retval = ERR; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 668 | |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 669 | *ignore_seq = FALSE; |
| 670 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 671 | if (seq_len > 1) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 672 | switch (seq[0]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 673 | case 'O': |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 674 | switch (seq[1]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 675 | case '2': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 676 | if (seq_len >= 3) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 677 | switch (seq[2]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 678 | case 'P': /* Esc O 2 P == F13 on |
| 679 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 680 | retval = KEY_F(13); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 681 | break; |
| 682 | case 'Q': /* Esc O 2 Q == F14 on |
| 683 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 684 | retval = KEY_F(14); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 685 | break; |
David Lawrence Ramsey | 8381fdd | 2004-11-01 22:40:02 +0000 | [diff] [blame] | 686 | case 'R': /* Esc O 2 R == F15 on |
| 687 | * xterm. */ |
| 688 | retval = KEY_F(15); |
| 689 | break; |
| 690 | case 'S': /* Esc O 2 S == F16 on |
| 691 | * xterm. */ |
| 692 | retval = KEY_F(16); |
| 693 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 697 | case 'A': /* Esc O A == Up on VT100/VT320/xterm. */ |
| 698 | case 'B': /* Esc O B == Down on |
| 699 | * VT100/VT320/xterm. */ |
| 700 | case 'C': /* Esc O C == Right on |
| 701 | * VT100/VT320/xterm. */ |
| 702 | case 'D': /* Esc O D == Left on |
| 703 | * VT100/VT320/xterm. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 704 | retval = get_escape_seq_abcd(seq[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 705 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 706 | case 'E': /* Esc O E == Center (5) on numeric keypad |
| 707 | * with NumLock off on xterm. */ |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 708 | *ignore_seq = TRUE; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 709 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 710 | case 'F': /* Esc O F == End on xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 711 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 712 | break; |
| 713 | case 'H': /* Esc O H == Home on xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 714 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 715 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 716 | case 'M': /* Esc O M == Enter on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 717 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 718 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 719 | retval = NANO_ENTER_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 720 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 721 | case 'P': /* Esc O P == F1 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 722 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 723 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 724 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 725 | case 'Q': /* Esc O Q == F2 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 726 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 727 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 728 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 729 | case 'R': /* Esc O R == F3 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 730 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 731 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 732 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 733 | case 'S': /* Esc O S == F4 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 734 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 735 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 736 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 737 | case 'T': /* Esc O T == F5 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 738 | retval = KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 739 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 740 | case 'U': /* Esc O U == F6 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 741 | retval = KEY_F(6); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 742 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 743 | case 'V': /* Esc O V == F7 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 744 | retval = KEY_F(7); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 745 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 746 | case 'W': /* Esc O W == F8 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 747 | retval = KEY_F(8); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 748 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 749 | case 'X': /* Esc O X == F9 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 750 | retval = KEY_F(9); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 751 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 752 | case 'Y': /* Esc O Y == F10 on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 753 | retval = KEY_F(10); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 754 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 755 | case 'a': /* Esc O a == Ctrl-Up on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 756 | case 'b': /* Esc O b == Ctrl-Down on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 757 | case 'c': /* Esc O c == Ctrl-Right on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 758 | case 'd': /* Esc O d == Ctrl-Left on rxvt. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 759 | retval = get_escape_seq_abcd(seq[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 760 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 761 | case 'j': /* Esc O j == '*' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 762 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 763 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 764 | retval = '*'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 765 | break; |
| 766 | case 'k': /* Esc O k == '+' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 767 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 768 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 769 | retval = '+'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 770 | break; |
| 771 | case 'l': /* Esc O l == ',' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 772 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 773 | * rxvt. */ |
David Lawrence Ramsey | 8f36d09 | 2005-09-24 19:42:48 +0000 | [diff] [blame] | 774 | retval = ','; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 775 | break; |
| 776 | case 'm': /* Esc O m == '-' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 777 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 778 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 779 | retval = '-'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 780 | break; |
| 781 | case 'n': /* Esc O n == Delete (.) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 782 | * with NumLock off on VT100/VT220/VT320/ |
| 783 | * xterm/rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 784 | retval = NANO_DELETE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 785 | break; |
| 786 | case 'o': /* Esc O o == '/' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 787 | * NumLock off on VT100/VT220/VT320/xterm/ |
| 788 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 789 | retval = '/'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 790 | break; |
| 791 | case 'p': /* Esc O p == Insert (0) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 792 | * with NumLock off on VT100/VT220/VT320/ |
| 793 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 794 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 795 | break; |
| 796 | case 'q': /* Esc O q == End (1) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 797 | * with NumLock off on VT100/VT220/VT320/ |
| 798 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 799 | retval = NANO_END_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 800 | break; |
| 801 | case 'r': /* Esc O r == Down (2) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 802 | * with NumLock off on VT100/VT220/VT320/ |
| 803 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 804 | retval = NANO_NEXTLINE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 805 | break; |
| 806 | case 's': /* Esc O s == PageDown (3) on numeric |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 807 | * keypad with NumLock off on VT100/VT220/ |
| 808 | * VT320/rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 809 | retval = NANO_NEXTPAGE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 810 | break; |
| 811 | case 't': /* Esc O t == Left (4) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 812 | * with NumLock off on VT100/VT220/VT320/ |
| 813 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 814 | retval = NANO_BACK_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 815 | break; |
| 816 | case 'u': /* Esc O u == Center (5) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 817 | * with NumLock off on VT100/VT220/VT320/ |
| 818 | * rxvt/Eterm. */ |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 819 | *ignore_seq = TRUE; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 820 | break; |
| 821 | case 'v': /* Esc O v == Right (6) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 822 | * with NumLock off on VT100/VT220/VT320/ |
| 823 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 824 | retval = NANO_FORWARD_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 825 | break; |
| 826 | case 'w': /* Esc O w == Home (7) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 827 | * with NumLock off on VT100/VT220/VT320/ |
| 828 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 829 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 830 | break; |
| 831 | case 'x': /* Esc O x == Up (8) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 832 | * with NumLock off on VT100/VT220/VT320/ |
| 833 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 834 | retval = NANO_PREVLINE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 835 | break; |
| 836 | case 'y': /* Esc O y == PageUp (9) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 837 | * with NumLock off on VT100/VT220/VT320/ |
| 838 | * rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 839 | retval = NANO_PREVPAGE_KEY; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 840 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 841 | } |
| 842 | break; |
| 843 | case 'o': |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 844 | switch (seq[1]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 845 | case 'a': /* Esc o a == Ctrl-Up on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 846 | case 'b': /* Esc o b == Ctrl-Down on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 847 | case 'c': /* Esc o c == Ctrl-Right on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 848 | case 'd': /* Esc o d == Ctrl-Left on Eterm. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 849 | retval = get_escape_seq_abcd(seq[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 850 | break; |
| 851 | } |
| 852 | break; |
| 853 | case '[': |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 854 | switch (seq[1]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 855 | case '1': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 856 | if (seq_len >= 3) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 857 | switch (seq[2]) { |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 858 | case '1': /* Esc [ 1 1 ~ == F1 on rxvt/ |
| 859 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 860 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 861 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 862 | case '2': /* Esc [ 1 2 ~ == F2 on rxvt/ |
| 863 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 864 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 865 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 866 | case '3': /* Esc [ 1 3 ~ == F3 on rxvt/ |
| 867 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 868 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 869 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 870 | case '4': /* Esc [ 1 4 ~ == F4 on rxvt/ |
| 871 | * Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 872 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 873 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 874 | case '5': /* Esc [ 1 5 ~ == F5 on xterm/ |
| 875 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 876 | retval = KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 877 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 878 | case '7': /* Esc [ 1 7 ~ == F6 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 879 | * VT220/VT320/Linux console/ |
| 880 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 881 | retval = KEY_F(6); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 882 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 883 | case '8': /* Esc [ 1 8 ~ == F7 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 884 | * VT220/VT320/Linux console/ |
| 885 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 886 | retval = KEY_F(7); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 887 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 888 | case '9': /* Esc [ 1 9 ~ == F8 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 889 | * VT220/VT320/Linux console/ |
| 890 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 891 | retval = KEY_F(8); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 892 | break; |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 893 | case ';': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 894 | if (seq_len >= 4) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 895 | switch (seq[3]) { |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 896 | case '2': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 897 | if (seq_len >= 5) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 898 | switch (seq[4]) { |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 899 | case 'A': /* Esc [ 1 ; 2 A == Shift-Up on |
| 900 | * xterm. */ |
| 901 | case 'B': /* Esc [ 1 ; 2 B == Shift-Down on |
| 902 | * xterm. */ |
| 903 | case 'C': /* Esc [ 1 ; 2 C == Shift-Right on |
| 904 | * xterm. */ |
| 905 | case 'D': /* Esc [ 1 ; 2 D == Shift-Left on |
| 906 | * xterm. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 907 | retval = get_escape_seq_abcd(seq[4]); |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 908 | break; |
| 909 | } |
| 910 | } |
| 911 | break; |
| 912 | case '5': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 913 | if (seq_len >= 5) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 914 | switch (seq[4]) { |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 915 | case 'A': /* Esc [ 1 ; 5 A == Ctrl-Up on |
| 916 | * xterm. */ |
| 917 | case 'B': /* Esc [ 1 ; 5 B == Ctrl-Down on |
| 918 | * xterm. */ |
| 919 | case 'C': /* Esc [ 1 ; 5 C == Ctrl-Right on |
| 920 | * xterm. */ |
| 921 | case 'D': /* Esc [ 1 ; 5 D == Ctrl-Left on |
| 922 | * xterm. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 923 | retval = get_escape_seq_abcd(seq[4]); |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 924 | break; |
| 925 | } |
| 926 | } |
| 927 | break; |
| 928 | } |
| 929 | } |
| 930 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 931 | default: /* Esc [ 1 ~ == Home on |
| 932 | * VT320/Linux console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 933 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 934 | break; |
| 935 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 936 | } |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 937 | break; |
| 938 | case '2': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 939 | if (seq_len >= 3) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 940 | switch (seq[2]) { |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 941 | case '0': /* Esc [ 2 0 ~ == F9 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 942 | * VT220/VT320/Linux console/ |
| 943 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 944 | retval = KEY_F(9); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 945 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 946 | case '1': /* Esc [ 2 1 ~ == F10 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 947 | * VT220/VT320/Linux console/ |
| 948 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 949 | retval = KEY_F(10); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 950 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 951 | case '3': /* Esc [ 2 3 ~ == F11 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 952 | * VT220/VT320/Linux console/ |
| 953 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 954 | retval = KEY_F(11); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 955 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 956 | case '4': /* Esc [ 2 4 ~ == F12 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 957 | * VT220/VT320/Linux console/ |
| 958 | * xterm/rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 959 | retval = KEY_F(12); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 960 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 961 | case '5': /* Esc [ 2 5 ~ == F13 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 962 | * VT220/VT320/Linux console/ |
| 963 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 964 | retval = KEY_F(13); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 965 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 966 | case '6': /* Esc [ 2 6 ~ == F14 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 967 | * VT220/VT320/Linux console/ |
| 968 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 969 | retval = KEY_F(14); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 970 | break; |
David Lawrence Ramsey | 8381fdd | 2004-11-01 22:40:02 +0000 | [diff] [blame] | 971 | case '8': /* Esc [ 2 8 ~ == F15 on |
| 972 | * VT220/VT320/Linux console/ |
| 973 | * rxvt/Eterm. */ |
| 974 | retval = KEY_F(15); |
| 975 | break; |
| 976 | case '9': /* Esc [ 2 9 ~ == F16 on |
| 977 | * VT220/VT320/Linux console/ |
| 978 | * rxvt/Eterm. */ |
| 979 | retval = KEY_F(16); |
| 980 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 981 | default: /* Esc [ 2 ~ == Insert on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 982 | * VT220/VT320/Linux console/ |
| 983 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 984 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 985 | break; |
| 986 | } |
| 987 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 988 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 989 | case '3': /* Esc [ 3 ~ == Delete on VT220/VT320/ |
| 990 | * Linux console/xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 991 | retval = NANO_DELETE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 992 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 993 | case '4': /* Esc [ 4 ~ == End on VT220/VT320/Linux |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 994 | * console/xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 995 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 996 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 997 | case '5': /* Esc [ 5 ~ == PageUp on VT220/VT320/ |
| 998 | * Linux console/xterm; Esc [ 5 ^ == |
| 999 | * PageUp on Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1000 | retval = NANO_PREVPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1001 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1002 | case '6': /* Esc [ 6 ~ == PageDown on VT220/VT320/ |
| 1003 | * Linux console/xterm; Esc [ 6 ^ == |
| 1004 | * PageDown on Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1005 | retval = NANO_NEXTPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1006 | break; |
| 1007 | case '7': /* Esc [ 7 ~ == Home on rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1008 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1009 | break; |
| 1010 | case '8': /* Esc [ 8 ~ == End on rxvt. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1011 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1012 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1013 | case '9': /* Esc [ 9 == Delete on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1014 | retval = NANO_DELETE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1015 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1016 | case '@': /* Esc [ @ == Insert on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1017 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1018 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1019 | case 'A': /* Esc [ A == Up on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1020 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1021 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1022 | case 'B': /* Esc [ B == Down on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1023 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1024 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1025 | case 'C': /* Esc [ C == Right on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1026 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1027 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1028 | case 'D': /* Esc [ D == Left on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1029 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1030 | * rxvt/Eterm. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1031 | retval = get_escape_seq_abcd(seq[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1032 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 1033 | case 'E': /* Esc [ E == Center (5) on numeric keypad |
| 1034 | * with NumLock off on FreeBSD console. */ |
David Lawrence Ramsey | e65e639 | 2004-06-04 18:18:17 +0000 | [diff] [blame] | 1035 | *ignore_seq = TRUE; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 1036 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1037 | case 'F': /* Esc [ F == End on FreeBSD |
| 1038 | * console/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1039 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1040 | break; |
| 1041 | case 'G': /* Esc [ G == PageDown on FreeBSD |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 1042 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1043 | retval = NANO_NEXTPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1044 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1045 | case 'H': /* Esc [ H == Home on ANSI/VT220/FreeBSD |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1046 | * console/Mach console/Eterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1047 | retval = NANO_HOME_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1048 | break; |
| 1049 | case 'I': /* Esc [ I == PageUp on FreeBSD |
| 1050 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1051 | retval = NANO_PREVPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1052 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1053 | case 'L': /* Esc [ L == Insert on ANSI/FreeBSD |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1054 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1055 | retval = NANO_INSERTFILE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1056 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1057 | case 'M': /* Esc [ M == F1 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1058 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1059 | break; |
| 1060 | case 'N': /* Esc [ N == F2 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1061 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1062 | break; |
| 1063 | case 'O': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1064 | if (seq_len >= 3) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1065 | switch (seq[2]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1066 | case 'P': /* Esc [ O P == F1 on |
| 1067 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1068 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1069 | break; |
| 1070 | case 'Q': /* Esc [ O Q == F2 on |
| 1071 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1072 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1073 | break; |
| 1074 | case 'R': /* Esc [ O R == F3 on |
| 1075 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1076 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1077 | break; |
| 1078 | case 'S': /* Esc [ O S == F4 on |
| 1079 | * xterm. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1080 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1081 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1082 | } |
David Lawrence Ramsey | ec72975 | 2005-09-25 18:42:05 +0000 | [diff] [blame] | 1083 | } else |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1084 | /* Esc [ O == F3 on FreeBSD console. */ |
| 1085 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1086 | break; |
| 1087 | case 'P': /* Esc [ P == F4 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1088 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1089 | break; |
| 1090 | case 'Q': /* Esc [ Q == F5 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1091 | retval = KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1092 | break; |
| 1093 | case 'R': /* Esc [ R == F6 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1094 | retval = KEY_F(6); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1095 | break; |
| 1096 | case 'S': /* Esc [ S == F7 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1097 | retval = KEY_F(7); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1098 | break; |
| 1099 | case 'T': /* Esc [ T == F8 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1100 | retval = KEY_F(8); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1101 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1102 | case 'U': /* Esc [ U == PageDown on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1103 | retval = NANO_NEXTPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1104 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1105 | case 'V': /* Esc [ V == PageUp on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1106 | retval = NANO_PREVPAGE_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1107 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1108 | case 'W': /* Esc [ W == F11 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1109 | retval = KEY_F(11); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1110 | break; |
| 1111 | case 'X': /* Esc [ X == F12 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1112 | retval = KEY_F(12); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1113 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1114 | case 'Y': /* Esc [ Y == End on Mach console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1115 | retval = NANO_END_KEY; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1116 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1117 | case 'Z': /* Esc [ Z == F14 on FreeBSD console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1118 | retval = KEY_F(14); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1119 | break; |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1120 | case 'a': /* Esc [ a == Shift-Up on rxvt/Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1121 | case 'b': /* Esc [ b == Shift-Down on rxvt/Eterm. */ |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1122 | case 'c': /* Esc [ c == Shift-Right on rxvt/ |
| 1123 | * Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1124 | case 'd': /* Esc [ d == Shift-Left on rxvt/Eterm. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1125 | retval = get_escape_seq_abcd(seq[1]); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | case '[': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1128 | if (seq_len >= 3) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1129 | switch (seq[2]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1130 | case 'A': /* Esc [ [ A == F1 on Linux |
| 1131 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1132 | retval = KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1133 | break; |
| 1134 | case 'B': /* Esc [ [ B == F2 on Linux |
| 1135 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1136 | retval = KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1137 | break; |
| 1138 | case 'C': /* Esc [ [ C == F3 on Linux |
| 1139 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1140 | retval = KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1141 | break; |
| 1142 | case 'D': /* Esc [ [ D == F4 on Linux |
| 1143 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1144 | retval = KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1145 | break; |
| 1146 | case 'E': /* Esc [ [ E == F5 on Linux |
| 1147 | * console. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1148 | retval = KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1149 | break; |
| 1150 | } |
| 1151 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1152 | break; |
| 1153 | } |
| 1154 | break; |
| 1155 | } |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1156 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1157 | |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1158 | #ifdef DEBUG |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1159 | 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] | 1160 | #endif |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1161 | |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1162 | return retval; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1165 | /* Return the equivalent arrow key value for the case-insensitive |
David Lawrence Ramsey | b7e5cf6 | 2004-02-07 03:39:48 +0000 | [diff] [blame] | 1166 | * 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] | 1167 | * to many escape sequences. */ |
| 1168 | int get_escape_seq_abcd(int kbinput) |
| 1169 | { |
| 1170 | switch (tolower(kbinput)) { |
| 1171 | case 'a': |
| 1172 | return NANO_PREVLINE_KEY; |
| 1173 | case 'b': |
| 1174 | return NANO_NEXTLINE_KEY; |
| 1175 | case 'c': |
| 1176 | return NANO_FORWARD_KEY; |
| 1177 | case 'd': |
| 1178 | return NANO_BACK_KEY; |
| 1179 | default: |
| 1180 | return ERR; |
| 1181 | } |
| 1182 | } |
| 1183 | |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1184 | /* Translate a byte sequence: turn a three-digit decimal number from |
| 1185 | * 000 to 255 into its corresponding byte value. */ |
| 1186 | int get_byte_kbinput(int kbinput |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1187 | #ifndef NANO_TINY |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1188 | , bool reset |
| 1189 | #endif |
| 1190 | ) |
| 1191 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1192 | static int byte_digits = 0, byte = 0; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1193 | int retval = ERR; |
| 1194 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1195 | #ifndef NANO_TINY |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1196 | if (reset) { |
| 1197 | byte_digits = 0; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1198 | byte = 0; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1199 | return ERR; |
| 1200 | } |
| 1201 | #endif |
| 1202 | |
| 1203 | /* Increment the byte digit counter. */ |
| 1204 | byte_digits++; |
| 1205 | |
| 1206 | switch (byte_digits) { |
| 1207 | case 1: |
| 1208 | /* One digit: reset the byte sequence holder and add the |
| 1209 | * digit we got to the 100's position of the byte sequence |
| 1210 | * holder. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1211 | byte = 0; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1212 | if ('0' <= kbinput && kbinput <= '2') |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1213 | byte += (kbinput - '0') * 100; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1214 | else |
| 1215 | /* If the character we got isn't a decimal digit, or if |
| 1216 | * it is and it would put the byte sequence out of byte |
| 1217 | * range, save it as the result. */ |
| 1218 | retval = kbinput; |
| 1219 | break; |
| 1220 | case 2: |
| 1221 | /* Two digits: add the digit we got to the 10's position of |
| 1222 | * the byte sequence holder. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1223 | if (('0' <= kbinput && kbinput <= '5') || (byte < 200 && |
| 1224 | '6' <= kbinput && kbinput <= '9')) |
| 1225 | byte += (kbinput - '0') * 10; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1226 | else |
| 1227 | /* If the character we got isn't a decimal digit, or if |
| 1228 | * it is and it would put the byte sequence out of byte |
| 1229 | * range, save it as the result. */ |
| 1230 | retval = kbinput; |
| 1231 | break; |
| 1232 | case 3: |
| 1233 | /* Three digits: add the digit we got to the 1's position of |
| 1234 | * the byte sequence holder, and save the corresponding word |
| 1235 | * value as the result. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1236 | if (('0' <= kbinput && kbinput <= '5') || (byte < 250 && |
| 1237 | '6' <= kbinput && kbinput <= '9')) { |
| 1238 | byte += (kbinput - '0'); |
| 1239 | retval = byte; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1240 | } else |
| 1241 | /* If the character we got isn't a decimal digit, or if |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1242 | * it is and it would put the byte sequence out of word |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1243 | * range, save it as the result. */ |
| 1244 | retval = kbinput; |
| 1245 | break; |
| 1246 | default: |
| 1247 | /* More than three digits: save the character we got as the |
| 1248 | * result. */ |
| 1249 | retval = kbinput; |
| 1250 | break; |
| 1251 | } |
| 1252 | |
| 1253 | /* If we have a result, reset the byte digit counter and the byte |
| 1254 | * sequence holder. */ |
| 1255 | if (retval != ERR) { |
| 1256 | byte_digits = 0; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1257 | byte = 0; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | #ifdef DEBUG |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1261 | 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] | 1262 | #endif |
| 1263 | |
| 1264 | return retval; |
| 1265 | } |
| 1266 | |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1267 | /* Translate a Unicode sequence: turn a six-digit hexadecimal number |
| 1268 | * from 000000 to 10FFFF (case-insensitive) into its corresponding |
| 1269 | * multibyte value. */ |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 1270 | long get_unicode_kbinput(int kbinput |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1271 | #ifndef NANO_TINY |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1272 | , bool reset |
| 1273 | #endif |
| 1274 | ) |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1275 | { |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 1276 | static int uni_digits = 0; |
| 1277 | static long uni = 0; |
| 1278 | long retval = ERR; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1279 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1280 | #ifndef NANO_TINY |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1281 | if (reset) { |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1282 | uni_digits = 0; |
| 1283 | uni = 0; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1284 | return ERR; |
| 1285 | } |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1286 | #endif |
| 1287 | |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1288 | /* Increment the Unicode digit counter. */ |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1289 | uni_digits++; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1290 | |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1291 | switch (uni_digits) { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1292 | case 1: |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1293 | /* One digit: reset the Unicode sequence holder and add the |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1294 | * digit we got to the 0x100000's position of the Unicode |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1295 | * sequence holder. */ |
| 1296 | uni = 0; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1297 | if ('0' <= kbinput && kbinput <= '1') |
| 1298 | uni += (kbinput - '0') * 0x100000; |
| 1299 | else |
| 1300 | /* If the character we got isn't a hexadecimal digit, or |
| 1301 | * if it is and it would put the Unicode sequence out of |
| 1302 | * valid range, save it as the result. */ |
| 1303 | retval = kbinput; |
| 1304 | break; |
| 1305 | case 2: |
| 1306 | /* Two digits: add the digit we got to the 0x10000's |
| 1307 | * position of the Unicode sequence holder. */ |
| 1308 | if ('0' == kbinput || (uni < 0x100000 && '1' <= kbinput && |
| 1309 | kbinput <= '9')) |
| 1310 | uni += (kbinput - '0') * 0x10000; |
| 1311 | else if (uni < 0x100000 && 'a' <= tolower(kbinput) && |
| 1312 | tolower(kbinput) <= 'f') |
| 1313 | uni += (tolower(kbinput) + 10 - 'a') * 0x10000; |
| 1314 | else |
| 1315 | /* If the character we got isn't a hexadecimal digit, or |
| 1316 | * if it is and it would put the Unicode sequence out of |
| 1317 | * valid range, save it as the result. */ |
| 1318 | retval = kbinput; |
| 1319 | break; |
| 1320 | case 3: |
| 1321 | /* Three digits: add the digit we got to the 0x1000's |
| 1322 | * position of the Unicode sequence holder. */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1323 | if ('0' <= kbinput && kbinput <= '9') |
David Lawrence Ramsey | b7bf27a | 2005-08-02 19:54:25 +0000 | [diff] [blame] | 1324 | uni += (kbinput - '0') * 0x1000; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1325 | else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') |
David Lawrence Ramsey | b7bf27a | 2005-08-02 19:54:25 +0000 | [diff] [blame] | 1326 | uni += (tolower(kbinput) + 10 - 'a') * 0x1000; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1327 | else |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1328 | /* If the character we got isn't a hexadecimal digit, or |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1329 | * if it is and it would put the Unicode sequence out of |
| 1330 | * valid range, save it as the result. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1331 | retval = kbinput; |
| 1332 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1333 | case 4: |
| 1334 | /* Four digits: add the digit we got to the 0x100's position |
David Lawrence Ramsey | b7bf27a | 2005-08-02 19:54:25 +0000 | [diff] [blame] | 1335 | * of the Unicode sequence holder. */ |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1336 | if ('0' <= kbinput && kbinput <= '9') |
David Lawrence Ramsey | b7bf27a | 2005-08-02 19:54:25 +0000 | [diff] [blame] | 1337 | uni += (kbinput - '0') * 0x100; |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1338 | else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') |
David Lawrence Ramsey | b7bf27a | 2005-08-02 19:54:25 +0000 | [diff] [blame] | 1339 | uni += (tolower(kbinput) + 10 - 'a') * 0x100; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1340 | else |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1341 | /* If the character we got isn't a hexadecimal digit, or |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1342 | * if it is and it would put the Unicode sequence out of |
| 1343 | * valid range, save it as the result. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1344 | retval = kbinput; |
| 1345 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1346 | case 5: |
| 1347 | /* Five digits: add the digit we got to the 0x10's position |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1348 | * of the Unicode sequence holder. */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1349 | if ('0' <= kbinput && kbinput <= '9') |
David Lawrence Ramsey | b7bf27a | 2005-08-02 19:54:25 +0000 | [diff] [blame] | 1350 | uni += (kbinput - '0') * 0x10; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1351 | else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') |
David Lawrence Ramsey | b7bf27a | 2005-08-02 19:54:25 +0000 | [diff] [blame] | 1352 | uni += (tolower(kbinput) + 10 - 'a') * 0x10; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1353 | else |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1354 | /* If the character we got isn't a hexadecimal digit, or |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1355 | * if it is and it would put the Unicode sequence out of |
| 1356 | * valid range, save it as the result. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1357 | retval = kbinput; |
| 1358 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1359 | case 6: |
| 1360 | /* Six digits: add the digit we got to the 1's position of |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1361 | * the Unicode sequence holder, and save the corresponding |
| 1362 | * Unicode value as the result. */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1363 | if ('0' <= kbinput && kbinput <= '9') { |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1364 | uni += (kbinput - '0'); |
| 1365 | retval = uni; |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1366 | } else if ('a' <= tolower(kbinput) && tolower(kbinput) <= |
| 1367 | 'f') { |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1368 | uni += (tolower(kbinput) + 10 - 'a'); |
| 1369 | retval = uni; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1370 | } else |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1371 | /* If the character we got isn't a hexadecimal digit, or |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1372 | * if it is and it would put the Unicode sequence out of |
| 1373 | * valid range, save it as the result. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1374 | retval = kbinput; |
| 1375 | break; |
| 1376 | default: |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1377 | /* More than six digits: save the character we got as the |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1378 | * result. */ |
| 1379 | retval = kbinput; |
| 1380 | break; |
| 1381 | } |
| 1382 | |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1383 | /* If we have a result, reset the Unicode digit counter and the |
| 1384 | * Unicode sequence holder. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1385 | if (retval != ERR) { |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1386 | uni_digits = 0; |
| 1387 | uni = 0; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | #ifdef DEBUG |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 1391 | fprintf(stderr, "get_unicode_kbinput(): kbinput = %d, uni_digits = %d, uni = %ld, retval = %ld\n", kbinput, uni_digits, uni, retval); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1392 | #endif |
| 1393 | |
| 1394 | return retval; |
| 1395 | } |
| 1396 | |
| 1397 | /* Translate a control character sequence: turn an ASCII non-control |
| 1398 | * character into its corresponding control character. */ |
| 1399 | int get_control_kbinput(int kbinput) |
| 1400 | { |
| 1401 | int retval; |
| 1402 | |
| 1403 | /* Ctrl-2 (Ctrl-Space, Ctrl-@, Ctrl-`) */ |
| 1404 | if (kbinput == '2' || kbinput == ' ' || kbinput == '@' || |
| 1405 | kbinput == '`') |
| 1406 | retval = NANO_CONTROL_SPACE; |
| 1407 | /* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-_) */ |
| 1408 | else if ('3' <= kbinput && kbinput <= '7') |
| 1409 | retval = kbinput - 24; |
| 1410 | /* Ctrl-8 (Ctrl-?) */ |
| 1411 | else if (kbinput == '8' || kbinput == '?') |
| 1412 | retval = NANO_CONTROL_8; |
| 1413 | /* Ctrl-A to Ctrl-_ */ |
| 1414 | else if ('A' <= kbinput && kbinput <= '_') |
| 1415 | retval = kbinput - 64; |
| 1416 | /* Ctrl-a to Ctrl-~ */ |
| 1417 | else if ('a' <= kbinput && kbinput <= '~') |
| 1418 | retval = kbinput - 96; |
| 1419 | else |
| 1420 | retval = kbinput; |
| 1421 | |
| 1422 | #ifdef DEBUG |
| 1423 | fprintf(stderr, "get_control_kbinput(): kbinput = %d, retval = %d\n", kbinput, retval); |
| 1424 | #endif |
| 1425 | |
| 1426 | return retval; |
| 1427 | } |
| 1428 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1429 | /* Put the output-formatted characters in output back into the default |
| 1430 | * keystroke buffer, so that they can be parsed and displayed as output |
| 1431 | * again. */ |
| 1432 | void unparse_kbinput(char *output, size_t output_len) |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1433 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1434 | int *input; |
| 1435 | size_t i; |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1436 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1437 | if (output_len == 0) |
| 1438 | return; |
| 1439 | |
| 1440 | input = (int *)nmalloc(output_len * sizeof(int)); |
| 1441 | for (i = 0; i < output_len; i++) |
| 1442 | input[i] = (int)output[i]; |
| 1443 | unget_input(input, output_len); |
| 1444 | free(input); |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1447 | /* 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] | 1448 | * string in kbinput_len. Assume nodelay(win) is FALSE. */ |
| 1449 | int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) |
| 1450 | { |
| 1451 | int *retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1452 | |
| 1453 | /* Turn off flow control characters if necessary so that we can type |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1454 | * them in verbatim, and turn the keypad off if necessary so that we |
| 1455 | * don't get extended keypad values. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1456 | if (ISSET(PRESERVE)) |
| 1457 | disable_flow_control(); |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1458 | if (!ISSET(REBIND_KEYPAD)) |
| 1459 | keypad(win, FALSE); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1460 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1461 | /* Read in a stream of characters and interpret it if possible. */ |
| 1462 | retval = parse_verbatim_kbinput(win, kbinput_len); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1463 | |
| 1464 | /* Turn flow control characters back on if necessary and turn the |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1465 | * keypad back on if necessary now that we're done. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1466 | if (ISSET(PRESERVE)) |
| 1467 | enable_flow_control(); |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1468 | if (!ISSET(REBIND_KEYPAD)) |
| 1469 | keypad(win, TRUE); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1470 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1471 | return retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1474 | /* Read in a stream of all available characters, and return the length |
| 1475 | * of the string in kbinput_len. Translate the first few characters of |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1476 | * the input into the corresponding multibyte value if possible. After |
| 1477 | * that, leave the input as-is. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1478 | int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1479 | { |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 1480 | int *kbinput, *retval; |
| 1481 | long uni; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1482 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1483 | /* Read in the first keystroke. */ |
| 1484 | while ((kbinput = get_input(win, 1)) == NULL); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1485 | |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1486 | /* Check whether the first keystroke is a hexadecimal digit. */ |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1487 | uni = get_unicode_kbinput(*kbinput |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1488 | #ifndef NANO_TINY |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1489 | , FALSE |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1490 | #endif |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1491 | ); |
| 1492 | |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1493 | /* If the first keystroke isn't a hexadecimal digit, put back the |
| 1494 | * first keystroke. */ |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1495 | if (uni != ERR) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1496 | unget_input(kbinput, 1); |
| 1497 | /* Otherwise, read in keystrokes until we have a complete word |
| 1498 | * sequence, and put back the corresponding word value. */ |
| 1499 | else { |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1500 | char *uni_mb; |
| 1501 | int uni_mb_len, *seq, i; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1502 | |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1503 | while (uni == ERR) { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1504 | while ((kbinput = get_input(win, 1)) == NULL); |
David Lawrence Ramsey | 6a2f068 | 2004-12-20 01:13:55 +0000 | [diff] [blame] | 1505 | |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1506 | uni = get_unicode_kbinput(*kbinput |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1507 | #ifndef NANO_TINY |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1508 | , FALSE |
| 1509 | #endif |
| 1510 | ); |
| 1511 | } |
| 1512 | |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1513 | /* Put back the multibyte equivalent of the Unicode value. */ |
| 1514 | uni_mb = make_mbchar(uni, &uni_mb_len); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1515 | |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1516 | seq = (int *)nmalloc(uni_mb_len * sizeof(int)); |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1517 | |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1518 | for (i = 0; i < uni_mb_len; i++) |
| 1519 | seq[i] = (unsigned char)uni_mb[i]; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1520 | |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1521 | unget_input(seq, uni_mb_len); |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1522 | |
| 1523 | free(seq); |
David Lawrence Ramsey | 8c55d21 | 2005-08-04 20:24:26 +0000 | [diff] [blame] | 1524 | free(uni_mb); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1527 | /* 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] | 1528 | * result. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 1529 | *kbinput_len = get_key_buffer_len(); |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1530 | retval = get_input(NULL, *kbinput_len); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1531 | |
| 1532 | return retval; |
| 1533 | } |
| 1534 | |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1535 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1536 | /* Check for a mouse event, and if one's taken place, save the |
| 1537 | * 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] | 1538 | * assuming allow_shortcuts is FALSE, if the shortcut list on the |
| 1539 | * 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] | 1540 | * place on it, figure out which shortcut was clicked and put back the |
| 1541 | * equivalent keystroke(s). Return FALSE if no keystrokes were |
| 1542 | * 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] | 1543 | * already been read in. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1544 | 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] | 1545 | { |
| 1546 | MEVENT mevent; |
| 1547 | |
| 1548 | *mouse_x = -1; |
| 1549 | *mouse_y = -1; |
| 1550 | |
| 1551 | /* First, get the actual mouse event. */ |
| 1552 | if (getmouse(&mevent) == ERR) |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1553 | return FALSE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1554 | |
| 1555 | /* Save the screen coordinates where the mouse event took place. */ |
| 1556 | *mouse_x = mevent.x; |
| 1557 | *mouse_y = mevent.y; |
| 1558 | |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1559 | /* If we're allowing shortcuts, the current shortcut list is being |
| 1560 | * displayed on the last two lines of the screen, and the mouse |
| 1561 | * 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] | 1562 | * was clicked and put back the equivalent keystroke(s) for it. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1563 | if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin, |
| 1564 | *mouse_y, *mouse_x)) { |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1565 | int i, j; |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1566 | size_t currslen; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1567 | /* The number of shortcuts in the current shortcut list. */ |
| 1568 | const shortcut *s = currshortcut; |
| 1569 | /* The actual shortcut we clicked on, starting at the first |
| 1570 | * one in the current shortcut list. */ |
| 1571 | |
| 1572 | /* Get the shortcut lists' length. */ |
| 1573 | if (currshortcut == main_list) |
| 1574 | currslen = MAIN_VISIBLE; |
David Lawrence Ramsey | fe0d366 | 2004-08-26 01:43:16 +0000 | [diff] [blame] | 1575 | else { |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1576 | currslen = length_of_list(currshortcut); |
| 1577 | |
David Lawrence Ramsey | fe0d366 | 2004-08-26 01:43:16 +0000 | [diff] [blame] | 1578 | /* We don't show any more shortcuts than the main list |
| 1579 | * does. */ |
| 1580 | if (currslen > MAIN_VISIBLE) |
| 1581 | currslen = MAIN_VISIBLE; |
| 1582 | } |
| 1583 | |
David Lawrence Ramsey | 0df61f1 | 2005-06-08 20:23:06 +0000 | [diff] [blame] | 1584 | /* Calculate the width of each shortcut in the list. It's the |
| 1585 | * same for all of them. */ |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1586 | if (currslen < 2) |
| 1587 | i = COLS / 6; |
| 1588 | else |
| 1589 | i = COLS / ((currslen / 2) + (currslen % 2)); |
| 1590 | |
David Lawrence Ramsey | 798e67e | 2005-01-28 19:11:51 +0000 | [diff] [blame] | 1591 | /* Calculate the y-coordinate relative to the beginning of |
David Lawrence Ramsey | f726053 | 2005-10-28 17:12:58 +0000 | [diff] [blame] | 1592 | * the shortcut list in bottomwin, i.e, with the sizes of |
| 1593 | * topwin, edit, and the first line of bottomwin subtracted |
| 1594 | * out. */ |
| 1595 | j = *mouse_y - (2 - no_more_space()) - editwinrows - 1; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1596 | |
| 1597 | /* If we're on the statusbar, beyond the end of the shortcut |
| 1598 | * list, or beyond the end of a shortcut on the right side of |
| 1599 | * the screen, don't do anything. */ |
| 1600 | if (j < 0 || (*mouse_x / i) >= currslen) |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1601 | return FALSE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1602 | j = (*mouse_x / i) * 2 + j; |
| 1603 | if (j >= currslen) |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1604 | return FALSE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1605 | |
| 1606 | /* Go through the shortcut list to determine which shortcut was |
| 1607 | * clicked. */ |
| 1608 | for (; j > 0; j--) |
| 1609 | s = s->next; |
| 1610 | |
David Lawrence Ramsey | db6015c | 2004-09-11 21:41:13 +0000 | [diff] [blame] | 1611 | /* And put back the equivalent key. Assume that each shortcut |
| 1612 | * has, at the very least, an equivalent control key, an |
| 1613 | * equivalent primary meta key sequence, or both. */ |
David Lawrence Ramsey | f4a799a | 2005-01-08 06:16:19 +0000 | [diff] [blame] | 1614 | if (s->ctrlval != NANO_NO_KEY) { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1615 | unget_kbinput(s->ctrlval, FALSE, FALSE); |
David Lawrence Ramsey | f4a799a | 2005-01-08 06:16:19 +0000 | [diff] [blame] | 1616 | return TRUE; |
| 1617 | } else if (s->metaval != NANO_NO_KEY) { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1618 | unget_kbinput(s->metaval, TRUE, FALSE); |
David Lawrence Ramsey | f4a799a | 2005-01-08 06:16:19 +0000 | [diff] [blame] | 1619 | return TRUE; |
| 1620 | } |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1621 | } |
David Lawrence Ramsey | ebd0d7c | 2004-07-01 18:59:52 +0000 | [diff] [blame] | 1622 | return FALSE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1623 | } |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1624 | #endif /* !DISABLE_MOUSE */ |
| 1625 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1626 | /* Return the shortcut corresponding to the values of kbinput (the key |
| 1627 | * itself), meta_key (whether the key is a meta sequence), and func_key |
| 1628 | * (whether the key is a function key), if any. The shortcut will be |
| 1629 | * the first one in the list (control key, meta key sequence, function |
| 1630 | * key, other meta key sequence) for the corresponding function. For |
| 1631 | * example, passing in a meta key sequence that corresponds to a |
| 1632 | * function with a control key, a function key, and a meta key sequence |
| 1633 | * will return the control key corresponding to that function. */ |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1634 | const shortcut *get_shortcut(const shortcut *s_list, int *kbinput, bool |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 1635 | *meta_key, bool *func_key) |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1636 | { |
| 1637 | const shortcut *s = s_list; |
| 1638 | size_t slen = length_of_list(s_list); |
| 1639 | |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1640 | #ifdef DEBUG |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1641 | 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] | 1642 | #endif |
| 1643 | |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1644 | /* Check for shortcuts. */ |
| 1645 | for (; slen > 0; slen--) { |
| 1646 | /* We've found a shortcut if: |
| 1647 | * |
| 1648 | * 1. The key exists. |
| 1649 | * 2. The key is a control key in the shortcut list. |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 1650 | * 3. meta_key is TRUE and the key is the primary or |
| 1651 | * miscellaneous meta sequence in the shortcut list. |
| 1652 | * 4. func_key is TRUE and the key is a function key in the |
| 1653 | * shortcut list. */ |
| 1654 | |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1655 | if (*kbinput != NANO_NO_KEY && (*kbinput == s->ctrlval || |
| 1656 | (*meta_key == TRUE && (*kbinput == s->metaval || |
| 1657 | *kbinput == s->miscval)) || (*func_key == TRUE && |
| 1658 | *kbinput == s->funcval))) { |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1659 | break; |
| 1660 | } |
| 1661 | |
| 1662 | s = s->next; |
| 1663 | } |
| 1664 | |
| 1665 | /* Translate the shortcut to either its control key or its meta key |
| 1666 | * equivalent. Assume that the shortcut has an equivalent control |
David Lawrence Ramsey | eb16f43 | 2004-09-27 01:04:50 +0000 | [diff] [blame] | 1667 | * key, an equivalent primary meta key sequence, or both. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1668 | if (slen > 0) { |
| 1669 | if (s->ctrlval != NANO_NO_KEY) { |
| 1670 | *meta_key = FALSE; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1671 | *func_key = FALSE; |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1672 | *kbinput = s->ctrlval; |
David Lawrence Ramsey | f4a799a | 2005-01-08 06:16:19 +0000 | [diff] [blame] | 1673 | return s; |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1674 | } else if (s->metaval != NANO_NO_KEY) { |
| 1675 | *meta_key = TRUE; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1676 | *func_key = FALSE; |
David Lawrence Ramsey | 1483ee3 | 2004-11-29 00:30:07 +0000 | [diff] [blame] | 1677 | *kbinput = s->metaval; |
David Lawrence Ramsey | f4a799a | 2005-01-08 06:16:19 +0000 | [diff] [blame] | 1678 | return s; |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1679 | } |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | return NULL; |
| 1683 | } |
| 1684 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1685 | #ifndef NANO_TINY |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1686 | /* Return the global toggle corresponding to the values of kbinput (the |
| 1687 | * key itself) and meta_key (whether the key is a meta sequence), if |
| 1688 | * any. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1689 | const toggle *get_toggle(int kbinput, bool meta_key) |
| 1690 | { |
| 1691 | const toggle *t = toggles; |
| 1692 | |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1693 | #ifdef DEBUG |
| 1694 | fprintf(stderr, "get_toggle(): kbinput = %d, meta_key = %d\n", kbinput, (int)meta_key); |
| 1695 | #endif |
| 1696 | |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1697 | /* Check for toggles. */ |
| 1698 | for (; t != NULL; t = t->next) { |
| 1699 | /* 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] | 1700 | * the meta key toggle list. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1701 | if (meta_key && kbinput == t->val) |
| 1702 | break; |
| 1703 | } |
| 1704 | |
| 1705 | return t; |
| 1706 | } |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1707 | #endif /* !NANO_TINY */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1708 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1709 | /* Move to (x, y) in win, and display a line of n spaces with the |
| 1710 | * current attributes. */ |
| 1711 | void blank_line(WINDOW *win, int y, int x, int n) |
| 1712 | { |
| 1713 | wmove(win, y, x); |
| 1714 | for (; n > 0; n--) |
| 1715 | waddch(win, ' '); |
| 1716 | } |
| 1717 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1718 | /* Blank the first line of the top portion of the window. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1719 | void blank_titlebar(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1720 | { |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1721 | blank_line(topwin, 0, 0, COLS); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1724 | /* If the MORE_SPACE flag isn't set, blank the second line of the top |
| 1725 | * portion of the window. */ |
David Lawrence Ramsey | 637b8bb | 2005-01-17 05:06:55 +0000 | [diff] [blame] | 1726 | void blank_topbar(void) |
| 1727 | { |
| 1728 | if (!ISSET(MORE_SPACE)) |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1729 | blank_line(topwin, 1, 0, COLS); |
David Lawrence Ramsey | 637b8bb | 2005-01-17 05:06:55 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1732 | /* Blank all the lines of the middle portion of the window, i.e, the |
| 1733 | * edit window. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1734 | void blank_edit(void) |
| 1735 | { |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 1736 | int i; |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 1737 | for (i = 0; i < editwinrows; i++) |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1738 | blank_line(edit, i, 0, COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1741 | /* Blank the first line of the bottom portion of the window. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1742 | void blank_statusbar(void) |
| 1743 | { |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1744 | blank_line(bottomwin, 0, 0, COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1747 | /* If the NO_HELP flag isn't set, blank the last two lines of the bottom |
| 1748 | * portion of the window. */ |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 1749 | void blank_bottombars(void) |
| 1750 | { |
| 1751 | if (!ISSET(NO_HELP)) { |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1752 | blank_line(bottomwin, 1, 0, COLS); |
| 1753 | blank_line(bottomwin, 2, 0, COLS); |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 1754 | } |
| 1755 | } |
| 1756 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1757 | /* Check if the number of keystrokes needed to blank the statusbar has |
| 1758 | * been pressed. If so, blank the statusbar, unless constant cursor |
| 1759 | * position display is on. */ |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 1760 | void check_statusblank(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1761 | { |
David Lawrence Ramsey | bf51aa4 | 2005-06-17 21:52:59 +0000 | [diff] [blame] | 1762 | if (statusblank > 0) |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 1763 | statusblank--; |
David Lawrence Ramsey | bf51aa4 | 2005-06-17 21:52:59 +0000 | [diff] [blame] | 1764 | |
| 1765 | if (statusblank == 0 && !ISSET(CONST_UPDATE)) { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1766 | blank_statusbar(); |
| 1767 | wnoutrefresh(bottomwin); |
| 1768 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 1769 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1773 | /* Convert buf into a string that can be displayed on screen. The |
| 1774 | * caller wants to display buf starting with column start_col, and |
| 1775 | * extending for at most len columns. start_col is zero-based. len is |
| 1776 | * one-based, so len == 0 means you get "" returned. The returned |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1777 | * string is dynamically allocated, and should be freed. If dollars is |
| 1778 | * TRUE, the caller might put "$" at the beginning or end of the line if |
| 1779 | * it's too long. */ |
| 1780 | char *display_string(const char *buf, size_t start_col, size_t len, bool |
| 1781 | dollars) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1782 | { |
| 1783 | size_t start_index; |
David Lawrence Ramsey | 61a7140 | 2004-12-24 15:45:36 +0000 | [diff] [blame] | 1784 | /* Index in buf of the first character shown. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1785 | size_t column; |
David Lawrence Ramsey | 61a7140 | 2004-12-24 15:45:36 +0000 | [diff] [blame] | 1786 | /* Screen column that start_index corresponds to. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1787 | size_t alloc_len; |
| 1788 | /* The length of memory allocated for converted. */ |
| 1789 | char *converted; |
| 1790 | /* The string we return. */ |
| 1791 | size_t index; |
| 1792 | /* Current position in converted. */ |
| 1793 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1794 | char *buf_mb = charalloc(mb_cur_max()); |
| 1795 | int buf_mb_len; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1796 | |
David Lawrence Ramsey | 9dffac9 | 2005-01-05 06:09:34 +0000 | [diff] [blame] | 1797 | /* If dollars is TRUE, make room for the "$" at the end of the |
| 1798 | * line. */ |
| 1799 | if (dollars && len > 0 && strlenpt(buf) > start_col + len) |
| 1800 | len--; |
| 1801 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1802 | if (len == 0) |
| 1803 | return mallocstrcpy(NULL, ""); |
| 1804 | |
| 1805 | start_index = actual_x(buf, start_col); |
| 1806 | column = strnlenpt(buf, start_index); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1807 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1808 | assert(column <= start_col); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1809 | |
David Lawrence Ramsey | c4b854d | 2005-09-20 04:15:33 +0000 | [diff] [blame] | 1810 | /* Allocate enough space for the entire line. */ |
David Lawrence Ramsey | 86b6c3e | 2005-10-04 03:40:41 +0000 | [diff] [blame] | 1811 | alloc_len = (mb_cur_max() * (COLS + 1)); |
David Lawrence Ramsey | bbd63e1 | 2005-01-05 16:59:49 +0000 | [diff] [blame] | 1812 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1813 | converted = charalloc(alloc_len + 1); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1814 | index = 0; |
| 1815 | |
David Lawrence Ramsey | 7f26c73 | 2005-09-05 01:36:47 +0000 | [diff] [blame] | 1816 | if (buf[start_index] != '\t' && (column < start_col || (dollars && |
| 1817 | column > 0))) { |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1818 | /* We don't display all of buf[start_index] since it starts to |
| 1819 | * the left of the screen. */ |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1820 | buf_mb_len = parse_mbchar(buf + start_index, buf_mb, NULL); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1821 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1822 | if (is_cntrl_mbchar(buf_mb)) { |
David Lawrence Ramsey | fe3627d | 2004-12-24 17:52:17 +0000 | [diff] [blame] | 1823 | if (column < start_col) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1824 | char *ctrl_buf_mb = charalloc(mb_cur_max()); |
| 1825 | int ctrl_buf_mb_len, i; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1826 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1827 | ctrl_buf_mb = control_mbrep(buf_mb, ctrl_buf_mb, |
| 1828 | &ctrl_buf_mb_len); |
David Lawrence Ramsey | 6a643cd | 2004-12-27 23:11:59 +0000 | [diff] [blame] | 1829 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1830 | for (i = 0; i < ctrl_buf_mb_len; i++) |
| 1831 | converted[index++] = ctrl_buf_mb[i]; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1832 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1833 | start_col += mbwidth(ctrl_buf_mb); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1834 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1835 | free(ctrl_buf_mb); |
David Lawrence Ramsey | a9b9913 | 2004-12-27 23:35:25 +0000 | [diff] [blame] | 1836 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1837 | start_index += buf_mb_len; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1838 | } |
David Lawrence Ramsey | 956da0d | 2005-01-03 06:56:38 +0000 | [diff] [blame] | 1839 | } |
David Lawrence Ramsey | 7eb30a8 | 2005-07-17 02:40:07 +0000 | [diff] [blame] | 1840 | #ifdef ENABLE_UTF8 |
David Lawrence Ramsey | 7a4aaa5 | 2005-06-16 02:09:57 +0000 | [diff] [blame] | 1841 | else if (ISSET(USE_UTF8) && mbwidth(buf_mb) > 1) { |
David Lawrence Ramsey | 9dffac9 | 2005-01-05 06:09:34 +0000 | [diff] [blame] | 1842 | converted[index++] = ' '; |
David Lawrence Ramsey | a9b9913 | 2004-12-27 23:35:25 +0000 | [diff] [blame] | 1843 | start_col++; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1844 | |
| 1845 | start_index += buf_mb_len; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1846 | } |
David Lawrence Ramsey | 956da0d | 2005-01-03 06:56:38 +0000 | [diff] [blame] | 1847 | #endif |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
David Lawrence Ramsey | 6d594a9 | 2005-01-05 21:43:43 +0000 | [diff] [blame] | 1850 | while (index < alloc_len - 1 && buf[start_index] != '\0') { |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1851 | buf_mb_len = parse_mbchar(buf + start_index, buf_mb, NULL); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1852 | |
David Lawrence Ramsey | 9838a51 | 2005-07-06 19:12:41 +0000 | [diff] [blame] | 1853 | /* If buf contains a tab character, interpret it. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1854 | if (*buf_mb == '\t') { |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1855 | #if !defined(NANO_TINY) && defined(ENABLE_NANORC) |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 1856 | if (ISSET(WHITESPACE_DISPLAY)) { |
| 1857 | int i; |
| 1858 | |
| 1859 | for (i = 0; i < whitespace_len[0]; i++) |
| 1860 | converted[index++] = whitespace[i]; |
| 1861 | } else |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 1862 | #endif |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 1863 | converted[index++] = ' '; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1864 | start_col++; |
David Lawrence Ramsey | c195820 | 2004-12-27 23:21:34 +0000 | [diff] [blame] | 1865 | while (start_col % tabsize != 0) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1866 | converted[index++] = ' '; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1867 | start_col++; |
| 1868 | } |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 1869 | /* If buf contains a control character, interpret it. If buf |
David Lawrence Ramsey | 61f5673 | 2005-07-21 22:12:03 +0000 | [diff] [blame] | 1870 | * contains an invalid multibyte control character, display it |
| 1871 | * as such.*/ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1872 | } else if (is_cntrl_mbchar(buf_mb)) { |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 1873 | char *ctrl_buf_mb = charalloc(mb_cur_max()); |
| 1874 | int ctrl_buf_mb_len, i; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1875 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1876 | converted[index++] = '^'; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1877 | start_col++; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1878 | |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 1879 | ctrl_buf_mb = control_mbrep(buf_mb, ctrl_buf_mb, |
| 1880 | &ctrl_buf_mb_len); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1881 | |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 1882 | for (i = 0; i < ctrl_buf_mb_len; i++) |
| 1883 | converted[index++] = ctrl_buf_mb[i]; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1884 | |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 1885 | start_col += mbwidth(ctrl_buf_mb); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1886 | |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 1887 | free(ctrl_buf_mb); |
David Lawrence Ramsey | 9838a51 | 2005-07-06 19:12:41 +0000 | [diff] [blame] | 1888 | /* If buf contains a space character, interpret it. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1889 | } else if (*buf_mb == ' ') { |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 1890 | #if !defined(NANO_TINY) && defined(ENABLE_NANORC) |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 1891 | if (ISSET(WHITESPACE_DISPLAY)) { |
| 1892 | int i; |
| 1893 | |
| 1894 | for (i = whitespace_len[0]; i < whitespace_len[0] + |
| 1895 | whitespace_len[1]; i++) |
| 1896 | converted[index++] = whitespace[i]; |
| 1897 | } else |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 1898 | #endif |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 1899 | converted[index++] = ' '; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1900 | start_col++; |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1901 | /* If buf contains a non-control character, interpret it. If |
| 1902 | * buf contains an invalid multibyte non-control character, |
| 1903 | * display it as such. */ |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1904 | } else { |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1905 | char *nctrl_buf_mb = charalloc(mb_cur_max()); |
| 1906 | int nctrl_buf_mb_len, i; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1907 | |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1908 | nctrl_buf_mb = mbrep(buf_mb, nctrl_buf_mb, |
| 1909 | &nctrl_buf_mb_len); |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 1910 | |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1911 | for (i = 0; i < nctrl_buf_mb_len; i++) |
| 1912 | converted[index++] = nctrl_buf_mb[i]; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1913 | |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1914 | start_col += mbwidth(nctrl_buf_mb); |
| 1915 | |
| 1916 | free(nctrl_buf_mb); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1919 | start_index += buf_mb_len; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
David Lawrence Ramsey | 6a0d5b8 | 2005-06-13 14:00:22 +0000 | [diff] [blame] | 1922 | free(buf_mb); |
| 1923 | |
David Lawrence Ramsey | 6d594a9 | 2005-01-05 21:43:43 +0000 | [diff] [blame] | 1924 | if (index < alloc_len - 1) |
David Lawrence Ramsey | 0251bdb | 2005-01-05 19:05:04 +0000 | [diff] [blame] | 1925 | converted[index] = '\0'; |
| 1926 | |
| 1927 | /* Make sure converted takes up no more than len columns. */ |
| 1928 | index = actual_x(converted, len); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1929 | null_at(&converted, index); |
David Lawrence Ramsey | 0251bdb | 2005-01-05 19:05:04 +0000 | [diff] [blame] | 1930 | |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1931 | return converted; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1934 | /* Display the path specified in path on the titlebar, along with the |
| 1935 | * current version of nano and whether the current file has been |
| 1936 | * modified. If path is NULL, assume we're in normal editing mode and |
| 1937 | * display the current filename instead. Otherwise, assume we're in the |
| 1938 | * file browser, and don't display whether the current file has been |
| 1939 | * modified. */ |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 1940 | void titlebar(const char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1941 | { |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 1942 | int space = COLS; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1943 | /* The space we have available for display. */ |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 1944 | size_t verlen = strlenpt(VERMSG) + 1; |
| 1945 | /* The length of the version message in columns, plus one for |
| 1946 | * padding. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1947 | const char *prefix; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1948 | /* "DIR:", "File:", or "New Buffer". Goes before filename. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1949 | size_t prefixlen; |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 1950 | /* The length of the prefix in columns, plus one for padding. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1951 | const char *state; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1952 | /* "Modified", "View", or "". Shows the state of this |
| 1953 | * buffer. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1954 | size_t statelen = 0; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1955 | /* The length of the state in columns, or the length of |
David Lawrence Ramsey | 90f772b | 2005-07-11 07:12:33 +0000 | [diff] [blame] | 1956 | * "Modified" if the state is blank. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1957 | char *exppath = NULL; |
| 1958 | /* The file name, expanded for display. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 1959 | bool newfie = FALSE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1960 | /* Do we say "New Buffer"? */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 1961 | bool dots = FALSE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1962 | /* Do we put an ellipsis before the path? */ |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 1963 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 1964 | assert(path != NULL || openfile->filename != NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1965 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1966 | wattron(topwin, A_REVERSE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1967 | blank_titlebar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1968 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 1969 | /* space has to be at least 4: two spaces before the version message, |
| 1970 | * at least one character of the version message, and one space |
| 1971 | * after the version message. */ |
| 1972 | if (space < 4) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1973 | space = 0; |
| 1974 | else { |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 1975 | /* Limit verlen to 1/3 the length of the screen in columns, |
| 1976 | * minus three columns for spaces. */ |
| 1977 | if (verlen > (COLS / 3) - 3) |
| 1978 | verlen = (COLS / 3) - 3; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1979 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1980 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 1981 | if (space >= 4) { |
David Lawrence Ramsey | 90f772b | 2005-07-11 07:12:33 +0000 | [diff] [blame] | 1982 | /* Add a space after the version message, and account for both |
| 1983 | * it and the two spaces before it. */ |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 1984 | mvwaddnstr(topwin, 0, 2, VERMSG, actual_x(VERMSG, verlen)); |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 1985 | verlen += 3; |
| 1986 | |
| 1987 | /* Account for the full length of the version message. */ |
| 1988 | space -= verlen; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1989 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1990 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1991 | #ifndef DISABLE_BROWSER |
| 1992 | /* Don't display the state if we're in the file browser. */ |
| 1993 | if (path != NULL) |
| 1994 | state = ""; |
| 1995 | else |
| 1996 | #endif |
| 1997 | state = openfile->modified ? _("Modified") : ISSET(VIEW_MODE) ? |
| 1998 | _("View") : ""; |
| 1999 | |
David Lawrence Ramsey | 90f772b | 2005-07-11 07:12:33 +0000 | [diff] [blame] | 2000 | statelen = strlenpt((state[0] != '\0') ? state : _("Modified")); |
David Lawrence Ramsey | 297851a | 2005-03-25 05:00:32 +0000 | [diff] [blame] | 2001 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2002 | /* If possible, add a space before state. */ |
| 2003 | if (space > 0 && statelen < space) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2004 | statelen++; |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2005 | else |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2006 | goto the_end; |
| 2007 | |
| 2008 | #ifndef DISABLE_BROWSER |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2009 | /* 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] | 2010 | if (path != NULL) |
| 2011 | prefix = _("DIR:"); |
| 2012 | else |
| 2013 | #endif |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2014 | if (openfile->filename[0] == '\0') { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2015 | prefix = _("New Buffer"); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2016 | newfie = TRUE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2017 | } else |
| 2018 | prefix = _("File:"); |
David Lawrence Ramsey | cb4f14b | 2005-03-24 22:28:25 +0000 | [diff] [blame] | 2019 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2020 | prefixlen = strnlenpt(prefix, space - statelen) + 1; |
David Lawrence Ramsey | cb4f14b | 2005-03-24 22:28:25 +0000 | [diff] [blame] | 2021 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2022 | /* If newfie is FALSE, add a space after prefix. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2023 | if (!newfie && prefixlen + statelen < space) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2024 | prefixlen++; |
| 2025 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2026 | /* If we're not in the file browser, path should be the current |
| 2027 | * filename. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2028 | if (path == NULL) |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2029 | path = openfile->filename; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2030 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2031 | /* Account for the full lengths of the prefix and the state. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2032 | if (space >= prefixlen + statelen) |
| 2033 | space -= prefixlen + statelen; |
| 2034 | else |
| 2035 | space = 0; |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2036 | /* space is now the room we have for the filename. */ |
David Lawrence Ramsey | 297851a | 2005-03-25 05:00:32 +0000 | [diff] [blame] | 2037 | |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2038 | if (!newfie) { |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2039 | size_t lenpt = strlenpt(path), start_col; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2040 | |
David Lawrence Ramsey | a03d9c0 | 2005-09-16 17:24:22 +0000 | [diff] [blame] | 2041 | dots = (lenpt >= space); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2042 | |
| 2043 | if (dots) { |
| 2044 | start_col = lenpt - space + 3; |
| 2045 | space -= 3; |
| 2046 | } else |
| 2047 | start_col = 0; |
| 2048 | |
| 2049 | exppath = display_string(path, start_col, space, FALSE); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | if (!dots) { |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2053 | size_t exppathlen = newfie ? 0 : strlenpt(exppath); |
| 2054 | /* The length of the expanded filename. */ |
| 2055 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2056 | /* There is room for the whole filename, so we center it. */ |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2057 | mvwaddnstr(topwin, 0, verlen + ((space - exppathlen) / 3), |
| 2058 | prefix, actual_x(prefix, prefixlen)); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2059 | if (!newfie) { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2060 | waddch(topwin, ' '); |
| 2061 | waddstr(topwin, exppath); |
| 2062 | } |
| 2063 | } else { |
| 2064 | /* We will say something like "File: ...ename". */ |
David Lawrence Ramsey | 90f772b | 2005-07-11 07:12:33 +0000 | [diff] [blame] | 2065 | mvwaddnstr(topwin, 0, verlen - 1, prefix, actual_x(prefix, |
| 2066 | prefixlen)); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2067 | if (space <= -3 || newfie) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2068 | goto the_end; |
| 2069 | waddch(topwin, ' '); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2070 | waddnstr(topwin, "...", space + 3); |
| 2071 | if (space <= 0) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2072 | goto the_end; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2073 | waddstr(topwin, exppath); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | the_end: |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2077 | free(exppath); |
| 2078 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2079 | if (state[0] != '\0') { |
David Lawrence Ramsey | 3d12f0f | 2005-10-26 23:14:59 +0000 | [diff] [blame] | 2080 | if (statelen >= COLS - 1) |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2081 | mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS)); |
| 2082 | else { |
David Lawrence Ramsey | caa8659 | 2005-07-10 23:57:32 +0000 | [diff] [blame] | 2083 | assert(COLS - statelen - 1 >= 0); |
David Lawrence Ramsey | cb4f14b | 2005-03-24 22:28:25 +0000 | [diff] [blame] | 2084 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2085 | mvwaddnstr(topwin, 0, COLS - statelen - 1, state, |
David Lawrence Ramsey | 297851a | 2005-03-25 05:00:32 +0000 | [diff] [blame] | 2086 | actual_x(state, statelen)); |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2087 | } |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2088 | } |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2089 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2090 | wattroff(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2091 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2092 | wnoutrefresh(topwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2093 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 2094 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 2097 | /* Mark the current file as modified if it isn't already, and then |
| 2098 | * update the titlebar to display the file's new status. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2099 | void set_modified(void) |
| 2100 | { |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2101 | if (!openfile->modified) { |
| 2102 | openfile->modified = TRUE; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2103 | titlebar(NULL); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2104 | } |
| 2105 | } |
| 2106 | |
David Lawrence Ramsey | 5593e20 | 2005-06-28 19:49:15 +0000 | [diff] [blame] | 2107 | /* Display a message on the statusbar, and set disable_cursorpos to |
| 2108 | * TRUE, so that the message won't be immediately overwritten if |
| 2109 | * constant cursor position display is on. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2110 | void statusbar(const char *msg, ...) |
| 2111 | { |
| 2112 | va_list ap; |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2113 | char *bar, *foo; |
| 2114 | size_t start_x, foo_len; |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2115 | #if !defined(NANO_TINY) && defined(ENABLE_NANORC) |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2116 | bool old_whitespace; |
| 2117 | #endif |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2118 | |
| 2119 | va_start(ap, msg); |
| 2120 | |
| 2121 | /* Curses mode is turned off. If we use wmove() now, it will muck |
| 2122 | * up the terminal settings. So we just use vfprintf(). */ |
| 2123 | if (curses_ended) { |
| 2124 | vfprintf(stderr, msg, ap); |
| 2125 | va_end(ap); |
| 2126 | return; |
| 2127 | } |
| 2128 | |
| 2129 | /* Blank out the line. */ |
| 2130 | blank_statusbar(); |
| 2131 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2132 | #if !defined(NANO_TINY) && defined(ENABLE_NANORC) |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2133 | old_whitespace = ISSET(WHITESPACE_DISPLAY); |
| 2134 | UNSET(WHITESPACE_DISPLAY); |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2135 | #endif |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2136 | bar = charalloc(mb_cur_max() * (COLS - 3)); |
| 2137 | vsnprintf(bar, mb_cur_max() * (COLS - 3), msg, ap); |
| 2138 | va_end(ap); |
| 2139 | foo = display_string(bar, 0, COLS - 4, FALSE); |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2140 | #if !defined(NANO_TINY) && defined(ENABLE_NANORC) |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2141 | if (old_whitespace) |
| 2142 | SET(WHITESPACE_DISPLAY); |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2143 | #endif |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2144 | free(bar); |
| 2145 | foo_len = strlenpt(foo); |
| 2146 | start_x = (COLS - foo_len - 4) / 2; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2147 | |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2148 | wmove(bottomwin, 0, start_x); |
| 2149 | wattron(bottomwin, A_REVERSE); |
| 2150 | waddstr(bottomwin, "[ "); |
| 2151 | waddstr(bottomwin, foo); |
| 2152 | free(foo); |
| 2153 | waddstr(bottomwin, " ]"); |
| 2154 | wattroff(bottomwin, A_REVERSE); |
| 2155 | wnoutrefresh(bottomwin); |
| 2156 | reset_cursor(); |
| 2157 | wnoutrefresh(edit); |
| 2158 | /* Leave the cursor at its position in the edit window, not in |
| 2159 | * the statusbar. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2160 | |
David Lawrence Ramsey | ea01474 | 2005-06-17 18:27:00 +0000 | [diff] [blame] | 2161 | disable_cursorpos = TRUE; |
David Lawrence Ramsey | c661853 | 2005-06-17 22:33:15 +0000 | [diff] [blame] | 2162 | |
| 2163 | /* If we're doing quick statusbar blanking, and constant cursor |
| 2164 | * position display is off, blank the statusbar after only one |
| 2165 | * keystroke. Otherwise, blank it after twenty-five keystrokes, |
| 2166 | * as Pico does. */ |
David Lawrence Ramsey | e29111f | 2005-06-17 19:06:25 +0000 | [diff] [blame] | 2167 | statusblank = |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2168 | #ifndef NANO_TINY |
David Lawrence Ramsey | bf51aa4 | 2005-06-17 21:52:59 +0000 | [diff] [blame] | 2169 | ISSET(QUICK_BLANK) && !ISSET(CONST_UPDATE) ? 1 : |
David Lawrence Ramsey | e29111f | 2005-06-17 19:06:25 +0000 | [diff] [blame] | 2170 | #endif |
| 2171 | 25; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2172 | } |
| 2173 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 2174 | /* Display the shortcut list in s on the last two rows of the bottom |
| 2175 | * portion of the window. */ |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2176 | void bottombars(const shortcut *s) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2177 | { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2178 | size_t i, colwidth, slen; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2179 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2180 | if (ISSET(NO_HELP)) |
| 2181 | return; |
| 2182 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2183 | if (s == main_list) { |
| 2184 | slen = MAIN_VISIBLE; |
David Lawrence Ramsey | 31b159c | 2005-05-26 05:17:13 +0000 | [diff] [blame] | 2185 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2186 | assert(slen <= length_of_list(s)); |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 2187 | } else { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2188 | slen = length_of_list(s); |
| 2189 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2190 | /* Don't show any more shortcuts than the main list does. */ |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 2191 | if (slen > MAIN_VISIBLE) |
| 2192 | slen = MAIN_VISIBLE; |
| 2193 | } |
| 2194 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2195 | /* 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] | 2196 | * 3 to display anything properly. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2197 | colwidth = COLS / ((slen / 2) + (slen % 2)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2198 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2199 | blank_bottombars(); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2200 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2201 | for (i = 0; i < slen; i++, s = s->next) { |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2202 | const char *keystr; |
David Lawrence Ramsey | 6bc26a9 | 2005-05-02 21:48:34 +0000 | [diff] [blame] | 2203 | char foo[4] = ""; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2204 | |
David Lawrence Ramsey | 6bc26a9 | 2005-05-02 21:48:34 +0000 | [diff] [blame] | 2205 | /* Yucky sentinel values that we can't handle a better way. */ |
| 2206 | if (s->ctrlval == NANO_CONTROL_SPACE) |
| 2207 | strcpy(foo, "^ "); |
| 2208 | else if (s->ctrlval == NANO_CONTROL_8) |
| 2209 | strcpy(foo, "^?"); |
| 2210 | /* Normal values. Assume that the shortcut has an equivalent |
| 2211 | * control key, meta key sequence, or both. */ |
| 2212 | else if (s->ctrlval != NANO_NO_KEY) |
| 2213 | sprintf(foo, "^%c", s->ctrlval + 64); |
| 2214 | else if (s->metaval != NANO_NO_KEY) |
| 2215 | sprintf(foo, "M-%c", toupper(s->metaval)); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2216 | |
David Lawrence Ramsey | 6bc26a9 | 2005-05-02 21:48:34 +0000 | [diff] [blame] | 2217 | keystr = foo; |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2218 | |
| 2219 | wmove(bottomwin, 1 + i % 2, (i / 2) * colwidth); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2220 | onekey(keystr, s->desc, colwidth); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2223 | wnoutrefresh(bottomwin); |
| 2224 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 2225 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2228 | /* Write a shortcut key to the help area at the bottom of the window. |
| 2229 | * keystroke is e.g. "^G" and desc is e.g. "Get Help". We are careful |
| 2230 | * to write at most len characters, even if len is very small and |
| 2231 | * keystroke and desc are long. Note that waddnstr(,,(size_t)-1) adds |
| 2232 | * the whole string! We do not bother padding the entry with blanks. */ |
| 2233 | void onekey(const char *keystroke, const char *desc, size_t len) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2234 | { |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2235 | size_t keystroke_len = strlenpt(keystroke) + 1; |
| 2236 | |
David Lawrence Ramsey | 12054fe | 2005-01-07 22:37:01 +0000 | [diff] [blame] | 2237 | assert(keystroke != NULL && desc != NULL); |
| 2238 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2239 | wattron(bottomwin, A_REVERSE); |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2240 | waddnstr(bottomwin, keystroke, actual_x(keystroke, len)); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2241 | wattroff(bottomwin, A_REVERSE); |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2242 | |
| 2243 | if (len > keystroke_len) |
| 2244 | len -= keystroke_len; |
| 2245 | else |
| 2246 | len = 0; |
| 2247 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2248 | if (len > 0) { |
| 2249 | waddch(bottomwin, ' '); |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2250 | waddnstr(bottomwin, desc, actual_x(desc, len)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2251 | } |
| 2252 | } |
| 2253 | |
David Lawrence Ramsey | 2b9d6a0 | 2005-11-01 17:45:31 +0000 | [diff] [blame] | 2254 | /* Reset current_y, based on the position of current, and put the cursor |
| 2255 | * in the edit window at (current_y, current_x). */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2256 | void reset_cursor(void) |
| 2257 | { |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2258 | /* If we haven't opened any files yet, put the cursor in the top |
| 2259 | * left corner of the edit window and get out. */ |
David Lawrence Ramsey | dbcaa3b | 2005-07-08 20:59:24 +0000 | [diff] [blame] | 2260 | if (openfile == NULL) { |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2261 | wmove(edit, 0, 0); |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2262 | return; |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2263 | } |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2264 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2265 | openfile->current_y = openfile->current->lineno - |
| 2266 | openfile->edittop->lineno; |
| 2267 | if (openfile->current_y < editwinrows) { |
David Lawrence Ramsey | cfffbf7 | 2005-11-16 03:14:11 +0000 | [diff] [blame] | 2268 | size_t xpt = xplustabs(); |
| 2269 | wmove(edit, openfile->current_y, xpt - get_page_start(xpt)); |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2270 | } |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2271 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2272 | |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2273 | /* edit_draw() takes care of the job of actually painting a line into |
| 2274 | * the edit window. fileptr is the line to be painted, at row line of |
| 2275 | * the window. converted is the actual string to be written to the |
| 2276 | * window, with tabs and control characters replaced by strings of |
| 2277 | * regular characters. start is the column number of the first |
| 2278 | * character of this page. That is, the first character of converted |
| 2279 | * corresponds to character number actual_x(fileptr->data, start) of the |
| 2280 | * line. */ |
| 2281 | void edit_draw(const filestruct *fileptr, const char *converted, int |
| 2282 | line, size_t start) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2283 | { |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2284 | #if !defined(NANO_TINY) || defined(ENABLE_COLOR) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2285 | size_t startpos = actual_x(fileptr->data, start); |
| 2286 | /* The position in fileptr->data of the leftmost character |
| 2287 | * that displays at least partially on the window. */ |
| 2288 | size_t endpos = actual_x(fileptr->data, start + COLS - 1) + 1; |
| 2289 | /* The position in fileptr->data of the first character that is |
| 2290 | * completely off the window to the right. |
| 2291 | * |
| 2292 | * Note that endpos might be beyond the null terminator of the |
| 2293 | * string. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2294 | #endif |
| 2295 | |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2296 | assert(openfile != NULL && fileptr != NULL && converted != NULL); |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2297 | assert(strlenpt(converted) <= COLS); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2298 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2299 | /* 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] | 2300 | * just the text that needs it). */ |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2301 | mvwaddstr(edit, line, 0, converted); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2302 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 2303 | #ifdef ENABLE_COLOR |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2304 | /* If color syntaxes are available and turned on, we need to display |
| 2305 | * them. */ |
| 2306 | if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) { |
| 2307 | const colortype *tmpcolor = openfile->colorstrings; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2308 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2309 | for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { |
| 2310 | int x_start; |
| 2311 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 2312 | int paintlen; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2313 | /* Number of chars to paint on this line. There are COLS |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2314 | * characters on a whole line. */ |
David Lawrence Ramsey | 179f0ea | 2005-01-04 02:55:45 +0000 | [diff] [blame] | 2315 | size_t index; |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2316 | /* Index in converted where we paint. */ |
David Lawrence Ramsey | 85f6a2d | 2005-06-26 22:59:54 +0000 | [diff] [blame] | 2317 | regmatch_t startmatch; |
| 2318 | /* Match position for start_regex. */ |
| 2319 | regmatch_t endmatch; |
| 2320 | /* Match position for end_regex. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2321 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2322 | if (tmpcolor->bright) |
| 2323 | wattron(edit, A_BOLD); |
| 2324 | wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); |
David Lawrence Ramsey | b0e04c0 | 2005-12-08 07:24:54 +0000 | [diff] [blame] | 2325 | /* Two notes about regexec(). A return value of zero means |
| 2326 | * that there is a match. Also, rm_eo is the first |
| 2327 | * non-matching character after the match. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2328 | |
| 2329 | /* First case, tmpcolor is a single-line expression. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2330 | if (tmpcolor->end == NULL) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2331 | size_t k = 0; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2332 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2333 | /* 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] | 2334 | * last match. Even though two matches may overlap, we |
| 2335 | * want to ignore them, so that we can highlight |
| 2336 | * C-strings correctly. */ |
| 2337 | while (k < endpos) { |
| 2338 | /* Note the fifth parameter to regexec(). It says |
| 2339 | * not to match the beginning-of-line character |
| 2340 | * unless k is 0. If regexec() returns REG_NOMATCH, |
| 2341 | * there are no more matches in the line. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2342 | if (regexec(tmpcolor->start, &fileptr->data[k], 1, |
David Lawrence Ramsey | 282a940 | 2005-07-29 21:41:04 +0000 | [diff] [blame] | 2343 | &startmatch, (k == 0) ? 0 : REG_NOTBOL) == |
| 2344 | REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2345 | break; |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2346 | /* Translate the match to the beginning of the |
| 2347 | * line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2348 | startmatch.rm_so += k; |
| 2349 | startmatch.rm_eo += k; |
David Lawrence Ramsey | 2ab03f6 | 2002-10-17 02:19:31 +0000 | [diff] [blame] | 2350 | if (startmatch.rm_so == startmatch.rm_eo) { |
| 2351 | startmatch.rm_eo++; |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2352 | statusbar( |
| 2353 | _("Refusing zero-length regex match")); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2354 | } else if (startmatch.rm_so < endpos && |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2355 | startmatch.rm_eo > startpos) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2356 | if (startmatch.rm_so <= startpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2357 | x_start = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2358 | else |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2359 | x_start = strnlenpt(fileptr->data, |
| 2360 | startmatch.rm_so) - start; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2361 | |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2362 | index = actual_x(converted, x_start); |
| 2363 | |
| 2364 | paintlen = actual_x(converted + index, |
David Lawrence Ramsey | c1e3d94 | 2005-01-12 18:23:09 +0000 | [diff] [blame] | 2365 | strnlenpt(fileptr->data, |
| 2366 | startmatch.rm_eo) - start - x_start); |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2367 | |
| 2368 | assert(0 <= x_start && 0 <= paintlen); |
| 2369 | |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2370 | mvwaddnstr(edit, line, x_start, converted + |
| 2371 | index, paintlen); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2372 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2373 | k = startmatch.rm_eo; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2374 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2375 | } else { |
David Lawrence Ramsey | 85f6a2d | 2005-06-26 22:59:54 +0000 | [diff] [blame] | 2376 | /* This is a multi-line regex. There are two steps. |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2377 | * First, we have to see if the beginning of the line is |
| 2378 | * colored by a start on an earlier line, and an end on |
| 2379 | * this line or later. |
| 2380 | * |
| 2381 | * We find the first line before fileptr matching the |
| 2382 | * start. If every match on that line is followed by an |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2383 | * end, then go to step two. Otherwise, find the next |
| 2384 | * line after start_line matching the end. If that line |
| 2385 | * is not before fileptr, then paint the beginning of |
| 2386 | * this line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2387 | const filestruct *start_line = fileptr->prev; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2388 | /* The first line before fileptr matching start. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2389 | regoff_t start_col; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2390 | /* Where it starts in that line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2391 | const filestruct *end_line; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2392 | |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2393 | while (start_line != NULL && regexec(tmpcolor->start, |
David Lawrence Ramsey | 282a940 | 2005-07-29 21:41:04 +0000 | [diff] [blame] | 2394 | start_line->data, 1, &startmatch, 0) == |
| 2395 | REG_NOMATCH) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2396 | /* If there is an end on this line, there is no need |
| 2397 | * to look for starts on earlier lines. */ |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2398 | if (regexec(tmpcolor->end, start_line->data, 0, |
| 2399 | NULL, 0) == 0) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2400 | goto step_two; |
| 2401 | start_line = start_line->prev; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2402 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2403 | /* No start found, so skip to the next step. */ |
| 2404 | if (start_line == NULL) |
| 2405 | goto step_two; |
| 2406 | /* Now start_line is the first line before fileptr |
| 2407 | * containing a start match. Is there a start on this |
| 2408 | * line not followed by an end on this line? */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2409 | start_col = 0; |
David Lawrence Ramsey | 6aec4b8 | 2004-03-15 20:26:30 +0000 | [diff] [blame] | 2410 | while (TRUE) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2411 | start_col += startmatch.rm_so; |
| 2412 | startmatch.rm_eo -= startmatch.rm_so; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2413 | if (regexec(tmpcolor->end, start_line->data + |
| 2414 | start_col + startmatch.rm_eo, 0, NULL, |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2415 | (start_col + startmatch.rm_eo == 0) ? 0 : |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2416 | REG_NOTBOL) == REG_NOMATCH) |
| 2417 | /* No end found after this start. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2418 | break; |
| 2419 | start_col++; |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2420 | if (regexec(tmpcolor->start, start_line->data + |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2421 | start_col, 1, &startmatch, |
| 2422 | REG_NOTBOL) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2423 | /* No later start on this line. */ |
| 2424 | goto step_two; |
| 2425 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2426 | /* Indeed, there is a start not followed on this line by |
| 2427 | * an end. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2428 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2429 | /* We have already checked that there is no end before |
| 2430 | * fileptr and after the start. Is there an end after |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2431 | * the start at all? We don't paint unterminated |
| 2432 | * starts. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2433 | end_line = fileptr; |
David Lawrence Ramsey | 282a940 | 2005-07-29 21:41:04 +0000 | [diff] [blame] | 2434 | while (end_line != NULL && regexec(tmpcolor->end, |
| 2435 | end_line->data, 1, &endmatch, 0) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2436 | end_line = end_line->next; |
| 2437 | |
| 2438 | /* No end found, or it is too early. */ |
David Lawrence Ramsey | 179f0ea | 2005-01-04 02:55:45 +0000 | [diff] [blame] | 2439 | if (end_line == NULL || (end_line == fileptr && |
| 2440 | endmatch.rm_eo <= startpos)) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2441 | goto step_two; |
| 2442 | |
| 2443 | /* Now paint the start of fileptr. */ |
David Lawrence Ramsey | 0c9df57 | 2005-01-12 16:20:18 +0000 | [diff] [blame] | 2444 | if (end_line != fileptr) |
| 2445 | /* If the start of fileptr is on a different line |
| 2446 | * from the end, paintlen is -1, meaning that |
| 2447 | * everything on the line gets painted. */ |
| 2448 | paintlen = -1; |
| 2449 | else |
| 2450 | /* Otherwise, paintlen is the expanded location of |
| 2451 | * the end of the match minus the expanded location |
| 2452 | * of the beginning of the page. */ |
| 2453 | paintlen = actual_x(converted, |
| 2454 | strnlenpt(fileptr->data, endmatch.rm_eo) - |
| 2455 | start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2456 | |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2457 | mvwaddnstr(edit, line, 0, converted, paintlen); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2458 | |
David Lawrence Ramsey | 94e7094 | 2004-05-13 18:04:31 +0000 | [diff] [blame] | 2459 | step_two: |
| 2460 | /* Second step, we look for starts on this line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2461 | start_col = 0; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2462 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2463 | while (start_col < endpos) { |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2464 | if (regexec(tmpcolor->start, fileptr->data + |
| 2465 | start_col, 1, &startmatch, (start_col == 0) ? |
| 2466 | 0 : REG_NOTBOL) == REG_NOMATCH || start_col + |
| 2467 | startmatch.rm_so >= endpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2468 | /* No more starts on this line. */ |
| 2469 | break; |
| 2470 | /* Translate the match to be relative to the |
| 2471 | * beginning of the line. */ |
| 2472 | startmatch.rm_so += start_col; |
| 2473 | startmatch.rm_eo += start_col; |
| 2474 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2475 | if (startmatch.rm_so <= startpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2476 | x_start = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2477 | else |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2478 | x_start = strnlenpt(fileptr->data, |
| 2479 | startmatch.rm_so) - start; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2480 | |
David Lawrence Ramsey | 179f0ea | 2005-01-04 02:55:45 +0000 | [diff] [blame] | 2481 | index = actual_x(converted, x_start); |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2482 | |
David Lawrence Ramsey | 282a940 | 2005-07-29 21:41:04 +0000 | [diff] [blame] | 2483 | if (regexec(tmpcolor->end, fileptr->data + |
| 2484 | startmatch.rm_eo, 1, &endmatch, |
| 2485 | (startmatch.rm_eo == 0) ? 0 : REG_NOTBOL) == |
| 2486 | 0) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2487 | /* Translate the end match to be relative to the |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2488 | * beginning of the line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2489 | endmatch.rm_so += startmatch.rm_eo; |
| 2490 | endmatch.rm_eo += startmatch.rm_eo; |
| 2491 | /* There is an end on this line. But does it |
David Lawrence Ramsey | 94e7094 | 2004-05-13 18:04:31 +0000 | [diff] [blame] | 2492 | * appear on this page, and is the match more |
| 2493 | * than zero characters long? */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2494 | if (endmatch.rm_eo > startpos && |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2495 | endmatch.rm_eo > startmatch.rm_so) { |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2496 | paintlen = actual_x(converted + index, |
David Lawrence Ramsey | c1e3d94 | 2005-01-12 18:23:09 +0000 | [diff] [blame] | 2497 | strnlenpt(fileptr->data, |
| 2498 | endmatch.rm_eo) - start - x_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2499 | |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2500 | assert(0 <= x_start && x_start < COLS); |
| 2501 | |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2502 | mvwaddnstr(edit, line, x_start, converted + |
| 2503 | index, paintlen); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2504 | } |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2505 | } else { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2506 | /* There is no end on this line. But we haven't |
| 2507 | * yet looked for one on later lines. */ |
| 2508 | end_line = fileptr->next; |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2509 | |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2510 | while (end_line != NULL && |
| 2511 | regexec(tmpcolor->end, end_line->data, |
| 2512 | 0, NULL, 0) == REG_NOMATCH) |
| 2513 | end_line = end_line->next; |
| 2514 | |
| 2515 | if (end_line != NULL) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2516 | assert(0 <= x_start && x_start < COLS); |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2517 | |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2518 | mvwaddnstr(edit, line, x_start, converted + |
| 2519 | index, -1); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2520 | /* We painted to the end of the line, so |
| 2521 | * don't bother checking any more starts. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2522 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 2523 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2524 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2525 | start_col = startmatch.rm_so + 1; |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2526 | } |
| 2527 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2528 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2529 | wattroff(edit, A_BOLD); |
| 2530 | wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2531 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2532 | } |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2533 | #endif /* ENABLE_COLOR */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2534 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2535 | #ifndef NANO_TINY |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2536 | /* If the mark is on, we need to display it. */ |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2537 | if (openfile->mark_set && (fileptr->lineno <= |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2538 | openfile->mark_begin->lineno || fileptr->lineno <= |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2539 | openfile->current->lineno) && (fileptr->lineno >= |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2540 | openfile->mark_begin->lineno || fileptr->lineno >= |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2541 | openfile->current->lineno)) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2542 | /* fileptr is at least partially selected. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2543 | const filestruct *top; |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2544 | /* Either current or mark_begin, whichever is first. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2545 | size_t top_x; |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2546 | /* current_x or mark_begin_x, corresponding to top. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2547 | const filestruct *bot; |
| 2548 | size_t bot_x; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2549 | int x_start; |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2550 | /* Starting column for mvwaddnstr(). Zero-based. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2551 | int paintlen; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2552 | /* Number of chars to paint on this line. There are COLS |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2553 | * characters on a whole line. */ |
David Lawrence Ramsey | 179f0ea | 2005-01-04 02:55:45 +0000 | [diff] [blame] | 2554 | size_t index; |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2555 | /* Index in converted where we paint. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2556 | |
David Lawrence Ramsey | 90e59c1 | 2004-11-05 23:03:03 +0000 | [diff] [blame] | 2557 | mark_order(&top, &top_x, &bot, &bot_x, NULL); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2558 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2559 | if (top->lineno < fileptr->lineno || top_x < startpos) |
| 2560 | top_x = startpos; |
| 2561 | if (bot->lineno > fileptr->lineno || bot_x > endpos) |
| 2562 | bot_x = endpos; |
| 2563 | |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2564 | /* The selected bit of fileptr is on this page. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2565 | if (top_x < endpos && bot_x > startpos) { |
| 2566 | assert(startpos <= top_x); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2567 | |
| 2568 | /* x_start is the expanded location of the beginning of the |
| 2569 | * mark minus the beginning of the page. */ |
| 2570 | x_start = strnlenpt(fileptr->data, top_x) - start; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2571 | |
| 2572 | if (bot_x >= endpos) |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2573 | /* If the end of the mark is off the page, paintlen is |
| 2574 | * -1, meaning that everything on the line gets |
| 2575 | * painted. */ |
| 2576 | paintlen = -1; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2577 | else |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2578 | /* Otherwise, paintlen is the expanded location of the |
| 2579 | * end of the mark minus the expanded location of the |
| 2580 | * beginning of the mark. */ |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2581 | paintlen = strnlenpt(fileptr->data, bot_x) - |
| 2582 | (x_start + start); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2583 | |
| 2584 | /* If x_start is before the beginning of the page, shift |
| 2585 | * paintlen x_start characters to compensate, and put |
| 2586 | * x_start at the beginning of the page. */ |
| 2587 | if (x_start < 0) { |
| 2588 | paintlen += x_start; |
| 2589 | x_start = 0; |
| 2590 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2591 | |
| 2592 | assert(x_start >= 0 && x_start <= strlen(converted)); |
| 2593 | |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2594 | index = actual_x(converted, x_start); |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2595 | |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2596 | if (paintlen > 0) |
| 2597 | paintlen = actual_x(converted + index, paintlen); |
| 2598 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2599 | wattron(edit, A_REVERSE); |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2600 | mvwaddnstr(edit, line, x_start, converted + index, |
David Lawrence Ramsey | 22e5eff | 2005-01-03 22:56:38 +0000 | [diff] [blame] | 2601 | paintlen); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2602 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2603 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 2604 | } |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2605 | #endif /* !NANO_TINY */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2608 | /* Just update one line in the edit buffer. This is basically a wrapper |
David Lawrence Ramsey | b3c6b40 | 2005-11-07 06:20:02 +0000 | [diff] [blame] | 2609 | * for edit_draw(). The line will be displayed starting with |
| 2610 | * fileptr->data[index]. Likely arguments are current_x or zero. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2611 | void update_line(const filestruct *fileptr, size_t index) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2612 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2613 | int line; |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2614 | /* The line in the edit window that we want to update. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2615 | char *converted; |
| 2616 | /* fileptr->data converted to have tabs and control characters |
| 2617 | * expanded. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2618 | size_t page_start; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2619 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2620 | assert(fileptr != NULL); |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 2621 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2622 | line = fileptr->lineno - openfile->edittop->lineno; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2623 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2624 | /* We assume the line numbers are valid. Is that really true? */ |
| 2625 | assert(line < 0 || line == check_linenumbers(fileptr)); |
| 2626 | |
| 2627 | if (line < 0 || line >= editwinrows) |
| 2628 | return; |
| 2629 | |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2630 | /* First, blank out the line. */ |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2631 | blank_line(edit, line, 0, COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2632 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2633 | /* Next, convert variables that index the line to their equivalent |
| 2634 | * positions in the expanded line. */ |
David Lawrence Ramsey | b3c6b40 | 2005-11-07 06:20:02 +0000 | [diff] [blame] | 2635 | index = strnlenpt(fileptr->data, index); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2636 | page_start = get_page_start(index); |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2637 | |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2638 | /* Expand the line, replacing tabs with spaces, and control |
| 2639 | * characters with their displayed forms. */ |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2640 | converted = display_string(fileptr->data, page_start, COLS, TRUE); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 2641 | |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2642 | /* Paint the line. */ |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2643 | edit_draw(fileptr, converted, line, page_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2644 | free(converted); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2645 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2646 | if (page_start > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2647 | mvwaddch(edit, line, 0, '$'); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2648 | if (strlenpt(fileptr->data) > page_start + COLS) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2649 | mvwaddch(edit, line, COLS - 1, '$'); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2650 | } |
| 2651 | |
David Lawrence Ramsey | feb89db | 2005-09-13 04:45:46 +0000 | [diff] [blame] | 2652 | /* Return TRUE if we need an update after moving horizontally, and FALSE |
| 2653 | * otherwise. 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] | 2654 | * placewewant are on different pages. */ |
David Lawrence Ramsey | feb89db | 2005-09-13 04:45:46 +0000 | [diff] [blame] | 2655 | bool need_horizontal_update(size_t old_pww) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2656 | { |
| 2657 | return |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2658 | #ifndef NANO_TINY |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2659 | openfile->mark_set || |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2660 | #endif |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2661 | get_page_start(old_pww) != |
| 2662 | get_page_start(openfile->placewewant); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
David Lawrence Ramsey | feb89db | 2005-09-13 04:45:46 +0000 | [diff] [blame] | 2665 | /* Return TRUE if we need an update after moving vertically, and FALSE |
| 2666 | * otherwise. We need one if the mark is on or if old_pww and |
| 2667 | * placewewant are on different pages. */ |
| 2668 | bool need_vertical_update(size_t old_pww) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2669 | { |
| 2670 | return |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2671 | #ifndef NANO_TINY |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2672 | openfile->mark_set || |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2673 | #endif |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2674 | get_page_start(old_pww) != |
| 2675 | get_page_start(openfile->placewewant); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | /* Scroll the edit window in the given direction and the given number |
| 2679 | * of lines, and draw new lines on the blank lines left after the |
| 2680 | * scrolling. direction is the direction to scroll, either UP or DOWN, |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 2681 | * and nlines is the number of lines to scroll. We change edittop, and |
David Lawrence Ramsey | 6969c99 | 2005-07-26 00:42:48 +0000 | [diff] [blame] | 2682 | * assume that current and current_x are up to date. We also assume |
| 2683 | * that scrollok(edit) is FALSE. */ |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 2684 | void edit_scroll(scroll_dir direction, ssize_t nlines) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2685 | { |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 2686 | bool do_redraw = need_vertical_update(0); |
David Lawrence Ramsey | 443a766 | 2005-07-14 23:06:22 +0000 | [diff] [blame] | 2687 | const filestruct *foo; |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 2688 | ssize_t i; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2689 | |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2690 | /* Don't bother scrolling less than one line. */ |
| 2691 | if (nlines < 1) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2692 | return; |
| 2693 | |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2694 | /* Part 1: nlines is the number of lines we're going to scroll the |
| 2695 | * text of the edit window. */ |
| 2696 | |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2697 | /* 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] | 2698 | * value of direction) nlines lines, or as many lines as we can if |
| 2699 | * there are fewer than nlines lines available. */ |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2700 | for (i = nlines; i > 0; i--) { |
| 2701 | if (direction == UP) { |
David Lawrence Ramsey | e99223d | 2005-11-10 04:27:30 +0000 | [diff] [blame] | 2702 | if (openfile->edittop == openfile->fileage) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2703 | break; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2704 | openfile->edittop = openfile->edittop->prev; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2705 | } else { |
David Lawrence Ramsey | e99223d | 2005-11-10 04:27:30 +0000 | [diff] [blame] | 2706 | if (openfile->edittop == openfile->filebot) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2707 | break; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2708 | openfile->edittop = openfile->edittop->next; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2709 | } |
| 2710 | } |
| 2711 | |
David Lawrence Ramsey | c25ed53 | 2005-08-01 21:53:54 +0000 | [diff] [blame] | 2712 | /* Limit nlines to the number of lines we could scroll. */ |
David Lawrence Ramsey | 945a913 | 2005-07-23 21:06:22 +0000 | [diff] [blame] | 2713 | nlines -= i; |
David Lawrence Ramsey | 258497f | 2005-08-01 21:17:38 +0000 | [diff] [blame] | 2714 | |
David Lawrence Ramsey | c25ed53 | 2005-08-01 21:53:54 +0000 | [diff] [blame] | 2715 | /* Don't bother scrolling zero lines or more than the number of |
| 2716 | * lines in the edit window minus one; in both cases, get out, and |
| 2717 | * in the latter case, call edit_refresh() beforehand. */ |
David Lawrence Ramsey | 258497f | 2005-08-01 21:17:38 +0000 | [diff] [blame] | 2718 | if (nlines == 0) |
| 2719 | return; |
| 2720 | |
| 2721 | if (nlines >= editwinrows) { |
| 2722 | edit_refresh(); |
| 2723 | return; |
| 2724 | } |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2725 | |
| 2726 | /* Scroll the text of the edit window up or down nlines lines, |
| 2727 | * depending on the value of direction. */ |
David Lawrence Ramsey | 47bb888 | 2005-07-22 22:56:03 +0000 | [diff] [blame] | 2728 | scrollok(edit, TRUE); |
| 2729 | wscrl(edit, (direction == UP) ? -nlines : nlines); |
| 2730 | scrollok(edit, FALSE); |
| 2731 | |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2732 | /* Part 2: nlines is the number of lines in the scrolled region of |
| 2733 | * the edit window that we need to draw. */ |
| 2734 | |
David Lawrence Ramsey | 6834650 | 2005-08-16 03:03:15 +0000 | [diff] [blame] | 2735 | /* If the top or bottom line of the file is now visible in the edit |
| 2736 | * window, we need to draw the entire edit window. */ |
| 2737 | if ((direction == UP && openfile->edittop == openfile->fileage) || |
| 2738 | (direction == DOWN && openfile->edittop->lineno + editwinrows - |
| 2739 | 1 >= openfile->filebot->lineno)) |
David Lawrence Ramsey | 945a913 | 2005-07-23 21:06:22 +0000 | [diff] [blame] | 2740 | nlines = editwinrows; |
David Lawrence Ramsey | a7f488b | 2005-07-17 02:19:47 +0000 | [diff] [blame] | 2741 | |
David Lawrence Ramsey | a6eb848 | 2006-01-10 07:51:49 +0000 | [diff] [blame] | 2742 | /* If the scrolled region contains only one line, and the line |
| 2743 | * before it is visible in the edit window, we need to draw it too. |
| 2744 | * If the scrolled region contains more than one line, and the lines |
| 2745 | * before and after the scrolled region are visible in the edit |
| 2746 | * window, we need to draw them too. */ |
| 2747 | nlines += (nlines == 1) ? 1 : 2; |
David Lawrence Ramsey | c25ed53 | 2005-08-01 21:53:54 +0000 | [diff] [blame] | 2748 | |
David Lawrence Ramsey | de0c5eb | 2005-07-17 22:51:44 +0000 | [diff] [blame] | 2749 | if (nlines > editwinrows) |
| 2750 | nlines = editwinrows; |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 2751 | |
| 2752 | /* If we scrolled up, we're on the line before the scrolled |
| 2753 | * region. */ |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2754 | foo = openfile->edittop; |
David Lawrence Ramsey | 1458891 | 2005-07-14 20:37:01 +0000 | [diff] [blame] | 2755 | |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 2756 | /* If we scrolled down, move down to the line before the scrolled |
| 2757 | * region. */ |
David Lawrence Ramsey | 1458891 | 2005-07-14 20:37:01 +0000 | [diff] [blame] | 2758 | if (direction == DOWN) { |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 2759 | for (i = editwinrows - nlines; i > 0 && foo != NULL; i--) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2760 | foo = foo->next; |
| 2761 | } |
| 2762 | |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 2763 | /* Draw new lines on any blank lines before or inside the scrolled |
| 2764 | * region. If we scrolled down and we're on the top line, or if we |
| 2765 | * scrolled up and we're on the bottom line, the line won't be |
| 2766 | * blank, so we don't need to draw it unless the mark is on or we're |
| 2767 | * not on the first page. */ |
| 2768 | for (i = nlines; i > 0 && foo != NULL; i--) { |
| 2769 | if ((i == nlines && direction == DOWN) || (i == 1 && |
| 2770 | direction == UP)) { |
| 2771 | if (do_redraw) |
| 2772 | update_line(foo, (foo == openfile->current) ? |
| 2773 | openfile->current_x : 0); |
| 2774 | } else |
| 2775 | update_line(foo, (foo == openfile->current) ? |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 2776 | openfile->current_x : 0); |
David Lawrence Ramsey | f00c961 | 2005-07-14 18:01:08 +0000 | [diff] [blame] | 2777 | foo = foo->next; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | /* Update any lines between old_current and current that need to be |
David Lawrence Ramsey | 75a29b7 | 2005-07-26 14:26:47 +0000 | [diff] [blame] | 2782 | * updated. Use this if we've moved without changing any text. */ |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 2783 | void edit_redraw(const filestruct *old_current, size_t old_pww) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2784 | { |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 2785 | bool do_redraw = need_vertical_update(0) || |
David Lawrence Ramsey | ce1d765 | 2004-06-01 18:32:36 +0000 | [diff] [blame] | 2786 | need_vertical_update(old_pww); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2787 | const filestruct *foo; |
| 2788 | |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 2789 | /* If either old_current or current is offscreen, scroll the edit |
| 2790 | * window until it's onscreen and get out. */ |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2791 | if (old_current->lineno < openfile->edittop->lineno || |
| 2792 | old_current->lineno >= openfile->edittop->lineno + |
| 2793 | editwinrows || openfile->current->lineno < |
| 2794 | openfile->edittop->lineno || openfile->current->lineno >= |
| 2795 | openfile->edittop->lineno + editwinrows) { |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 2796 | filestruct *old_edittop = openfile->edittop; |
| 2797 | ssize_t nlines; |
| 2798 | |
| 2799 | /* Put edittop in range of current, get the difference in lines |
| 2800 | * between the original edittop and the current edittop, and |
| 2801 | * then restore the original edittop. */ |
| 2802 | edit_update( |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2803 | #ifndef NANO_TINY |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 2804 | ISSET(SMOOTH_SCROLL) ? NONE : |
| 2805 | #endif |
| 2806 | CENTER); |
| 2807 | |
| 2808 | nlines = openfile->edittop->lineno - old_edittop->lineno; |
| 2809 | |
| 2810 | openfile->edittop = old_edittop; |
| 2811 | |
David Lawrence Ramsey | a6eb848 | 2006-01-10 07:51:49 +0000 | [diff] [blame] | 2812 | /* Update old_current if we're not on the first page and/or |
| 2813 | * we're not on the same page as before. */ |
| 2814 | if (do_redraw) |
| 2815 | update_line(old_current, 0); |
| 2816 | |
David Lawrence Ramsey | 258497f | 2005-08-01 21:17:38 +0000 | [diff] [blame] | 2817 | /* Scroll the edit window up or down until edittop is in range |
| 2818 | * of current. */ |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 2819 | if (nlines < 0) |
| 2820 | edit_scroll(UP, -nlines); |
| 2821 | else |
| 2822 | edit_scroll(DOWN, nlines); |
| 2823 | |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2824 | return; |
| 2825 | } |
| 2826 | |
David Lawrence Ramsey | ce1d765 | 2004-06-01 18:32:36 +0000 | [diff] [blame] | 2827 | /* Update old_current and current if we're not on the first page |
| 2828 | * and/or we're not on the same page as before. If the mark is on, |
| 2829 | * update all the lines between old_current and current too. */ |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2830 | foo = old_current; |
David Lawrence Ramsey | f00c961 | 2005-07-14 18:01:08 +0000 | [diff] [blame] | 2831 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2832 | while (foo != openfile->current) { |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 2833 | if (do_redraw) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2834 | update_line(foo, 0); |
David Lawrence Ramsey | e5806be | 2005-07-16 02:12:18 +0000 | [diff] [blame] | 2835 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2836 | #ifndef NANO_TINY |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2837 | if (!openfile->mark_set) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2838 | #endif |
| 2839 | break; |
David Lawrence Ramsey | e5806be | 2005-07-16 02:12:18 +0000 | [diff] [blame] | 2840 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2841 | #ifndef NANO_TINY |
David Lawrence Ramsey | e5806be | 2005-07-16 02:12:18 +0000 | [diff] [blame] | 2842 | foo = (foo->lineno > openfile->current->lineno) ? foo->prev : |
| 2843 | foo->next; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2844 | #endif |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2845 | } |
David Lawrence Ramsey | f00c961 | 2005-07-14 18:01:08 +0000 | [diff] [blame] | 2846 | |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 2847 | if (do_redraw) |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2848 | update_line(openfile->current, openfile->current_x); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
David Lawrence Ramsey | 75a29b7 | 2005-07-26 14:26:47 +0000 | [diff] [blame] | 2851 | /* Refresh the screen without changing the position of lines. Use this |
| 2852 | * if we've moved and changed text. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2853 | void edit_refresh(void) |
| 2854 | { |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 2855 | const filestruct *foo; |
| 2856 | int nlines; |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2857 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2858 | if (openfile->current->lineno < openfile->edittop->lineno || |
| 2859 | openfile->current->lineno >= openfile->edittop->lineno + |
| 2860 | editwinrows) |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 2861 | /* Put the top line of the edit window in range of the current |
| 2862 | * line. */ |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 2863 | edit_update( |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2864 | #ifndef NANO_TINY |
David Lawrence Ramsey | b2b6976 | 2005-06-16 02:13:10 +0000 | [diff] [blame] | 2865 | ISSET(SMOOTH_SCROLL) ? NONE : |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 2866 | #endif |
| 2867 | CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2868 | |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 2869 | foo = openfile->edittop; |
| 2870 | |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2871 | #ifdef DEBUG |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2872 | 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] | 2873 | #endif |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2874 | |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 2875 | for (nlines = 0; nlines < editwinrows && foo != NULL; nlines++) { |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2876 | update_line(foo, (foo == openfile->current) ? |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2877 | openfile->current_x : 0); |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2878 | foo = foo->next; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2879 | } |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2880 | |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 2881 | for (; nlines < editwinrows; nlines++) |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2882 | blank_line(edit, nlines, 0, COLS); |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2883 | |
| 2884 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 2885 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2888 | /* Move edittop to put it in range of current, keeping current in the |
| 2889 | * same place. location determines how we move it: if it's CENTER, we |
| 2890 | * center current, and if it's NONE, we put current current_y lines |
| 2891 | * below edittop. */ |
David Lawrence Ramsey | bf0e47d | 2005-08-01 18:27:10 +0000 | [diff] [blame] | 2892 | void edit_update(update_type location) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2893 | { |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2894 | filestruct *foo = openfile->current; |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2895 | int goal; |
David Lawrence Ramsey | 20b8350 | 2004-08-26 18:07:58 +0000 | [diff] [blame] | 2896 | |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2897 | /* If location is CENTER, we move edittop up (editwinrows / 2) |
| 2898 | * lines. This puts current at the center of the screen. If |
| 2899 | * location is NONE, we move edittop up current_y lines if current_y |
| 2900 | * is in range of the screen, 0 lines if current_y is less than 0, |
| 2901 | * or (editwinrows - 1) lines if current_y is greater than |
| 2902 | * (editwinrows - 1). This puts current at the same place on the |
| 2903 | * screen as before, or at the top or bottom of the screen if |
| 2904 | * edittop is beyond either. */ |
| 2905 | if (location == CENTER) |
| 2906 | goal = editwinrows / 2; |
| 2907 | else { |
| 2908 | goal = openfile->current_y; |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 2909 | |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2910 | /* Limit goal to (editwinrows - 1) lines maximum. */ |
| 2911 | if (goal > editwinrows - 1) |
| 2912 | goal = editwinrows - 1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2913 | } |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 2914 | |
David Lawrence Ramsey | b885c9c | 2005-11-10 05:20:25 +0000 | [diff] [blame] | 2915 | for (; goal > 0 && foo->prev != NULL; goal--) |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2916 | foo = foo->prev; |
| 2917 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2918 | openfile->edittop = foo; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 2921 | /* Unconditionally redraw the entire screen. */ |
David Lawrence Ramsey | c54c4d1 | 2005-06-18 15:49:17 +0000 | [diff] [blame] | 2922 | void total_redraw(void) |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2923 | { |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2924 | #ifdef USE_SLANG |
| 2925 | /* Slang curses emulation brain damage, part 3: Slang doesn't define |
| 2926 | * curscr. */ |
| 2927 | SLsmg_touch_screen(); |
| 2928 | SLsmg_refresh(); |
| 2929 | #else |
| 2930 | wrefresh(curscr); |
| 2931 | #endif |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 2934 | /* Unconditionally redraw the entire screen, and then refresh it using |
| 2935 | * the current file. */ |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 2936 | void total_refresh(void) |
| 2937 | { |
David Lawrence Ramsey | c54c4d1 | 2005-06-18 15:49:17 +0000 | [diff] [blame] | 2938 | total_redraw(); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2939 | titlebar(NULL); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 2940 | edit_refresh(); |
David Lawrence Ramsey | 637b8bb | 2005-01-17 05:06:55 +0000 | [diff] [blame] | 2941 | bottombars(currshortcut); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2942 | } |
| 2943 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 2944 | /* Display the main shortcut list on the last two rows of the bottom |
| 2945 | * portion of the window. */ |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2946 | void display_main_list(void) |
| 2947 | { |
| 2948 | bottombars(main_list); |
| 2949 | } |
| 2950 | |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 2951 | /* If constant is TRUE, we display the current cursor position only if |
| 2952 | * disable_cursorpos is FALSE. Otherwise, we display it |
| 2953 | * unconditionally and set disable_cursorpos to FALSE. If constant is |
| 2954 | * TRUE and disable_cursorpos is TRUE, we also set disable_cursorpos to |
| 2955 | * FALSE, so that we leave the current statusbar alone this time, and |
| 2956 | * display the current cursor position next time. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 2957 | void do_cursorpos(bool constant) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2958 | { |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 2959 | filestruct *f; |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 2960 | char c; |
David Lawrence Ramsey | 5745c0a | 2005-07-31 20:20:37 +0000 | [diff] [blame] | 2961 | size_t i, cur_xpt = xplustabs() + 1; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2962 | size_t cur_lenpt = strlenpt(openfile->current->data) + 1; |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 2963 | int linepct, colpct, charpct; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2964 | |
David Lawrence Ramsey | 4ab8015 | 2005-07-31 18:51:51 +0000 | [diff] [blame] | 2965 | assert(openfile->fileage != NULL && openfile->current != NULL); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2966 | |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 2967 | f = openfile->current->next; |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 2968 | c = openfile->current->data[openfile->current_x]; |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 2969 | |
| 2970 | openfile->current->next = NULL; |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 2971 | openfile->current->data[openfile->current_x] = '\0'; |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 2972 | |
| 2973 | i = get_totsize(openfile->fileage, openfile->current); |
| 2974 | |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 2975 | openfile->current->data[openfile->current_x] = c; |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 2976 | openfile->current->next = f; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 2977 | |
David Lawrence Ramsey | ea01474 | 2005-06-17 18:27:00 +0000 | [diff] [blame] | 2978 | if (constant && disable_cursorpos) { |
| 2979 | disable_cursorpos = FALSE; |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 2980 | return; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2981 | } |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 2982 | |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 2983 | /* Display the current cursor position on the statusbar, and set |
| 2984 | * disable_cursorpos to FALSE. */ |
David Lawrence Ramsey | 520a90c | 2005-07-25 21:23:11 +0000 | [diff] [blame] | 2985 | linepct = 100 * openfile->current->lineno / |
| 2986 | openfile->filebot->lineno; |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 2987 | colpct = 100 * cur_xpt / cur_lenpt; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2988 | charpct = (openfile->totsize == 0) ? 0 : 100 * i / |
| 2989 | openfile->totsize; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2990 | |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 2991 | statusbar( |
David Lawrence Ramsey | 520a90c | 2005-07-25 21:23:11 +0000 | [diff] [blame] | 2992 | _("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"), |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2993 | (long)openfile->current->lineno, |
David Lawrence Ramsey | 520a90c | 2005-07-25 21:23:11 +0000 | [diff] [blame] | 2994 | (long)openfile->filebot->lineno, linepct, |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 2995 | (unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct, |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2996 | (unsigned long)i, (unsigned long)openfile->totsize, charpct); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2997 | |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 2998 | disable_cursorpos = FALSE; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 3001 | /* Unconditionally display the current cursor position. */ |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3002 | void do_cursorpos_void(void) |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3003 | { |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3004 | do_cursorpos(FALSE); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3007 | /* Highlight the current word being replaced or spell checked. We |
| 3008 | * expect word to have tabs and control characters expanded. */ |
David Lawrence Ramsey | 7bde053 | 2005-06-30 03:55:55 +0000 | [diff] [blame] | 3009 | void do_replace_highlight(bool highlight, const char *word) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3010 | { |
David Lawrence Ramsey | 6168cb7 | 2005-06-30 03:53:28 +0000 | [diff] [blame] | 3011 | size_t y = xplustabs(), word_len = strlenpt(word); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3012 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3013 | y = get_page_start(y) + COLS - y; |
David Lawrence Ramsey | 913db83 | 2005-01-05 05:08:14 +0000 | [diff] [blame] | 3014 | /* 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] | 3015 | * line. */ |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3016 | |
David Lawrence Ramsey | 913db83 | 2005-01-05 05:08:14 +0000 | [diff] [blame] | 3017 | assert(y > 0); |
| 3018 | |
| 3019 | if (word_len > y) |
| 3020 | y--; |
| 3021 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3022 | reset_cursor(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3023 | |
David Lawrence Ramsey | 7bde053 | 2005-06-30 03:55:55 +0000 | [diff] [blame] | 3024 | if (highlight) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3025 | wattron(edit, A_REVERSE); |
| 3026 | |
David Lawrence Ramsey | 2a4ab6d | 2003-12-24 08:29:49 +0000 | [diff] [blame] | 3027 | #ifdef HAVE_REGEX_H |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 3028 | /* This is so we can show zero-length regexes. */ |
| 3029 | if (word_len == 0) |
David Lawrence Ramsey | 5b9f522 | 2005-06-13 02:22:44 +0000 | [diff] [blame] | 3030 | waddch(edit, ' '); |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 3031 | else |
David Lawrence Ramsey | 2a4ab6d | 2003-12-24 08:29:49 +0000 | [diff] [blame] | 3032 | #endif |
David Lawrence Ramsey | 913db83 | 2005-01-05 05:08:14 +0000 | [diff] [blame] | 3033 | waddnstr(edit, word, actual_x(word, y)); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3034 | |
| 3035 | if (word_len > y) |
| 3036 | waddch(edit, '$'); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3037 | |
David Lawrence Ramsey | 7bde053 | 2005-06-30 03:55:55 +0000 | [diff] [blame] | 3038 | if (highlight) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3039 | wattroff(edit, A_REVERSE); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3042 | #ifdef NANO_EXTRA |
David Lawrence Ramsey | 315eb32 | 2005-11-28 19:35:29 +0000 | [diff] [blame] | 3043 | #define CREDIT_LEN 55 |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 3044 | #define XLCREDIT_LEN 8 |
| 3045 | |
David Lawrence Ramsey | 8ad58bc | 2005-08-16 03:02:46 +0000 | [diff] [blame] | 3046 | /* Easter egg: Display credits. Assume nodelay(edit) and scrollok(edit) |
| 3047 | * are FALSE. */ |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3048 | void do_credits(void) |
| 3049 | { |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3050 | bool old_more_space = ISSET(MORE_SPACE); |
| 3051 | bool old_no_help = ISSET(NO_HELP); |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3052 | int kbinput = ERR, crpos = 0, xlpos = 0; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3053 | const char *credits[CREDIT_LEN] = { |
| 3054 | NULL, /* "The nano text editor" */ |
| 3055 | NULL, /* "version" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3056 | VERSION, |
| 3057 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3058 | NULL, /* "Brought to you by:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3059 | "Chris Allegretta", |
| 3060 | "Jordi Mallach", |
| 3061 | "Adam Rogoyski", |
| 3062 | "Rob Siemborski", |
| 3063 | "Rocco Corsi", |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 3064 | "David Lawrence Ramsey", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 3065 | "David Benbennick", |
David Lawrence Ramsey | 47daf02 | 2005-08-29 18:29:02 +0000 | [diff] [blame] | 3066 | "Mike Frysinger", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3067 | "Ken Tyler", |
| 3068 | "Sven Guckes", |
David Lawrence Ramsey | 47daf02 | 2005-08-29 18:29:02 +0000 | [diff] [blame] | 3069 | NULL, /* credits[15], handled below. */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3070 | "Pauli Virtanen", |
| 3071 | "Daniele Medri", |
| 3072 | "Clement Laforet", |
| 3073 | "Tedi Heriyanto", |
| 3074 | "Bill Soudan", |
| 3075 | "Christian Weisgerber", |
| 3076 | "Erik Andersen", |
| 3077 | "Big Gaute", |
| 3078 | "Joshua Jensen", |
| 3079 | "Ryan Krebs", |
| 3080 | "Albert Chin", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3081 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3082 | NULL, /* "Special thanks to:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3083 | "Plattsburgh State University", |
| 3084 | "Benet Laboratories", |
| 3085 | "Amy Allegretta", |
| 3086 | "Linda Young", |
| 3087 | "Jeremy Robichaud", |
| 3088 | "Richard Kolb II", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3089 | NULL, /* "The Free Software Foundation" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3090 | "Linus Torvalds", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3091 | NULL, /* "For ncurses:" */ |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 3092 | "Thomas Dickey", |
| 3093 | "Pavel Curtis", |
| 3094 | "Zeyd Ben-Halim", |
| 3095 | "Eric S. Raymond", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3096 | NULL, /* "and anyone else we forgot..." */ |
| 3097 | NULL, /* "Thank you for using nano!" */ |
| 3098 | "", |
| 3099 | "", |
| 3100 | "", |
| 3101 | "", |
David Lawrence Ramsey | 315eb32 | 2005-11-28 19:35:29 +0000 | [diff] [blame] | 3102 | "(c) 1999-2004 Chris Allegretta", |
| 3103 | "(c) 2005 David Lawrence Ramsey", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3104 | "", |
| 3105 | "", |
| 3106 | "", |
| 3107 | "", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 3108 | "http://www.nano-editor.org/" |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3109 | }; |
| 3110 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3111 | const char *xlcredits[XLCREDIT_LEN] = { |
David Lawrence Ramsey | 576bf33 | 2004-07-12 03:10:30 +0000 | [diff] [blame] | 3112 | N_("The nano text editor"), |
| 3113 | N_("version"), |
| 3114 | N_("Brought to you by:"), |
| 3115 | N_("Special thanks to:"), |
| 3116 | N_("The Free Software Foundation"), |
| 3117 | N_("For ncurses:"), |
| 3118 | N_("and anyone else we forgot..."), |
| 3119 | N_("Thank you for using nano!") |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3120 | }; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 3121 | |
David Lawrence Ramsey | 47daf02 | 2005-08-29 18:29:02 +0000 | [diff] [blame] | 3122 | /* credits[15]: Make sure this name is displayed properly, since we |
David Lawrence Ramsey | 62d616b | 2005-07-06 19:20:32 +0000 | [diff] [blame] | 3123 | * can't dynamically assign it above, using Unicode 00F6 (Latin |
| 3124 | * Small Letter O with Diaresis) if applicable. */ |
David Lawrence Ramsey | 47daf02 | 2005-08-29 18:29:02 +0000 | [diff] [blame] | 3125 | credits[15] = |
David Lawrence Ramsey | 7eb30a8 | 2005-07-17 02:40:07 +0000 | [diff] [blame] | 3126 | #ifdef ENABLE_UTF8 |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3127 | ISSET(USE_UTF8) ? "Florian K\xC3\xB6nig" : |
| 3128 | #endif |
| 3129 | "Florian K\xF6nig"; |
| 3130 | |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3131 | if (!old_more_space || !old_no_help) { |
| 3132 | SET(MORE_SPACE); |
| 3133 | SET(NO_HELP); |
| 3134 | window_init(); |
| 3135 | } |
| 3136 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3137 | curs_set(0); |
| 3138 | nodelay(edit, TRUE); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3139 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3140 | blank_titlebar(); |
David Lawrence Ramsey | 637b8bb | 2005-01-17 05:06:55 +0000 | [diff] [blame] | 3141 | blank_topbar(); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 3142 | blank_edit(); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3143 | blank_statusbar(); |
| 3144 | blank_bottombars(); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3145 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3146 | wrefresh(topwin); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 3147 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3148 | wrefresh(bottomwin); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3149 | napms(700); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3150 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3151 | for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) { |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3152 | if ((kbinput = wgetch(edit)) != ERR) |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3153 | break; |
David Lawrence Ramsey | 0099a8f | 2005-03-15 06:34:09 +0000 | [diff] [blame] | 3154 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3155 | if (crpos < CREDIT_LEN) { |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3156 | const char *what; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3157 | size_t start_x; |
| 3158 | |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3159 | if (credits[crpos] == NULL) { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3160 | assert(0 <= xlpos && xlpos < XLCREDIT_LEN); |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3161 | |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3162 | what = _(xlcredits[xlpos]); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3163 | xlpos++; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3164 | } else |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3165 | what = credits[crpos]; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3166 | |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 3167 | start_x = COLS / 2 - strlenpt(what) / 2 - 1; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3168 | mvwaddstr(edit, editwinrows - 1 - (editwinrows % 2), |
| 3169 | start_x, what); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3170 | } |
David Lawrence Ramsey | 0099a8f | 2005-03-15 06:34:09 +0000 | [diff] [blame] | 3171 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3172 | wrefresh(edit); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3173 | |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3174 | if ((kbinput = wgetch(edit)) != ERR) |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3175 | break; |
| 3176 | napms(700); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3177 | |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3178 | scrollok(edit, TRUE); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3179 | wscrl(edit, 1); |
| 3180 | scrollok(edit, FALSE); |
| 3181 | wrefresh(edit); |
| 3182 | |
| 3183 | if ((kbinput = wgetch(edit)) != ERR) |
| 3184 | break; |
| 3185 | napms(700); |
| 3186 | |
| 3187 | scrollok(edit, TRUE); |
| 3188 | wscrl(edit, 1); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3189 | scrollok(edit, FALSE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3190 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3193 | if (kbinput != ERR) |
| 3194 | ungetch(kbinput); |
| 3195 | |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3196 | if (!old_more_space || !old_no_help) { |
| 3197 | UNSET(MORE_SPACE); |
| 3198 | UNSET(NO_HELP); |
| 3199 | window_init(); |
| 3200 | } |
| 3201 | |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3202 | curs_set(1); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3203 | nodelay(edit, FALSE); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3204 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3205 | total_refresh(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3206 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3207 | #endif |