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