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