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