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, * |
Benno Schulenberg | 7a9f4a4 | 2014-04-30 20:18:26 +0000 | [diff] [blame^] | 6 | * 2008, 2009, 2010, 2011, 2013, 2014 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 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 115 | #ifndef NANO_TINY |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 116 | allow_pending_sigwinch(TRUE); |
| 117 | #endif |
David Lawrence Ramsey | 78ea5e4 | 2004-12-12 19:04:56 +0000 | [diff] [blame] | 118 | |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 119 | /* Just before reading in the first character, display any pending |
| 120 | * screen updates. */ |
| 121 | doupdate(); |
| 122 | |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 123 | /* Read in the first character using whatever mode we're in. */ |
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 | |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 177 | /* Switch back to waiting mode for input. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 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 |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 307 | * off. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 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 |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 327 | * a function key. */ |
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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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. */ |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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': |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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': |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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': |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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': |
Benno Schulenberg | 25e5896 | 2014-04-23 19:33:03 +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 |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 1304 | * was two and the second was five, and may be any decimal |
| 1305 | * value otherwise. Put it in the 1's position of the byte |
| 1306 | * sequence holder. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1307 | if (('0' <= kbinput && kbinput <= '5') || (byte < 250 && |
| 1308 | '6' <= kbinput && kbinput <= '9')) { |
David Lawrence Ramsey | 2888964 | 2006-05-30 20:51:15 +0000 | [diff] [blame] | 1309 | byte += kbinput - '0'; |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 1310 | /* The byte sequence is complete. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1311 | retval = byte; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1312 | } else |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1313 | /* This isn't the third digit of a byte sequence. |
| 1314 | * Return this character as the result. */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1315 | retval = kbinput; |
| 1316 | break; |
| 1317 | default: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1318 | /* If there are more than three digits, return this |
| 1319 | * character as the result. (Maybe we should produce an |
| 1320 | * error instead?) */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1321 | retval = kbinput; |
| 1322 | break; |
| 1323 | } |
| 1324 | |
| 1325 | /* If we have a result, reset the byte digit counter and the byte |
| 1326 | * sequence holder. */ |
| 1327 | if (retval != ERR) { |
| 1328 | byte_digits = 0; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1329 | byte = 0; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | #ifdef DEBUG |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1333 | 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] | 1334 | #endif |
| 1335 | |
| 1336 | return retval; |
| 1337 | } |
| 1338 | |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1339 | #ifdef ENABLE_UTF8 |
David Lawrence Ramsey | 7f1b119 | 2006-05-28 17:30:28 +0000 | [diff] [blame] | 1340 | /* If the character in kbinput is a valid hexadecimal digit, multiply it |
| 1341 | * by factor and add the result to uni. */ |
| 1342 | long add_unicode_digit(int kbinput, long factor, long *uni) |
| 1343 | { |
| 1344 | long retval = ERR; |
| 1345 | |
| 1346 | if ('0' <= kbinput && kbinput <= '9') |
| 1347 | *uni += (kbinput - '0') * factor; |
| 1348 | else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') |
| 1349 | *uni += (tolower(kbinput) - 'a' + 10) * factor; |
| 1350 | else |
| 1351 | /* If this character isn't a valid hexadecimal value, save it as |
| 1352 | * the result. */ |
| 1353 | retval = kbinput; |
| 1354 | |
| 1355 | return retval; |
| 1356 | } |
| 1357 | |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1358 | /* Translate a Unicode sequence: turn a six-digit hexadecimal number |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1359 | * (from 000000 to 10FFFF, case-insensitive) into its corresponding |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1360 | * multibyte value. */ |
David Lawrence Ramsey | fc0f8f8 | 2006-05-10 13:41:53 +0000 | [diff] [blame] | 1361 | long get_unicode_kbinput(int kbinput) |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1362 | { |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 1363 | static int uni_digits = 0; |
| 1364 | static long uni = 0; |
| 1365 | long retval = ERR; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1366 | |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1367 | /* Increment the Unicode digit counter. */ |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1368 | uni_digits++; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1369 | |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1370 | switch (uni_digits) { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1371 | case 1: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1372 | /* First digit: This must be zero or one. Put it in the |
| 1373 | * 0x100000's position of the Unicode sequence holder. */ |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1374 | if ('0' <= kbinput && kbinput <= '1') |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1375 | uni = (kbinput - '0') * 0x100000; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1376 | else |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1377 | /* This isn't the first digit of a Unicode sequence. |
| 1378 | * Return this character as the result. */ |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1379 | retval = kbinput; |
| 1380 | break; |
| 1381 | case 2: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1382 | /* Second digit: This must be zero if the first was one, and |
| 1383 | * may be any hexadecimal value if the first was zero. Put |
| 1384 | * it in the 0x10000's position of the Unicode sequence |
| 1385 | * holder. */ |
| 1386 | if (uni == 0 || '0' == kbinput) |
| 1387 | retval = add_unicode_digit(kbinput, 0x10000, &uni); |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1388 | else |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1389 | /* This isn't the second digit of a Unicode sequence. |
| 1390 | * Return this character as the result. */ |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1391 | retval = kbinput; |
| 1392 | break; |
| 1393 | case 3: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1394 | /* Third digit: This may be any hexadecimal value. Put it |
| 1395 | * in the 0x1000's position of the Unicode sequence |
| 1396 | * holder. */ |
| 1397 | retval = add_unicode_digit(kbinput, 0x1000, &uni); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1398 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1399 | case 4: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1400 | /* Fourth digit: This may be any hexadecimal value. Put it |
| 1401 | * in the 0x100's position of the Unicode sequence |
| 1402 | * holder. */ |
| 1403 | retval = add_unicode_digit(kbinput, 0x100, &uni); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1404 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1405 | case 5: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1406 | /* Fifth digit: This may be any hexadecimal value. Put it |
| 1407 | * in the 0x10's position of the Unicode sequence holder. */ |
| 1408 | retval = add_unicode_digit(kbinput, 0x10, &uni); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1409 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1410 | case 6: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1411 | /* Sixth digit: This may be any hexadecimal value. Put it |
| 1412 | * in the 0x1's position of the Unicode sequence holder. */ |
| 1413 | retval = add_unicode_digit(kbinput, 0x1, &uni); |
| 1414 | /* If this character is a valid hexadecimal value, then the |
| 1415 | * Unicode sequence is complete. */ |
| 1416 | if (retval == ERR) |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1417 | retval = uni; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | default: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1420 | /* If there are more than six digits, return this character |
| 1421 | * as the result. (Maybe we should produce an error |
| 1422 | * instead?) */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1423 | retval = kbinput; |
| 1424 | break; |
| 1425 | } |
| 1426 | |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1427 | /* If we have a result, reset the Unicode digit counter and the |
| 1428 | * Unicode sequence holder. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1429 | if (retval != ERR) { |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1430 | uni_digits = 0; |
| 1431 | uni = 0; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | #ifdef DEBUG |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 1435 | 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] | 1436 | #endif |
| 1437 | |
| 1438 | return retval; |
| 1439 | } |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1440 | #endif /* ENABLE_UTF8 */ |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1441 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1442 | /* Translate a control character sequence: turn an ASCII non-control |
| 1443 | * character into its corresponding control character. */ |
| 1444 | int get_control_kbinput(int kbinput) |
| 1445 | { |
| 1446 | int retval; |
| 1447 | |
David Lawrence Ramsey | 4d9ef69 | 2006-04-28 18:26:07 +0000 | [diff] [blame] | 1448 | /* Ctrl-Space (Ctrl-2, Ctrl-@, Ctrl-`) */ |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1449 | if (kbinput == ' ' || kbinput == '2') |
| 1450 | retval = NANO_CONTROL_SPACE; |
David Lawrence Ramsey | 4d9ef69 | 2006-04-28 18:26:07 +0000 | [diff] [blame] | 1451 | /* Ctrl-/ (Ctrl-7, Ctrl-_) */ |
| 1452 | else if (kbinput == '/') |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1453 | retval = NANO_CONTROL_7; |
David Lawrence Ramsey | 4d9ef69 | 2006-04-28 18:26:07 +0000 | [diff] [blame] | 1454 | /* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-/, Ctrl-_) */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1455 | else if ('3' <= kbinput && kbinput <= '7') |
| 1456 | retval = kbinput - 24; |
| 1457 | /* Ctrl-8 (Ctrl-?) */ |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1458 | else if (kbinput == '8' || kbinput == '?') |
| 1459 | retval = NANO_CONTROL_8; |
David Lawrence Ramsey | 51cb7fd | 2006-05-20 17:19:09 +0000 | [diff] [blame] | 1460 | /* Ctrl-@ (Ctrl-Space, Ctrl-2, Ctrl-`) to Ctrl-_ (Ctrl-/, Ctrl-7) */ |
| 1461 | else if ('@' <= kbinput && kbinput <= '_') |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1462 | retval = kbinput - '@'; |
David Lawrence Ramsey | 4d9ef69 | 2006-04-28 18:26:07 +0000 | [diff] [blame] | 1463 | /* Ctrl-` (Ctrl-2, Ctrl-Space, Ctrl-@) to Ctrl-~ (Ctrl-6, Ctrl-^) */ |
| 1464 | else if ('`' <= kbinput && kbinput <= '~') |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1465 | retval = kbinput - '`'; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1466 | else |
| 1467 | retval = kbinput; |
| 1468 | |
| 1469 | #ifdef DEBUG |
| 1470 | fprintf(stderr, "get_control_kbinput(): kbinput = %d, retval = %d\n", kbinput, retval); |
| 1471 | #endif |
| 1472 | |
| 1473 | return retval; |
| 1474 | } |
| 1475 | |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 1476 | /* Put the output-formatted characters in output back into the keystroke |
| 1477 | * 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] | 1478 | void unparse_kbinput(char *output, size_t output_len) |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1479 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1480 | int *input; |
| 1481 | size_t i; |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1482 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1483 | if (output_len == 0) |
| 1484 | return; |
| 1485 | |
| 1486 | input = (int *)nmalloc(output_len * sizeof(int)); |
David Lawrence Ramsey | bd53980 | 2006-12-02 23:39:16 +0000 | [diff] [blame] | 1487 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1488 | for (i = 0; i < output_len; i++) |
| 1489 | input[i] = (int)output[i]; |
David Lawrence Ramsey | bd53980 | 2006-12-02 23:39:16 +0000 | [diff] [blame] | 1490 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1491 | unget_input(input, output_len); |
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 | free(input); |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1496 | /* 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] | 1497 | * string in kbinput_len. Assume nodelay(win) is FALSE. */ |
| 1498 | int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) |
| 1499 | { |
| 1500 | int *retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1501 | |
| 1502 | /* 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] | 1503 | * them in verbatim, and turn the keypad off if necessary so that we |
| 1504 | * don't get extended keypad values. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1505 | if (ISSET(PRESERVE)) |
| 1506 | disable_flow_control(); |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1507 | if (!ISSET(REBIND_KEYPAD)) |
| 1508 | keypad(win, FALSE); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1509 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1510 | /* Read in a stream of characters and interpret it if possible. */ |
| 1511 | retval = parse_verbatim_kbinput(win, kbinput_len); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1512 | |
| 1513 | /* Turn flow control characters back on if necessary and turn the |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1514 | * keypad back on if necessary now that we're done. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1515 | if (ISSET(PRESERVE)) |
| 1516 | enable_flow_control(); |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1517 | if (!ISSET(REBIND_KEYPAD)) |
| 1518 | keypad(win, TRUE); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1519 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1520 | return retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1523 | /* Read in a stream of all available characters, and return the length |
| 1524 | * 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] | 1525 | * the input into the corresponding multibyte value if possible. After |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 1526 | * that, leave the input as-is. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1527 | int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1528 | { |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 1529 | int *kbinput, *retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1530 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1531 | /* Read in the first keystroke. */ |
| 1532 | while ((kbinput = get_input(win, 1)) == NULL); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1533 | |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1534 | #ifdef ENABLE_UTF8 |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1535 | if (using_utf8()) { |
| 1536 | /* Check whether the first keystroke is a valid hexadecimal |
| 1537 | * digit. */ |
David Lawrence Ramsey | a5b1ca2 | 2006-05-28 17:09:49 +0000 | [diff] [blame] | 1538 | long uni = get_unicode_kbinput(*kbinput); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1539 | |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1540 | /* If the first keystroke isn't a valid hexadecimal digit, put |
| 1541 | * back the first keystroke. */ |
| 1542 | if (uni != ERR) |
| 1543 | unget_input(kbinput, 1); |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1544 | |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1545 | /* Otherwise, read in keystrokes until we have a complete |
| 1546 | * Unicode sequence, and put back the corresponding Unicode |
| 1547 | * value. */ |
| 1548 | else { |
| 1549 | char *uni_mb; |
| 1550 | int uni_mb_len, *seq, i; |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1551 | |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1552 | if (win == edit) |
| 1553 | /* TRANSLATORS: This is displayed during the input of a |
| 1554 | * six-digit hexadecimal Unicode character code. */ |
| 1555 | statusbar(_("Unicode Input")); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1556 | |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1557 | while (uni == ERR) { |
| 1558 | while ((kbinput = get_input(win, 1)) == NULL); |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1559 | |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1560 | uni = get_unicode_kbinput(*kbinput); |
| 1561 | } |
David Lawrence Ramsey | 6a2f068 | 2004-12-20 01:13:55 +0000 | [diff] [blame] | 1562 | |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1563 | /* Put back the multibyte equivalent of the Unicode |
| 1564 | * value. */ |
| 1565 | uni_mb = make_mbchar(uni, &uni_mb_len); |
| 1566 | |
| 1567 | seq = (int *)nmalloc(uni_mb_len * sizeof(int)); |
| 1568 | |
| 1569 | for (i = 0; i < uni_mb_len; i++) |
| 1570 | seq[i] = (unsigned char)uni_mb[i]; |
| 1571 | |
| 1572 | unget_input(seq, uni_mb_len); |
| 1573 | |
| 1574 | free(seq); |
| 1575 | free(uni_mb); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1576 | } |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1577 | } else |
David Lawrence Ramsey | a5b1ca2 | 2006-05-28 17:09:49 +0000 | [diff] [blame] | 1578 | #endif /* ENABLE_UTF8 */ |
| 1579 | |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1580 | /* Put back the first keystroke. */ |
| 1581 | unget_input(kbinput, 1); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1582 | |
David Lawrence Ramsey | ad36bdc | 2006-12-02 17:22:21 +0000 | [diff] [blame] | 1583 | free(kbinput); |
| 1584 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1585 | /* 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] | 1586 | * result. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 1587 | *kbinput_len = get_key_buffer_len(); |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1588 | retval = get_input(NULL, *kbinput_len); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1589 | |
| 1590 | return retval; |
| 1591 | } |
| 1592 | |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1593 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1594 | /* Handle any mouse event that may have occurred. We currently handle |
David Lawrence Ramsey | 3a50470 | 2007-05-29 17:01:12 +0000 | [diff] [blame] | 1595 | * releases/clicks of the first mouse button. If allow_shortcuts is |
| 1596 | * TRUE, releasing/clicking on a visible shortcut will put back the |
| 1597 | * keystroke associated with that shortcut. If NCURSES_MOUSE_VERSION is |
| 1598 | * at least 2, we also currently handle presses of the fourth mouse |
| 1599 | * button (upward rolls of the mouse wheel) by putting back the |
| 1600 | * keystrokes to move up, and presses of the fifth mouse button |
| 1601 | * (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] | 1602 | * move down. We also store the coordinates of a mouse event that needs |
| 1603 | * to be handled in mouse_x and mouse_y, relative to the entire screen. |
| 1604 | * Return -1 on error, 0 if the mouse event needs to be handled, 1 if |
| 1605 | * it's been handled by putting back keystrokes that need to be handled. |
| 1606 | * or 2 if it's been ignored. Assume that KEY_MOUSE has already been |
| 1607 | * read in. */ |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1608 | 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] | 1609 | { |
| 1610 | MEVENT mevent; |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1611 | bool in_bottomwin; |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1612 | subnfunc *f; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1613 | |
| 1614 | *mouse_x = -1; |
| 1615 | *mouse_y = -1; |
| 1616 | |
| 1617 | /* First, get the actual mouse event. */ |
| 1618 | if (getmouse(&mevent) == ERR) |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1619 | return -1; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1620 | |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1621 | /* Save the screen coordinates where the mouse event took place. */ |
| 1622 | *mouse_x = mevent.x; |
| 1623 | *mouse_y = mevent.y; |
David Lawrence Ramsey | 98e4d4f | 2006-06-28 21:54:55 +0000 | [diff] [blame] | 1624 | |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1625 | in_bottomwin = wenclose(bottomwin, *mouse_y, *mouse_x); |
| 1626 | |
David Lawrence Ramsey | 5fcf8bf | 2007-06-28 18:31:13 +0000 | [diff] [blame] | 1627 | /* Handle releases/clicks of the first mouse button. */ |
David Lawrence Ramsey | 3a50470 | 2007-05-29 17:01:12 +0000 | [diff] [blame] | 1628 | if (mevent.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) { |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1629 | /* If we're allowing shortcuts, the current shortcut list is |
| 1630 | * 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] | 1631 | * first mouse button was released on/clicked inside it, we need |
| 1632 | * to figure out which shortcut was released on/clicked and put |
| 1633 | * back the equivalent keystroke(s) for it. */ |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1634 | if (allow_shortcuts && !ISSET(NO_HELP) && in_bottomwin) { |
David Lawrence Ramsey | bc65313 | 2007-05-22 17:20:28 +0000 | [diff] [blame] | 1635 | int i; |
| 1636 | /* The width of all the shortcuts, except for the last |
| 1637 | * two, in the shortcut list in bottomwin. */ |
| 1638 | int j; |
| 1639 | /* The y-coordinate relative to the beginning of the |
| 1640 | * shortcut list in bottomwin. */ |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1641 | size_t currslen; |
| 1642 | /* The number of shortcuts in the current shortcut |
| 1643 | * list. */ |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1644 | |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1645 | /* Translate the mouse event coordinates so that they're |
| 1646 | * relative to bottomwin. */ |
| 1647 | wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE); |
| 1648 | |
| 1649 | /* Handle releases/clicks of the first mouse button on the |
| 1650 | * statusbar elsewhere. */ |
| 1651 | if (*mouse_y == 0) { |
| 1652 | /* Restore the untranslated mouse event coordinates, so |
| 1653 | * that they're relative to the entire screen again. */ |
| 1654 | *mouse_x = mevent.x; |
| 1655 | *mouse_y = mevent.y; |
| 1656 | |
| 1657 | return 0; |
| 1658 | } |
David Lawrence Ramsey | bc65313 | 2007-05-22 17:20:28 +0000 | [diff] [blame] | 1659 | |
| 1660 | /* Calculate the y-coordinate relative to the beginning of |
| 1661 | * the shortcut list in bottomwin. */ |
| 1662 | j = *mouse_y - 1; |
| 1663 | |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1664 | /* Get the shortcut lists' length. */ |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1665 | if (currmenu == MMAIN) |
David Lawrence Ramsey | fe0d366 | 2004-08-26 01:43:16 +0000 | [diff] [blame] | 1666 | currslen = MAIN_VISIBLE; |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1667 | else { |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1668 | currslen = length_of_list(currmenu); |
David Lawrence Ramsey | fe0d366 | 2004-08-26 01:43:16 +0000 | [diff] [blame] | 1669 | |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1670 | /* We don't show any more shortcuts than the main list |
| 1671 | * does. */ |
| 1672 | if (currslen > MAIN_VISIBLE) |
| 1673 | currslen = MAIN_VISIBLE; |
| 1674 | } |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1675 | |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1676 | /* Calculate the width of all of the shortcuts in the list |
| 1677 | * except for the last two, which are longer by (COLS % i) |
| 1678 | * columns so as to not waste space. */ |
| 1679 | if (currslen < 2) |
| 1680 | i = COLS / (MAIN_VISIBLE / 2); |
| 1681 | else |
| 1682 | i = COLS / ((currslen / 2) + (currslen % 2)); |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1683 | |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1684 | /* Calculate the x-coordinate relative to the beginning of |
| 1685 | * the shortcut list in bottomwin, and add it to j. j |
| 1686 | * should now be the index in the shortcut list of the |
David Lawrence Ramsey | 3a50470 | 2007-05-29 17:01:12 +0000 | [diff] [blame] | 1687 | * shortcut we released/clicked on. */ |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1688 | j = (*mouse_x / i) * 2 + j; |
| 1689 | |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1690 | /* Adjust j if we released on the last two shortcuts. */ |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1691 | if ((j >= currslen) && (*mouse_x % i < COLS % i)) |
| 1692 | j -= 2; |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1693 | #ifdef DEBUG |
| 1694 | fprintf(stderr, "Calculated %i as index in shortcut list, currmenu = %x.\n", j, currmenu); |
| 1695 | #endif |
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 | |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1701 | /* Go through the list of functions to determine which |
| 1702 | * shortcut in the current menu 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 | |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1705 | while (TRUE) { |
| 1706 | while ((f->menus & currmenu) == 0 |
Chris Allegretta | 1d77823 | 2008-08-30 21:00:00 +0000 | [diff] [blame] | 1707 | #ifndef DISABLE_HELP |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1708 | || strlen(f->help) == 0 |
Chris Allegretta | 1d77823 | 2008-08-30 21:00:00 +0000 | [diff] [blame] | 1709 | #endif |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1710 | ) |
| 1711 | f = f->next; |
| 1712 | if (j == 0) |
| 1713 | break; |
| 1714 | f = f->next; |
| 1715 | j -= 1; |
Chris Allegretta | c0b7872 | 2008-03-11 04:52:57 +0000 | [diff] [blame] | 1716 | } |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1717 | #ifdef DEBUG |
Benno Schulenberg | 27a52a8 | 2014-04-21 13:07:18 +0000 | [diff] [blame] | 1718 | fprintf(stderr, "Stopped on func %ld present in menus %x\n", (long)f->scfunc, f->menus); |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1719 | #endif |
Chris Allegretta | c0b7872 | 2008-03-11 04:52:57 +0000 | [diff] [blame] | 1720 | |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1721 | /* And put the corresponding key into the keyboard buffer. */ |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1722 | if (f != NULL) { |
Chris Allegretta | a117163 | 2009-01-19 19:10:39 +0000 | [diff] [blame] | 1723 | const sc *s = first_sc_for(currmenu, f->scfunc); |
Chris Allegretta | c0b7872 | 2008-03-11 04:52:57 +0000 | [diff] [blame] | 1724 | if (s != NULL) |
| 1725 | unget_kbinput(s->seq, s->type == META, FALSE); |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1726 | } |
| 1727 | } else |
David Lawrence Ramsey | 3a50470 | 2007-05-29 17:01:12 +0000 | [diff] [blame] | 1728 | /* Handle releases/clicks of the first mouse button that |
| 1729 | * aren't on the current shortcut list elsewhere. */ |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1730 | return 0; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1731 | } |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1732 | #if NCURSES_MOUSE_VERSION >= 2 |
| 1733 | /* Handle presses of the fourth mouse button (upward rolls of the |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1734 | * mouse wheel) and presses of the fifth mouse button (downward |
| 1735 | * rolls of the mouse wheel) . */ |
| 1736 | else if (mevent.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) { |
David Lawrence Ramsey | def6091 | 2007-12-08 16:59:13 +0000 | [diff] [blame] | 1737 | bool in_edit = wenclose(edit, *mouse_y, *mouse_x); |
David Lawrence Ramsey | bc65313 | 2007-05-22 17:20:28 +0000 | [diff] [blame] | 1738 | |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1739 | if (in_bottomwin) |
| 1740 | /* Translate the mouse event coordinates so that they're |
| 1741 | * relative to bottomwin. */ |
| 1742 | wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE); |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1743 | |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1744 | if (in_edit || (in_bottomwin && *mouse_y == 0)) { |
David Lawrence Ramsey | def6091 | 2007-12-08 16:59:13 +0000 | [diff] [blame] | 1745 | int i; |
| 1746 | |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1747 | /* One upward roll of the mouse wheel is equivalent to |
| 1748 | * moving up three lines, and one downward roll of the mouse |
| 1749 | * wheel is equivalent to moving down three lines. */ |
| 1750 | for (i = 0; i < 3; i++) |
| 1751 | unget_kbinput((mevent.bstate & BUTTON4_PRESSED) ? |
Benno Schulenberg | c4520d5 | 2014-02-22 19:36:35 +0000 | [diff] [blame] | 1752 | sc_seq_or(do_up_void, 0) : sc_seq_or(do_down_void, 0), |
| 1753 | FALSE, FALSE); |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1754 | |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1755 | return 1; |
| 1756 | } else |
| 1757 | /* Ignore presses of the fourth mouse button and presses of |
| 1758 | * the fifth mouse buttons that aren't on the edit window or |
| 1759 | * the statusbar. */ |
| 1760 | return 2; |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1761 | } |
| 1762 | #endif |
David Lawrence Ramsey | c8bde57 | 2007-06-28 16:38:00 +0000 | [diff] [blame] | 1763 | |
| 1764 | /* Ignore all other mouse events. */ |
| 1765 | return 2; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1766 | } |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1767 | #endif /* !DISABLE_MOUSE */ |
| 1768 | |
Benno Schulenberg | 7828a80 | 2014-04-14 09:22:29 +0000 | [diff] [blame] | 1769 | /* Return the shortcut that corresponds to the values of kbinput (the |
| 1770 | * key itself) and meta_key (whether the key is a meta sequence). The |
| 1771 | * returned shortcut will be the first in the list that corresponds to |
| 1772 | * the given sequence. */ |
| 1773 | const sc *get_shortcut(int menu, int *kbinput, bool *meta_key) |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1774 | { |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1775 | sc *s; |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1776 | |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1777 | #ifdef DEBUG |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1778 | fprintf(stderr, "get_shortcut(): kbinput = %d, meta_key = %s -- ", *kbinput, *meta_key ? "TRUE" : "FALSE"); |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1779 | #endif |
| 1780 | |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1781 | /* Check for shortcuts. */ |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1782 | for (s = sclist; s != NULL; s = s->next) { |
| 1783 | if ((menu & s->menu) |
| 1784 | && ((s->type == META && *meta_key == TRUE && *kbinput == s->seq) |
| 1785 | || (s->type != META && *kbinput == s->seq))) { |
| 1786 | #ifdef DEBUG |
Benno Schulenberg | 7828a80 | 2014-04-14 09:22:29 +0000 | [diff] [blame] | 1787 | fprintf (stderr, "matched seq \"%s\", and btw meta was %d (menu is %x from %x)\n", |
| 1788 | s->keystr, *meta_key, menu, s->menu); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1789 | #endif |
David Lawrence Ramsey | f4a799a | 2005-01-08 06:16:19 +0000 | [diff] [blame] | 1790 | return s; |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1791 | } |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1792 | } |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1793 | #ifdef DEBUG |
Benno Schulenberg | 18c252d | 2014-03-24 20:35:17 +0000 | [diff] [blame] | 1794 | fprintf (stderr, "matched nothing, btw meta was %d\n", *meta_key); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1795 | #endif |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1796 | |
| 1797 | return NULL; |
| 1798 | } |
| 1799 | |
Benno Schulenberg | 1e3f6bc | 2014-04-14 10:03:32 +0000 | [diff] [blame] | 1800 | /* Try to get a function back from a window. Just a wrapper. */ |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 1801 | const subnfunc *getfuncfromkey(WINDOW *win) |
| 1802 | { |
| 1803 | int kbinput; |
| 1804 | bool func_key = FALSE, meta_key = FALSE; |
| 1805 | const sc *s; |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 1806 | |
| 1807 | kbinput = parse_kbinput(win, &meta_key, &func_key); |
| 1808 | if (kbinput == 0) |
| 1809 | return NULL; |
| 1810 | |
Benno Schulenberg | 7828a80 | 2014-04-14 09:22:29 +0000 | [diff] [blame] | 1811 | s = get_shortcut(currmenu, &kbinput, &meta_key); |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 1812 | if (!s) |
| 1813 | return NULL; |
| 1814 | |
Benno Schulenberg | 1e3f6bc | 2014-04-14 10:03:32 +0000 | [diff] [blame] | 1815 | return sctofunc((sc *) s); |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1818 | /* Move to (x, y) in win, and display a line of n spaces with the |
| 1819 | * current attributes. */ |
| 1820 | void blank_line(WINDOW *win, int y, int x, int n) |
| 1821 | { |
| 1822 | wmove(win, y, x); |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 1823 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1824 | for (; n > 0; n--) |
| 1825 | waddch(win, ' '); |
| 1826 | } |
| 1827 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1828 | /* Blank the first line of the top portion of the window. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1829 | void blank_titlebar(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1830 | { |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1831 | blank_line(topwin, 0, 0, COLS); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1834 | /* If the MORE_SPACE flag isn't set, blank the second line of the top |
| 1835 | * portion of the window. */ |
David Lawrence Ramsey | 637b8bb | 2005-01-17 05:06:55 +0000 | [diff] [blame] | 1836 | void blank_topbar(void) |
| 1837 | { |
| 1838 | if (!ISSET(MORE_SPACE)) |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1839 | blank_line(topwin, 1, 0, COLS); |
David Lawrence Ramsey | 637b8bb | 2005-01-17 05:06:55 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
David Lawrence Ramsey | b159f94 | 2006-07-28 17:06:27 +0000 | [diff] [blame] | 1842 | /* 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] | 1843 | * edit window. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1844 | void blank_edit(void) |
| 1845 | { |
David Lawrence Ramsey | 86e851b | 2004-07-28 20:46:25 +0000 | [diff] [blame] | 1846 | int i; |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 1847 | |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 1848 | for (i = 0; i < editwinrows; i++) |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1849 | blank_line(edit, i, 0, COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1852 | /* Blank the first line of the bottom portion of the window. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1853 | void blank_statusbar(void) |
| 1854 | { |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1855 | blank_line(bottomwin, 0, 0, COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1858 | /* If the NO_HELP flag isn't set, blank the last two lines of the bottom |
| 1859 | * portion of the window. */ |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 1860 | void blank_bottombars(void) |
| 1861 | { |
| 1862 | if (!ISSET(NO_HELP)) { |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1863 | blank_line(bottomwin, 1, 0, COLS); |
| 1864 | blank_line(bottomwin, 2, 0, COLS); |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 1865 | } |
| 1866 | } |
| 1867 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1868 | /* Check if the number of keystrokes needed to blank the statusbar has |
| 1869 | * been pressed. If so, blank the statusbar, unless constant cursor |
| 1870 | * position display is on. */ |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 1871 | void check_statusblank(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1872 | { |
David Lawrence Ramsey | 100bc30 | 2006-05-27 18:06:11 +0000 | [diff] [blame] | 1873 | if (statusblank > 0) { |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 1874 | statusblank--; |
David Lawrence Ramsey | bf51aa4 | 2005-06-17 21:52:59 +0000 | [diff] [blame] | 1875 | |
David Lawrence Ramsey | 100bc30 | 2006-05-27 18:06:11 +0000 | [diff] [blame] | 1876 | if (statusblank == 0 && !ISSET(CONST_UPDATE)) { |
| 1877 | blank_statusbar(); |
| 1878 | wnoutrefresh(bottomwin); |
| 1879 | reset_cursor(); |
| 1880 | wnoutrefresh(edit); |
| 1881 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1885 | /* Convert buf into a string that can be displayed on screen. The |
| 1886 | * caller wants to display buf starting with column start_col, and |
| 1887 | * extending for at most len columns. start_col is zero-based. len is |
| 1888 | * one-based, so len == 0 means you get "" returned. The returned |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1889 | * string is dynamically allocated, and should be freed. If dollars is |
| 1890 | * TRUE, the caller might put "$" at the beginning or end of the line if |
| 1891 | * it's too long. */ |
| 1892 | char *display_string(const char *buf, size_t start_col, size_t len, bool |
| 1893 | dollars) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1894 | { |
| 1895 | size_t start_index; |
David Lawrence Ramsey | 61a7140 | 2004-12-24 15:45:36 +0000 | [diff] [blame] | 1896 | /* Index in buf of the first character shown. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1897 | size_t column; |
David Lawrence Ramsey | 61a7140 | 2004-12-24 15:45:36 +0000 | [diff] [blame] | 1898 | /* Screen column that start_index corresponds to. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1899 | size_t alloc_len; |
| 1900 | /* The length of memory allocated for converted. */ |
| 1901 | char *converted; |
| 1902 | /* The string we return. */ |
| 1903 | size_t index; |
| 1904 | /* Current position in converted. */ |
David Lawrence Ramsey | 1f104f8 | 2006-02-03 03:51:51 +0000 | [diff] [blame] | 1905 | char *buf_mb; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1906 | int buf_mb_len; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1907 | |
David Lawrence Ramsey | 9dffac9 | 2005-01-05 06:09:34 +0000 | [diff] [blame] | 1908 | /* If dollars is TRUE, make room for the "$" at the end of the |
| 1909 | * line. */ |
| 1910 | if (dollars && len > 0 && strlenpt(buf) > start_col + len) |
| 1911 | len--; |
| 1912 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1913 | if (len == 0) |
| 1914 | return mallocstrcpy(NULL, ""); |
| 1915 | |
David Lawrence Ramsey | 1f104f8 | 2006-02-03 03:51:51 +0000 | [diff] [blame] | 1916 | buf_mb = charalloc(mb_cur_max()); |
| 1917 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1918 | start_index = actual_x(buf, start_col); |
| 1919 | column = strnlenpt(buf, start_index); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1920 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1921 | assert(column <= start_col); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1922 | |
David Lawrence Ramsey | 114cfb6 | 2006-02-03 03:58:49 +0000 | [diff] [blame] | 1923 | /* Make sure there's enough room for the initial character, whether |
| 1924 | * it's a multibyte control character, a non-control multibyte |
| 1925 | * character, a tab character, or a null terminator. Rationale: |
| 1926 | * |
| 1927 | * multibyte control character followed by a null terminator: |
| 1928 | * 1 byte ('^') + mb_cur_max() bytes + 1 byte ('\0') |
| 1929 | * multibyte non-control character followed by a null terminator: |
| 1930 | * mb_cur_max() bytes + 1 byte ('\0') |
| 1931 | * tab character followed by a null terminator: |
| 1932 | * mb_cur_max() bytes + (tabsize - 1) bytes + 1 byte ('\0') |
| 1933 | * |
| 1934 | * Since tabsize has a minimum value of 1, it can substitute for 1 |
| 1935 | * byte above. */ |
| 1936 | alloc_len = (mb_cur_max() + tabsize + 1) * MAX_BUF_SIZE; |
| 1937 | converted = charalloc(alloc_len); |
David Lawrence Ramsey | bbd63e1 | 2005-01-05 16:59:49 +0000 | [diff] [blame] | 1938 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1939 | index = 0; |
| 1940 | |
David Lawrence Ramsey | 567d471 | 2006-07-05 05:31:21 +0000 | [diff] [blame] | 1941 | if (buf[start_index] != '\0' && buf[start_index] != '\t' && |
| 1942 | (column < start_col || (dollars && column > 0))) { |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1943 | /* We don't display all of buf[start_index] since it starts to |
| 1944 | * the left of the screen. */ |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1945 | buf_mb_len = parse_mbchar(buf + start_index, buf_mb, NULL); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1946 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1947 | if (is_cntrl_mbchar(buf_mb)) { |
David Lawrence Ramsey | fe3627d | 2004-12-24 17:52:17 +0000 | [diff] [blame] | 1948 | if (column < start_col) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1949 | char *ctrl_buf_mb = charalloc(mb_cur_max()); |
| 1950 | int ctrl_buf_mb_len, i; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1951 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1952 | ctrl_buf_mb = control_mbrep(buf_mb, ctrl_buf_mb, |
| 1953 | &ctrl_buf_mb_len); |
David Lawrence Ramsey | 6a643cd | 2004-12-27 23:11:59 +0000 | [diff] [blame] | 1954 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1955 | for (i = 0; i < ctrl_buf_mb_len; i++) |
| 1956 | converted[index++] = ctrl_buf_mb[i]; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1957 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1958 | start_col += mbwidth(ctrl_buf_mb); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1959 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1960 | free(ctrl_buf_mb); |
David Lawrence Ramsey | a9b9913 | 2004-12-27 23:35:25 +0000 | [diff] [blame] | 1961 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1962 | start_index += buf_mb_len; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1963 | } |
David Lawrence Ramsey | 956da0d | 2005-01-03 06:56:38 +0000 | [diff] [blame] | 1964 | } |
David Lawrence Ramsey | 7eb30a8 | 2005-07-17 02:40:07 +0000 | [diff] [blame] | 1965 | #ifdef ENABLE_UTF8 |
David Lawrence Ramsey | d99b0e1 | 2006-05-19 17:50:01 +0000 | [diff] [blame] | 1966 | else if (using_utf8() && mbwidth(buf_mb) == 2) { |
| 1967 | if (column >= start_col) { |
| 1968 | converted[index++] = ' '; |
| 1969 | start_col++; |
| 1970 | } |
| 1971 | |
David Lawrence Ramsey | 9dffac9 | 2005-01-05 06:09:34 +0000 | [diff] [blame] | 1972 | converted[index++] = ' '; |
David Lawrence Ramsey | a9b9913 | 2004-12-27 23:35:25 +0000 | [diff] [blame] | 1973 | start_col++; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1974 | |
| 1975 | start_index += buf_mb_len; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1976 | } |
David Lawrence Ramsey | 956da0d | 2005-01-03 06:56:38 +0000 | [diff] [blame] | 1977 | #endif |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
David Lawrence Ramsey | 114cfb6 | 2006-02-03 03:58:49 +0000 | [diff] [blame] | 1980 | while (buf[start_index] != '\0') { |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 1981 | buf_mb_len = parse_mbchar(buf + start_index, buf_mb, NULL); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1982 | |
David Lawrence Ramsey | 114cfb6 | 2006-02-03 03:58:49 +0000 | [diff] [blame] | 1983 | /* Make sure there's enough room for the next character, whether |
| 1984 | * it's a multibyte control character, a non-control multibyte |
| 1985 | * character, a tab character, or a null terminator. */ |
| 1986 | if (index + mb_cur_max() + tabsize + 1 >= alloc_len - 1) { |
| 1987 | alloc_len += (mb_cur_max() + tabsize + 1) * MAX_BUF_SIZE; |
| 1988 | converted = charealloc(converted, alloc_len); |
| 1989 | } |
| 1990 | |
David Lawrence Ramsey | 9838a51 | 2005-07-06 19:12:41 +0000 | [diff] [blame] | 1991 | /* If buf contains a tab character, interpret it. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1992 | if (*buf_mb == '\t') { |
Benno Schulenberg | eea0908 | 2014-04-13 20:50:20 +0000 | [diff] [blame] | 1993 | #if !defined(NANO_TINY) && !defined(DISABLE_NANORC) |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 1994 | if (ISSET(WHITESPACE_DISPLAY)) { |
| 1995 | int i; |
| 1996 | |
| 1997 | for (i = 0; i < whitespace_len[0]; i++) |
| 1998 | converted[index++] = whitespace[i]; |
| 1999 | } else |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2000 | #endif |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 2001 | converted[index++] = ' '; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2002 | start_col++; |
David Lawrence Ramsey | c195820 | 2004-12-27 23:21:34 +0000 | [diff] [blame] | 2003 | while (start_col % tabsize != 0) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2004 | converted[index++] = ' '; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2005 | start_col++; |
| 2006 | } |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 2007 | /* If buf contains a control character, interpret it. If buf |
David Lawrence Ramsey | 61f5673 | 2005-07-21 22:12:03 +0000 | [diff] [blame] | 2008 | * contains an invalid multibyte control character, display it |
| 2009 | * as such.*/ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 2010 | } else if (is_cntrl_mbchar(buf_mb)) { |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 2011 | char *ctrl_buf_mb = charalloc(mb_cur_max()); |
| 2012 | int ctrl_buf_mb_len, i; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2013 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2014 | converted[index++] = '^'; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2015 | start_col++; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2016 | |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 2017 | ctrl_buf_mb = control_mbrep(buf_mb, ctrl_buf_mb, |
| 2018 | &ctrl_buf_mb_len); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2019 | |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 2020 | for (i = 0; i < ctrl_buf_mb_len; i++) |
| 2021 | converted[index++] = ctrl_buf_mb[i]; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2022 | |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 2023 | start_col += mbwidth(ctrl_buf_mb); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2024 | |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 2025 | free(ctrl_buf_mb); |
David Lawrence Ramsey | 9838a51 | 2005-07-06 19:12:41 +0000 | [diff] [blame] | 2026 | /* If buf contains a space character, interpret it. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 2027 | } else if (*buf_mb == ' ') { |
Benno Schulenberg | eea0908 | 2014-04-13 20:50:20 +0000 | [diff] [blame] | 2028 | #if !defined(NANO_TINY) && !defined(DISABLE_NANORC) |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 2029 | if (ISSET(WHITESPACE_DISPLAY)) { |
| 2030 | int i; |
| 2031 | |
| 2032 | for (i = whitespace_len[0]; i < whitespace_len[0] + |
| 2033 | whitespace_len[1]; i++) |
| 2034 | converted[index++] = whitespace[i]; |
| 2035 | } else |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2036 | #endif |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 2037 | converted[index++] = ' '; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2038 | start_col++; |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 2039 | /* If buf contains a non-control character, interpret it. If |
| 2040 | * buf contains an invalid multibyte non-control character, |
| 2041 | * display it as such. */ |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2042 | } else { |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 2043 | char *nctrl_buf_mb = charalloc(mb_cur_max()); |
| 2044 | int nctrl_buf_mb_len, i; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2045 | |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 2046 | nctrl_buf_mb = mbrep(buf_mb, nctrl_buf_mb, |
| 2047 | &nctrl_buf_mb_len); |
David Lawrence Ramsey | f7bcbeb | 2005-07-18 03:23:37 +0000 | [diff] [blame] | 2048 | |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 2049 | for (i = 0; i < nctrl_buf_mb_len; i++) |
| 2050 | converted[index++] = nctrl_buf_mb[i]; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 2051 | |
David Lawrence Ramsey | 96452cb | 2005-07-26 06:13:45 +0000 | [diff] [blame] | 2052 | start_col += mbwidth(nctrl_buf_mb); |
| 2053 | |
| 2054 | free(nctrl_buf_mb); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 2057 | start_index += buf_mb_len; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
David Lawrence Ramsey | 6a0d5b8 | 2005-06-13 14:00:22 +0000 | [diff] [blame] | 2060 | free(buf_mb); |
| 2061 | |
David Lawrence Ramsey | 114cfb6 | 2006-02-03 03:58:49 +0000 | [diff] [blame] | 2062 | assert(alloc_len >= index + 1); |
| 2063 | |
David Lawrence Ramsey | e54f1c4 | 2006-10-29 21:14:53 +0000 | [diff] [blame] | 2064 | /* Null-terminate converted. */ |
David Lawrence Ramsey | 114cfb6 | 2006-02-03 03:58:49 +0000 | [diff] [blame] | 2065 | converted[index] = '\0'; |
David Lawrence Ramsey | 0251bdb | 2005-01-05 19:05:04 +0000 | [diff] [blame] | 2066 | |
| 2067 | /* Make sure converted takes up no more than len columns. */ |
| 2068 | index = actual_x(converted, len); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2069 | null_at(&converted, index); |
David Lawrence Ramsey | 0251bdb | 2005-01-05 19:05:04 +0000 | [diff] [blame] | 2070 | |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2071 | return converted; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
David Lawrence Ramsey | 4ea2eac | 2006-07-09 00:52:16 +0000 | [diff] [blame] | 2074 | /* If path is NULL, we're in normal editing mode, so display the current |
| 2075 | * version of nano, the current filename, and whether the current file |
| 2076 | * has been modified on the titlebar. If path isn't NULL, we're in the |
| 2077 | * file browser, and path contains the directory to start the file |
| 2078 | * browser in, so display the current version of nano and the contents |
| 2079 | * of path on the titlebar. */ |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 2080 | void titlebar(const char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2081 | { |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2082 | int space = COLS; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2083 | /* The space we have available for display. */ |
David Lawrence Ramsey | 3c43d3d | 2006-03-30 01:18:29 +0000 | [diff] [blame] | 2084 | size_t verlen = strlenpt(PACKAGE_STRING) + 1; |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2085 | /* The length of the version message in columns, plus one for |
| 2086 | * padding. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2087 | const char *prefix; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2088 | /* "DIR:", "File:", or "New Buffer". Goes before filename. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2089 | size_t prefixlen; |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2090 | /* The length of the prefix in columns, plus one for padding. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2091 | const char *state; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2092 | /* "Modified", "View", or "". Shows the state of this |
| 2093 | * buffer. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2094 | size_t statelen = 0; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2095 | /* The length of the state in columns, or the length of |
David Lawrence Ramsey | 4ea2eac | 2006-07-09 00:52:16 +0000 | [diff] [blame] | 2096 | * "Modified" if the state is blank and we're not in the file |
| 2097 | * browser. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2098 | char *exppath = NULL; |
David Lawrence Ramsey | 345a5b8 | 2006-07-04 03:47:36 +0000 | [diff] [blame] | 2099 | /* The filename, expanded for display. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2100 | bool newfie = FALSE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2101 | /* Do we say "New Buffer"? */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2102 | bool dots = FALSE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2103 | /* Do we put an ellipsis before the path? */ |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 2104 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2105 | assert(path != NULL || openfile->filename != NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2106 | |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 2107 | wattron(topwin, reverse_attr); |
David Lawrence Ramsey | 85ffaee | 2006-07-02 18:29:49 +0000 | [diff] [blame] | 2108 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2109 | blank_titlebar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2110 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2111 | /* space has to be at least 4: two spaces before the version message, |
| 2112 | * at least one character of the version message, and one space |
| 2113 | * after the version message. */ |
| 2114 | if (space < 4) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2115 | space = 0; |
| 2116 | else { |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2117 | /* Limit verlen to 1/3 the length of the screen in columns, |
| 2118 | * minus three columns for spaces. */ |
| 2119 | if (verlen > (COLS / 3) - 3) |
| 2120 | verlen = (COLS / 3) - 3; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2121 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2122 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2123 | if (space >= 4) { |
David Lawrence Ramsey | 90f772b | 2005-07-11 07:12:33 +0000 | [diff] [blame] | 2124 | /* Add a space after the version message, and account for both |
| 2125 | * it and the two spaces before it. */ |
David Lawrence Ramsey | 3c43d3d | 2006-03-30 01:18:29 +0000 | [diff] [blame] | 2126 | mvwaddnstr(topwin, 0, 2, PACKAGE_STRING, |
| 2127 | actual_x(PACKAGE_STRING, verlen)); |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2128 | verlen += 3; |
| 2129 | |
| 2130 | /* Account for the full length of the version message. */ |
| 2131 | space -= verlen; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2132 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2133 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2134 | #ifndef DISABLE_BROWSER |
| 2135 | /* Don't display the state if we're in the file browser. */ |
| 2136 | if (path != NULL) |
| 2137 | state = ""; |
| 2138 | else |
| 2139 | #endif |
| 2140 | state = openfile->modified ? _("Modified") : ISSET(VIEW_MODE) ? |
| 2141 | _("View") : ""; |
| 2142 | |
David Lawrence Ramsey | 1904f51 | 2007-07-01 21:33:17 +0000 | [diff] [blame] | 2143 | statelen = strlenpt((*state == '\0' && path == NULL) ? |
David Lawrence Ramsey | e328169 | 2006-07-09 00:50:23 +0000 | [diff] [blame] | 2144 | _("Modified") : state); |
David Lawrence Ramsey | 297851a | 2005-03-25 05:00:32 +0000 | [diff] [blame] | 2145 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2146 | /* If possible, add a space before state. */ |
| 2147 | if (space > 0 && statelen < space) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2148 | statelen++; |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2149 | else |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2150 | goto the_end; |
| 2151 | |
| 2152 | #ifndef DISABLE_BROWSER |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2153 | /* 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] | 2154 | if (path != NULL) |
| 2155 | prefix = _("DIR:"); |
| 2156 | else |
| 2157 | #endif |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2158 | if (openfile->filename[0] == '\0') { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2159 | prefix = _("New Buffer"); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2160 | newfie = TRUE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2161 | } else |
| 2162 | prefix = _("File:"); |
David Lawrence Ramsey | cb4f14b | 2005-03-24 22:28:25 +0000 | [diff] [blame] | 2163 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2164 | prefixlen = strnlenpt(prefix, space - statelen) + 1; |
David Lawrence Ramsey | cb4f14b | 2005-03-24 22:28:25 +0000 | [diff] [blame] | 2165 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2166 | /* If newfie is FALSE, add a space after prefix. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2167 | if (!newfie && prefixlen + statelen < space) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2168 | prefixlen++; |
| 2169 | |
David Lawrence Ramsey | 4ea2eac | 2006-07-09 00:52:16 +0000 | [diff] [blame] | 2170 | /* 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] | 2171 | * filename. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2172 | if (path == NULL) |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2173 | path = openfile->filename; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2174 | |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2175 | /* Account for the full lengths of the prefix and the state. */ |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2176 | if (space >= prefixlen + statelen) |
| 2177 | space -= prefixlen + statelen; |
| 2178 | else |
| 2179 | space = 0; |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2180 | /* space is now the room we have for the filename. */ |
David Lawrence Ramsey | 297851a | 2005-03-25 05:00:32 +0000 | [diff] [blame] | 2181 | |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2182 | if (!newfie) { |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2183 | size_t lenpt = strlenpt(path), start_col; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2184 | |
David Lawrence Ramsey | 8125e08 | 2006-11-25 22:27:22 +0000 | [diff] [blame] | 2185 | /* Don't set dots to TRUE if we have fewer than eight columns |
| 2186 | * (i.e. one column for padding, plus seven columns for a |
| 2187 | * filename). */ |
David Lawrence Ramsey | 49172ca | 2006-07-13 02:10:27 +0000 | [diff] [blame] | 2188 | dots = (space >= 8 && lenpt >= space); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2189 | |
| 2190 | if (dots) { |
| 2191 | start_col = lenpt - space + 3; |
| 2192 | space -= 3; |
| 2193 | } else |
| 2194 | start_col = 0; |
| 2195 | |
| 2196 | exppath = display_string(path, start_col, space, FALSE); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
David Lawrence Ramsey | 85ffaee | 2006-07-02 18:29:49 +0000 | [diff] [blame] | 2199 | /* If dots is TRUE, we will display something like "File: |
| 2200 | * ...ename". */ |
| 2201 | if (dots) { |
| 2202 | mvwaddnstr(topwin, 0, verlen - 1, prefix, actual_x(prefix, |
| 2203 | prefixlen)); |
| 2204 | if (space <= -3 || newfie) |
| 2205 | goto the_end; |
| 2206 | waddch(topwin, ' '); |
| 2207 | waddnstr(topwin, "...", space + 3); |
| 2208 | if (space <= 0) |
| 2209 | goto the_end; |
| 2210 | waddstr(topwin, exppath); |
| 2211 | } else { |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 2212 | size_t exppathlen = newfie ? 0 : strlenpt(exppath); |
| 2213 | /* The length of the expanded filename. */ |
| 2214 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2215 | /* There is room for the whole filename, so we center it. */ |
David Lawrence Ramsey | d4dab46 | 2005-07-10 23:45:23 +0000 | [diff] [blame] | 2216 | mvwaddnstr(topwin, 0, verlen + ((space - exppathlen) / 3), |
| 2217 | prefix, actual_x(prefix, prefixlen)); |
David Lawrence Ramsey | f326ed7 | 2004-12-05 05:42:46 +0000 | [diff] [blame] | 2218 | if (!newfie) { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2219 | waddch(topwin, ' '); |
| 2220 | waddstr(topwin, exppath); |
| 2221 | } |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | the_end: |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2225 | free(exppath); |
| 2226 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2227 | if (state[0] != '\0') { |
David Lawrence Ramsey | 3d12f0f | 2005-10-26 23:14:59 +0000 | [diff] [blame] | 2228 | if (statelen >= COLS - 1) |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2229 | mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS)); |
| 2230 | else { |
David Lawrence Ramsey | caa8659 | 2005-07-10 23:57:32 +0000 | [diff] [blame] | 2231 | assert(COLS - statelen - 1 >= 0); |
David Lawrence Ramsey | cb4f14b | 2005-03-24 22:28:25 +0000 | [diff] [blame] | 2232 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2233 | mvwaddnstr(topwin, 0, COLS - statelen - 1, state, |
David Lawrence Ramsey | 297851a | 2005-03-25 05:00:32 +0000 | [diff] [blame] | 2234 | actual_x(state, statelen)); |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2235 | } |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2236 | } |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2237 | |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 2238 | wattroff(topwin, reverse_attr); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2239 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2240 | wnoutrefresh(topwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2241 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 2242 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 2245 | /* Mark the current file as modified if it isn't already, and then |
| 2246 | * update the titlebar to display the file's new status. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2247 | void set_modified(void) |
| 2248 | { |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2249 | if (!openfile->modified) { |
| 2250 | openfile->modified = TRUE; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2251 | titlebar(NULL); |
Chris Allegretta | 21f73f9 | 2013-01-03 03:07:27 +0000 | [diff] [blame] | 2252 | #ifndef NANO_TINY |
Chris Allegretta | d70c7f3 | 2013-01-03 03:36:20 +0000 | [diff] [blame] | 2253 | if (ISSET(LOCKING)) { |
Chris Allegretta | d2f29d0 | 2014-01-26 04:09:04 +0000 | [diff] [blame] | 2254 | if (!strcmp(openfile->filename, "")) |
| 2255 | return; |
| 2256 | else if (openfile->lock_filename == NULL) { |
Chris Allegretta | d70c7f3 | 2013-01-03 03:36:20 +0000 | [diff] [blame] | 2257 | /* Translators: Try to keep this at most 80 characters. */ |
| 2258 | statusbar(_("Warning: Modifying a file which is not locked, check directory permission?")); |
| 2259 | } else { |
| 2260 | write_lockfile(openfile->lock_filename, |
| 2261 | get_full_path(openfile->filename), TRUE); |
| 2262 | } |
| 2263 | } |
Chris Allegretta | 21f73f9 | 2013-01-03 03:07:27 +0000 | [diff] [blame] | 2264 | #endif |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
David Lawrence Ramsey | 5593e20 | 2005-06-28 19:49:15 +0000 | [diff] [blame] | 2268 | /* Display a message on the statusbar, and set disable_cursorpos to |
| 2269 | * TRUE, so that the message won't be immediately overwritten if |
| 2270 | * constant cursor position display is on. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2271 | void statusbar(const char *msg, ...) |
| 2272 | { |
| 2273 | va_list ap; |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2274 | char *bar, *foo; |
| 2275 | size_t start_x, foo_len; |
Benno Schulenberg | eea0908 | 2014-04-13 20:50:20 +0000 | [diff] [blame] | 2276 | #if !defined(NANO_TINY) && !defined(DISABLE_NANORC) |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2277 | bool old_whitespace; |
| 2278 | #endif |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2279 | |
| 2280 | va_start(ap, msg); |
| 2281 | |
| 2282 | /* Curses mode is turned off. If we use wmove() now, it will muck |
| 2283 | * up the terminal settings. So we just use vfprintf(). */ |
David Lawrence Ramsey | f70f67b | 2006-06-03 17:31:52 +0000 | [diff] [blame] | 2284 | if (isendwin()) { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2285 | vfprintf(stderr, msg, ap); |
| 2286 | va_end(ap); |
| 2287 | return; |
| 2288 | } |
| 2289 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2290 | blank_statusbar(); |
| 2291 | |
Benno Schulenberg | eea0908 | 2014-04-13 20:50:20 +0000 | [diff] [blame] | 2292 | #if !defined(NANO_TINY) && !defined(DISABLE_NANORC) |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2293 | old_whitespace = ISSET(WHITESPACE_DISPLAY); |
| 2294 | UNSET(WHITESPACE_DISPLAY); |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2295 | #endif |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2296 | bar = charalloc(mb_cur_max() * (COLS - 3)); |
| 2297 | vsnprintf(bar, mb_cur_max() * (COLS - 3), msg, ap); |
| 2298 | va_end(ap); |
| 2299 | foo = display_string(bar, 0, COLS - 4, FALSE); |
Benno Schulenberg | eea0908 | 2014-04-13 20:50:20 +0000 | [diff] [blame] | 2300 | #if !defined(NANO_TINY) && !defined(DISABLE_NANORC) |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2301 | if (old_whitespace) |
| 2302 | SET(WHITESPACE_DISPLAY); |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 2303 | #endif |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2304 | free(bar); |
| 2305 | foo_len = strlenpt(foo); |
| 2306 | start_x = (COLS - foo_len - 4) / 2; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2307 | |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2308 | wmove(bottomwin, 0, start_x); |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 2309 | wattron(bottomwin, reverse_attr); |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2310 | waddstr(bottomwin, "[ "); |
| 2311 | waddstr(bottomwin, foo); |
| 2312 | free(foo); |
| 2313 | waddstr(bottomwin, " ]"); |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 2314 | wattroff(bottomwin, reverse_attr); |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2315 | wnoutrefresh(bottomwin); |
| 2316 | reset_cursor(); |
| 2317 | wnoutrefresh(edit); |
| 2318 | /* Leave the cursor at its position in the edit window, not in |
| 2319 | * the statusbar. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2320 | |
David Lawrence Ramsey | ea01474 | 2005-06-17 18:27:00 +0000 | [diff] [blame] | 2321 | disable_cursorpos = TRUE; |
David Lawrence Ramsey | c661853 | 2005-06-17 22:33:15 +0000 | [diff] [blame] | 2322 | |
| 2323 | /* If we're doing quick statusbar blanking, and constant cursor |
| 2324 | * position display is off, blank the statusbar after only one |
David Lawrence Ramsey | ce86236 | 2006-05-21 21:23:21 +0000 | [diff] [blame] | 2325 | * keystroke. Otherwise, blank it after twenty-six keystrokes, as |
| 2326 | * Pico does. */ |
David Lawrence Ramsey | e29111f | 2005-06-17 19:06:25 +0000 | [diff] [blame] | 2327 | statusblank = |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2328 | #ifndef NANO_TINY |
David Lawrence Ramsey | bf51aa4 | 2005-06-17 21:52:59 +0000 | [diff] [blame] | 2329 | ISSET(QUICK_BLANK) && !ISSET(CONST_UPDATE) ? 1 : |
David Lawrence Ramsey | e29111f | 2005-06-17 19:06:25 +0000 | [diff] [blame] | 2330 | #endif |
David Lawrence Ramsey | ce86236 | 2006-05-21 21:23:21 +0000 | [diff] [blame] | 2331 | 26; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2332 | } |
| 2333 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 2334 | /* Display the shortcut list in s on the last two rows of the bottom |
| 2335 | * portion of the window. */ |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2336 | void bottombars(int menu) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2337 | { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2338 | size_t i, colwidth, slen; |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2339 | subnfunc *f; |
| 2340 | const sc *s; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2341 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2342 | if (ISSET(NO_HELP)) |
| 2343 | return; |
| 2344 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2345 | if (menu == MMAIN) { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2346 | slen = MAIN_VISIBLE; |
David Lawrence Ramsey | 31b159c | 2005-05-26 05:17:13 +0000 | [diff] [blame] | 2347 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2348 | assert(slen <= length_of_list(menu)); |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 2349 | } else { |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2350 | slen = length_of_list(menu); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2351 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2352 | /* Don't show any more shortcuts than the main list does. */ |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 2353 | if (slen > MAIN_VISIBLE) |
| 2354 | slen = MAIN_VISIBLE; |
| 2355 | } |
| 2356 | |
David Lawrence Ramsey | e806ab8 | 2006-04-18 16:13:35 +0000 | [diff] [blame] | 2357 | /* There will be this many characters per column, except for the |
| 2358 | * last two, which will be longer by (COLS % colwidth) columns so as |
| 2359 | * to not waste space. We need at least three columns to display |
| 2360 | * anything properly. */ |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2361 | colwidth = COLS / ((slen / 2) + (slen % 2)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2362 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2363 | blank_bottombars(); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2364 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2365 | #ifdef DEBUG |
| 2366 | fprintf(stderr, "In bottombars, and slen == \"%d\"\n", (int) slen); |
| 2367 | #endif |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2368 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2369 | for (f = allfuncs, i = 0; i < slen && f != NULL; f = f->next) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2370 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2371 | #ifdef DEBUG |
| 2372 | fprintf(stderr, "Checking menu items...."); |
| 2373 | #endif |
| 2374 | if ((f->menus & menu) == 0) |
| 2375 | continue; |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2376 | |
Chris Allegretta | 0018d8e | 2008-03-13 08:23:52 +0000 | [diff] [blame] | 2377 | if (!f->desc || strlen(f->desc) == 0) |
Chris Allegretta | eb64314 | 2008-03-12 04:44:14 +0000 | [diff] [blame] | 2378 | continue; |
| 2379 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2380 | #ifdef DEBUG |
Benno Schulenberg | 18c252d | 2014-03-24 20:35:17 +0000 | [diff] [blame] | 2381 | fprintf(stderr, "found one! f->menus = %x, desc = \"%s\"\n", f->menus, f->desc); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2382 | #endif |
| 2383 | s = first_sc_for(menu, f->scfunc); |
| 2384 | if (s == NULL) { |
| 2385 | #ifdef DEBUG |
| 2386 | fprintf(stderr, "Whoops, guess not, no shortcut key found for func!\n"); |
| 2387 | #endif |
| 2388 | continue; |
| 2389 | } |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2390 | wmove(bottomwin, 1 + i % 2, (i / 2) * colwidth); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2391 | #ifdef DEBUG |
| 2392 | fprintf(stderr, "Calling onekey with keystr \"%s\" and desc \"%s\"\n", s->keystr, f->desc); |
| 2393 | #endif |
Chris Allegretta | 1fb25fd | 2008-03-18 03:06:27 +0000 | [diff] [blame] | 2394 | onekey(s->keystr, _(f->desc), colwidth + (COLS % colwidth)); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2395 | i++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2398 | wnoutrefresh(bottomwin); |
| 2399 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 2400 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2403 | /* Write a shortcut key to the help area at the bottom of the window. |
| 2404 | * keystroke is e.g. "^G" and desc is e.g. "Get Help". We are careful |
| 2405 | * to write at most len characters, even if len is very small and |
| 2406 | * keystroke and desc are long. Note that waddnstr(,,(size_t)-1) adds |
| 2407 | * the whole string! We do not bother padding the entry with blanks. */ |
| 2408 | void onekey(const char *keystroke, const char *desc, size_t len) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2409 | { |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2410 | size_t keystroke_len = strlenpt(keystroke) + 1; |
| 2411 | |
David Lawrence Ramsey | 12054fe | 2005-01-07 22:37:01 +0000 | [diff] [blame] | 2412 | assert(keystroke != NULL && desc != NULL); |
| 2413 | |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 2414 | wattron(bottomwin, reverse_attr); |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2415 | waddnstr(bottomwin, keystroke, actual_x(keystroke, len)); |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 2416 | wattroff(bottomwin, reverse_attr); |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2417 | |
| 2418 | if (len > keystroke_len) |
| 2419 | len -= keystroke_len; |
| 2420 | else |
| 2421 | len = 0; |
| 2422 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2423 | if (len > 0) { |
| 2424 | waddch(bottomwin, ' '); |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2425 | waddnstr(bottomwin, desc, actual_x(desc, len)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | |
David Lawrence Ramsey | 2b9d6a0 | 2005-11-01 17:45:31 +0000 | [diff] [blame] | 2429 | /* Reset current_y, based on the position of current, and put the cursor |
| 2430 | * in the edit window at (current_y, current_x). */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2431 | void reset_cursor(void) |
| 2432 | { |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2433 | size_t xpt; |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2434 | /* If we haven't opened any files yet, put the cursor in the top |
| 2435 | * left corner of the edit window and get out. */ |
David Lawrence Ramsey | dbcaa3b | 2005-07-08 20:59:24 +0000 | [diff] [blame] | 2436 | if (openfile == NULL) { |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2437 | wmove(edit, 0, 0); |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2438 | return; |
David Lawrence Ramsey | 02517e0 | 2004-09-05 21:40:31 +0000 | [diff] [blame] | 2439 | } |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2440 | |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2441 | xpt = xplustabs(); |
David Lawrence Ramsey | 964722a | 2006-05-26 03:02:50 +0000 | [diff] [blame] | 2442 | |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2443 | if (ISSET(SOFTWRAP)) { |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2444 | filestruct *tmp; |
Chris Allegretta | 6f08332 | 2009-11-11 06:00:33 +0000 | [diff] [blame] | 2445 | openfile->current_y = 0; |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2446 | |
Chris Allegretta | 6f08332 | 2009-11-11 06:00:33 +0000 | [diff] [blame] | 2447 | for (tmp = openfile->edittop; tmp && tmp != openfile->current; tmp = tmp->next) |
| 2448 | openfile->current_y += 1 + strlenpt(tmp->data) / COLS; |
| 2449 | |
| 2450 | openfile->current_y += xplustabs() / COLS; |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2451 | if (openfile->current_y < editwinrows) |
Chris Allegretta | 6f08332 | 2009-11-11 06:00:33 +0000 | [diff] [blame] | 2452 | wmove(edit, openfile->current_y, xpt % COLS); |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2453 | } else { |
| 2454 | openfile->current_y = openfile->current->lineno - |
| 2455 | openfile->edittop->lineno; |
| 2456 | |
| 2457 | if (openfile->current_y < editwinrows) |
| 2458 | wmove(edit, openfile->current_y, xpt - get_page_start(xpt)); |
| 2459 | } |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2460 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2461 | |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2462 | /* edit_draw() takes care of the job of actually painting a line into |
| 2463 | * the edit window. fileptr is the line to be painted, at row line of |
| 2464 | * the window. converted is the actual string to be written to the |
| 2465 | * window, with tabs and control characters replaced by strings of |
| 2466 | * regular characters. start is the column number of the first |
| 2467 | * character of this page. That is, the first character of converted |
| 2468 | * corresponds to character number actual_x(fileptr->data, start) of the |
| 2469 | * line. */ |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 2470 | void edit_draw(filestruct *fileptr, const char *converted, int |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2471 | line, size_t start) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2472 | { |
Benno Schulenberg | 0038992 | 2014-04-04 11:59:03 +0000 | [diff] [blame] | 2473 | #if !defined(NANO_TINY) || !defined(DISABLE_COLOR) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2474 | size_t startpos = actual_x(fileptr->data, start); |
| 2475 | /* The position in fileptr->data of the leftmost character |
| 2476 | * that displays at least partially on the window. */ |
| 2477 | size_t endpos = actual_x(fileptr->data, start + COLS - 1) + 1; |
| 2478 | /* The position in fileptr->data of the first character that is |
| 2479 | * completely off the window to the right. |
| 2480 | * |
| 2481 | * Note that endpos might be beyond the null terminator of the |
| 2482 | * string. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2483 | #endif |
| 2484 | |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2485 | assert(openfile != NULL && fileptr != NULL && converted != NULL); |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2486 | assert(strlenpt(converted) <= COLS); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2487 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2488 | /* 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] | 2489 | * just the text that needs it). */ |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2490 | mvwaddstr(edit, line, 0, converted); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2491 | |
Benno Schulenberg | 0038992 | 2014-04-04 11:59:03 +0000 | [diff] [blame] | 2492 | #ifndef DISABLE_COLOR |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2493 | /* If color syntaxes are available and turned on, we need to display |
| 2494 | * them. */ |
| 2495 | if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) { |
| 2496 | const colortype *tmpcolor = openfile->colorstrings; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2497 | |
Benno Schulenberg | 8f61511 | 2014-04-14 09:57:06 +0000 | [diff] [blame] | 2498 | /* 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] | 2499 | if (fileptr->multidata == NULL && openfile->syntax |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 2500 | && openfile->syntax->nmultis > 0) { |
Benno Schulenberg | a65ef42 | 2014-03-17 21:36:37 +0000 | [diff] [blame] | 2501 | int i; |
Chris Allegretta | 5a018f0 | 2009-11-29 06:13:22 +0000 | [diff] [blame] | 2502 | fileptr->multidata = (short *) nmalloc(openfile->syntax->nmultis * sizeof(short)); |
Chris Allegretta | 22c83ec | 2013-03-17 22:09:38 +0000 | [diff] [blame] | 2503 | for (i = 0; i < openfile->syntax->nmultis; i++) |
Benno Schulenberg | 8f61511 | 2014-04-14 09:57:06 +0000 | [diff] [blame] | 2504 | fileptr->multidata[i] = -1; /* Assume this applies until we know otherwise. */ |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 2505 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2506 | for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { |
| 2507 | int x_start; |
| 2508 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 2509 | int paintlen; |
David Lawrence Ramsey | 2ea7fb0 | 2006-08-02 18:41:55 +0000 | [diff] [blame] | 2510 | /* Number of chars to paint on this line. There are |
| 2511 | * COLS characters on a whole line. */ |
David Lawrence Ramsey | 179f0ea | 2005-01-04 02:55:45 +0000 | [diff] [blame] | 2512 | size_t index; |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2513 | /* Index in converted where we paint. */ |
David Lawrence Ramsey | 85f6a2d | 2005-06-26 22:59:54 +0000 | [diff] [blame] | 2514 | regmatch_t startmatch; |
| 2515 | /* Match position for start_regex. */ |
| 2516 | regmatch_t endmatch; |
| 2517 | /* Match position for end_regex. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2518 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2519 | if (tmpcolor->bright) |
| 2520 | wattron(edit, A_BOLD); |
| 2521 | wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); |
David Lawrence Ramsey | b0e04c0 | 2005-12-08 07:24:54 +0000 | [diff] [blame] | 2522 | /* Two notes about regexec(). A return value of zero means |
| 2523 | * that there is a match. Also, rm_eo is the first |
| 2524 | * non-matching character after the match. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2525 | |
Chris Allegretta | 22c83ec | 2013-03-17 22:09:38 +0000 | [diff] [blame] | 2526 | /* First case, tmpcolor is a single-line expression. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2527 | if (tmpcolor->end == NULL) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2528 | size_t k = 0; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2529 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2530 | /* 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] | 2531 | * last match. Even though two matches may overlap, we |
David Lawrence Ramsey | 2ef7dae | 2006-05-26 11:58:37 +0000 | [diff] [blame] | 2532 | * want to ignore them, so that we can highlight e.g. C |
| 2533 | * strings correctly. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2534 | while (k < endpos) { |
| 2535 | /* Note the fifth parameter to regexec(). It says |
| 2536 | * not to match the beginning-of-line character |
David Lawrence Ramsey | 2ef7dae | 2006-05-26 11:58:37 +0000 | [diff] [blame] | 2537 | * unless k is zero. If regexec() returns |
| 2538 | * REG_NOMATCH, there are no more matches in the |
| 2539 | * line. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2540 | if (regexec(tmpcolor->start, &fileptr->data[k], 1, |
David Lawrence Ramsey | 282a940 | 2005-07-29 21:41:04 +0000 | [diff] [blame] | 2541 | &startmatch, (k == 0) ? 0 : REG_NOTBOL) == |
| 2542 | REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2543 | break; |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2544 | /* Translate the match to the beginning of the |
| 2545 | * line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2546 | startmatch.rm_so += k; |
| 2547 | startmatch.rm_eo += k; |
David Lawrence Ramsey | d76de38 | 2006-06-21 20:51:36 +0000 | [diff] [blame] | 2548 | |
| 2549 | /* Skip over a zero-length regex match. */ |
| 2550 | if (startmatch.rm_so == startmatch.rm_eo) |
David Lawrence Ramsey | 2ab03f6 | 2002-10-17 02:19:31 +0000 | [diff] [blame] | 2551 | startmatch.rm_eo++; |
David Lawrence Ramsey | d76de38 | 2006-06-21 20:51:36 +0000 | [diff] [blame] | 2552 | else if (startmatch.rm_so < endpos && |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2553 | startmatch.rm_eo > startpos) { |
David Lawrence Ramsey | b02a195 | 2006-05-08 16:25:12 +0000 | [diff] [blame] | 2554 | x_start = (startmatch.rm_so <= startpos) ? 0 : |
| 2555 | strnlenpt(fileptr->data, |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2556 | startmatch.rm_so) - start; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2557 | |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2558 | index = actual_x(converted, x_start); |
| 2559 | |
| 2560 | paintlen = actual_x(converted + index, |
David Lawrence Ramsey | c1e3d94 | 2005-01-12 18:23:09 +0000 | [diff] [blame] | 2561 | strnlenpt(fileptr->data, |
| 2562 | startmatch.rm_eo) - start - x_start); |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2563 | |
| 2564 | assert(0 <= x_start && 0 <= paintlen); |
| 2565 | |
Chris Allegretta | 22c83ec | 2013-03-17 22:09:38 +0000 | [diff] [blame] | 2566 | mvwaddnstr(edit, line, x_start, converted + |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2567 | index, paintlen); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2568 | } |
Chris Allegretta | 22c83ec | 2013-03-17 22:09:38 +0000 | [diff] [blame] | 2569 | k = startmatch.rm_eo; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2570 | } |
Chris Allegretta | 56a295b | 2009-02-07 14:48:30 +0000 | [diff] [blame] | 2571 | } else if (fileptr->multidata != NULL && fileptr->multidata[tmpcolor->id] != CNONE) { |
David Lawrence Ramsey | 85f6a2d | 2005-06-26 22:59:54 +0000 | [diff] [blame] | 2572 | /* This is a multi-line regex. There are two steps. |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2573 | * First, we have to see if the beginning of the line is |
| 2574 | * colored by a start on an earlier line, and an end on |
| 2575 | * this line or later. |
| 2576 | * |
| 2577 | * We find the first line before fileptr matching the |
| 2578 | * start. If every match on that line is followed by an |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2579 | * end, then go to step two. Otherwise, find the next |
| 2580 | * line after start_line matching the end. If that line |
| 2581 | * is not before fileptr, then paint the beginning of |
| 2582 | * this line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2583 | const filestruct *start_line = fileptr->prev; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2584 | /* The first line before fileptr matching start. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2585 | regoff_t start_col; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2586 | /* Where it starts in that line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2587 | const filestruct *end_line; |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2588 | short md = fileptr->multidata[tmpcolor->id]; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2589 | |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2590 | if (md == -1) |
Chris Allegretta | 56a295b | 2009-02-07 14:48:30 +0000 | [diff] [blame] | 2591 | fileptr->multidata[tmpcolor->id] = CNONE; /* until we find out otherwise */ |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2592 | else if (md == CNONE) |
| 2593 | continue; |
| 2594 | else if (md == CWHOLELINE) { |
| 2595 | mvwaddnstr(edit, line, 0, converted, -1); |
| 2596 | continue; |
Chris Allegretta | 803379c | 2009-02-07 07:09:31 +0000 | [diff] [blame] | 2597 | } else if (md == CBEGINBEFORE) { |
| 2598 | regexec(tmpcolor->end, fileptr->data, 1, &endmatch, 0); |
| 2599 | paintlen = actual_x(converted, strnlenpt(fileptr->data, |
| 2600 | endmatch.rm_eo) - start); |
| 2601 | mvwaddnstr(edit, line, 0, converted, paintlen); |
| 2602 | continue; |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2603 | } |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 2604 | |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2605 | while (start_line != NULL && regexec(tmpcolor->start, |
David Lawrence Ramsey | 282a940 | 2005-07-29 21:41:04 +0000 | [diff] [blame] | 2606 | start_line->data, 1, &startmatch, 0) == |
| 2607 | REG_NOMATCH) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2608 | /* If there is an end on this line, there is no need |
| 2609 | * to look for starts on earlier lines. */ |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2610 | if (regexec(tmpcolor->end, start_line->data, 0, |
| 2611 | NULL, 0) == 0) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2612 | goto step_two; |
| 2613 | start_line = start_line->prev; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2614 | } |
David Lawrence Ramsey | d76de38 | 2006-06-21 20:51:36 +0000 | [diff] [blame] | 2615 | |
| 2616 | /* Skip over a zero-length regex match. */ |
| 2617 | if (startmatch.rm_so == startmatch.rm_eo) |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2618 | startmatch.rm_eo++; |
David Lawrence Ramsey | d76de38 | 2006-06-21 20:51:36 +0000 | [diff] [blame] | 2619 | else { |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2620 | /* No start found, so skip to the next step. */ |
| 2621 | if (start_line == NULL) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2622 | goto step_two; |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2623 | /* Now start_line is the first line before fileptr |
| 2624 | * containing a start match. Is there a start on |
| 2625 | * this line not followed by an end on this line? */ |
| 2626 | start_col = 0; |
| 2627 | while (TRUE) { |
| 2628 | start_col += startmatch.rm_so; |
| 2629 | startmatch.rm_eo -= startmatch.rm_so; |
| 2630 | if (regexec(tmpcolor->end, start_line->data + |
| 2631 | start_col + startmatch.rm_eo, 0, NULL, |
| 2632 | (start_col + startmatch.rm_eo == 0) ? |
| 2633 | 0 : REG_NOTBOL) == REG_NOMATCH) |
| 2634 | /* No end found after this start. */ |
| 2635 | break; |
| 2636 | start_col++; |
| 2637 | if (regexec(tmpcolor->start, start_line->data + |
| 2638 | start_col, 1, &startmatch, |
| 2639 | REG_NOTBOL) == REG_NOMATCH) |
| 2640 | /* No later start on this line. */ |
| 2641 | goto step_two; |
| 2642 | } |
| 2643 | /* Indeed, there is a start not followed on this |
| 2644 | * line by an end. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2645 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2646 | /* We have already checked that there is no end |
| 2647 | * before fileptr and after the start. Is there an |
| 2648 | * end after the start at all? We don't paint |
| 2649 | * unterminated starts. */ |
| 2650 | end_line = fileptr; |
| 2651 | while (end_line != NULL && regexec(tmpcolor->end, |
David Lawrence Ramsey | 282a940 | 2005-07-29 21:41:04 +0000 | [diff] [blame] | 2652 | end_line->data, 1, &endmatch, 0) == REG_NOMATCH) |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2653 | end_line = end_line->next; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2654 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2655 | /* No end found, or it is too early. */ |
| 2656 | if (end_line == NULL || (end_line == fileptr && |
David Lawrence Ramsey | 179f0ea | 2005-01-04 02:55:45 +0000 | [diff] [blame] | 2657 | endmatch.rm_eo <= startpos)) |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2658 | goto step_two; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2659 | |
David Lawrence Ramsey | cbab273 | 2006-08-02 18:38:45 +0000 | [diff] [blame] | 2660 | /* Now paint the start of fileptr. If the start of |
| 2661 | * fileptr is on a different line from the end, |
| 2662 | * paintlen is -1, meaning that everything on the |
| 2663 | * line gets painted. Otherwise, paintlen is the |
| 2664 | * expanded location of the end of the match minus |
| 2665 | * the expanded location of the beginning of the |
| 2666 | * page. */ |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2667 | if (end_line != fileptr) { |
David Lawrence Ramsey | 1c9dd10 | 2006-11-21 17:05:04 +0000 | [diff] [blame] | 2668 | paintlen = -1; |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2669 | fileptr->multidata[tmpcolor->id] = CWHOLELINE; |
| 2670 | } else { |
David Lawrence Ramsey | 1c9dd10 | 2006-11-21 17:05:04 +0000 | [diff] [blame] | 2671 | paintlen = actual_x(converted, |
| 2672 | strnlenpt(fileptr->data, |
| 2673 | endmatch.rm_eo) - start); |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2674 | fileptr->multidata[tmpcolor->id] = CBEGINBEFORE; |
| 2675 | } |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2676 | mvwaddnstr(edit, line, 0, converted, paintlen); |
David Lawrence Ramsey | 94e7094 | 2004-05-13 18:04:31 +0000 | [diff] [blame] | 2677 | step_two: |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2678 | /* Second step, we look for starts on this line. */ |
| 2679 | start_col = 0; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2680 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2681 | while (start_col < endpos) { |
| 2682 | if (regexec(tmpcolor->start, fileptr->data + |
| 2683 | start_col, 1, &startmatch, (start_col == |
| 2684 | 0) ? 0 : REG_NOTBOL) == REG_NOMATCH || |
| 2685 | start_col + startmatch.rm_so >= endpos) |
| 2686 | /* No more starts on this line. */ |
| 2687 | break; |
| 2688 | /* Translate the match to be relative to the |
| 2689 | * beginning of the line. */ |
| 2690 | startmatch.rm_so += start_col; |
| 2691 | startmatch.rm_eo += start_col; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2692 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2693 | x_start = (startmatch.rm_so <= startpos) ? 0 : |
| 2694 | strnlenpt(fileptr->data, |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2695 | startmatch.rm_so) - start; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2696 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2697 | index = actual_x(converted, x_start); |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2698 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2699 | if (regexec(tmpcolor->end, fileptr->data + |
| 2700 | startmatch.rm_eo, 1, &endmatch, |
| 2701 | (startmatch.rm_eo == 0) ? 0 : |
| 2702 | REG_NOTBOL) == 0) { |
| 2703 | /* Translate the end match to be relative to |
| 2704 | * the beginning of the line. */ |
| 2705 | endmatch.rm_so += startmatch.rm_eo; |
| 2706 | endmatch.rm_eo += startmatch.rm_eo; |
| 2707 | /* There is an end on this line. But does |
| 2708 | * it appear on this page, and is the match |
| 2709 | * more than zero characters long? */ |
| 2710 | if (endmatch.rm_eo > startpos && |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2711 | endmatch.rm_eo > startmatch.rm_so) { |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2712 | paintlen = actual_x(converted + index, |
| 2713 | strnlenpt(fileptr->data, |
| 2714 | endmatch.rm_eo) - start - |
| 2715 | x_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2716 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2717 | assert(0 <= x_start && x_start < COLS); |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2718 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2719 | mvwaddnstr(edit, line, x_start, |
| 2720 | converted + index, paintlen); |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 2721 | if (paintlen > 0) |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2722 | fileptr->multidata[tmpcolor->id] = CSTARTENDHERE; |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 2723 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2724 | } |
| 2725 | } else { |
| 2726 | /* There is no end on this line. But we |
| 2727 | * haven't yet looked for one on later |
| 2728 | * lines. */ |
| 2729 | end_line = fileptr->next; |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2730 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2731 | while (end_line != NULL && |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2732 | regexec(tmpcolor->end, end_line->data, |
| 2733 | 0, NULL, 0) == REG_NOMATCH) |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2734 | end_line = end_line->next; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2735 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2736 | if (end_line != NULL) { |
| 2737 | assert(0 <= x_start && x_start < COLS); |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2738 | |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2739 | mvwaddnstr(edit, line, x_start, |
| 2740 | converted + index, -1); |
| 2741 | /* We painted to the end of the line, so |
| 2742 | * don't bother checking any more |
| 2743 | * starts. */ |
Chris Allegretta | 364763f | 2009-02-03 05:05:58 +0000 | [diff] [blame] | 2744 | fileptr->multidata[tmpcolor->id] = CENDAFTER; |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2745 | break; |
| 2746 | } |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 2747 | } |
David Lawrence Ramsey | a5f833d | 2006-05-08 15:57:04 +0000 | [diff] [blame] | 2748 | start_col = startmatch.rm_so + 1; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2749 | } |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2750 | } |
| 2751 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2752 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2753 | wattroff(edit, A_BOLD); |
| 2754 | wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2755 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2756 | } |
Benno Schulenberg | 0038992 | 2014-04-04 11:59:03 +0000 | [diff] [blame] | 2757 | #endif /* !DISABLE_COLOR */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2758 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2759 | #ifndef NANO_TINY |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2760 | /* If the mark is on, we need to display it. */ |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2761 | if (openfile->mark_set && (fileptr->lineno <= |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2762 | openfile->mark_begin->lineno || fileptr->lineno <= |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2763 | openfile->current->lineno) && (fileptr->lineno >= |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2764 | openfile->mark_begin->lineno || fileptr->lineno >= |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2765 | openfile->current->lineno)) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2766 | /* fileptr is at least partially selected. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2767 | const filestruct *top; |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2768 | /* Either current or mark_begin, whichever is first. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2769 | size_t top_x; |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2770 | /* current_x or mark_begin_x, corresponding to top. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2771 | const filestruct *bot; |
| 2772 | size_t bot_x; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2773 | int x_start; |
David Lawrence Ramsey | 5128de8 | 2005-07-12 17:40:16 +0000 | [diff] [blame] | 2774 | /* Starting column for mvwaddnstr(). Zero-based. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2775 | int paintlen; |
David Lawrence Ramsey | c6bef76 | 2006-08-02 19:13:31 +0000 | [diff] [blame] | 2776 | /* Number of characters to paint on this line. There are |
| 2777 | * COLS characters on a whole line. */ |
David Lawrence Ramsey | 179f0ea | 2005-01-04 02:55:45 +0000 | [diff] [blame] | 2778 | size_t index; |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2779 | /* Index in converted where we paint. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2780 | |
David Lawrence Ramsey | 90e59c1 | 2004-11-05 23:03:03 +0000 | [diff] [blame] | 2781 | mark_order(&top, &top_x, &bot, &bot_x, NULL); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2782 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2783 | if (top->lineno < fileptr->lineno || top_x < startpos) |
| 2784 | top_x = startpos; |
| 2785 | if (bot->lineno > fileptr->lineno || bot_x > endpos) |
| 2786 | bot_x = endpos; |
| 2787 | |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2788 | /* The selected bit of fileptr is on this page. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2789 | if (top_x < endpos && bot_x > startpos) { |
| 2790 | assert(startpos <= top_x); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2791 | |
| 2792 | /* x_start is the expanded location of the beginning of the |
| 2793 | * mark minus the beginning of the page. */ |
| 2794 | x_start = strnlenpt(fileptr->data, top_x) - start; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2795 | |
David Lawrence Ramsey | cbab273 | 2006-08-02 18:38:45 +0000 | [diff] [blame] | 2796 | /* If the end of the mark is off the page, paintlen is -1, |
| 2797 | * meaning that everything on the line gets painted. |
| 2798 | * Otherwise, paintlen is the expanded location of the end |
| 2799 | * of the mark minus the expanded location of the beginning |
| 2800 | * of the mark. */ |
David Lawrence Ramsey | 1c9dd10 | 2006-11-21 17:05:04 +0000 | [diff] [blame] | 2801 | if (bot_x >= endpos) |
| 2802 | paintlen = -1; |
| 2803 | else |
| 2804 | paintlen = strnlenpt(fileptr->data, bot_x) - (x_start + |
| 2805 | start); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2806 | |
| 2807 | /* If x_start is before the beginning of the page, shift |
| 2808 | * paintlen x_start characters to compensate, and put |
| 2809 | * x_start at the beginning of the page. */ |
| 2810 | if (x_start < 0) { |
| 2811 | paintlen += x_start; |
| 2812 | x_start = 0; |
| 2813 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2814 | |
| 2815 | assert(x_start >= 0 && x_start <= strlen(converted)); |
| 2816 | |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2817 | index = actual_x(converted, x_start); |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2818 | |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2819 | if (paintlen > 0) |
| 2820 | paintlen = actual_x(converted + index, paintlen); |
| 2821 | |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 2822 | wattron(edit, reverse_attr); |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2823 | mvwaddnstr(edit, line, x_start, converted + index, |
David Lawrence Ramsey | 22e5eff | 2005-01-03 22:56:38 +0000 | [diff] [blame] | 2824 | paintlen); |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 2825 | wattroff(edit, reverse_attr); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2826 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 2827 | } |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2828 | #endif /* !NANO_TINY */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2831 | /* 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] | 2832 | * for edit_draw(). The line will be displayed starting with |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2833 | * fileptr->data[index]. Likely arguments are current_x or zero. |
Benno Schulenberg | d0dec31 | 2014-04-08 12:35:18 +0000 | [diff] [blame] | 2834 | * Returns: Number of additional lines consumed (needed for SOFTWRAP). */ |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2835 | int update_line(filestruct *fileptr, size_t index) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2836 | { |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2837 | int line = 0; |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2838 | /* The line in the edit window that we want to update. */ |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 2839 | int extralinesused = 0; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2840 | char *converted; |
| 2841 | /* fileptr->data converted to have tabs and control characters |
| 2842 | * expanded. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2843 | size_t page_start; |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2844 | filestruct *tmp; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2845 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2846 | assert(fileptr != NULL); |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 2847 | |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2848 | if (ISSET(SOFTWRAP)) { |
Chris Allegretta | 139934a | 2009-08-30 03:50:16 +0000 | [diff] [blame] | 2849 | for (tmp = openfile->edittop; tmp && tmp != fileptr; tmp = tmp->next) { |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2850 | line += 1 + (strlenpt(tmp->data) / COLS); |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2851 | } |
| 2852 | } else |
| 2853 | line = fileptr->lineno - openfile->edittop->lineno; |
| 2854 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2855 | if (line < 0 || line >= editwinrows) |
Chris Allegretta | d233e7e | 2009-09-15 04:51:09 +0000 | [diff] [blame] | 2856 | return 1; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2857 | |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2858 | /* First, blank out the line. */ |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2859 | blank_line(edit, line, 0, COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2860 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2861 | /* Next, convert variables that index the line to their equivalent |
| 2862 | * positions in the expanded line. */ |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2863 | if (ISSET(SOFTWRAP)) |
| 2864 | index = 0; |
| 2865 | else |
| 2866 | index = strnlenpt(fileptr->data, index); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2867 | page_start = get_page_start(index); |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2868 | |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2869 | /* Expand the line, replacing tabs with spaces, and control |
| 2870 | * characters with their displayed forms. */ |
Chris Allegretta | 6f08332 | 2009-11-11 06:00:33 +0000 | [diff] [blame] | 2871 | converted = display_string(fileptr->data, page_start, COLS, !ISSET(SOFTWRAP)); |
| 2872 | |
| 2873 | #ifdef DEBUG |
| 2874 | if (ISSET(SOFTWRAP) && strlen(converted) >= COLS - 2) |
| 2875 | fprintf(stderr, "update_line(): converted(1) line = %s\n", converted); |
| 2876 | #endif |
| 2877 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 2878 | |
David Lawrence Ramsey | abc9423 | 2004-12-08 23:24:31 +0000 | [diff] [blame] | 2879 | /* Paint the line. */ |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2880 | edit_draw(fileptr, converted, line, page_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2881 | free(converted); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2882 | |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2883 | if (!ISSET(SOFTWRAP)) { |
| 2884 | if (page_start > 0) |
| 2885 | mvwaddch(edit, line, 0, '$'); |
| 2886 | if (strlenpt(fileptr->data) > page_start + COLS) |
| 2887 | mvwaddch(edit, line, COLS - 1, '$'); |
| 2888 | } else { |
| 2889 | int full_length = strlenpt(fileptr->data); |
Chris Allegretta | 6f08332 | 2009-11-11 06:00:33 +0000 | [diff] [blame] | 2890 | for (index += COLS; index <= full_length && line < editwinrows; index += COLS) { |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2891 | line++; |
| 2892 | #ifdef DEBUG |
Chris Allegretta | 6f08332 | 2009-11-11 06:00:33 +0000 | [diff] [blame] | 2893 | 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] | 2894 | #endif |
| 2895 | blank_line(edit, line, 0, COLS); |
| 2896 | |
| 2897 | /* Expand the line, replacing tabs with spaces, and control |
| 2898 | * characters with their displayed forms. */ |
Chris Allegretta | 6f08332 | 2009-11-11 06:00:33 +0000 | [diff] [blame] | 2899 | converted = display_string(fileptr->data, index, COLS, !ISSET(SOFTWRAP)); |
| 2900 | #ifdef DEBUG |
| 2901 | if (ISSET(SOFTWRAP) && strlen(converted) >= COLS - 2) |
| 2902 | fprintf(stderr, "update_line(): converted(2) line = %s\n", converted); |
| 2903 | #endif |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2904 | |
| 2905 | /* Paint the line. */ |
| 2906 | edit_draw(fileptr, converted, line, index); |
| 2907 | free(converted); |
| 2908 | extralinesused++; |
| 2909 | } |
| 2910 | } |
| 2911 | return extralinesused; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2912 | } |
| 2913 | |
David Lawrence Ramsey | feb89db | 2005-09-13 04:45:46 +0000 | [diff] [blame] | 2914 | /* 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] | 2915 | * 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] | 2916 | * placewewant are on different pages. */ |
David Lawrence Ramsey | fa38795 | 2006-08-26 16:50:51 +0000 | [diff] [blame] | 2917 | bool need_horizontal_update(size_t pww_save) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2918 | { |
| 2919 | return |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2920 | #ifndef NANO_TINY |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2921 | openfile->mark_set || |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2922 | #endif |
David Lawrence Ramsey | fa38795 | 2006-08-26 16:50:51 +0000 | [diff] [blame] | 2923 | get_page_start(pww_save) != |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2924 | get_page_start(openfile->placewewant); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2925 | } |
| 2926 | |
David Lawrence Ramsey | feb89db | 2005-09-13 04:45:46 +0000 | [diff] [blame] | 2927 | /* 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] | 2928 | * 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] | 2929 | * placewewant are on different pages. */ |
David Lawrence Ramsey | fa38795 | 2006-08-26 16:50:51 +0000 | [diff] [blame] | 2930 | bool need_vertical_update(size_t pww_save) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2931 | { |
| 2932 | return |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2933 | #ifndef NANO_TINY |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2934 | openfile->mark_set || |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2935 | #endif |
David Lawrence Ramsey | fa38795 | 2006-08-26 16:50:51 +0000 | [diff] [blame] | 2936 | get_page_start(pww_save) != |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2937 | get_page_start(openfile->placewewant); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2938 | } |
| 2939 | |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2940 | /* When edittop changes, try and figure out how many lines |
Benno Schulenberg | d0dec31 | 2014-04-08 12:35:18 +0000 | [diff] [blame] | 2941 | * we really have to work with (i.e. set maxrows). */ |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2942 | void compute_maxrows(void) |
| 2943 | { |
| 2944 | int n; |
| 2945 | filestruct *foo = openfile->edittop; |
| 2946 | |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 2947 | if (!ISSET(SOFTWRAP)) { |
| 2948 | maxrows = editwinrows; |
| 2949 | return; |
| 2950 | } |
| 2951 | |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2952 | maxrows = 0; |
| 2953 | for (n = 0; n < editwinrows && foo; n++) { |
Benno Schulenberg | d0dec31 | 2014-04-08 12:35:18 +0000 | [diff] [blame] | 2954 | maxrows++; |
Chris Allegretta | e2df2c8 | 2009-11-24 17:15:53 +0000 | [diff] [blame] | 2955 | n += strlenpt(foo->data) / COLS; |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2956 | foo = foo->next; |
| 2957 | } |
| 2958 | |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 2959 | if (n < editwinrows) |
| 2960 | maxrows += editwinrows - n; |
| 2961 | |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2962 | #ifdef DEBUG |
Benno Schulenberg | 55a0d76 | 2014-03-24 13:35:50 +0000 | [diff] [blame] | 2963 | fprintf(stderr, "compute_maxrows(): maxrows = %i\n", maxrows); |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2964 | #endif |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2967 | /* Scroll the edit window in the given direction and the given number |
| 2968 | * 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] | 2969 | * scrolling. direction is the direction to scroll, either UP_DIR or |
| 2970 | * DOWN_DIR, and nlines is the number of lines to scroll. We change |
| 2971 | * edittop, and assume that current and current_x are up to date. We |
| 2972 | * also assume that scrollok(edit) is FALSE. */ |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 2973 | void edit_scroll(scroll_dir direction, ssize_t nlines) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2974 | { |
Benno Schulenberg | a8353bd | 2014-03-17 13:15:50 +0000 | [diff] [blame] | 2975 | ssize_t i; |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 2976 | filestruct *foo; |
Chris Allegretta | 139934a | 2009-08-30 03:50:16 +0000 | [diff] [blame] | 2977 | bool do_redraw = FALSE; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2978 | |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2979 | /* Don't bother scrolling less than one line. */ |
| 2980 | if (nlines < 1) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2981 | return; |
| 2982 | |
Chris Allegretta | 5687c3d | 2009-09-03 02:48:35 +0000 | [diff] [blame] | 2983 | if (need_vertical_update(0)) |
Chris Allegretta | 139934a | 2009-08-30 03:50:16 +0000 | [diff] [blame] | 2984 | do_redraw = TRUE; |
| 2985 | |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2986 | /* Part 1: nlines is the number of lines we're going to scroll the |
| 2987 | * text of the edit window. */ |
| 2988 | |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2989 | /* 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] | 2990 | * value of direction) nlines lines, or as many lines as we can if |
| 2991 | * there are fewer than nlines lines available. */ |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2992 | for (i = nlines; i > 0; i--) { |
David Lawrence Ramsey | 6ff22e7 | 2006-07-19 00:14:52 +0000 | [diff] [blame] | 2993 | if (direction == UP_DIR) { |
David Lawrence Ramsey | e99223d | 2005-11-10 04:27:30 +0000 | [diff] [blame] | 2994 | if (openfile->edittop == openfile->fileage) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2995 | break; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2996 | openfile->edittop = openfile->edittop->prev; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2997 | } else { |
David Lawrence Ramsey | e99223d | 2005-11-10 04:27:30 +0000 | [diff] [blame] | 2998 | if (openfile->edittop == openfile->filebot) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2999 | break; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3000 | openfile->edittop = openfile->edittop->next; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3001 | } |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 3002 | /* Don't over-scroll on long lines. */ |
Benno Schulenberg | b1a7fdd | 2014-03-03 10:02:13 +0000 | [diff] [blame] | 3003 | if (ISSET(SOFTWRAP) && (direction == UP_DIR)) { |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 3004 | ssize_t len = strlenpt(openfile->edittop->data) / COLS; |
| 3005 | i -= len; |
| 3006 | if (len > 0) |
| 3007 | do_redraw = TRUE; |
| 3008 | } |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
David Lawrence Ramsey | c25ed53 | 2005-08-01 21:53:54 +0000 | [diff] [blame] | 3011 | /* Limit nlines to the number of lines we could scroll. */ |
David Lawrence Ramsey | 945a913 | 2005-07-23 21:06:22 +0000 | [diff] [blame] | 3012 | nlines -= i; |
David Lawrence Ramsey | 258497f | 2005-08-01 21:17:38 +0000 | [diff] [blame] | 3013 | |
David Lawrence Ramsey | c25ed53 | 2005-08-01 21:53:54 +0000 | [diff] [blame] | 3014 | /* Don't bother scrolling zero lines or more than the number of |
| 3015 | * 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] | 3016 | * call edit_refresh() beforehand if we need to. */ |
Chris Allegretta | 139934a | 2009-08-30 03:50:16 +0000 | [diff] [blame] | 3017 | if (nlines == 0 || do_redraw || nlines >= editwinrows) { |
David Lawrence Ramsey | 1072fce | 2007-09-16 16:53:20 +0000 | [diff] [blame] | 3018 | if (do_redraw || nlines >= editwinrows) |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 3019 | edit_refresh_needed = TRUE; |
David Lawrence Ramsey | 258497f | 2005-08-01 21:17:38 +0000 | [diff] [blame] | 3020 | return; |
| 3021 | } |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 3022 | |
| 3023 | /* Scroll the text of the edit window up or down nlines lines, |
| 3024 | * depending on the value of direction. */ |
David Lawrence Ramsey | 47bb888 | 2005-07-22 22:56:03 +0000 | [diff] [blame] | 3025 | scrollok(edit, TRUE); |
David Lawrence Ramsey | 6ff22e7 | 2006-07-19 00:14:52 +0000 | [diff] [blame] | 3026 | wscrl(edit, (direction == UP_DIR) ? -nlines : nlines); |
David Lawrence Ramsey | 47bb888 | 2005-07-22 22:56:03 +0000 | [diff] [blame] | 3027 | scrollok(edit, FALSE); |
| 3028 | |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 3029 | /* Part 2: nlines is the number of lines in the scrolled region of |
| 3030 | * the edit window that we need to draw. */ |
| 3031 | |
David Lawrence Ramsey | 6834650 | 2005-08-16 03:03:15 +0000 | [diff] [blame] | 3032 | /* If the top or bottom line of the file is now visible in the edit |
| 3033 | * window, we need to draw the entire edit window. */ |
David Lawrence Ramsey | 6ff22e7 | 2006-07-19 00:14:52 +0000 | [diff] [blame] | 3034 | if ((direction == UP_DIR && openfile->edittop == |
| 3035 | openfile->fileage) || (direction == DOWN_DIR && |
| 3036 | openfile->edittop->lineno + editwinrows - 1 >= |
| 3037 | openfile->filebot->lineno)) |
David Lawrence Ramsey | 945a913 | 2005-07-23 21:06:22 +0000 | [diff] [blame] | 3038 | nlines = editwinrows; |
David Lawrence Ramsey | a7f488b | 2005-07-17 02:19:47 +0000 | [diff] [blame] | 3039 | |
David Lawrence Ramsey | a6eb848 | 2006-01-10 07:51:49 +0000 | [diff] [blame] | 3040 | /* If the scrolled region contains only one line, and the line |
| 3041 | * before it is visible in the edit window, we need to draw it too. |
| 3042 | * If the scrolled region contains more than one line, and the lines |
| 3043 | * before and after the scrolled region are visible in the edit |
| 3044 | * window, we need to draw them too. */ |
| 3045 | nlines += (nlines == 1) ? 1 : 2; |
David Lawrence Ramsey | c25ed53 | 2005-08-01 21:53:54 +0000 | [diff] [blame] | 3046 | |
David Lawrence Ramsey | de0c5eb | 2005-07-17 22:51:44 +0000 | [diff] [blame] | 3047 | if (nlines > editwinrows) |
| 3048 | nlines = editwinrows; |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 3049 | |
| 3050 | /* If we scrolled up, we're on the line before the scrolled |
| 3051 | * region. */ |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3052 | foo = openfile->edittop; |
David Lawrence Ramsey | 1458891 | 2005-07-14 20:37:01 +0000 | [diff] [blame] | 3053 | |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 3054 | /* If we scrolled down, move down to the line before the scrolled |
| 3055 | * region. */ |
David Lawrence Ramsey | 6ff22e7 | 2006-07-19 00:14:52 +0000 | [diff] [blame] | 3056 | if (direction == DOWN_DIR) { |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 3057 | for (i = editwinrows - nlines; i > 0 && foo != NULL; i--) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3058 | foo = foo->next; |
| 3059 | } |
| 3060 | |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 3061 | /* Draw new lines on any blank lines before or inside the scrolled |
| 3062 | * region. If we scrolled down and we're on the top line, or if we |
| 3063 | * scrolled up and we're on the bottom line, the line won't be |
| 3064 | * blank, so we don't need to draw it unless the mark is on or we're |
| 3065 | * not on the first page. */ |
| 3066 | for (i = nlines; i > 0 && foo != NULL; i--) { |
David Lawrence Ramsey | 6ff22e7 | 2006-07-19 00:14:52 +0000 | [diff] [blame] | 3067 | if ((i == nlines && direction == DOWN_DIR) || (i == 1 && |
| 3068 | direction == UP_DIR)) { |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 3069 | if (do_redraw) |
| 3070 | update_line(foo, (foo == openfile->current) ? |
| 3071 | openfile->current_x : 0); |
| 3072 | } else |
| 3073 | update_line(foo, (foo == openfile->current) ? |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 3074 | openfile->current_x : 0); |
David Lawrence Ramsey | f00c961 | 2005-07-14 18:01:08 +0000 | [diff] [blame] | 3075 | foo = foo->next; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3076 | } |
Benno Schulenberg | df7bba3 | 2014-02-26 11:38:30 +0000 | [diff] [blame] | 3077 | compute_maxrows(); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | /* 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] | 3081 | * updated. Use this if we've moved without changing any text. */ |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 3082 | void edit_redraw(filestruct *old_current, size_t pww_save) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3083 | { |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 3084 | bool do_redraw = need_vertical_update(0) || |
David Lawrence Ramsey | fa38795 | 2006-08-26 16:50:51 +0000 | [diff] [blame] | 3085 | need_vertical_update(pww_save); |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 3086 | filestruct *foo = NULL; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3087 | |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 3088 | /* If either old_current or current is offscreen, scroll the edit |
| 3089 | * window until it's onscreen and get out. */ |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3090 | if (old_current->lineno < openfile->edittop->lineno || |
| 3091 | old_current->lineno >= openfile->edittop->lineno + |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 3092 | maxrows || openfile->current->lineno < |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3093 | openfile->edittop->lineno || openfile->current->lineno >= |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 3094 | openfile->edittop->lineno + maxrows) { |
Chris Allegretta | 139934a | 2009-08-30 03:50:16 +0000 | [diff] [blame] | 3095 | |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 3096 | #ifdef DEBUG |
Benno Schulenberg | 55a0d76 | 2014-03-24 13:35:50 +0000 | [diff] [blame] | 3097 | fprintf(stderr, "edit_redraw(): line %d was offscreen, oldcurrent = %d edittop = %d", |
| 3098 | openfile->current->lineno, old_current->lineno, openfile->edittop->lineno); |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 3099 | #endif |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 3100 | |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3101 | #ifndef NANO_TINY |
| 3102 | /* 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] | 3103 | * and either the old first line or old last line (depending on |
| 3104 | * whether we've scrolled up or down) of the edit window. */ |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3105 | if (openfile->mark_set) { |
David Lawrence Ramsey | 3c780e1 | 2006-05-26 03:46:03 +0000 | [diff] [blame] | 3106 | ssize_t old_lineno; |
Chris Allegretta | 4cc2462 | 2013-01-03 04:23:10 +0000 | [diff] [blame] | 3107 | filestruct *old_edittop = openfile->edittop; |
David Lawrence Ramsey | 3c780e1 | 2006-05-26 03:46:03 +0000 | [diff] [blame] | 3108 | |
| 3109 | if (old_edittop->lineno < openfile->edittop->lineno) |
| 3110 | old_lineno = old_edittop->lineno; |
| 3111 | else |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 3112 | old_lineno = (old_edittop->lineno + maxrows <= |
David Lawrence Ramsey | 3c780e1 | 2006-05-26 03:46:03 +0000 | [diff] [blame] | 3113 | openfile->filebot->lineno) ? |
| 3114 | old_edittop->lineno + editwinrows : |
| 3115 | openfile->filebot->lineno; |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3116 | |
| 3117 | foo = old_current; |
| 3118 | |
David Lawrence Ramsey | 3c780e1 | 2006-05-26 03:46:03 +0000 | [diff] [blame] | 3119 | while (foo->lineno != old_lineno) { |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3120 | update_line(foo, 0); |
| 3121 | |
David Lawrence Ramsey | 3c780e1 | 2006-05-26 03:46:03 +0000 | [diff] [blame] | 3122 | foo = (foo->lineno > old_lineno) ? foo->prev : |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3123 | foo->next; |
| 3124 | } |
| 3125 | } |
| 3126 | #endif /* !NANO_TINY */ |
| 3127 | |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 3128 | /* Put edittop in range of current, get the difference in lines |
| 3129 | * between the original edittop and the current edittop, and |
| 3130 | * then restore the original edittop. */ |
Chris Allegretta | 374216f | 2010-01-04 19:00:55 +0000 | [diff] [blame] | 3131 | edit_update(CENTER); |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 3132 | |
David Lawrence Ramsey | b006367 | 2006-07-06 18:29:37 +0000 | [diff] [blame] | 3133 | /* Update old_current if we're not on the same page as |
| 3134 | * before. */ |
David Lawrence Ramsey | a6eb848 | 2006-01-10 07:51:49 +0000 | [diff] [blame] | 3135 | if (do_redraw) |
| 3136 | update_line(old_current, 0); |
| 3137 | |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3138 | #ifndef NANO_TINY |
David Lawrence Ramsey | 3c780e1 | 2006-05-26 03:46:03 +0000 | [diff] [blame] | 3139 | /* If the mark is on, update all the lines between the old first |
| 3140 | * line or old last line of the edit window (depending on |
| 3141 | * whether we've scrolled up or down) and current. */ |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3142 | if (openfile->mark_set) { |
David Lawrence Ramsey | 3c780e1 | 2006-05-26 03:46:03 +0000 | [diff] [blame] | 3143 | while (foo->lineno != openfile->current->lineno) { |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3144 | update_line(foo, 0); |
| 3145 | |
David Lawrence Ramsey | 3c780e1 | 2006-05-26 03:46:03 +0000 | [diff] [blame] | 3146 | foo = (foo->lineno > openfile->current->lineno) ? |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 3147 | foo->prev : foo->next; |
| 3148 | } |
| 3149 | } |
| 3150 | #endif /* !NANO_TINY */ |
| 3151 | |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3152 | return; |
| 3153 | } |
| 3154 | |
David Lawrence Ramsey | b006367 | 2006-07-06 18:29:37 +0000 | [diff] [blame] | 3155 | /* Update old_current and current if we're not on the same page as |
| 3156 | * before. If the mark is on, update all the lines between |
| 3157 | * old_current and current too. */ |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3158 | foo = old_current; |
David Lawrence Ramsey | f00c961 | 2005-07-14 18:01:08 +0000 | [diff] [blame] | 3159 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3160 | while (foo != openfile->current) { |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 3161 | if (do_redraw) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3162 | update_line(foo, 0); |
David Lawrence Ramsey | e5806be | 2005-07-16 02:12:18 +0000 | [diff] [blame] | 3163 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 3164 | #ifndef NANO_TINY |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3165 | if (!openfile->mark_set) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3166 | #endif |
| 3167 | break; |
David Lawrence Ramsey | e5806be | 2005-07-16 02:12:18 +0000 | [diff] [blame] | 3168 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 3169 | #ifndef NANO_TINY |
David Lawrence Ramsey | e5806be | 2005-07-16 02:12:18 +0000 | [diff] [blame] | 3170 | foo = (foo->lineno > openfile->current->lineno) ? foo->prev : |
| 3171 | foo->next; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3172 | #endif |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3173 | } |
David Lawrence Ramsey | f00c961 | 2005-07-14 18:01:08 +0000 | [diff] [blame] | 3174 | |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 3175 | if (do_redraw) |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3176 | update_line(openfile->current, openfile->current_x); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
David Lawrence Ramsey | 75a29b7 | 2005-07-26 14:26:47 +0000 | [diff] [blame] | 3179 | /* Refresh the screen without changing the position of lines. Use this |
| 3180 | * if we've moved and changed text. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3181 | void edit_refresh(void) |
| 3182 | { |
Chris Allegretta | d47d8cd | 2009-01-25 07:25:17 +0000 | [diff] [blame] | 3183 | filestruct *foo; |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 3184 | int nlines; |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3185 | |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 3186 | /* Figure out what maxrows should really be. */ |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 3187 | compute_maxrows(); |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 3188 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3189 | if (openfile->current->lineno < openfile->edittop->lineno || |
| 3190 | openfile->current->lineno >= openfile->edittop->lineno + |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 3191 | maxrows) { |
| 3192 | |
| 3193 | #ifdef DEBUG |
| 3194 | fprintf(stderr, "edit_refresh(): line = %d, edittop %d + maxrows %d\n", openfile->current->lineno, openfile->edittop->lineno, maxrows); |
| 3195 | #endif |
| 3196 | |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 3197 | /* Put the top line of the edit window in range of the current |
| 3198 | * line. */ |
Chris Allegretta | 374216f | 2010-01-04 19:00:55 +0000 | [diff] [blame] | 3199 | edit_update(CENTER); |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 3200 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3201 | |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 3202 | foo = openfile->edittop; |
| 3203 | |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 3204 | #ifdef DEBUG |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3205 | 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] | 3206 | #endif |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 3207 | |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 3208 | for (nlines = 0; nlines < editwinrows && foo != NULL; nlines++) { |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 3209 | nlines += update_line(foo, (foo == openfile->current) ? |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3210 | openfile->current_x : 0); |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3211 | foo = foo->next; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 3212 | } |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3213 | |
David Lawrence Ramsey | 157ce91 | 2005-07-16 23:36:10 +0000 | [diff] [blame] | 3214 | for (; nlines < editwinrows; nlines++) |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3215 | blank_line(edit, nlines, 0, COLS); |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3216 | |
| 3217 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 3218 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3221 | /* Move edittop to put it in range of current, keeping current in the |
| 3222 | * same place. location determines how we move it: if it's CENTER, we |
| 3223 | * center current, and if it's NONE, we put current current_y lines |
| 3224 | * below edittop. */ |
David Lawrence Ramsey | bf0e47d | 2005-08-01 18:27:10 +0000 | [diff] [blame] | 3225 | void edit_update(update_type location) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3226 | { |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3227 | filestruct *foo = openfile->current; |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3228 | int goal; |
David Lawrence Ramsey | 20b8350 | 2004-08-26 18:07:58 +0000 | [diff] [blame] | 3229 | |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3230 | /* If location is CENTER, we move edittop up (editwinrows / 2) |
| 3231 | * lines. This puts current at the center of the screen. If |
| 3232 | * location is NONE, we move edittop up current_y lines if current_y |
| 3233 | * is in range of the screen, 0 lines if current_y is less than 0, |
| 3234 | * or (editwinrows - 1) lines if current_y is greater than |
| 3235 | * (editwinrows - 1). This puts current at the same place on the |
| 3236 | * screen as before, or at the top or bottom of the screen if |
| 3237 | * edittop is beyond either. */ |
| 3238 | if (location == CENTER) |
Chris Allegretta | 374216f | 2010-01-04 19:00:55 +0000 | [diff] [blame] | 3239 | goal = editwinrows / 2; |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3240 | else { |
| 3241 | goal = openfile->current_y; |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 3242 | |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3243 | /* Limit goal to (editwinrows - 1) lines maximum. */ |
Chris Allegretta | 374216f | 2010-01-04 19:00:55 +0000 | [diff] [blame] | 3244 | if (goal > editwinrows - 1) |
| 3245 | goal = editwinrows - 1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 3246 | } |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 3247 | |
Chris Allegretta | 35afab5 | 2009-09-13 04:50:44 +0000 | [diff] [blame] | 3248 | for (; goal > 0 && foo->prev != NULL; goal--) { |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 3249 | foo = foo->prev; |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 3250 | if (ISSET(SOFTWRAP) && foo) |
| 3251 | goal -= strlenpt(foo->data) / COLS; |
Chris Allegretta | 35afab5 | 2009-09-13 04:50:44 +0000 | [diff] [blame] | 3252 | } |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3253 | openfile->edittop = foo; |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 3254 | #ifdef DEBUG |
| 3255 | fprintf(stderr, "edit_udpate(), setting edittop to lineno %d\n", openfile->edittop->lineno); |
| 3256 | #endif |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 3257 | compute_maxrows(); |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 3258 | edit_refresh_needed = TRUE; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3259 | } |
| 3260 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 3261 | /* Unconditionally redraw the entire screen. */ |
David Lawrence Ramsey | c54c4d1 | 2005-06-18 15:49:17 +0000 | [diff] [blame] | 3262 | void total_redraw(void) |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3263 | { |
David Lawrence Ramsey | f78bc85 | 2007-12-18 15:55:48 +0000 | [diff] [blame] | 3264 | #ifdef USE_SLANG |
| 3265 | /* Slang curses emulation brain damage, part 4: Slang doesn't define |
| 3266 | * curscr. */ |
| 3267 | SLsmg_touch_screen(); |
| 3268 | SLsmg_refresh(); |
| 3269 | #else |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 3270 | wrefresh(curscr); |
David Lawrence Ramsey | f78bc85 | 2007-12-18 15:55:48 +0000 | [diff] [blame] | 3271 | #endif |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 3274 | /* Unconditionally redraw the entire screen, and then refresh it using |
| 3275 | * the current file. */ |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 3276 | void total_refresh(void) |
| 3277 | { |
David Lawrence Ramsey | c54c4d1 | 2005-06-18 15:49:17 +0000 | [diff] [blame] | 3278 | total_redraw(); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3279 | titlebar(NULL); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 3280 | edit_refresh(); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 3281 | bottombars(currmenu); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 3284 | /* Display the main shortcut list on the last two rows of the bottom |
| 3285 | * portion of the window. */ |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3286 | void display_main_list(void) |
| 3287 | { |
Benno Schulenberg | 0038992 | 2014-04-04 11:59:03 +0000 | [diff] [blame] | 3288 | #ifndef DISABLE_COLOR |
Chris Allegretta | 5575bfa | 2014-02-24 10:18:15 +0000 | [diff] [blame] | 3289 | if (openfile->syntax && openfile->syntax->linter) |
| 3290 | set_lint_shortcuts(); |
| 3291 | else |
| 3292 | set_spell_shortcuts(); |
| 3293 | #endif |
| 3294 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 3295 | bottombars(MMAIN); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3298 | /* If constant is TRUE, we display the current cursor position only if |
| 3299 | * disable_cursorpos is FALSE. Otherwise, we display it |
| 3300 | * unconditionally and set disable_cursorpos to FALSE. If constant is |
| 3301 | * TRUE and disable_cursorpos is TRUE, we also set disable_cursorpos to |
| 3302 | * FALSE, so that we leave the current statusbar alone this time, and |
| 3303 | * display the current cursor position next time. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 3304 | void do_cursorpos(bool constant) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3305 | { |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 3306 | filestruct *f; |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 3307 | char c; |
David Lawrence Ramsey | 5745c0a | 2005-07-31 20:20:37 +0000 | [diff] [blame] | 3308 | size_t i, cur_xpt = xplustabs() + 1; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3309 | size_t cur_lenpt = strlenpt(openfile->current->data) + 1; |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3310 | int linepct, colpct, charpct; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3311 | |
David Lawrence Ramsey | 4ab8015 | 2005-07-31 18:51:51 +0000 | [diff] [blame] | 3312 | assert(openfile->fileage != NULL && openfile->current != NULL); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3313 | |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 3314 | f = openfile->current->next; |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 3315 | c = openfile->current->data[openfile->current_x]; |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 3316 | |
| 3317 | openfile->current->next = NULL; |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 3318 | openfile->current->data[openfile->current_x] = '\0'; |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 3319 | |
| 3320 | i = get_totsize(openfile->fileage, openfile->current); |
| 3321 | |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 3322 | openfile->current->data[openfile->current_x] = c; |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 3323 | openfile->current->next = f; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 3324 | |
David Lawrence Ramsey | ea01474 | 2005-06-17 18:27:00 +0000 | [diff] [blame] | 3325 | if (constant && disable_cursorpos) { |
| 3326 | disable_cursorpos = FALSE; |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3327 | return; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3328 | } |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 3329 | |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 3330 | /* Display the current cursor position on the statusbar, and set |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3331 | * disable_cursorpos to FALSE. */ |
David Lawrence Ramsey | 520a90c | 2005-07-25 21:23:11 +0000 | [diff] [blame] | 3332 | linepct = 100 * openfile->current->lineno / |
| 3333 | openfile->filebot->lineno; |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3334 | colpct = 100 * cur_xpt / cur_lenpt; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3335 | charpct = (openfile->totsize == 0) ? 0 : 100 * i / |
| 3336 | openfile->totsize; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3337 | |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3338 | statusbar( |
David Lawrence Ramsey | 520a90c | 2005-07-25 21:23:11 +0000 | [diff] [blame] | 3339 | _("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] | 3340 | (long)openfile->current->lineno, |
David Lawrence Ramsey | 520a90c | 2005-07-25 21:23:11 +0000 | [diff] [blame] | 3341 | (long)openfile->filebot->lineno, linepct, |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3342 | (unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct, |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3343 | (unsigned long)i, (unsigned long)openfile->totsize, charpct); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3344 | |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3345 | disable_cursorpos = FALSE; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 3348 | /* Unconditionally display the current cursor position. */ |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3349 | void do_cursorpos_void(void) |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3350 | { |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3351 | do_cursorpos(FALSE); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3352 | } |
| 3353 | |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 3354 | void enable_nodelay(void) |
| 3355 | { |
| 3356 | nodelay_mode = TRUE; |
| 3357 | nodelay(edit, TRUE); |
| 3358 | } |
| 3359 | |
| 3360 | void disable_nodelay(void) |
| 3361 | { |
| 3362 | nodelay_mode = FALSE; |
| 3363 | nodelay(edit, FALSE); |
| 3364 | } |
| 3365 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3366 | /* Highlight the current word being replaced or spell checked. We |
| 3367 | * expect word to have tabs and control characters expanded. */ |
David Lawrence Ramsey | 7bde053 | 2005-06-30 03:55:55 +0000 | [diff] [blame] | 3368 | void do_replace_highlight(bool highlight, const char *word) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3369 | { |
David Lawrence Ramsey | 6168cb7 | 2005-06-30 03:53:28 +0000 | [diff] [blame] | 3370 | size_t y = xplustabs(), word_len = strlenpt(word); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3371 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3372 | y = get_page_start(y) + COLS - y; |
David Lawrence Ramsey | 913db83 | 2005-01-05 05:08:14 +0000 | [diff] [blame] | 3373 | /* 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] | 3374 | * line. */ |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3375 | |
David Lawrence Ramsey | 913db83 | 2005-01-05 05:08:14 +0000 | [diff] [blame] | 3376 | assert(y > 0); |
| 3377 | |
| 3378 | if (word_len > y) |
| 3379 | y--; |
| 3380 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3381 | reset_cursor(); |
David Lawrence Ramsey | 98958e8 | 2007-12-04 16:38:47 +0000 | [diff] [blame] | 3382 | wnoutrefresh(edit); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3383 | |
David Lawrence Ramsey | 7bde053 | 2005-06-30 03:55:55 +0000 | [diff] [blame] | 3384 | if (highlight) |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 3385 | wattron(edit, reverse_attr); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3386 | |
David Lawrence Ramsey | 21b946e | 2006-11-10 20:13:38 +0000 | [diff] [blame] | 3387 | /* This is so we can show zero-length matches. */ |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 3388 | if (word_len == 0) |
David Lawrence Ramsey | 5b9f522 | 2005-06-13 02:22:44 +0000 | [diff] [blame] | 3389 | waddch(edit, ' '); |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 3390 | else |
David Lawrence Ramsey | 913db83 | 2005-01-05 05:08:14 +0000 | [diff] [blame] | 3391 | waddnstr(edit, word, actual_x(word, y)); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3392 | |
| 3393 | if (word_len > y) |
| 3394 | waddch(edit, '$'); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +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 | wattroff(edit, reverse_attr); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3398 | } |
| 3399 | |
Benno Schulenberg | d17438b | 2014-04-03 20:57:44 +0000 | [diff] [blame] | 3400 | #ifndef DISABLE_EXTRA |
Chris Allegretta | 34b7f1c | 2014-02-24 15:15:51 +0000 | [diff] [blame] | 3401 | #define CREDIT_LEN 57 |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 3402 | #define XLCREDIT_LEN 8 |
| 3403 | |
David Lawrence Ramsey | 8ad58bc | 2005-08-16 03:02:46 +0000 | [diff] [blame] | 3404 | /* Easter egg: Display credits. Assume nodelay(edit) and scrollok(edit) |
| 3405 | * are FALSE. */ |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3406 | void do_credits(void) |
| 3407 | { |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3408 | bool old_more_space = ISSET(MORE_SPACE); |
| 3409 | bool old_no_help = ISSET(NO_HELP); |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3410 | int kbinput = ERR, crpos = 0, xlpos = 0; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3411 | const char *credits[CREDIT_LEN] = { |
| 3412 | NULL, /* "The nano text editor" */ |
| 3413 | NULL, /* "version" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3414 | VERSION, |
| 3415 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3416 | NULL, /* "Brought to you by:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3417 | "Chris Allegretta", |
| 3418 | "Jordi Mallach", |
| 3419 | "Adam Rogoyski", |
| 3420 | "Rob Siemborski", |
| 3421 | "Rocco Corsi", |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 3422 | "David Lawrence Ramsey", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 3423 | "David Benbennick", |
David Lawrence Ramsey | 47daf02 | 2005-08-29 18:29:02 +0000 | [diff] [blame] | 3424 | "Mike Frysinger", |
Chris Allegretta | 34b7f1c | 2014-02-24 15:15:51 +0000 | [diff] [blame] | 3425 | "Benno Schulenberg", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3426 | "Ken Tyler", |
| 3427 | "Sven Guckes", |
Chris Allegretta | 34b7f1c | 2014-02-24 15:15:51 +0000 | [diff] [blame] | 3428 | NULL, /* credits[16], handled below. */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3429 | "Pauli Virtanen", |
| 3430 | "Daniele Medri", |
| 3431 | "Clement Laforet", |
| 3432 | "Tedi Heriyanto", |
| 3433 | "Bill Soudan", |
| 3434 | "Christian Weisgerber", |
| 3435 | "Erik Andersen", |
| 3436 | "Big Gaute", |
| 3437 | "Joshua Jensen", |
| 3438 | "Ryan Krebs", |
| 3439 | "Albert Chin", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3440 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3441 | NULL, /* "Special thanks to:" */ |
Chris Allegretta | 34b7f1c | 2014-02-24 15:15:51 +0000 | [diff] [blame] | 3442 | "Monique, Brielle & Joseph", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3443 | "Plattsburgh State University", |
| 3444 | "Benet Laboratories", |
| 3445 | "Amy Allegretta", |
| 3446 | "Linda Young", |
| 3447 | "Jeremy Robichaud", |
| 3448 | "Richard Kolb II", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3449 | NULL, /* "The Free Software Foundation" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3450 | "Linus Torvalds", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3451 | NULL, /* "For ncurses:" */ |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 3452 | "Thomas Dickey", |
| 3453 | "Pavel Curtis", |
| 3454 | "Zeyd Ben-Halim", |
| 3455 | "Eric S. Raymond", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3456 | NULL, /* "and anyone else we forgot..." */ |
| 3457 | NULL, /* "Thank you for using nano!" */ |
| 3458 | "", |
| 3459 | "", |
| 3460 | "", |
| 3461 | "", |
Chris Allegretta | 34b7f1c | 2014-02-24 15:15:51 +0000 | [diff] [blame] | 3462 | "(C) 1999 - 2014", |
David Lawrence Ramsey | d8a1d37 | 2007-10-11 05:01:32 +0000 | [diff] [blame] | 3463 | "Free Software Foundation, Inc.", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3464 | "", |
| 3465 | "", |
| 3466 | "", |
| 3467 | "", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 3468 | "http://www.nano-editor.org/" |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3469 | }; |
| 3470 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3471 | const char *xlcredits[XLCREDIT_LEN] = { |
David Lawrence Ramsey | 576bf33 | 2004-07-12 03:10:30 +0000 | [diff] [blame] | 3472 | N_("The nano text editor"), |
| 3473 | N_("version"), |
| 3474 | N_("Brought to you by:"), |
| 3475 | N_("Special thanks to:"), |
| 3476 | N_("The Free Software Foundation"), |
| 3477 | N_("For ncurses:"), |
| 3478 | N_("and anyone else we forgot..."), |
| 3479 | N_("Thank you for using nano!") |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3480 | }; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 3481 | |
Benno Schulenberg | d0dec31 | 2014-04-08 12:35:18 +0000 | [diff] [blame] | 3482 | /* credits[16]: Make sure this name is displayed properly, since we |
David Lawrence Ramsey | 62d616b | 2005-07-06 19:20:32 +0000 | [diff] [blame] | 3483 | * can't dynamically assign it above, using Unicode 00F6 (Latin |
| 3484 | * Small Letter O with Diaresis) if applicable. */ |
Chris Allegretta | 34b7f1c | 2014-02-24 15:15:51 +0000 | [diff] [blame] | 3485 | credits[16] = |
David Lawrence Ramsey | 7eb30a8 | 2005-07-17 02:40:07 +0000 | [diff] [blame] | 3486 | #ifdef ENABLE_UTF8 |
David Lawrence Ramsey | 4d72de7 | 2006-04-12 15:27:40 +0000 | [diff] [blame] | 3487 | using_utf8() ? "Florian K\xC3\xB6nig" : |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3488 | #endif |
| 3489 | "Florian K\xF6nig"; |
| 3490 | |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3491 | if (!old_more_space || !old_no_help) { |
| 3492 | SET(MORE_SPACE); |
| 3493 | SET(NO_HELP); |
| 3494 | window_init(); |
| 3495 | } |
| 3496 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3497 | curs_set(0); |
| 3498 | nodelay(edit, TRUE); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3499 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3500 | blank_titlebar(); |
David Lawrence Ramsey | 637b8bb | 2005-01-17 05:06:55 +0000 | [diff] [blame] | 3501 | blank_topbar(); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 3502 | blank_edit(); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3503 | blank_statusbar(); |
| 3504 | blank_bottombars(); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3505 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3506 | wrefresh(topwin); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 3507 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3508 | wrefresh(bottomwin); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3509 | napms(700); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3510 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3511 | for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) { |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3512 | if ((kbinput = wgetch(edit)) != ERR) |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3513 | break; |
David Lawrence Ramsey | 0099a8f | 2005-03-15 06:34:09 +0000 | [diff] [blame] | 3514 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3515 | if (crpos < CREDIT_LEN) { |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3516 | const char *what; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3517 | size_t start_x; |
| 3518 | |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3519 | if (credits[crpos] == NULL) { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3520 | assert(0 <= xlpos && xlpos < XLCREDIT_LEN); |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3521 | |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3522 | what = _(xlcredits[xlpos]); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3523 | xlpos++; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3524 | } else |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3525 | what = credits[crpos]; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3526 | |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 3527 | start_x = COLS / 2 - strlenpt(what) / 2 - 1; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3528 | mvwaddstr(edit, editwinrows - 1 - (editwinrows % 2), |
| 3529 | start_x, what); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3530 | } |
David Lawrence Ramsey | 0099a8f | 2005-03-15 06:34:09 +0000 | [diff] [blame] | 3531 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3532 | wrefresh(edit); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3533 | |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3534 | if ((kbinput = wgetch(edit)) != ERR) |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3535 | break; |
| 3536 | napms(700); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3537 | |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3538 | scrollok(edit, TRUE); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3539 | wscrl(edit, 1); |
| 3540 | scrollok(edit, FALSE); |
| 3541 | wrefresh(edit); |
| 3542 | |
| 3543 | if ((kbinput = wgetch(edit)) != ERR) |
| 3544 | break; |
| 3545 | napms(700); |
| 3546 | |
| 3547 | scrollok(edit, TRUE); |
| 3548 | wscrl(edit, 1); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3549 | scrollok(edit, FALSE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3550 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3553 | if (kbinput != ERR) |
| 3554 | ungetch(kbinput); |
| 3555 | |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3556 | if (!old_more_space || !old_no_help) { |
| 3557 | UNSET(MORE_SPACE); |
| 3558 | UNSET(NO_HELP); |
| 3559 | window_init(); |
| 3560 | } |
| 3561 | |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3562 | curs_set(1); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3563 | nodelay(edit, FALSE); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3564 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3565 | total_refresh(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3566 | } |
Benno Schulenberg | d17438b | 2014-04-03 20:57:44 +0000 | [diff] [blame] | 3567 | #endif /* !DISABLE_EXTRA */ |