Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1 | /************************************************************************** |
Benno Schulenberg | 514cd9a | 2016-08-29 17:10:49 +0200 | [diff] [blame] | 2 | * winio.c -- This file is part of GNU nano. * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3 | * * |
Chris Allegretta | 8a07a96 | 2009-12-02 03:36:22 +0000 | [diff] [blame] | 4 | * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, * |
Benno Schulenberg | 7a9f4a4 | 2014-04-30 20:18:26 +0000 | [diff] [blame] | 5 | * 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. * |
Benno Schulenberg | c118397 | 2017-02-21 20:27:49 +0100 | [diff] [blame] | 6 | * Copyright (C) 2014, 2015, 2016, 2017 Benno Schulenberg * |
Benno Schulenberg | 406e524 | 2016-08-29 15:14:18 +0200 | [diff] [blame] | 7 | * * |
Benno Schulenberg | 514cd9a | 2016-08-29 17:10:49 +0200 | [diff] [blame] | 8 | * GNU nano is free software: you can redistribute it and/or modify * |
| 9 | * it under the terms of the GNU General Public License as published * |
| 10 | * by the Free Software Foundation, either version 3 of the License, * |
| 11 | * or (at your option) any later version. * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 12 | * * |
Benno Schulenberg | 514cd9a | 2016-08-29 17:10:49 +0200 | [diff] [blame] | 13 | * GNU nano is distributed in the hope that it will be useful, * |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty * |
| 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
| 16 | * See the GNU General Public License for more details. * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 17 | * * |
| 18 | * You should have received a copy of the GNU General Public License * |
Benno Schulenberg | 514cd9a | 2016-08-29 17:10:49 +0200 | [diff] [blame] | 19 | * along with this program. If not, see http://www.gnu.org/licenses/. * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 20 | * * |
| 21 | **************************************************************************/ |
| 22 | |
David Lawrence Ramsey | 034b994 | 2005-12-08 02:47:10 +0000 | [diff] [blame] | 23 | #include "proto.h" |
Benno Schulenberg | 2ae490c | 2016-05-20 12:59:57 +0200 | [diff] [blame] | 24 | #include "revision.h" |
David Lawrence Ramsey | e21adfa | 2002-09-13 18:14:04 +0000 | [diff] [blame] | 25 | |
Benno Schulenberg | 08cd197 | 2016-09-08 21:00:51 +0200 | [diff] [blame] | 26 | #ifdef __linux__ |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 27 | #include <sys/ioctl.h> |
Benno Schulenberg | 928a24c | 2016-08-11 12:37:11 +0200 | [diff] [blame] | 28 | #endif |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 29 | |
David Lawrence Ramsey | 143b8c7 | 2005-11-01 18:35:47 +0000 | [diff] [blame] | 30 | #include <stdio.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 31 | #include <stdarg.h> |
| 32 | #include <string.h> |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 33 | #include <unistd.h> |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 34 | #include <ctype.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 35 | |
Benno Schulenberg | 2ae490c | 2016-05-20 12:59:57 +0200 | [diff] [blame] | 36 | #ifdef REVISION |
| 37 | #define BRANDING REVISION |
| 38 | #else |
| 39 | #define BRANDING PACKAGE_STRING |
| 40 | #endif |
| 41 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 42 | static int *key_buffer = NULL; |
David Lawrence Ramsey | 6335fb5 | 2007-01-01 05:15:32 +0000 | [diff] [blame] | 43 | /* The keystroke buffer, containing all the keystrokes we |
| 44 | * haven't handled yet at a given point. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 45 | static size_t key_buffer_len = 0; |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 46 | /* The length of the keystroke buffer. */ |
Benno Schulenberg | f2150d3 | 2016-07-11 14:21:38 +0200 | [diff] [blame] | 47 | static bool solitary = FALSE; |
| 48 | /* Whether an Esc arrived by itself -- not as leader of a sequence. */ |
David Lawrence Ramsey | fe7d53e | 2005-06-25 20:56:36 +0000 | [diff] [blame] | 49 | static int statusblank = 0; |
Benno Schulenberg | 2cd21da | 2016-05-15 11:17:55 +0200 | [diff] [blame] | 50 | /* The number of keystrokes left before we blank the statusbar. */ |
Benno Schulenberg | 9d6d5b6 | 2016-05-04 12:18:21 +0200 | [diff] [blame] | 51 | static bool suppress_cursorpos = FALSE; |
Benno Schulenberg | e0e788e | 2016-05-23 21:34:02 +0200 | [diff] [blame] | 52 | /* Should we skip constant position display for one keystroke? */ |
Benno Schulenberg | 8c7a385 | 2016-07-12 21:05:09 +0200 | [diff] [blame] | 53 | #ifdef USING_OLD_NCURSES |
Benno Schulenberg | 954d04b | 2015-09-05 09:14:24 +0000 | [diff] [blame] | 54 | static bool seen_wide = FALSE; |
| 55 | /* Whether we've seen a multicolumn character in the current line. */ |
Benno Schulenberg | 8c7a385 | 2016-07-12 21:05:09 +0200 | [diff] [blame] | 56 | #endif |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 57 | |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 58 | /* Control character compatibility: |
| 59 | * |
Benno Schulenberg | 1c2d2a4 | 2016-07-22 15:57:20 +0200 | [diff] [blame] | 60 | * - Ctrl-H is Backspace under ASCII, ANSI, VT100, and VT220. |
| 61 | * - Ctrl-I is Tab under ASCII, ANSI, VT100, VT220, and VT320. |
| 62 | * - Ctrl-M is Enter under ASCII, ANSI, VT100, VT220, and VT320. |
| 63 | * - Ctrl-Q is XON under ASCII, ANSI, VT100, VT220, and VT320. |
| 64 | * - Ctrl-S is XOFF under ASCII, ANSI, VT100, VT220, and VT320. |
Benno Schulenberg | 90a9036 | 2016-08-01 12:56:05 +0200 | [diff] [blame] | 65 | * - Ctrl-8 (Ctrl-?) is Delete under ASCII, ANSI, VT100, and VT220, |
| 66 | * but is Backspace under VT320. |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 67 | * |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 68 | * Note: VT220 and VT320 also generate Esc [ 3 ~ for Delete. By |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 69 | * default, xterm assumes it's running on a VT320 and generates Ctrl-8 |
| 70 | * (Ctrl-?) for Backspace and Esc [ 3 ~ for Delete. This causes |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 71 | * problems for VT100-derived terminals such as the FreeBSD console, |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 72 | * 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] | 73 | * on which the VT320 sequences are translated by the keypad to KEY_DC |
| 74 | * and [nothing]. We work around this conflict via the REBIND_DELETE |
| 75 | * flag: if it's not set, we assume VT320 compatibility, and if it is, |
| 76 | * we assume VT100 compatibility. Thanks to Lee Nelson and Wouter van |
| 77 | * Hemel for helping work this conflict out. |
| 78 | * |
| 79 | * Escape sequence compatibility: |
| 80 | * |
| 81 | * We support escape sequences for ANSI, VT100, VT220, VT320, the Linux |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 82 | * console, the FreeBSD console, the Mach console, xterm, rxvt, Eterm, |
Benno Schulenberg | 1c2d2a4 | 2016-07-22 15:57:20 +0200 | [diff] [blame] | 83 | * and Terminal, and some for iTerm2. Among these, there are several |
| 84 | * conflicts and omissions, outlined as follows: |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 85 | * |
| 86 | * - Tab on ANSI == PageUp on FreeBSD console; the former is omitted. |
| 87 | * (Ctrl-I is also Tab on ANSI, which we already support.) |
| 88 | * - PageDown on FreeBSD console == Center (5) on numeric keypad with |
| 89 | * NumLock off on Linux console; the latter is omitted. (The editing |
| 90 | * keypad key is more important to have working than the numeric |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 91 | * 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] | 92 | * - F1 on FreeBSD console == the mouse key on xterm/rxvt/Eterm; the |
| 93 | * latter is omitted. (Mouse input will only work properly if the |
| 94 | * extended keypad value KEY_MOUSE is generated on mouse events |
| 95 | * instead of the escape sequence.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 96 | * - F9 on FreeBSD console == PageDown on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 97 | * omitted. (The editing keypad is more important to have working |
| 98 | * than the function keys, because the functions of the former are not |
| 99 | * arbitrary and the functions of the latter are.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 100 | * - F10 on FreeBSD console == PageUp on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 101 | * omitted. (Same as above.) |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 102 | * - F13 on FreeBSD console == End on Mach console; the former is |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 103 | * omitted. (Same as above.) |
David Lawrence Ramsey | 8381fdd | 2004-11-01 22:40:02 +0000 | [diff] [blame] | 104 | * - F15 on FreeBSD console == Shift-Up on rxvt/Eterm; the former is |
| 105 | * omitted. (The arrow keys, with or without modifiers, are more |
| 106 | * important to have working than the function keys, because the |
| 107 | * functions of the former are not arbitrary and the functions of the |
| 108 | * latter are.) |
| 109 | * - 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] | 110 | * omitted. (Same as above.) */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 111 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 112 | /* 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] | 113 | * keystroke buffer. This should only be called when the keystroke |
| 114 | * buffer is empty. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 115 | void get_key_buffer(WINDOW *win) |
David Lawrence Ramsey | dfca1c4 | 2004-08-25 16:37:06 +0000 | [diff] [blame] | 116 | { |
David Lawrence Ramsey | ec8a055 | 2006-03-19 19:26:52 +0000 | [diff] [blame] | 117 | int input; |
Benno Schulenberg | 5cbaf59 | 2016-05-17 22:12:28 +0200 | [diff] [blame] | 118 | size_t errcount = 0; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 119 | |
| 120 | /* If the keystroke buffer isn't empty, get out. */ |
| 121 | if (key_buffer != NULL) |
| 122 | return; |
| 123 | |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 124 | /* Just before reading in the first character, display any pending |
| 125 | * screen updates. */ |
| 126 | doupdate(); |
| 127 | |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 128 | /* Read in the first character using whatever mode we're in. */ |
Benno Schulenberg | 5cbaf59 | 2016-05-17 22:12:28 +0200 | [diff] [blame] | 129 | input = wgetch(win); |
David Lawrence Ramsey | 9149325 | 2006-03-19 19:25:29 +0000 | [diff] [blame] | 130 | |
Benno Schulenberg | a878f5f | 2016-05-18 11:14:17 +0200 | [diff] [blame] | 131 | #ifndef NANO_TINY |
Benno Schulenberg | b77e6bd | 2016-12-14 20:37:03 +0100 | [diff] [blame] | 132 | if (the_window_resized) { |
Benno Schulenberg | 1d7c177 | 2016-06-29 15:53:08 +0200 | [diff] [blame] | 133 | ungetch(input); |
Benno Schulenberg | b77e6bd | 2016-12-14 20:37:03 +0100 | [diff] [blame] | 134 | regenerate_screen(); |
Benno Schulenberg | a878f5f | 2016-05-18 11:14:17 +0200 | [diff] [blame] | 135 | input = KEY_WINCH; |
Benno Schulenberg | 1d7c177 | 2016-06-29 15:53:08 +0200 | [diff] [blame] | 136 | } |
Benno Schulenberg | a878f5f | 2016-05-18 11:14:17 +0200 | [diff] [blame] | 137 | #endif |
| 138 | |
Benno Schulenberg | 5cbaf59 | 2016-05-17 22:12:28 +0200 | [diff] [blame] | 139 | if (input == ERR && nodelay_mode) |
| 140 | return; |
| 141 | |
| 142 | while (input == ERR) { |
| 143 | /* If we've failed to get a character MAX_BUF_SIZE times in a row, |
| 144 | * assume our input source is gone and die gracefully. We could |
| 145 | * check if errno is set to EIO ("Input/output error") and die in |
| 146 | * that case, but it's not always set properly. Argh. */ |
| 147 | if (++errcount == MAX_BUF_SIZE) |
| 148 | handle_hupterm(0); |
| 149 | |
| 150 | #ifndef NANO_TINY |
Benno Schulenberg | b77e6bd | 2016-12-14 20:37:03 +0100 | [diff] [blame] | 151 | if (the_window_resized) { |
| 152 | regenerate_screen(); |
Benno Schulenberg | 5cbaf59 | 2016-05-17 22:12:28 +0200 | [diff] [blame] | 153 | input = KEY_WINCH; |
| 154 | break; |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 155 | } |
Benno Schulenberg | 5cbaf59 | 2016-05-17 22:12:28 +0200 | [diff] [blame] | 156 | #endif |
| 157 | input = wgetch(win); |
Benno Schulenberg | 75d64e6 | 2015-05-28 13:02:29 +0000 | [diff] [blame] | 158 | } |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 159 | |
David Lawrence Ramsey | 14aa37c | 2007-05-25 16:54:06 +0000 | [diff] [blame] | 160 | /* Increment the length of the keystroke buffer, and save the value |
| 161 | * of the keystroke at the end of it. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 162 | key_buffer_len++; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 163 | key_buffer = (int *)nmalloc(sizeof(int)); |
| 164 | key_buffer[0] = input; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 165 | |
Benno Schulenberg | 75d64e6 | 2015-05-28 13:02:29 +0000 | [diff] [blame] | 166 | #ifndef NANO_TINY |
| 167 | /* If we got SIGWINCH, get out immediately since the win argument is |
| 168 | * no longer valid. */ |
| 169 | if (input == KEY_WINCH) |
| 170 | return; |
| 171 | #endif |
| 172 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 173 | /* Read in the remaining characters using non-blocking input. */ |
| 174 | nodelay(win, TRUE); |
| 175 | |
| 176 | while (TRUE) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 177 | input = wgetch(win); |
David Lawrence Ramsey | 78ea5e4 | 2004-12-12 19:04:56 +0000 | [diff] [blame] | 178 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 179 | /* If there aren't any more characters, stop reading. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 180 | if (input == ERR) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 181 | break; |
| 182 | |
David Lawrence Ramsey | 14aa37c | 2007-05-25 16:54:06 +0000 | [diff] [blame] | 183 | /* Otherwise, increment the length of the keystroke buffer, and |
| 184 | * save the value of the keystroke at the end of it. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 185 | key_buffer_len++; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 186 | key_buffer = (int *)nrealloc(key_buffer, key_buffer_len * |
| 187 | sizeof(int)); |
| 188 | key_buffer[key_buffer_len - 1] = input; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Benno Schulenberg | c918c65 | 2016-05-05 21:44:45 +0200 | [diff] [blame] | 191 | /* Restore waiting mode if it was on. */ |
| 192 | if (!nodelay_mode) |
| 193 | nodelay(win, FALSE); |
David Lawrence Ramsey | a17a130 | 2005-03-16 14:39:42 +0000 | [diff] [blame] | 194 | |
| 195 | #ifdef DEBUG |
Benno Schulenberg | e00b3e8 | 2015-06-11 19:01:28 +0000 | [diff] [blame] | 196 | { |
| 197 | size_t i; |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 198 | fprintf(stderr, "\nget_key_buffer(): the sequence of hex codes:"); |
Benno Schulenberg | e00b3e8 | 2015-06-11 19:01:28 +0000 | [diff] [blame] | 199 | for (i = 0; i < key_buffer_len; i++) |
| 200 | fprintf(stderr, " %3x", key_buffer[i]); |
| 201 | fprintf(stderr, "\n"); |
| 202 | } |
David Lawrence Ramsey | a17a130 | 2005-03-16 14:39:42 +0000 | [diff] [blame] | 203 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 204 | } |
| 205 | |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 206 | /* Return the length of the keystroke buffer. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 207 | size_t get_key_buffer_len(void) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 208 | { |
| 209 | return key_buffer_len; |
| 210 | } |
| 211 | |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 212 | /* Add the keystrokes in input to the keystroke buffer. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 213 | void unget_input(int *input, size_t input_len) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 214 | { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 215 | /* If input is empty, get out. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 216 | if (input_len == 0) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 217 | return; |
| 218 | |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 219 | /* If adding input would put the keystroke buffer beyond maximum |
| 220 | * capacity, only add enough of input to put it at maximum |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 221 | * capacity. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 222 | if (key_buffer_len + input_len < key_buffer_len) |
| 223 | input_len = (size_t)-1 - key_buffer_len; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 224 | |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 225 | /* Add the length of input to the length of the keystroke buffer, |
| 226 | * and reallocate the keystroke buffer so that it has enough room |
| 227 | * for input. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 228 | key_buffer_len += input_len; |
| 229 | key_buffer = (int *)nrealloc(key_buffer, key_buffer_len * |
| 230 | sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 231 | |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 232 | /* If the keystroke buffer wasn't empty before, move its beginning |
| 233 | * 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] | 234 | if (key_buffer_len > input_len) |
| 235 | memmove(key_buffer + input_len, key_buffer, |
| 236 | (key_buffer_len - input_len) * sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 237 | |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 238 | /* Copy input to the beginning of the keystroke buffer. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 239 | memcpy(key_buffer, input, input_len * sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Benno Schulenberg | 91951ab | 2016-07-23 14:01:38 +0200 | [diff] [blame] | 242 | /* Put the character given in kbinput back into the input stream. If it |
| 243 | * is a Meta key, also insert an Escape character in front of it. */ |
| 244 | void unget_kbinput(int kbinput, bool metakey) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 245 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 246 | unget_input(&kbinput, 1); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 247 | |
Benno Schulenberg | 7e5324d | 2014-06-30 18:04:33 +0000 | [diff] [blame] | 248 | if (metakey) { |
Benno Schulenberg | 90a9036 | 2016-08-01 12:56:05 +0200 | [diff] [blame] | 249 | kbinput = ESC_CODE; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 250 | unget_input(&kbinput, 1); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 254 | /* Try to read input_len codes from the keystroke buffer. If the |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 255 | * keystroke buffer is empty and win isn't NULL, try to read in more |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 256 | * codes from win and add them to the keystroke buffer before doing |
Benno Schulenberg | e666f8c | 2016-05-02 21:58:43 +0200 | [diff] [blame] | 257 | * anything else. If the keystroke buffer is (still) empty, return NULL. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 258 | int *get_input(WINDOW *win, size_t input_len) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 259 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 260 | int *input; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 261 | |
Benno Schulenberg | e666f8c | 2016-05-02 21:58:43 +0200 | [diff] [blame] | 262 | if (key_buffer_len == 0 && win != NULL) |
| 263 | get_key_buffer(win); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 264 | |
Benno Schulenberg | e666f8c | 2016-05-02 21:58:43 +0200 | [diff] [blame] | 265 | if (key_buffer_len == 0) |
| 266 | return NULL; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 267 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 268 | /* Limit the request to the number of available codes in the 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 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 272 | /* Copy input_len codes from the head of the keystroke buffer. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 273 | input = (int *)nmalloc(input_len * sizeof(int)); |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 274 | memcpy(input, key_buffer, input_len * sizeof(int)); |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 275 | key_buffer_len -= input_len; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 276 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 277 | /* If the keystroke buffer is now empty, mark it as such. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 278 | if (key_buffer_len == 0) { |
| 279 | free(key_buffer); |
| 280 | key_buffer = NULL; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 281 | } else { |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 282 | /* Trim from the buffer the codes that were copied. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 283 | memmove(key_buffer, key_buffer + input_len, key_buffer_len * |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 284 | sizeof(int)); |
| 285 | key_buffer = (int *)nrealloc(key_buffer, key_buffer_len * |
| 286 | sizeof(int)); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | return input; |
| 290 | } |
| 291 | |
Benno Schulenberg | ddd9c7a | 2016-06-24 22:45:41 +0200 | [diff] [blame] | 292 | /* Read in a single keystroke, ignoring any that are invalid. */ |
Benno Schulenberg | 7e5324d | 2014-06-30 18:04:33 +0000 | [diff] [blame] | 293 | int get_kbinput(WINDOW *win) |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 294 | { |
Benno Schulenberg | db310ac | 2016-08-30 09:40:51 +0200 | [diff] [blame] | 295 | int kbinput = ERR; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 296 | |
Benno Schulenberg | ddd9c7a | 2016-06-24 22:45:41 +0200 | [diff] [blame] | 297 | /* Extract one keystroke from the input stream. */ |
Benno Schulenberg | db310ac | 2016-08-30 09:40:51 +0200 | [diff] [blame] | 298 | while (kbinput == ERR) |
Benno Schulenberg | db310ac | 2016-08-30 09:40:51 +0200 | [diff] [blame] | 299 | kbinput = parse_kbinput(win); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 300 | |
Benno Schulenberg | b9e83fe | 2016-07-13 17:38:28 +0200 | [diff] [blame] | 301 | #ifdef DEBUG |
| 302 | fprintf(stderr, "after parsing: kbinput = %d, meta_key = %s\n", |
| 303 | kbinput, meta_key ? "TRUE" : "FALSE"); |
| 304 | #endif |
| 305 | |
Benno Schulenberg | ddd9c7a | 2016-06-24 22:45:41 +0200 | [diff] [blame] | 306 | /* If we read from the edit window, blank the statusbar if needed. */ |
David Lawrence Ramsey | 6b49e9e | 2006-05-22 01:29:30 +0000 | [diff] [blame] | 307 | if (win == edit) |
David Lawrence Ramsey | ce86236 | 2006-05-21 21:23:21 +0000 | [diff] [blame] | 308 | check_statusblank(); |
| 309 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 310 | return kbinput; |
| 311 | } |
| 312 | |
Benno Schulenberg | ddd9c7a | 2016-06-24 22:45:41 +0200 | [diff] [blame] | 313 | /* Extract a single keystroke from the input stream. Translate escape |
| 314 | * sequences and extended keypad codes into their corresponding values. |
Benno Schulenberg | cb10b2b | 2016-07-13 16:22:56 +0200 | [diff] [blame] | 315 | * Set meta_key to TRUE when appropriate. Supported extended keypad values |
Benno Schulenberg | ddd9c7a | 2016-06-24 22:45:41 +0200 | [diff] [blame] | 316 | * are: [arrow key], Ctrl-[arrow key], Shift-[arrow key], Enter, Backspace, |
| 317 | * the editing keypad (Insert, Delete, Home, End, PageUp, and PageDown), |
| 318 | * the function keys (F1-F16), and the numeric keypad with NumLock off. */ |
Benno Schulenberg | 7e5324d | 2014-06-30 18:04:33 +0000 | [diff] [blame] | 319 | int parse_kbinput(WINDOW *win) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 320 | { |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 321 | static int escapes = 0, byte_digits = 0; |
Mike Scalora | d851ccd | 2016-04-02 12:13:24 +0200 | [diff] [blame] | 322 | static bool double_esc = FALSE; |
Benno Schulenberg | 19dfd20 | 2016-07-13 12:09:49 +0200 | [diff] [blame] | 323 | int *kbinput, keycode, retval = ERR; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 324 | |
Benno Schulenberg | 7e5324d | 2014-06-30 18:04:33 +0000 | [diff] [blame] | 325 | meta_key = FALSE; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 326 | shift_held = FALSE; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 327 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 328 | /* Read in a character. */ |
Benno Schulenberg | a101b30 | 2016-04-16 11:57:05 +0200 | [diff] [blame] | 329 | kbinput = get_input(win, 1); |
| 330 | |
| 331 | if (kbinput == NULL && nodelay_mode) |
| 332 | return 0; |
| 333 | |
| 334 | while (kbinput == NULL) |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 335 | kbinput = get_input(win, 1); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 336 | |
Benno Schulenberg | 19dfd20 | 2016-07-13 12:09:49 +0200 | [diff] [blame] | 337 | keycode = *kbinput; |
| 338 | free(kbinput); |
| 339 | |
Benno Schulenberg | b9e83fe | 2016-07-13 17:38:28 +0200 | [diff] [blame] | 340 | #ifdef DEBUG |
| 341 | fprintf(stderr, "before parsing: keycode = %d, escapes = %d, byte_digits = %d\n", |
| 342 | keycode, escapes, byte_digits); |
| 343 | #endif |
| 344 | |
Benno Schulenberg | 1af1f5c | 2016-07-13 18:08:44 +0200 | [diff] [blame] | 345 | if (keycode == ERR) |
| 346 | return ERR; |
| 347 | |
Benno Schulenberg | 90a9036 | 2016-08-01 12:56:05 +0200 | [diff] [blame] | 348 | if (keycode == ESC_CODE) { |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 349 | /* Increment the escape counter, but trim an overabundance. */ |
| 350 | escapes++; |
| 351 | if (escapes > 3) |
| 352 | escapes = 1; |
| 353 | /* Take note when an Esc arrived by itself. */ |
| 354 | solitary = (escapes == 1 && key_buffer_len == 0); |
| 355 | return ERR; |
Benno Schulenberg | 1af1f5c | 2016-07-13 18:08:44 +0200 | [diff] [blame] | 356 | } |
| 357 | |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 358 | switch (escapes) { |
| 359 | case 0: |
| 360 | /* One non-escape: normal input mode. */ |
| 361 | retval = keycode; |
| 362 | break; |
| 363 | case 1: |
Benno Schulenberg | 8edb096 | 2016-08-06 19:51:52 +0200 | [diff] [blame] | 364 | if (keycode >= 0x80) |
| 365 | retval = keycode; |
| 366 | else if ((keycode != 'O' && keycode != 'o' && keycode != '[') || |
Benno Schulenberg | 90a9036 | 2016-08-01 12:56:05 +0200 | [diff] [blame] | 367 | key_buffer_len == 0 || *key_buffer == ESC_CODE) { |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 368 | /* One escape followed by a single non-escape: |
| 369 | * meta key sequence mode. */ |
| 370 | if (!solitary || (keycode >= 0x20 && keycode < 0x7F)) |
| 371 | meta_key = TRUE; |
| 372 | retval = tolower(keycode); |
| 373 | } else |
| 374 | /* One escape followed by a non-escape, and there |
| 375 | * are more codes waiting: escape sequence mode. */ |
| 376 | retval = parse_escape_sequence(win, keycode); |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 377 | escapes = 0; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 378 | break; |
| 379 | case 2: |
| 380 | if (double_esc) { |
David Lawrence Ramsey | 059c8ef | 2016-11-18 14:14:36 +0100 | [diff] [blame] | 381 | /* An "ESC ESC [ X" sequence from Option+arrow, or |
| 382 | * an "ESC ESC [ x" sequence from Shift+Alt+arrow. */ |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 383 | switch (keycode) { |
| 384 | case 'A': |
| 385 | retval = KEY_HOME; |
| 386 | break; |
| 387 | case 'B': |
| 388 | retval = KEY_END; |
| 389 | break; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 390 | case 'C': |
Benno Schulenberg | 0333b87 | 2016-11-23 20:45:45 +0100 | [diff] [blame] | 391 | retval = CONTROL_RIGHT; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 392 | break; |
| 393 | case 'D': |
Benno Schulenberg | 0333b87 | 2016-11-23 20:45:45 +0100 | [diff] [blame] | 394 | retval = CONTROL_LEFT; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 395 | break; |
Benno Schulenberg | 7401670 | 2016-11-30 11:05:07 +0100 | [diff] [blame] | 396 | #ifndef NANO_TINY |
David Lawrence Ramsey | 059c8ef | 2016-11-18 14:14:36 +0100 | [diff] [blame] | 397 | case 'a': |
| 398 | retval = shiftaltup; |
| 399 | break; |
| 400 | case 'b': |
| 401 | retval = shiftaltdown; |
| 402 | break; |
| 403 | case 'c': |
| 404 | retval = shiftaltright; |
| 405 | break; |
| 406 | case 'd': |
| 407 | retval = shiftaltleft; |
| 408 | break; |
Benno Schulenberg | 7401670 | 2016-11-30 11:05:07 +0100 | [diff] [blame] | 409 | #endif |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 410 | } |
| 411 | double_esc = FALSE; |
| 412 | escapes = 0; |
Benno Schulenberg | f33d8ca | 2016-07-15 21:53:46 +0200 | [diff] [blame] | 413 | } else if (key_buffer_len == 0) { |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 414 | if (('0' <= keycode && keycode <= '2' && |
| 415 | byte_digits == 0) || ('0' <= keycode && |
| 416 | keycode <= '9' && byte_digits > 0)) { |
| 417 | /* Two escapes followed by one or more decimal |
| 418 | * digits, and there aren't any other codes |
| 419 | * waiting: byte sequence mode. If the range |
| 420 | * of the byte sequence is limited to 2XX (the |
| 421 | * first digit is between '0' and '2' and the |
| 422 | * others between '0' and '9', interpret it. */ |
| 423 | int byte; |
| 424 | |
| 425 | byte_digits++; |
| 426 | byte = get_byte_kbinput(keycode); |
| 427 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 428 | /* If the decimal byte value is complete, convert it and |
| 429 | * put the obtained byte(s) back into the input buffer. */ |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 430 | if (byte != ERR) { |
| 431 | char *byte_mb; |
| 432 | int byte_mb_len, *seq, i; |
| 433 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 434 | /* Convert the decimal code to one or two bytes. */ |
| 435 | byte_mb = make_mbchar((long)byte, &byte_mb_len); |
David Lawrence Ramsey | 95a0224 | 2004-12-06 04:14:42 +0000 | [diff] [blame] | 436 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 437 | seq = (int *)nmalloc(byte_mb_len * sizeof(int)); |
David Lawrence Ramsey | ce9d299 | 2005-06-14 23:38:08 +0000 | [diff] [blame] | 438 | |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 439 | for (i = 0; i < byte_mb_len; i++) |
| 440 | seq[i] = (unsigned char)byte_mb[i]; |
David Lawrence Ramsey | a44ca78 | 2006-07-23 16:00:03 +0000 | [diff] [blame] | 441 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 442 | /* Insert the byte(s) into the input buffer. */ |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 443 | unget_input(seq, byte_mb_len); |
David Lawrence Ramsey | a44ca78 | 2006-07-23 16:00:03 +0000 | [diff] [blame] | 444 | |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 445 | free(byte_mb); |
| 446 | free(seq); |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 447 | |
| 448 | byte_digits = 0; |
| 449 | escapes = 0; |
David Lawrence Ramsey | 2888964 | 2006-05-30 20:51:15 +0000 | [diff] [blame] | 450 | } |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 451 | } else { |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 452 | if (byte_digits == 0) |
| 453 | /* Two escapes followed by a non-decimal |
| 454 | * digit (or a decimal digit that would |
| 455 | * create a byte sequence greater than 2XX) |
| 456 | * and there aren't any other codes waiting: |
| 457 | * control character sequence mode. */ |
| 458 | retval = get_control_kbinput(keycode); |
| 459 | else { |
| 460 | /* An invalid digit in the middle of a byte |
| 461 | * sequence: reset the byte sequence counter |
| 462 | * and save the code we got as the result. */ |
| 463 | byte_digits = 0; |
Benno Schulenberg | 19dfd20 | 2016-07-13 12:09:49 +0200 | [diff] [blame] | 464 | retval = keycode; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 465 | } |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 466 | escapes = 0; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 467 | } |
| 468 | } else if (keycode == '[' && key_buffer_len > 0 && |
David Lawrence Ramsey | 059c8ef | 2016-11-18 14:14:36 +0100 | [diff] [blame] | 469 | (('A' <= *key_buffer && *key_buffer <= 'D') || |
| 470 | ('a' <= *key_buffer && *key_buffer <= 'd'))) { |
| 471 | /* An iTerm2/Eterm/rxvt sequence: ^[ ^[ [ X. */ |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 472 | double_esc = TRUE; |
| 473 | } else { |
| 474 | /* Two escapes followed by a non-escape, and there are more |
| 475 | * codes waiting: combined meta and escape sequence mode. */ |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 476 | retval = parse_escape_sequence(win, keycode); |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 477 | meta_key = TRUE; |
| 478 | escapes = 0; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 479 | } |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 480 | break; |
| 481 | case 3: |
Benno Schulenberg | f33d8ca | 2016-07-15 21:53:46 +0200 | [diff] [blame] | 482 | if (key_buffer_len == 0) |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 483 | /* Three escapes followed by a non-escape, and no |
| 484 | * other codes are waiting: normal input mode. */ |
| 485 | retval = keycode; |
| 486 | else |
| 487 | /* Three escapes followed by a non-escape, and more |
| 488 | * codes are waiting: combined control character and |
| 489 | * escape sequence mode. First interpret the escape |
| 490 | * sequence, then the result as a control sequence. */ |
| 491 | retval = get_control_kbinput( |
| 492 | parse_escape_sequence(win, keycode)); |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 493 | escapes = 0; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 494 | break; |
| 495 | } |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 496 | |
Benno Schulenberg | 1af1f5c | 2016-07-13 18:08:44 +0200 | [diff] [blame] | 497 | if (retval == ERR) |
| 498 | return ERR; |
| 499 | |
Benno Schulenberg | e471e2d | 2016-07-31 18:29:57 +0200 | [diff] [blame] | 500 | if (retval == controlleft) |
Benno Schulenberg | fdee0df | 2016-10-11 10:50:04 +0200 | [diff] [blame] | 501 | return CONTROL_LEFT; |
Benno Schulenberg | e471e2d | 2016-07-31 18:29:57 +0200 | [diff] [blame] | 502 | else if (retval == controlright) |
Benno Schulenberg | fdee0df | 2016-10-11 10:50:04 +0200 | [diff] [blame] | 503 | return CONTROL_RIGHT; |
Benno Schulenberg | e471e2d | 2016-07-31 18:29:57 +0200 | [diff] [blame] | 504 | else if (retval == controlup) |
Benno Schulenberg | fdee0df | 2016-10-11 10:50:04 +0200 | [diff] [blame] | 505 | return CONTROL_UP; |
Benno Schulenberg | e471e2d | 2016-07-31 18:29:57 +0200 | [diff] [blame] | 506 | else if (retval == controldown) |
Benno Schulenberg | fdee0df | 2016-10-11 10:50:04 +0200 | [diff] [blame] | 507 | return CONTROL_DOWN; |
Benno Schulenberg | 08cd197 | 2016-09-08 21:00:51 +0200 | [diff] [blame] | 508 | #ifndef NANO_TINY |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 509 | else if (retval == shiftcontrolleft) { |
| 510 | shift_held = TRUE; |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 511 | return CONTROL_LEFT; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 512 | } else if (retval == shiftcontrolright) { |
| 513 | shift_held = TRUE; |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 514 | return CONTROL_RIGHT; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 515 | } else if (retval == shiftcontrolup) { |
| 516 | shift_held = TRUE; |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 517 | return CONTROL_UP; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 518 | } else if (retval == shiftcontroldown) { |
| 519 | shift_held = TRUE; |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 520 | return CONTROL_DOWN; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 521 | } else if (retval == shiftaltleft) { |
| 522 | shift_held = TRUE; |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 523 | return KEY_HOME; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 524 | } else if (retval == shiftaltright) { |
| 525 | shift_held = TRUE; |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 526 | return KEY_END; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 527 | } else if (retval == shiftaltup) { |
| 528 | shift_held = TRUE; |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 529 | return KEY_PPAGE; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 530 | } else if (retval == shiftaltdown) { |
| 531 | shift_held = TRUE; |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 532 | return KEY_NPAGE; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 533 | } |
Benno Schulenberg | e471e2d | 2016-07-31 18:29:57 +0200 | [diff] [blame] | 534 | #endif |
| 535 | |
Benno Schulenberg | 08cd197 | 2016-09-08 21:00:51 +0200 | [diff] [blame] | 536 | #ifdef __linux__ |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 537 | /* When not running under X, check for the bare arrow keys whether |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 538 | * Shift/Ctrl/Alt are being held together with them. */ |
| 539 | unsigned char modifiers = 6; |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 540 | |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 541 | if (console && ioctl(0, TIOCLINUX, &modifiers) >= 0) { |
Benno Schulenberg | db897b5 | 2016-12-22 10:42:49 +0100 | [diff] [blame] | 542 | #ifndef NANO_TINY |
| 543 | /* Is Shift being held? */ |
| 544 | if (modifiers & 0x01) |
| 545 | shift_held = TRUE; |
| 546 | #endif |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 547 | /* Is Ctrl being held? */ |
| 548 | if (modifiers & 0x04) { |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 549 | if (retval == KEY_UP) |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 550 | return CONTROL_UP; |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 551 | else if (retval == KEY_DOWN) |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 552 | return CONTROL_DOWN; |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 553 | else if (retval == KEY_LEFT) |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 554 | return CONTROL_LEFT; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 555 | else if (retval == KEY_RIGHT) |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 556 | return CONTROL_RIGHT; |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 557 | } |
Benno Schulenberg | 08cd197 | 2016-09-08 21:00:51 +0200 | [diff] [blame] | 558 | #ifndef NANO_TINY |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 559 | /* Are both Shift and Alt being held? */ |
| 560 | if ((modifiers & 0x09) == 0x09) { |
| 561 | if (retval == KEY_UP) |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 562 | return KEY_PPAGE; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 563 | else if (retval == KEY_DOWN) |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 564 | return KEY_NPAGE; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 565 | else if (retval == KEY_LEFT) |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 566 | return KEY_HOME; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 567 | else if (retval == KEY_RIGHT) |
Benno Schulenberg | 026393a | 2016-12-22 11:42:13 +0100 | [diff] [blame] | 568 | return KEY_END; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 569 | } |
Benno Schulenberg | 08cd197 | 2016-09-08 21:00:51 +0200 | [diff] [blame] | 570 | #endif |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 571 | } |
Benno Schulenberg | 08cd197 | 2016-09-08 21:00:51 +0200 | [diff] [blame] | 572 | #endif /* __linux__ */ |
Benno Schulenberg | 290d278 | 2016-07-29 09:15:07 +0200 | [diff] [blame] | 573 | |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 574 | switch (retval) { |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 575 | #ifdef KEY_SLEFT |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 576 | /* Slang doesn't support KEY_SLEFT. */ |
| 577 | case KEY_SLEFT: |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 578 | shift_held = TRUE; |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 579 | return KEY_LEFT; |
Benno Schulenberg | b472f5a | 2016-07-11 16:22:30 +0200 | [diff] [blame] | 580 | #endif |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 581 | #ifdef KEY_SRIGHT |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 582 | /* Slang doesn't support KEY_SRIGHT. */ |
| 583 | case KEY_SRIGHT: |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 584 | shift_held = TRUE; |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 585 | return KEY_RIGHT; |
Benno Schulenberg | b472f5a | 2016-07-11 16:22:30 +0200 | [diff] [blame] | 586 | #endif |
Benno Schulenberg | 272a953 | 2016-08-30 10:11:29 +0200 | [diff] [blame] | 587 | #ifdef KEY_SR |
Benno Schulenberg | 0c319f8 | 2016-07-10 20:49:52 +0200 | [diff] [blame] | 588 | #ifdef KEY_SUP |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 589 | /* ncurses and Slang don't support KEY_SUP. */ |
| 590 | case KEY_SUP: |
Benno Schulenberg | b472f5a | 2016-07-11 16:22:30 +0200 | [diff] [blame] | 591 | #endif |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 592 | case KEY_SR: /* Scroll backward, on Xfce4-terminal. */ |
| 593 | shift_held = TRUE; |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 594 | return KEY_UP; |
Benno Schulenberg | 272a953 | 2016-08-30 10:11:29 +0200 | [diff] [blame] | 595 | #endif |
| 596 | #ifdef KEY_SF |
Benno Schulenberg | 0c319f8 | 2016-07-10 20:49:52 +0200 | [diff] [blame] | 597 | #ifdef KEY_SDOWN |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 598 | /* ncurses and Slang don't support KEY_SDOWN. */ |
| 599 | case KEY_SDOWN: |
Benno Schulenberg | b472f5a | 2016-07-11 16:22:30 +0200 | [diff] [blame] | 600 | #endif |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 601 | case KEY_SF: /* Scroll forward, on Xfce4-terminal. */ |
| 602 | shift_held = TRUE; |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 603 | return KEY_DOWN; |
Benno Schulenberg | 272a953 | 2016-08-30 10:11:29 +0200 | [diff] [blame] | 604 | #endif |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 605 | #ifdef KEY_SHOME |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 606 | /* HP-UX 10-11 and Slang don't support KEY_SHOME. */ |
| 607 | case KEY_SHOME: |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 608 | #endif |
Benno Schulenberg | 272a953 | 2016-08-30 10:11:29 +0200 | [diff] [blame] | 609 | case SHIFT_HOME: |
| 610 | shift_held = TRUE; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 611 | case KEY_A1: /* Home (7) on keypad with NumLock off. */ |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 612 | return KEY_HOME; |
Benno Schulenberg | 0c319f8 | 2016-07-10 20:49:52 +0200 | [diff] [blame] | 613 | #ifdef KEY_SEND |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 614 | /* HP-UX 10-11 and Slang don't support KEY_SEND. */ |
| 615 | case KEY_SEND: |
Benno Schulenberg | 0c319f8 | 2016-07-10 20:49:52 +0200 | [diff] [blame] | 616 | #endif |
Benno Schulenberg | 272a953 | 2016-08-30 10:11:29 +0200 | [diff] [blame] | 617 | case SHIFT_END: |
| 618 | shift_held = TRUE; |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 619 | case KEY_C1: /* End (1) on keypad with NumLock off. */ |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 620 | return KEY_END; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 621 | #ifndef NANO_TINY |
Benno Schulenberg | c9680b8 | 2016-12-01 16:51:40 +0100 | [diff] [blame] | 622 | #ifdef KEY_SPREVIOUS |
| 623 | case KEY_SPREVIOUS: |
| 624 | #endif |
| 625 | case SHIFT_PAGEUP: /* Fake key, from Shift+Alt+Up. */ |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 626 | shift_held = TRUE; |
| 627 | #endif |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 628 | case KEY_A3: /* PageUp (9) on keypad with NumLock off. */ |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 629 | return KEY_PPAGE; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 630 | #ifndef NANO_TINY |
Benno Schulenberg | c9680b8 | 2016-12-01 16:51:40 +0100 | [diff] [blame] | 631 | #ifdef KEY_SNEXT |
| 632 | case KEY_SNEXT: |
| 633 | #endif |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 634 | case SHIFT_PAGEDOWN: /* Fake key, from Shift+Alt+Down. */ |
| 635 | shift_held = TRUE; |
| 636 | #endif |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 637 | case KEY_C3: /* PageDown (3) on keypad with NumLock off. */ |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 638 | return KEY_NPAGE; |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 639 | #ifdef KEY_SDC |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 640 | /* Slang doesn't support KEY_SDC. */ |
| 641 | case KEY_SDC: |
Benno Schulenberg | d2b2512 | 2016-07-10 21:36:25 +0200 | [diff] [blame] | 642 | #endif |
Benno Schulenberg | 90a9036 | 2016-08-01 12:56:05 +0200 | [diff] [blame] | 643 | case DEL_CODE: |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 644 | if (ISSET(REBIND_DELETE)) |
Benno Schulenberg | a9b5a0e | 2016-12-22 12:02:11 +0100 | [diff] [blame] | 645 | return the_code_for(do_delete, KEY_DC); |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 646 | else |
Benno Schulenberg | acd8809 | 2016-09-01 09:46:50 +0200 | [diff] [blame] | 647 | return KEY_BACKSPACE; |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 648 | #ifdef KEY_SIC |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 649 | /* Slang doesn't support KEY_SIC. */ |
| 650 | case KEY_SIC: |
Benno Schulenberg | a9b5a0e | 2016-12-22 12:02:11 +0100 | [diff] [blame] | 651 | return the_code_for(do_insertfile_void, KEY_IC); |
Chris Allegretta | 17436ce | 2008-03-11 03:03:53 +0000 | [diff] [blame] | 652 | #endif |
Benno Schulenberg | 4fcc760 | 2016-07-10 20:01:23 +0200 | [diff] [blame] | 653 | #ifdef KEY_SBEG |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 654 | /* Slang doesn't support KEY_SBEG. */ |
| 655 | case KEY_SBEG: |
Benno Schulenberg | 4fcc760 | 2016-07-10 20:01:23 +0200 | [diff] [blame] | 656 | #endif |
David Lawrence Ramsey | 19f3bd6 | 2006-07-23 17:25:38 +0000 | [diff] [blame] | 657 | #ifdef KEY_BEG |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 658 | /* Slang doesn't support KEY_BEG. */ |
| 659 | case KEY_BEG: |
Benno Schulenberg | 4fcc760 | 2016-07-10 20:01:23 +0200 | [diff] [blame] | 660 | #endif |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 661 | case KEY_B2: /* Center (5) on keypad with NumLock off. */ |
| 662 | return ERR; |
David Lawrence Ramsey | 6a8b350 | 2007-04-18 14:06:34 +0000 | [diff] [blame] | 663 | #ifdef KEY_CANCEL |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 664 | #ifdef KEY_SCANCEL |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 665 | /* Slang doesn't support KEY_SCANCEL. */ |
| 666 | case KEY_SCANCEL: |
David Lawrence Ramsey | 6a8b350 | 2007-04-18 14:06:34 +0000 | [diff] [blame] | 667 | #endif |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 668 | /* Slang doesn't support KEY_CANCEL. */ |
| 669 | case KEY_CANCEL: |
Benno Schulenberg | a9b5a0e | 2016-12-22 12:02:11 +0100 | [diff] [blame] | 670 | return the_code_for(do_cancel, 0x03); |
David Lawrence Ramsey | 19f3bd6 | 2006-07-23 17:25:38 +0000 | [diff] [blame] | 671 | #endif |
Benno Schulenberg | 4fcc760 | 2016-07-10 20:01:23 +0200 | [diff] [blame] | 672 | #ifdef KEY_SUSPEND |
David Lawrence Ramsey | 19f3bd6 | 2006-07-23 17:25:38 +0000 | [diff] [blame] | 673 | #ifdef KEY_SSUSPEND |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 674 | /* Slang doesn't support KEY_SSUSPEND. */ |
| 675 | case KEY_SSUSPEND: |
David Lawrence Ramsey | 19f3bd6 | 2006-07-23 17:25:38 +0000 | [diff] [blame] | 676 | #endif |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 677 | /* Slang doesn't support KEY_SUSPEND. */ |
| 678 | case KEY_SUSPEND: |
Benno Schulenberg | a9b5a0e | 2016-12-22 12:02:11 +0100 | [diff] [blame] | 679 | return the_code_for(do_suspend_void, KEY_SUSPEND); |
David Lawrence Ramsey | 19f3bd6 | 2006-07-23 17:25:38 +0000 | [diff] [blame] | 680 | #endif |
| 681 | #ifdef PDCURSES |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 682 | case KEY_SHIFT_L: |
| 683 | case KEY_SHIFT_R: |
| 684 | case KEY_CONTROL_L: |
| 685 | case KEY_CONTROL_R: |
| 686 | case KEY_ALT_L: |
| 687 | case KEY_ALT_R: |
| 688 | return ERR; |
David Lawrence Ramsey | 19f3bd6 | 2006-07-23 17:25:38 +0000 | [diff] [blame] | 689 | #endif |
Benno Schulenberg | ad83ed2 | 2016-09-06 12:05:22 +0200 | [diff] [blame] | 690 | #ifdef KEY_RESIZE |
| 691 | /* Slang and SunOS 5.7-5.9 don't support KEY_RESIZE. */ |
Benno Schulenberg | fe38b78 | 2016-07-13 18:26:45 +0200 | [diff] [blame] | 692 | case KEY_RESIZE: |
| 693 | return ERR; |
David Lawrence Ramsey | 19f3bd6 | 2006-07-23 17:25:38 +0000 | [diff] [blame] | 694 | #endif |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 695 | } |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 696 | |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 697 | return retval; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 698 | } |
| 699 | |
David Lawrence Ramsey | 58f6d83 | 2004-01-27 07:12:47 +0000 | [diff] [blame] | 700 | /* Translate escape sequences, most of which correspond to extended |
David Lawrence Ramsey | 832db76 | 2004-11-27 23:28:39 +0000 | [diff] [blame] | 701 | * keypad values, into their corresponding key values. These sequences |
David Lawrence Ramsey | 1b4ae69 | 2006-07-25 19:23:35 +0000 | [diff] [blame] | 702 | * are generated when the keypad doesn't support the needed keys. |
| 703 | * Assume that Escape has already been read in. */ |
Benno Schulenberg | 46082bd | 2015-12-22 19:00:25 +0000 | [diff] [blame] | 704 | int convert_sequence(const int *seq, size_t seq_len) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 705 | { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 706 | if (seq_len > 1) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 707 | switch (seq[0]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 708 | case 'O': |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 709 | switch (seq[1]) { |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 710 | case '1': |
Benno Schulenberg | 6d6f5bd | 2016-07-28 21:27:45 +0200 | [diff] [blame] | 711 | if (seq_len > 4 && seq[2] == ';') { |
| 712 | |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 713 | switch (seq[3]) { |
| 714 | case '2': |
Benno Schulenberg | ecef093 | 2016-07-28 21:35:42 +0200 | [diff] [blame] | 715 | switch (seq[4]) { |
| 716 | case 'A': /* Esc O 1 ; 2 A == Shift-Up on Terminal. */ |
| 717 | case 'B': /* Esc O 1 ; 2 B == Shift-Down on Terminal. */ |
| 718 | case 'C': /* Esc O 1 ; 2 C == Shift-Right on Terminal. */ |
| 719 | case 'D': /* Esc O 1 ; 2 D == Shift-Left on Terminal. */ |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 720 | shift_held = TRUE; |
Benno Schulenberg | ecef093 | 2016-07-28 21:35:42 +0200 | [diff] [blame] | 721 | return arrow_from_abcd(seq[4]); |
| 722 | case 'P': /* Esc O 1 ; 2 P == F13 on Terminal. */ |
| 723 | return KEY_F(13); |
| 724 | case 'Q': /* Esc O 1 ; 2 Q == F14 on Terminal. */ |
| 725 | return KEY_F(14); |
| 726 | case 'R': /* Esc O 1 ; 2 R == F15 on Terminal. */ |
| 727 | return KEY_F(15); |
| 728 | case 'S': /* Esc O 1 ; 2 S == F16 on Terminal. */ |
| 729 | return KEY_F(16); |
| 730 | } |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 731 | break; |
| 732 | case '5': |
Benno Schulenberg | ecef093 | 2016-07-28 21:35:42 +0200 | [diff] [blame] | 733 | switch (seq[4]) { |
| 734 | case 'A': /* Esc O 1 ; 5 A == Ctrl-Up on Terminal. */ |
| 735 | return CONTROL_UP; |
| 736 | case 'B': /* Esc O 1 ; 5 B == Ctrl-Down on Terminal. */ |
| 737 | return CONTROL_DOWN; |
| 738 | case 'C': /* Esc O 1 ; 5 C == Ctrl-Right on Terminal. */ |
| 739 | return CONTROL_RIGHT; |
| 740 | case 'D': /* Esc O 1 ; 5 D == Ctrl-Left on Terminal. */ |
| 741 | return CONTROL_LEFT; |
| 742 | } |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 743 | break; |
| 744 | } |
Benno Schulenberg | 6d6f5bd | 2016-07-28 21:27:45 +0200 | [diff] [blame] | 745 | |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 746 | } |
| 747 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 748 | case '2': |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 749 | if (seq_len >= 3) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 750 | switch (seq[2]) { |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 751 | case 'P': /* Esc O 2 P == F13 on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 752 | return KEY_F(13); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 753 | case 'Q': /* Esc O 2 Q == F14 on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 754 | return KEY_F(14); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 755 | case 'R': /* Esc O 2 R == F15 on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 756 | return KEY_F(15); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 757 | case 'S': /* Esc O 2 S == F16 on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 758 | return KEY_F(16); |
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. */ |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 763 | case 'B': /* Esc O B == Down on VT100/VT320/xterm. */ |
| 764 | case 'C': /* Esc O C == Right on VT100/VT320/xterm. */ |
| 765 | case 'D': /* Esc O D == Left on VT100/VT320/xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 766 | return arrow_from_abcd(seq[1]); |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 767 | case 'E': /* Esc O E == Center (5) on numeric keypad |
| 768 | * with NumLock off on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 769 | return KEY_B2; |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 770 | case 'F': /* Esc O F == End on xterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 771 | return KEY_END; |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 772 | case 'H': /* Esc O H == Home on xterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 773 | return KEY_HOME; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 774 | case 'M': /* Esc O M == Enter on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 775 | * NumLock off on VT100/VT220/VT320/xterm/ |
David Lawrence Ramsey | 2888964 | 2006-05-30 20:51:15 +0000 | [diff] [blame] | 776 | * rxvt/Eterm. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 777 | return KEY_ENTER; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 778 | case 'P': /* Esc O P == F1 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 779 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 780 | return KEY_F(1); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 781 | case 'Q': /* Esc O Q == F2 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 782 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 783 | return KEY_F(2); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 784 | case 'R': /* Esc O R == F3 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 785 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 786 | return KEY_F(3); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 787 | case 'S': /* Esc O S == F4 on VT100/VT220/VT320/Mach |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 788 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 789 | return KEY_F(4); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 790 | case 'T': /* Esc O T == F5 on Mach console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 791 | return KEY_F(5); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 792 | case 'U': /* Esc O U == F6 on Mach console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 793 | return KEY_F(6); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 794 | case 'V': /* Esc O V == F7 on Mach console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 795 | return KEY_F(7); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 796 | case 'W': /* Esc O W == F8 on Mach console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 797 | return KEY_F(8); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 798 | case 'X': /* Esc O X == F9 on Mach console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 799 | return KEY_F(9); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 800 | case 'Y': /* Esc O Y == F10 on Mach console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 801 | return KEY_F(10); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 802 | case 'a': /* Esc O a == Ctrl-Up on rxvt. */ |
Benno Schulenberg | c6dbcf9 | 2016-06-25 15:16:52 +0200 | [diff] [blame] | 803 | return CONTROL_UP; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 804 | case 'b': /* Esc O b == Ctrl-Down on rxvt. */ |
Benno Schulenberg | c6dbcf9 | 2016-06-25 15:16:52 +0200 | [diff] [blame] | 805 | return CONTROL_DOWN; |
Benno Schulenberg | 09dd0a4 | 2014-06-29 20:53:00 +0000 | [diff] [blame] | 806 | case 'c': /* Esc O c == Ctrl-Right on rxvt. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 807 | return CONTROL_RIGHT; |
Benno Schulenberg | 09dd0a4 | 2014-06-29 20:53:00 +0000 | [diff] [blame] | 808 | case 'd': /* Esc O d == Ctrl-Left on rxvt. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 809 | return CONTROL_LEFT; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 810 | case 'j': /* Esc O j == '*' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 811 | * NumLock off on VT100/VT220/VT320/xterm/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 812 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 813 | return '*'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 814 | case 'k': /* Esc O k == '+' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 815 | * NumLock off on VT100/VT220/VT320/xterm/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 816 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 817 | return '+'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 818 | case 'l': /* Esc O l == ',' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 819 | * NumLock off on VT100/VT220/VT320/xterm/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 820 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 821 | return ','; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 822 | case 'm': /* Esc O m == '-' on numeric keypad with |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 823 | * NumLock off on VT100/VT220/VT320/xterm/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 824 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 825 | return '-'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 826 | case 'n': /* Esc O n == Delete (.) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 827 | * with NumLock off on VT100/VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 828 | * xterm/rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 829 | return KEY_DC; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 830 | case 'o': /* Esc O o == '/' 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. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 833 | return '/'; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 834 | case 'p': /* Esc O p == Insert (0) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 835 | * with NumLock off on VT100/VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 836 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 837 | return KEY_IC; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 838 | case 'q': /* Esc O q == End (1) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 839 | * with NumLock off on VT100/VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 840 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 841 | return KEY_END; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 842 | case 'r': /* Esc O r == Down (2) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 843 | * with NumLock off on VT100/VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 844 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 845 | return KEY_DOWN; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 846 | case 's': /* Esc O s == PageDown (3) on numeric |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 847 | * keypad with NumLock off on VT100/VT220/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 848 | * VT320/rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 849 | return KEY_NPAGE; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 850 | case 't': /* Esc O t == Left (4) 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 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 853 | return KEY_LEFT; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 854 | case 'u': /* Esc O u == Center (5) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 855 | * with NumLock off on VT100/VT220/VT320/ |
| 856 | * rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 857 | return KEY_B2; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 858 | case 'v': /* Esc O v == Right (6) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 859 | * with NumLock off on VT100/VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 860 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 861 | return KEY_RIGHT; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 862 | case 'w': /* Esc O w == Home (7) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 863 | * with NumLock off on VT100/VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 864 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 865 | return KEY_HOME; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 866 | case 'x': /* Esc O x == Up (8) on numeric keypad |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 867 | * with NumLock off on VT100/VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 868 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 869 | return KEY_UP; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 870 | case 'y': /* Esc O y == PageUp (9) 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 | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 873 | return KEY_PPAGE; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 874 | } |
| 875 | break; |
| 876 | case 'o': |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 877 | switch (seq[1]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 878 | case 'a': /* Esc o a == Ctrl-Up on Eterm. */ |
Benno Schulenberg | c6dbcf9 | 2016-06-25 15:16:52 +0200 | [diff] [blame] | 879 | return CONTROL_UP; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 880 | case 'b': /* Esc o b == Ctrl-Down on Eterm. */ |
Benno Schulenberg | c6dbcf9 | 2016-06-25 15:16:52 +0200 | [diff] [blame] | 881 | return CONTROL_DOWN; |
Benno Schulenberg | 09dd0a4 | 2014-06-29 20:53:00 +0000 | [diff] [blame] | 882 | case 'c': /* Esc o c == Ctrl-Right on Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 883 | return CONTROL_RIGHT; |
Benno Schulenberg | 09dd0a4 | 2014-06-29 20:53:00 +0000 | [diff] [blame] | 884 | case 'd': /* Esc o d == Ctrl-Left on Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 885 | return CONTROL_LEFT; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 886 | } |
| 887 | break; |
| 888 | case '[': |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 889 | switch (seq[1]) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 890 | case '1': |
Benno Schulenberg | e3dbffc | 2016-07-28 21:12:18 +0200 | [diff] [blame] | 891 | if (seq_len > 3 && seq[3] == '~') { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 892 | switch (seq[2]) { |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 893 | case '1': /* Esc [ 1 1 ~ == F1 on rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 894 | return KEY_F(1); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 895 | case '2': /* Esc [ 1 2 ~ == F2 on rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 896 | return KEY_F(2); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 897 | case '3': /* Esc [ 1 3 ~ == F3 on rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 898 | return KEY_F(3); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 899 | case '4': /* Esc [ 1 4 ~ == F4 on rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 900 | return KEY_F(4); |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 901 | case '5': /* Esc [ 1 5 ~ == F5 on xterm/ |
| 902 | * rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 903 | return KEY_F(5); |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 904 | case '7': /* Esc [ 1 7 ~ == F6 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 905 | * VT220/VT320/Linux console/ |
| 906 | * xterm/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 907 | return KEY_F(6); |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 908 | case '8': /* Esc [ 1 8 ~ == F7 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 909 | * VT220/VT320/Linux console/ |
| 910 | * xterm/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 911 | return KEY_F(7); |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 912 | case '9': /* Esc [ 1 9 ~ == F8 on |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 913 | * VT220/VT320/Linux console/ |
| 914 | * xterm/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 915 | return KEY_F(8); |
Benno Schulenberg | e3dbffc | 2016-07-28 21:12:18 +0200 | [diff] [blame] | 916 | } |
| 917 | } else if (seq_len > 4 && seq[2] == ';') { |
| 918 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 919 | switch (seq[3]) { |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 920 | case '2': |
Benno Schulenberg | ecef093 | 2016-07-28 21:35:42 +0200 | [diff] [blame] | 921 | switch (seq[4]) { |
| 922 | case 'A': /* Esc [ 1 ; 2 A == Shift-Up on xterm. */ |
| 923 | case 'B': /* Esc [ 1 ; 2 B == Shift-Down on xterm. */ |
| 924 | case 'C': /* Esc [ 1 ; 2 C == Shift-Right on xterm. */ |
| 925 | case 'D': /* Esc [ 1 ; 2 D == Shift-Left on xterm. */ |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 926 | shift_held = TRUE; |
Benno Schulenberg | ecef093 | 2016-07-28 21:35:42 +0200 | [diff] [blame] | 927 | return arrow_from_abcd(seq[4]); |
| 928 | } |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 929 | break; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 930 | #ifndef NANO_TINY |
| 931 | case '4': |
| 932 | /* When the arrow keys are held together with Shift+Meta, |
| 933 | * act as if they are Home/End/PgUp/PgDown with Shift. */ |
| 934 | switch (seq[4]) { |
| 935 | case 'A': /* Esc [ 1 ; 4 A == Shift-Alt-Up on xterm. */ |
| 936 | return SHIFT_PAGEUP; |
| 937 | case 'B': /* Esc [ 1 ; 4 B == Shift-Alt-Down on xterm. */ |
| 938 | return SHIFT_PAGEDOWN; |
| 939 | case 'C': /* Esc [ 1 ; 4 C == Shift-Alt-Right on xterm. */ |
Benno Schulenberg | 272a953 | 2016-08-30 10:11:29 +0200 | [diff] [blame] | 940 | return SHIFT_END; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 941 | case 'D': /* Esc [ 1 ; 4 D == Shift-Alt-Left on xterm. */ |
Benno Schulenberg | 272a953 | 2016-08-30 10:11:29 +0200 | [diff] [blame] | 942 | return SHIFT_HOME; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 943 | } |
| 944 | break; |
| 945 | #endif |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 946 | case '5': |
Benno Schulenberg | ecef093 | 2016-07-28 21:35:42 +0200 | [diff] [blame] | 947 | switch (seq[4]) { |
| 948 | case 'A': /* Esc [ 1 ; 5 A == Ctrl-Up on xterm. */ |
| 949 | return CONTROL_UP; |
| 950 | case 'B': /* Esc [ 1 ; 5 B == Ctrl-Down on xterm. */ |
| 951 | return CONTROL_DOWN; |
| 952 | case 'C': /* Esc [ 1 ; 5 C == Ctrl-Right on xterm. */ |
| 953 | return CONTROL_RIGHT; |
| 954 | case 'D': /* Esc [ 1 ; 5 D == Ctrl-Left on xterm. */ |
| 955 | return CONTROL_LEFT; |
| 956 | } |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 957 | break; |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 958 | #ifndef NANO_TINY |
| 959 | case '6': |
| 960 | switch (seq[4]) { |
| 961 | case 'A': /* Esc [ 1 ; 6 A == Shift-Ctrl-Up on xterm. */ |
| 962 | return shiftcontrolup; |
| 963 | case 'B': /* Esc [ 1 ; 6 B == Shift-Ctrl-Down on xterm. */ |
| 964 | return shiftcontroldown; |
| 965 | case 'C': /* Esc [ 1 ; 6 C == Shift-Ctrl-Right on xterm. */ |
| 966 | return shiftcontrolright; |
| 967 | case 'D': /* Esc [ 1 ; 6 D == Shift-Ctrl-Left on xterm. */ |
| 968 | return shiftcontrolleft; |
| 969 | } |
| 970 | break; |
| 971 | #endif |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 972 | } |
Benno Schulenberg | e3dbffc | 2016-07-28 21:12:18 +0200 | [diff] [blame] | 973 | |
| 974 | } else if (seq_len > 2 && seq[2] == '~') |
| 975 | /* Esc [ 1 ~ == Home on VT320/Linux console. */ |
| 976 | return KEY_HOME; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 977 | break; |
| 978 | case '2': |
Benno Schulenberg | e3dbffc | 2016-07-28 21:12:18 +0200 | [diff] [blame] | 979 | if (seq_len > 3 && seq[3] == '~') { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 980 | switch (seq[2]) { |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 981 | case '0': /* Esc [ 2 0 ~ == F9 on VT220/VT320/ |
| 982 | * Linux console/xterm/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 983 | return KEY_F(9); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 984 | case '1': /* Esc [ 2 1 ~ == F10 on VT220/VT320/ |
| 985 | * Linux console/xterm/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 986 | return KEY_F(10); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 987 | case '3': /* Esc [ 2 3 ~ == F11 on VT220/VT320/ |
| 988 | * Linux console/xterm/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 989 | return KEY_F(11); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 990 | case '4': /* Esc [ 2 4 ~ == F12 on VT220/VT320/ |
| 991 | * Linux console/xterm/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 992 | return KEY_F(12); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 993 | case '5': /* Esc [ 2 5 ~ == F13 on VT220/VT320/ |
| 994 | * Linux console/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 995 | return KEY_F(13); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 996 | case '6': /* Esc [ 2 6 ~ == F14 on VT220/VT320/ |
| 997 | * Linux console/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 998 | return KEY_F(14); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 999 | case '8': /* Esc [ 2 8 ~ == F15 on VT220/VT320/ |
| 1000 | * Linux console/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1001 | return KEY_F(15); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1002 | case '9': /* Esc [ 2 9 ~ == F16 on VT220/VT320/ |
| 1003 | * Linux console/rxvt/Eterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1004 | return KEY_F(16); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1005 | } |
Benno Schulenberg | e3dbffc | 2016-07-28 21:12:18 +0200 | [diff] [blame] | 1006 | } else if (seq_len > 2 && seq[2] == '~') |
| 1007 | /* Esc [ 2 ~ == Insert on VT220/VT320/ |
| 1008 | * Linux console/xterm/Terminal. */ |
| 1009 | return KEY_IC; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1010 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1011 | case '3': /* Esc [ 3 ~ == Delete on VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 1012 | * Linux console/xterm/Terminal. */ |
David Lawrence Ramsey | d48071b | 2016-11-26 13:33:31 -0600 | [diff] [blame] | 1013 | if (seq_len > 2 && seq[2] == '~') |
| 1014 | return KEY_DC; |
| 1015 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1016 | case '4': /* Esc [ 4 ~ == End on VT220/VT320/Linux |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1017 | * console/xterm. */ |
David Lawrence Ramsey | d48071b | 2016-11-26 13:33:31 -0600 | [diff] [blame] | 1018 | if (seq_len > 2 && seq[2] == '~') |
| 1019 | return KEY_END; |
| 1020 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1021 | case '5': /* Esc [ 5 ~ == PageUp on VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 1022 | * Linux console/xterm/Terminal; |
| 1023 | * Esc [ 5 ^ == PageUp on Eterm. */ |
David Lawrence Ramsey | d48071b | 2016-11-26 13:33:31 -0600 | [diff] [blame] | 1024 | if (seq_len > 2 && (seq[2] == '~' || seq[2] == '^')) |
| 1025 | return KEY_PPAGE; |
| 1026 | break; |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1027 | case '6': /* Esc [ 6 ~ == PageDown on VT220/VT320/ |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 1028 | * Linux console/xterm/Terminal; |
Benno Schulenberg | 1de337d | 2014-06-04 16:02:51 +0000 | [diff] [blame] | 1029 | * Esc [ 6 ^ == PageDown on Eterm. */ |
David Lawrence Ramsey | d48071b | 2016-11-26 13:33:31 -0600 | [diff] [blame] | 1030 | if (seq_len > 2 && (seq[2] == '~' || seq[2] == '^')) |
| 1031 | return KEY_NPAGE; |
| 1032 | break; |
Benno Schulenberg | 3cc561e | 2016-11-26 12:25:36 +0100 | [diff] [blame] | 1033 | case '7': /* Esc [ 7 ~ == Home on Eterm/rxvt, |
| 1034 | * Esc [ 7 $ == Shift-Home on Eterm/rxvt. */ |
| 1035 | if (seq_len > 2 && seq[2] == '~') |
| 1036 | return KEY_HOME; |
| 1037 | else if (seq_len > 2 && seq[2] == '$') |
| 1038 | return SHIFT_HOME; |
| 1039 | break; |
| 1040 | case '8': /* Esc [ 8 ~ == End on Eterm/rxvt. |
| 1041 | * Esc [ 8 $ == Shift-End on Eterm/rxvt. */ |
| 1042 | if (seq_len > 2 && seq[2] == '~') |
| 1043 | return KEY_END; |
| 1044 | else if (seq_len > 2 && seq[2] == '$') |
| 1045 | return SHIFT_END; |
| 1046 | break; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1047 | case '9': /* Esc [ 9 == Delete on Mach console. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1048 | return KEY_DC; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1049 | case '@': /* Esc [ @ == Insert on Mach console. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1050 | return KEY_IC; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1051 | case 'A': /* Esc [ A == Up on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1052 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | a31d54e | 2007-04-18 13:48:37 +0000 | [diff] [blame] | 1053 | * rxvt/Eterm/Terminal. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1054 | case 'B': /* Esc [ B == Down on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1055 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | a31d54e | 2007-04-18 13:48:37 +0000 | [diff] [blame] | 1056 | * rxvt/Eterm/Terminal. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1057 | case 'C': /* Esc [ C == Right on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1058 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | a31d54e | 2007-04-18 13:48:37 +0000 | [diff] [blame] | 1059 | * rxvt/Eterm/Terminal. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1060 | case 'D': /* Esc [ D == Left on ANSI/VT220/Linux |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1061 | * console/FreeBSD console/Mach console/ |
David Lawrence Ramsey | a31d54e | 2007-04-18 13:48:37 +0000 | [diff] [blame] | 1062 | * rxvt/Eterm/Terminal. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1063 | return arrow_from_abcd(seq[1]); |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 1064 | case 'E': /* Esc [ E == Center (5) on numeric keypad |
David Lawrence Ramsey | 267daeb | 2007-04-04 20:36:56 +0000 | [diff] [blame] | 1065 | * with NumLock off on FreeBSD console/ |
| 1066 | * Terminal. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1067 | return KEY_B2; |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1068 | case 'F': /* Esc [ F == End on FreeBSD console/Eterm. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1069 | return KEY_END; |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1070 | case 'G': /* Esc [ G == PageDown on FreeBSD console. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1071 | return KEY_NPAGE; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 1072 | case 'H': /* Esc [ H == Home on ANSI/VT220/FreeBSD |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1073 | * console/Mach console/Eterm. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1074 | return KEY_HOME; |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1075 | case 'I': /* Esc [ I == PageUp on FreeBSD console. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1076 | return KEY_PPAGE; |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1077 | case 'L': /* Esc [ L == Insert on ANSI/FreeBSD console. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1078 | return KEY_IC; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1079 | case 'M': /* Esc [ M == F1 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1080 | return KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1081 | case 'N': /* Esc [ N == F2 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1082 | return KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1083 | case 'O': |
Benno Schulenberg | e3dbffc | 2016-07-28 21:12:18 +0200 | [diff] [blame] | 1084 | if (seq_len > 2) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1085 | switch (seq[2]) { |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1086 | case 'P': /* Esc [ O P == F1 on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1087 | return KEY_F(1); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1088 | case 'Q': /* Esc [ O Q == F2 on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1089 | return KEY_F(2); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1090 | case 'R': /* Esc [ O R == F3 on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1091 | return KEY_F(3); |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1092 | case 'S': /* Esc [ O S == F4 on xterm. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1093 | return KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1094 | } |
David Lawrence Ramsey | ec72975 | 2005-09-25 18:42:05 +0000 | [diff] [blame] | 1095 | } else |
David Lawrence Ramsey | 973a96b | 2004-06-22 14:30:18 +0000 | [diff] [blame] | 1096 | /* Esc [ O == F3 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1097 | return KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1098 | break; |
| 1099 | case 'P': /* Esc [ P == F4 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1100 | return KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1101 | case 'Q': /* Esc [ Q == F5 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1102 | return KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1103 | case 'R': /* Esc [ R == F6 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1104 | return KEY_F(6); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1105 | case 'S': /* Esc [ S == F7 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1106 | return KEY_F(7); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1107 | case 'T': /* Esc [ T == F8 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1108 | return KEY_F(8); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1109 | case 'U': /* Esc [ U == PageDown on Mach console. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1110 | return KEY_NPAGE; |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1111 | case 'V': /* Esc [ V == PageUp on Mach console. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1112 | return KEY_PPAGE; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1113 | case 'W': /* Esc [ W == F11 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1114 | return KEY_F(11); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1115 | case 'X': /* Esc [ X == F12 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1116 | return KEY_F(12); |
David Lawrence Ramsey | cc823ab | 2004-10-24 22:51:39 +0000 | [diff] [blame] | 1117 | case 'Y': /* Esc [ Y == End on Mach console. */ |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1118 | return KEY_END; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1119 | case 'Z': /* Esc [ Z == F14 on FreeBSD console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1120 | return KEY_F(14); |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1121 | case 'a': /* Esc [ a == Shift-Up on rxvt/Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1122 | case 'b': /* Esc [ b == Shift-Down on rxvt/Eterm. */ |
Benno Schulenberg | 7f3bd26 | 2015-04-28 20:09:40 +0000 | [diff] [blame] | 1123 | case 'c': /* Esc [ c == Shift-Right on rxvt/Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 1124 | case 'd': /* Esc [ d == Shift-Left on rxvt/Eterm. */ |
Benno Schulenberg | 382c9d7 | 2016-04-24 11:28:28 +0200 | [diff] [blame] | 1125 | shift_held = TRUE; |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1126 | return arrow_from_abcd(seq[1]); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1127 | case '[': |
Benno Schulenberg | e3dbffc | 2016-07-28 21:12:18 +0200 | [diff] [blame] | 1128 | if (seq_len > 2 ) { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1129 | switch (seq[2]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1130 | case 'A': /* Esc [ [ A == F1 on Linux |
| 1131 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1132 | return KEY_F(1); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1133 | case 'B': /* Esc [ [ B == F2 on Linux |
| 1134 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1135 | return KEY_F(2); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1136 | case 'C': /* Esc [ [ C == F3 on Linux |
| 1137 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1138 | return KEY_F(3); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1139 | case 'D': /* Esc [ [ D == F4 on Linux |
| 1140 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1141 | return KEY_F(4); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1142 | case 'E': /* Esc [ [ E == F5 on Linux |
| 1143 | * console. */ |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1144 | return KEY_F(5); |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1145 | } |
| 1146 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1147 | break; |
| 1148 | } |
| 1149 | break; |
| 1150 | } |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1151 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1152 | |
Benno Schulenberg | bd91785 | 2015-12-22 20:24:50 +0000 | [diff] [blame] | 1153 | return ERR; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1156 | /* Return the equivalent arrow-key value for the first four letters |
| 1157 | * in the alphabet, common to many escape sequences. */ |
Benno Schulenberg | 46082bd | 2015-12-22 19:00:25 +0000 | [diff] [blame] | 1158 | int arrow_from_abcd(int kbinput) |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1159 | { |
| 1160 | switch (tolower(kbinput)) { |
| 1161 | case 'a': |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1162 | return KEY_UP; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1163 | case 'b': |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1164 | return KEY_DOWN; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1165 | case 'c': |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1166 | return KEY_RIGHT; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1167 | case 'd': |
Benno Schulenberg | 2225d54 | 2016-07-28 16:19:30 +0200 | [diff] [blame] | 1168 | return KEY_LEFT; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1169 | default: |
| 1170 | return ERR; |
| 1171 | } |
| 1172 | } |
| 1173 | |
David Lawrence Ramsey | 1320d29 | 2006-05-25 22:10:27 +0000 | [diff] [blame] | 1174 | /* Interpret the escape sequence in the keystroke buffer, the first |
David Lawrence Ramsey | 5370b0c | 2006-07-23 17:54:35 +0000 | [diff] [blame] | 1175 | * character of which is kbinput. Assume that the keystroke buffer |
| 1176 | * isn't empty, and that the initial escape has already been read in. */ |
Benno Schulenberg | 46082bd | 2015-12-22 19:00:25 +0000 | [diff] [blame] | 1177 | int parse_escape_sequence(WINDOW *win, int kbinput) |
David Lawrence Ramsey | 1320d29 | 2006-05-25 22:10:27 +0000 | [diff] [blame] | 1178 | { |
| 1179 | int retval, *seq; |
| 1180 | size_t seq_len; |
David Lawrence Ramsey | 1320d29 | 2006-05-25 22:10:27 +0000 | [diff] [blame] | 1181 | |
| 1182 | /* Put back the non-escape character, get the complete escape |
| 1183 | * sequence, translate the sequence into its corresponding key |
| 1184 | * value, and save that as the result. */ |
| 1185 | unget_input(&kbinput, 1); |
Benno Schulenberg | f33d8ca | 2016-07-15 21:53:46 +0200 | [diff] [blame] | 1186 | seq_len = key_buffer_len; |
David Lawrence Ramsey | 1320d29 | 2006-05-25 22:10:27 +0000 | [diff] [blame] | 1187 | seq = get_input(NULL, seq_len); |
Benno Schulenberg | 46082bd | 2015-12-22 19:00:25 +0000 | [diff] [blame] | 1188 | retval = convert_sequence(seq, seq_len); |
David Lawrence Ramsey | 1320d29 | 2006-05-25 22:10:27 +0000 | [diff] [blame] | 1189 | |
| 1190 | free(seq); |
| 1191 | |
Benno Schulenberg | 46082bd | 2015-12-22 19:00:25 +0000 | [diff] [blame] | 1192 | /* If we got an unrecognized escape sequence, notify the user. */ |
David Lawrence Ramsey | 1b4ae69 | 2006-07-25 19:23:35 +0000 | [diff] [blame] | 1193 | if (retval == ERR) { |
David Lawrence Ramsey | 8a72370 | 2006-07-23 18:00:50 +0000 | [diff] [blame] | 1194 | if (win == edit) { |
Benno Schulenberg | eb871e7 | 2016-05-01 10:02:49 +0200 | [diff] [blame] | 1195 | /* TRANSLATORS: This refers to a sequence of escape codes |
| 1196 | * (from the keyboard) that nano does not know about. */ |
Benno Schulenberg | 2535f51 | 2016-04-30 17:31:43 +0200 | [diff] [blame] | 1197 | statusline(ALERT, _("Unknown sequence")); |
Benno Schulenberg | 73aa48b | 2016-05-14 22:14:37 +0200 | [diff] [blame] | 1198 | suppress_cursorpos = FALSE; |
Benno Schulenberg | c8f530a | 2016-05-19 20:43:08 +0200 | [diff] [blame] | 1199 | lastmessage = HUSH; |
Benno Schulenberg | 73aa48b | 2016-05-14 22:14:37 +0200 | [diff] [blame] | 1200 | if (currmenu == MMAIN) { |
| 1201 | reset_cursor(); |
| 1202 | curs_set(1); |
| 1203 | } |
David Lawrence Ramsey | 5370b0c | 2006-07-23 17:54:35 +0000 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
David Lawrence Ramsey | 1320d29 | 2006-05-25 22:10:27 +0000 | [diff] [blame] | 1207 | #ifdef DEBUG |
Benno Schulenberg | 46082bd | 2015-12-22 19:00:25 +0000 | [diff] [blame] | 1208 | fprintf(stderr, "parse_escape_sequence(): kbinput = %d, seq_len = %lu, retval = %d\n", |
| 1209 | kbinput, (unsigned long)seq_len, retval); |
David Lawrence Ramsey | 1320d29 | 2006-05-25 22:10:27 +0000 | [diff] [blame] | 1210 | #endif |
| 1211 | |
| 1212 | return retval; |
| 1213 | } |
| 1214 | |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1215 | /* Translate a byte sequence: turn a three-digit decimal number (from |
| 1216 | * 000 to 255) into its corresponding byte value. */ |
David Lawrence Ramsey | fc0f8f8 | 2006-05-10 13:41:53 +0000 | [diff] [blame] | 1217 | int get_byte_kbinput(int kbinput) |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1218 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1219 | static int byte_digits = 0, byte = 0; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1220 | int retval = ERR; |
| 1221 | |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1222 | /* Increment the byte digit counter. */ |
| 1223 | byte_digits++; |
| 1224 | |
| 1225 | switch (byte_digits) { |
| 1226 | case 1: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1227 | /* First digit: This must be from zero to two. Put it in |
| 1228 | * the 100's position of the byte sequence holder. */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1229 | if ('0' <= kbinput && kbinput <= '2') |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1230 | byte = (kbinput - '0') * 100; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1231 | else |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1232 | /* This isn't the start of a byte sequence. Return this |
| 1233 | * character as the result. */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1234 | retval = kbinput; |
| 1235 | break; |
| 1236 | case 2: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1237 | /* Second digit: This must be from zero to five if the first |
| 1238 | * was two, and may be any decimal value if the first was |
| 1239 | * zero or one. Put it in the 10's position of the byte |
| 1240 | * sequence holder. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1241 | if (('0' <= kbinput && kbinput <= '5') || (byte < 200 && |
| 1242 | '6' <= kbinput && kbinput <= '9')) |
| 1243 | byte += (kbinput - '0') * 10; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1244 | else |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1245 | /* This isn't the second digit of a byte sequence. |
| 1246 | * Return this character as the result. */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1247 | retval = kbinput; |
| 1248 | break; |
| 1249 | case 3: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1250 | /* Third digit: This must be from zero to five if the first |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 1251 | * was two and the second was five, and may be any decimal |
| 1252 | * value otherwise. Put it in the 1's position of the byte |
| 1253 | * sequence holder. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1254 | if (('0' <= kbinput && kbinput <= '5') || (byte < 250 && |
| 1255 | '6' <= kbinput && kbinput <= '9')) { |
David Lawrence Ramsey | 2888964 | 2006-05-30 20:51:15 +0000 | [diff] [blame] | 1256 | byte += kbinput - '0'; |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 1257 | /* The byte sequence is complete. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1258 | retval = byte; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1259 | } else |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1260 | /* This isn't the third digit of a byte sequence. |
| 1261 | * Return this character as the result. */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1262 | retval = kbinput; |
| 1263 | break; |
| 1264 | default: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1265 | /* If there are more than three digits, return this |
| 1266 | * character as the result. (Maybe we should produce an |
| 1267 | * error instead?) */ |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1268 | retval = kbinput; |
| 1269 | break; |
| 1270 | } |
| 1271 | |
| 1272 | /* If we have a result, reset the byte digit counter and the byte |
| 1273 | * sequence holder. */ |
| 1274 | if (retval != ERR) { |
| 1275 | byte_digits = 0; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1276 | byte = 0; |
David Lawrence Ramsey | f0a53f0 | 2005-01-03 19:56:56 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | #ifdef DEBUG |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1280 | 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] | 1281 | #endif |
| 1282 | |
| 1283 | return retval; |
| 1284 | } |
| 1285 | |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1286 | #ifdef ENABLE_UTF8 |
David Lawrence Ramsey | 7f1b119 | 2006-05-28 17:30:28 +0000 | [diff] [blame] | 1287 | /* If the character in kbinput is a valid hexadecimal digit, multiply it |
Benno Schulenberg | e679c51 | 2016-06-24 15:39:03 +0200 | [diff] [blame] | 1288 | * by factor and add the result to uni, and return ERR to signify okay. */ |
David Lawrence Ramsey | 7f1b119 | 2006-05-28 17:30:28 +0000 | [diff] [blame] | 1289 | long add_unicode_digit(int kbinput, long factor, long *uni) |
| 1290 | { |
David Lawrence Ramsey | 7f1b119 | 2006-05-28 17:30:28 +0000 | [diff] [blame] | 1291 | if ('0' <= kbinput && kbinput <= '9') |
| 1292 | *uni += (kbinput - '0') * factor; |
| 1293 | else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') |
| 1294 | *uni += (tolower(kbinput) - 'a' + 10) * factor; |
| 1295 | else |
Benno Schulenberg | e679c51 | 2016-06-24 15:39:03 +0200 | [diff] [blame] | 1296 | /* The character isn't hexadecimal; give it as the result. */ |
| 1297 | return (long)kbinput; |
David Lawrence Ramsey | 7f1b119 | 2006-05-28 17:30:28 +0000 | [diff] [blame] | 1298 | |
Benno Schulenberg | e679c51 | 2016-06-24 15:39:03 +0200 | [diff] [blame] | 1299 | return ERR; |
David Lawrence Ramsey | 7f1b119 | 2006-05-28 17:30:28 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1302 | /* Translate a Unicode sequence: turn a six-digit hexadecimal number |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1303 | * (from 000000 to 10FFFF, case-insensitive) into its corresponding |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1304 | * multibyte value. */ |
David Lawrence Ramsey | fc0ddab | 2016-07-24 12:34:56 +0200 | [diff] [blame] | 1305 | long get_unicode_kbinput(WINDOW *win, int kbinput) |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1306 | { |
David Lawrence Ramsey | 8b006c2 | 2005-08-08 23:03:25 +0000 | [diff] [blame] | 1307 | static int uni_digits = 0; |
| 1308 | static long uni = 0; |
| 1309 | long retval = ERR; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1310 | |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1311 | /* Increment the Unicode digit counter. */ |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1312 | uni_digits++; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1313 | |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1314 | switch (uni_digits) { |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1315 | case 1: |
Benno Schulenberg | a472f48 | 2016-07-24 13:44:16 +0200 | [diff] [blame] | 1316 | /* The first digit must be zero or one. Put it in the |
| 1317 | * 0x100000's position of the Unicode sequence holder. |
| 1318 | * Otherwise, return the character itself as the result. */ |
| 1319 | if (kbinput == '0' || kbinput == '1') |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1320 | uni = (kbinput - '0') * 0x100000; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1321 | else |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1322 | retval = kbinput; |
| 1323 | break; |
| 1324 | case 2: |
Benno Schulenberg | a472f48 | 2016-07-24 13:44:16 +0200 | [diff] [blame] | 1325 | /* The second digit must be zero if the first was one, but |
| 1326 | * may be any hexadecimal value if the first was zero. */ |
| 1327 | if (kbinput == '0' || uni == 0) |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1328 | retval = add_unicode_digit(kbinput, 0x10000, &uni); |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1329 | else |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1330 | retval = kbinput; |
| 1331 | break; |
| 1332 | case 3: |
Benno Schulenberg | a472f48 | 2016-07-24 13:44:16 +0200 | [diff] [blame] | 1333 | /* Later digits may be any hexadecimal value. */ |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1334 | retval = add_unicode_digit(kbinput, 0x1000, &uni); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1335 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1336 | case 4: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1337 | retval = add_unicode_digit(kbinput, 0x100, &uni); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1338 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1339 | case 5: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1340 | retval = add_unicode_digit(kbinput, 0x10, &uni); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1341 | break; |
David Lawrence Ramsey | 8c7a562 | 2005-08-08 23:47:28 +0000 | [diff] [blame] | 1342 | case 6: |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1343 | retval = add_unicode_digit(kbinput, 0x1, &uni); |
Benno Schulenberg | a472f48 | 2016-07-24 13:44:16 +0200 | [diff] [blame] | 1344 | /* If also the sixth digit was a valid hexadecimal value, then |
| 1345 | * the Unicode sequence is complete, so return it. */ |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1346 | if (retval == ERR) |
David Lawrence Ramsey | 6a83647 | 2005-08-01 19:12:05 +0000 | [diff] [blame] | 1347 | retval = uni; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1348 | break; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
David Lawrence Ramsey | fc0ddab | 2016-07-24 12:34:56 +0200 | [diff] [blame] | 1351 | /* Show feedback only when editing, not when at a prompt. */ |
Benno Schulenberg | 4416d9c | 2016-07-24 13:15:45 +0200 | [diff] [blame] | 1352 | if (retval == ERR && win == edit) { |
David Lawrence Ramsey | fc0ddab | 2016-07-24 12:34:56 +0200 | [diff] [blame] | 1353 | char partial[7] = "......"; |
| 1354 | |
| 1355 | /* Construct the partial result, right-padding it with dots. */ |
| 1356 | snprintf(partial, uni_digits + 1, "%06lX", uni); |
| 1357 | partial[uni_digits] = '.'; |
| 1358 | |
| 1359 | /* TRANSLATORS: This is shown while a six-digit hexadecimal |
| 1360 | * Unicode character code (%s) is being typed in. */ |
| 1361 | statusline(HUSH, _("Unicode Input: %s"), partial); |
| 1362 | } |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1363 | |
| 1364 | #ifdef DEBUG |
Benno Schulenberg | 4416d9c | 2016-07-24 13:15:45 +0200 | [diff] [blame] | 1365 | fprintf(stderr, "get_unicode_kbinput(): kbinput = %d, uni_digits = %d, uni = %ld, retval = %ld\n", |
| 1366 | kbinput, uni_digits, uni, retval); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1367 | #endif |
| 1368 | |
Benno Schulenberg | 4416d9c | 2016-07-24 13:15:45 +0200 | [diff] [blame] | 1369 | /* If we have an end result, reset the Unicode digit counter. */ |
| 1370 | if (retval != ERR) |
| 1371 | uni_digits = 0; |
| 1372 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1373 | return retval; |
| 1374 | } |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1375 | #endif /* ENABLE_UTF8 */ |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1376 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1377 | /* Translate a control character sequence: turn an ASCII non-control |
| 1378 | * character into its corresponding control character. */ |
| 1379 | int get_control_kbinput(int kbinput) |
| 1380 | { |
| 1381 | int retval; |
| 1382 | |
Benno Schulenberg | cdcd365 | 2016-05-17 11:33:21 +0200 | [diff] [blame] | 1383 | /* Ctrl-Space (Ctrl-2, Ctrl-@, Ctrl-`) */ |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1384 | if (kbinput == ' ' || kbinput == '2') |
Benno Schulenberg | 90a9036 | 2016-08-01 12:56:05 +0200 | [diff] [blame] | 1385 | retval = 0; |
David Lawrence Ramsey | 4d9ef69 | 2006-04-28 18:26:07 +0000 | [diff] [blame] | 1386 | /* Ctrl-/ (Ctrl-7, Ctrl-_) */ |
| 1387 | else if (kbinput == '/') |
Benno Schulenberg | 90a9036 | 2016-08-01 12:56:05 +0200 | [diff] [blame] | 1388 | retval = 31; |
David Lawrence Ramsey | 4d9ef69 | 2006-04-28 18:26:07 +0000 | [diff] [blame] | 1389 | /* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-/, Ctrl-_) */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1390 | else if ('3' <= kbinput && kbinput <= '7') |
| 1391 | retval = kbinput - 24; |
| 1392 | /* Ctrl-8 (Ctrl-?) */ |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1393 | else if (kbinput == '8' || kbinput == '?') |
Benno Schulenberg | 90a9036 | 2016-08-01 12:56:05 +0200 | [diff] [blame] | 1394 | retval = DEL_CODE; |
David Lawrence Ramsey | 51cb7fd | 2006-05-20 17:19:09 +0000 | [diff] [blame] | 1395 | /* Ctrl-@ (Ctrl-Space, Ctrl-2, Ctrl-`) to Ctrl-_ (Ctrl-/, Ctrl-7) */ |
| 1396 | else if ('@' <= kbinput && kbinput <= '_') |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1397 | retval = kbinput - '@'; |
David Lawrence Ramsey | 4d9ef69 | 2006-04-28 18:26:07 +0000 | [diff] [blame] | 1398 | /* Ctrl-` (Ctrl-2, Ctrl-Space, Ctrl-@) to Ctrl-~ (Ctrl-6, Ctrl-^) */ |
| 1399 | else if ('`' <= kbinput && kbinput <= '~') |
David Lawrence Ramsey | 12e3708 | 2006-05-27 15:52:26 +0000 | [diff] [blame] | 1400 | retval = kbinput - '`'; |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1401 | else |
| 1402 | retval = kbinput; |
| 1403 | |
| 1404 | #ifdef DEBUG |
| 1405 | fprintf(stderr, "get_control_kbinput(): kbinput = %d, retval = %d\n", kbinput, retval); |
| 1406 | #endif |
| 1407 | |
| 1408 | return retval; |
| 1409 | } |
| 1410 | |
David Lawrence Ramsey | 561db3a | 2006-05-26 03:22:44 +0000 | [diff] [blame] | 1411 | /* Put the output-formatted characters in output back into the keystroke |
| 1412 | * 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] | 1413 | void unparse_kbinput(char *output, size_t output_len) |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1414 | { |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1415 | int *input; |
| 1416 | size_t i; |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1417 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1418 | if (output_len == 0) |
| 1419 | return; |
| 1420 | |
| 1421 | input = (int *)nmalloc(output_len * sizeof(int)); |
David Lawrence Ramsey | bd53980 | 2006-12-02 23:39:16 +0000 | [diff] [blame] | 1422 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1423 | for (i = 0; i < output_len; i++) |
| 1424 | input[i] = (int)output[i]; |
David Lawrence Ramsey | bd53980 | 2006-12-02 23:39:16 +0000 | [diff] [blame] | 1425 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1426 | unget_input(input, output_len); |
David Lawrence Ramsey | bd53980 | 2006-12-02 23:39:16 +0000 | [diff] [blame] | 1427 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1428 | free(input); |
David Lawrence Ramsey | d9ad76b | 2005-01-02 22:35:31 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1431 | /* 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] | 1432 | * string in kbinput_len. Assume nodelay(win) is FALSE. */ |
| 1433 | int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) |
| 1434 | { |
| 1435 | int *retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1436 | |
| 1437 | /* 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] | 1438 | * them in verbatim, and turn the keypad off if necessary so that we |
| 1439 | * don't get extended keypad values. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1440 | if (ISSET(PRESERVE)) |
| 1441 | disable_flow_control(); |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1442 | if (!ISSET(REBIND_KEYPAD)) |
| 1443 | keypad(win, FALSE); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1444 | |
Benno Schulenberg | 908663e | 2016-12-27 12:20:20 +0100 | [diff] [blame] | 1445 | /* Read in one keycode, or one or two escapes. */ |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1446 | retval = parse_verbatim_kbinput(win, kbinput_len); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1447 | |
Benno Schulenberg | 908663e | 2016-12-27 12:20:20 +0100 | [diff] [blame] | 1448 | /* If the code is invalid in the current mode, discard it. */ |
| 1449 | if ((*retval == '\n' && as_an_at) || (*retval == '\0' && !as_an_at)) { |
| 1450 | *kbinput_len = 0; |
| 1451 | beep(); |
| 1452 | } |
| 1453 | |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1454 | /* Turn flow control characters back on if necessary and turn the |
David Lawrence Ramsey | 057edf7 | 2005-08-10 21:22:15 +0000 | [diff] [blame] | 1455 | * keypad back on if necessary now that we're done. */ |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1456 | if (ISSET(PRESERVE)) |
| 1457 | enable_flow_control(); |
Benno Schulenberg | 103dd06 | 2016-07-16 22:11:14 +0200 | [diff] [blame] | 1458 | /* Use the global window pointers, because a resize may have freed |
| 1459 | * the data that the win parameter points to. */ |
| 1460 | if (!ISSET(REBIND_KEYPAD)) { |
| 1461 | keypad(edit, TRUE); |
| 1462 | keypad(bottomwin, TRUE); |
| 1463 | } |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1464 | |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1465 | return retval; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
David Lawrence Ramsey | 059c8ef | 2016-11-18 14:14:36 +0100 | [diff] [blame] | 1468 | /* Read in one control character (or an iTerm/Eterm/rxvt double Escape), |
| 1469 | * or convert a series of six digits into a Unicode codepoint. Return |
| 1470 | * in count either 1 (for a control character or the first byte of a |
| 1471 | * multibyte sequence), or 2 (for an iTerm/Eterm/rxvt double Escape). */ |
Benno Schulenberg | 08c51cf | 2016-07-16 19:44:24 +0200 | [diff] [blame] | 1472 | int *parse_verbatim_kbinput(WINDOW *win, size_t *count) |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1473 | { |
Benno Schulenberg | 08c51cf | 2016-07-16 19:44:24 +0200 | [diff] [blame] | 1474 | int *kbinput; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1475 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 1476 | /* Read in the first code. */ |
Benno Schulenberg | 71c9a52 | 2014-05-13 20:14:01 +0000 | [diff] [blame] | 1477 | while ((kbinput = get_input(win, 1)) == NULL) |
| 1478 | ; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1479 | |
Benno Schulenberg | 68cfb08 | 2016-07-25 17:28:54 +0200 | [diff] [blame] | 1480 | #ifndef NANO_TINY |
Benno Schulenberg | 103dd06 | 2016-07-16 22:11:14 +0200 | [diff] [blame] | 1481 | /* When the window was resized, abort and return nothing. */ |
| 1482 | if (*kbinput == KEY_WINCH) { |
Benno Schulenberg | 103dd06 | 2016-07-16 22:11:14 +0200 | [diff] [blame] | 1483 | free(kbinput); |
Benno Schulenberg | 08c51cf | 2016-07-16 19:44:24 +0200 | [diff] [blame] | 1484 | *count = 0; |
Benno Schulenberg | 103dd06 | 2016-07-16 22:11:14 +0200 | [diff] [blame] | 1485 | return NULL; |
| 1486 | } |
Benno Schulenberg | 68cfb08 | 2016-07-25 17:28:54 +0200 | [diff] [blame] | 1487 | #endif |
Benno Schulenberg | 103dd06 | 2016-07-16 22:11:14 +0200 | [diff] [blame] | 1488 | |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1489 | #ifdef ENABLE_UTF8 |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1490 | if (using_utf8()) { |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 1491 | /* Check whether the first code is a valid starter digit: 0 or 1. */ |
David Lawrence Ramsey | fc0ddab | 2016-07-24 12:34:56 +0200 | [diff] [blame] | 1492 | long uni = get_unicode_kbinput(win, *kbinput); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1493 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 1494 | /* If the first code isn't the digit 0 nor 1, put it back. */ |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1495 | if (uni != ERR) |
| 1496 | unget_input(kbinput, 1); |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 1497 | /* Otherwise, continue reading in digits until we have a complete |
| 1498 | * Unicode value, and put back the corresponding byte(s). */ |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1499 | else { |
| 1500 | char *uni_mb; |
| 1501 | int uni_mb_len, *seq, i; |
David Lawrence Ramsey | 6fb6689 | 2006-05-27 17:39:19 +0000 | [diff] [blame] | 1502 | |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1503 | while (uni == ERR) { |
Benno Schulenberg | 1d4c1e0 | 2016-07-17 12:00:33 +0200 | [diff] [blame] | 1504 | free(kbinput); |
Benno Schulenberg | 71c9a52 | 2014-05-13 20:14:01 +0000 | [diff] [blame] | 1505 | while ((kbinput = get_input(win, 1)) == NULL) |
| 1506 | ; |
David Lawrence Ramsey | fc0ddab | 2016-07-24 12:34:56 +0200 | [diff] [blame] | 1507 | uni = get_unicode_kbinput(win, *kbinput); |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1508 | } |
David Lawrence Ramsey | 6a2f068 | 2004-12-20 01:13:55 +0000 | [diff] [blame] | 1509 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 1510 | /* Convert the Unicode value to a multibyte sequence. */ |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1511 | uni_mb = make_mbchar(uni, &uni_mb_len); |
| 1512 | |
| 1513 | seq = (int *)nmalloc(uni_mb_len * sizeof(int)); |
| 1514 | |
| 1515 | for (i = 0; i < uni_mb_len; i++) |
| 1516 | seq[i] = (unsigned char)uni_mb[i]; |
| 1517 | |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 1518 | /* Insert the multibyte sequence into the input buffer. */ |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1519 | unget_input(seq, uni_mb_len); |
| 1520 | |
| 1521 | free(seq); |
| 1522 | free(uni_mb); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 1523 | } |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1524 | } else |
David Lawrence Ramsey | a5b1ca2 | 2006-05-28 17:09:49 +0000 | [diff] [blame] | 1525 | #endif /* ENABLE_UTF8 */ |
Benno Schulenberg | 5806bf5 | 2016-08-01 14:05:42 +0200 | [diff] [blame] | 1526 | /* Put back the first code. */ |
David Lawrence Ramsey | 5c7d88d | 2006-05-28 16:25:15 +0000 | [diff] [blame] | 1527 | unget_input(kbinput, 1); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1528 | |
David Lawrence Ramsey | ad36bdc | 2006-12-02 17:22:21 +0000 | [diff] [blame] | 1529 | free(kbinput); |
| 1530 | |
Benno Schulenberg | 08c51cf | 2016-07-16 19:44:24 +0200 | [diff] [blame] | 1531 | *count = 1; |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1532 | |
David Lawrence Ramsey | 059c8ef | 2016-11-18 14:14:36 +0100 | [diff] [blame] | 1533 | /* If this is an iTerm/Eterm/rxvt double escape, take both Escapes. */ |
Benno Schulenberg | 08c51cf | 2016-07-16 19:44:24 +0200 | [diff] [blame] | 1534 | if (key_buffer_len > 3 && *key_buffer == ESC_CODE && |
| 1535 | key_buffer[1] == ESC_CODE && key_buffer[2] == '[') |
| 1536 | *count = 2; |
| 1537 | |
| 1538 | return get_input(NULL, *count); |
David Lawrence Ramsey | 48ae986 | 2004-05-28 17:23:33 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1541 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1542 | /* Handle any mouse event that may have occurred. We currently handle |
David Lawrence Ramsey | 3a50470 | 2007-05-29 17:01:12 +0000 | [diff] [blame] | 1543 | * releases/clicks of the first mouse button. If allow_shortcuts is |
| 1544 | * TRUE, releasing/clicking on a visible shortcut will put back the |
| 1545 | * keystroke associated with that shortcut. If NCURSES_MOUSE_VERSION is |
| 1546 | * at least 2, we also currently handle presses of the fourth mouse |
| 1547 | * button (upward rolls of the mouse wheel) by putting back the |
| 1548 | * keystrokes to move up, and presses of the fifth mouse button |
| 1549 | * (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] | 1550 | * move down. We also store the coordinates of a mouse event that needs |
| 1551 | * to be handled in mouse_x and mouse_y, relative to the entire screen. |
| 1552 | * Return -1 on error, 0 if the mouse event needs to be handled, 1 if |
| 1553 | * it's been handled by putting back keystrokes that need to be handled. |
| 1554 | * or 2 if it's been ignored. Assume that KEY_MOUSE has already been |
| 1555 | * read in. */ |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1556 | 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] | 1557 | { |
| 1558 | MEVENT mevent; |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1559 | bool in_bottomwin; |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1560 | subnfunc *f; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1561 | |
| 1562 | *mouse_x = -1; |
| 1563 | *mouse_y = -1; |
| 1564 | |
| 1565 | /* First, get the actual mouse event. */ |
| 1566 | if (getmouse(&mevent) == ERR) |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1567 | return -1; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1568 | |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1569 | /* Save the screen coordinates where the mouse event took place. */ |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 1570 | *mouse_x = mevent.x - margin; |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1571 | *mouse_y = mevent.y; |
David Lawrence Ramsey | 98e4d4f | 2006-06-28 21:54:55 +0000 | [diff] [blame] | 1572 | |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1573 | in_bottomwin = wenclose(bottomwin, *mouse_y, *mouse_x); |
| 1574 | |
David Lawrence Ramsey | 5fcf8bf | 2007-06-28 18:31:13 +0000 | [diff] [blame] | 1575 | /* Handle releases/clicks of the first mouse button. */ |
David Lawrence Ramsey | 3a50470 | 2007-05-29 17:01:12 +0000 | [diff] [blame] | 1576 | if (mevent.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) { |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1577 | /* If we're allowing shortcuts, the current shortcut list is |
| 1578 | * 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] | 1579 | * first mouse button was released on/clicked inside it, we need |
| 1580 | * to figure out which shortcut was released on/clicked and put |
| 1581 | * back the equivalent keystroke(s) for it. */ |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1582 | if (allow_shortcuts && !ISSET(NO_HELP) && in_bottomwin) { |
David Lawrence Ramsey | bc65313 | 2007-05-22 17:20:28 +0000 | [diff] [blame] | 1583 | int i; |
| 1584 | /* The width of all the shortcuts, except for the last |
| 1585 | * two, in the shortcut list in bottomwin. */ |
| 1586 | int j; |
Benno Schulenberg | 59cd3e6 | 2014-05-09 11:44:17 +0000 | [diff] [blame] | 1587 | /* The calculated index number of the clicked item. */ |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 1588 | size_t number; |
| 1589 | /* The number of available shortcuts in the current menu. */ |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1590 | |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1591 | /* Translate the mouse event coordinates so that they're |
| 1592 | * relative to bottomwin. */ |
| 1593 | wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE); |
| 1594 | |
| 1595 | /* Handle releases/clicks of the first mouse button on the |
| 1596 | * statusbar elsewhere. */ |
| 1597 | if (*mouse_y == 0) { |
| 1598 | /* Restore the untranslated mouse event coordinates, so |
| 1599 | * that they're relative to the entire screen again. */ |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 1600 | *mouse_x = mevent.x - margin; |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1601 | *mouse_y = mevent.y; |
| 1602 | |
| 1603 | return 0; |
| 1604 | } |
David Lawrence Ramsey | bc65313 | 2007-05-22 17:20:28 +0000 | [diff] [blame] | 1605 | |
Benno Schulenberg | c19f0c7 | 2016-08-27 10:03:34 +0200 | [diff] [blame] | 1606 | /* Determine how many shortcuts are being shown. */ |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 1607 | number = length_of_list(currmenu); |
David Lawrence Ramsey | fe0d366 | 2004-08-26 01:43:16 +0000 | [diff] [blame] | 1608 | |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 1609 | if (number > MAIN_VISIBLE) |
| 1610 | number = MAIN_VISIBLE; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1611 | |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1612 | /* Calculate the width of all of the shortcuts in the list |
| 1613 | * except for the last two, which are longer by (COLS % i) |
| 1614 | * columns so as to not waste space. */ |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 1615 | if (number < 2) |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1616 | i = COLS / (MAIN_VISIBLE / 2); |
| 1617 | else |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 1618 | i = COLS / ((number / 2) + (number % 2)); |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1619 | |
Benno Schulenberg | 59cd3e6 | 2014-05-09 11:44:17 +0000 | [diff] [blame] | 1620 | /* Calculate the one-based index in the shortcut list. */ |
| 1621 | j = (*mouse_x / i) * 2 + *mouse_y; |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1622 | |
Benno Schulenberg | 59cd3e6 | 2014-05-09 11:44:17 +0000 | [diff] [blame] | 1623 | /* Adjust the index if we hit the last two wider ones. */ |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 1624 | if ((j > number) && (*mouse_x % i < COLS % i)) |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1625 | j -= 2; |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1626 | #ifdef DEBUG |
| 1627 | fprintf(stderr, "Calculated %i as index in shortcut list, currmenu = %x.\n", j, currmenu); |
| 1628 | #endif |
David Lawrence Ramsey | 3a50470 | 2007-05-29 17:01:12 +0000 | [diff] [blame] | 1629 | /* Ignore releases/clicks of the first mouse button beyond |
| 1630 | * the last shortcut. */ |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 1631 | if (j > number) |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1632 | return 2; |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1633 | |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1634 | /* Go through the list of functions to determine which |
| 1635 | * shortcut in the current menu we released/clicked on. */ |
Benno Schulenberg | 59cd3e6 | 2014-05-09 11:44:17 +0000 | [diff] [blame] | 1636 | for (f = allfuncs; f != NULL; f = f->next) { |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 1637 | if ((f->menus & currmenu) == 0) |
Benno Schulenberg | 59cd3e6 | 2014-05-09 11:44:17 +0000 | [diff] [blame] | 1638 | continue; |
Benno Schulenberg | 59cd3e6 | 2014-05-09 11:44:17 +0000 | [diff] [blame] | 1639 | if (first_sc_for(currmenu, f->scfunc) == NULL) |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 1640 | continue; |
Benno Schulenberg | 59cd3e6 | 2014-05-09 11:44:17 +0000 | [diff] [blame] | 1641 | /* Tick off an actually shown shortcut. */ |
| 1642 | j -= 1; |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1643 | if (j == 0) |
| 1644 | break; |
Chris Allegretta | c0b7872 | 2008-03-11 04:52:57 +0000 | [diff] [blame] | 1645 | } |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1646 | #ifdef DEBUG |
Benno Schulenberg | 27a52a8 | 2014-04-21 13:07:18 +0000 | [diff] [blame] | 1647 | 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] | 1648 | #endif |
Chris Allegretta | c0b7872 | 2008-03-11 04:52:57 +0000 | [diff] [blame] | 1649 | |
Benno Schulenberg | 0d84301 | 2014-04-16 08:24:32 +0000 | [diff] [blame] | 1650 | /* And put the corresponding key into the keyboard buffer. */ |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1651 | if (f != NULL) { |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 1652 | const sc *s = first_sc_for(currmenu, f->scfunc); |
Benno Schulenberg | 1c9ab8b | 2016-07-24 21:49:07 +0200 | [diff] [blame] | 1653 | unget_kbinput(s->keycode, s->meta); |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1654 | } |
Benno Schulenberg | a3f421c | 2014-06-11 18:04:36 +0000 | [diff] [blame] | 1655 | return 1; |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1656 | } else |
David Lawrence Ramsey | 3a50470 | 2007-05-29 17:01:12 +0000 | [diff] [blame] | 1657 | /* Handle releases/clicks of the first mouse button that |
| 1658 | * aren't on the current shortcut list elsewhere. */ |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1659 | return 0; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1660 | } |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1661 | #if NCURSES_MOUSE_VERSION >= 2 |
| 1662 | /* Handle presses of the fourth mouse button (upward rolls of the |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1663 | * mouse wheel) and presses of the fifth mouse button (downward |
| 1664 | * rolls of the mouse wheel) . */ |
| 1665 | else if (mevent.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) { |
David Lawrence Ramsey | def6091 | 2007-12-08 16:59:13 +0000 | [diff] [blame] | 1666 | bool in_edit = wenclose(edit, *mouse_y, *mouse_x); |
David Lawrence Ramsey | bc65313 | 2007-05-22 17:20:28 +0000 | [diff] [blame] | 1667 | |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1668 | if (in_bottomwin) |
| 1669 | /* Translate the mouse event coordinates so that they're |
| 1670 | * relative to bottomwin. */ |
| 1671 | wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE); |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1672 | |
David Lawrence Ramsey | 97a6ecb | 2007-12-08 04:21:15 +0000 | [diff] [blame] | 1673 | if (in_edit || (in_bottomwin && *mouse_y == 0)) { |
David Lawrence Ramsey | def6091 | 2007-12-08 16:59:13 +0000 | [diff] [blame] | 1674 | int i; |
| 1675 | |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1676 | /* One upward roll of the mouse wheel is equivalent to |
| 1677 | * moving up three lines, and one downward roll of the mouse |
| 1678 | * wheel is equivalent to moving down three lines. */ |
| 1679 | for (i = 0; i < 3; i++) |
| 1680 | unget_kbinput((mevent.bstate & BUTTON4_PRESSED) ? |
Benno Schulenberg | 91951ab | 2016-07-23 14:01:38 +0200 | [diff] [blame] | 1681 | KEY_PPAGE : KEY_NPAGE, FALSE); |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1682 | |
David Lawrence Ramsey | 3a5eaeb | 2007-05-20 23:41:56 +0000 | [diff] [blame] | 1683 | return 1; |
| 1684 | } else |
| 1685 | /* Ignore presses of the fourth mouse button and presses of |
| 1686 | * the fifth mouse buttons that aren't on the edit window or |
| 1687 | * the statusbar. */ |
| 1688 | return 2; |
David Lawrence Ramsey | b9fa1b1 | 2007-05-15 18:04:25 +0000 | [diff] [blame] | 1689 | } |
| 1690 | #endif |
David Lawrence Ramsey | c8bde57 | 2007-06-28 16:38:00 +0000 | [diff] [blame] | 1691 | |
| 1692 | /* Ignore all other mouse events. */ |
| 1693 | return 2; |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1694 | } |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1695 | #endif /* !DISABLE_MOUSE */ |
| 1696 | |
Benno Schulenberg | 7828a80 | 2014-04-14 09:22:29 +0000 | [diff] [blame] | 1697 | /* Return the shortcut that corresponds to the values of kbinput (the |
| 1698 | * key itself) and meta_key (whether the key is a meta sequence). The |
| 1699 | * returned shortcut will be the first in the list that corresponds to |
| 1700 | * the given sequence. */ |
Benno Schulenberg | 49816fe | 2014-07-01 10:41:10 +0000 | [diff] [blame] | 1701 | const sc *get_shortcut(int *kbinput) |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1702 | { |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1703 | sc *s; |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1704 | |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1705 | #ifdef DEBUG |
Benno Schulenberg | 73a0721 | 2016-07-18 12:44:34 +0200 | [diff] [blame] | 1706 | fprintf(stderr, "get_shortcut(): kbinput = %d, meta_key = %s -- ", |
| 1707 | *kbinput, meta_key ? "TRUE" : "FALSE"); |
David Lawrence Ramsey | 08eab72 | 2004-11-27 06:43:06 +0000 | [diff] [blame] | 1708 | #endif |
| 1709 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1710 | for (s = sclist; s != NULL; s = s->next) { |
Benno Schulenberg | 1c9ab8b | 2016-07-24 21:49:07 +0200 | [diff] [blame] | 1711 | if ((s->menus & currmenu) && *kbinput == s->keycode && |
Benno Schulenberg | e295070 | 2016-07-23 14:42:40 +0200 | [diff] [blame] | 1712 | meta_key == s->meta) { |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1713 | #ifdef DEBUG |
Benno Schulenberg | 73a0721 | 2016-07-18 12:44:34 +0200 | [diff] [blame] | 1714 | fprintf (stderr, "matched seq '%s' (menu is %x from %x)\n", |
| 1715 | s->keystr, currmenu, s->menus); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1716 | #endif |
David Lawrence Ramsey | f4a799a | 2005-01-08 06:16:19 +0000 | [diff] [blame] | 1717 | return s; |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1718 | } |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1719 | } |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1720 | #ifdef DEBUG |
Benno Schulenberg | 73a0721 | 2016-07-18 12:44:34 +0200 | [diff] [blame] | 1721 | fprintf (stderr, "matched nothing\n"); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 1722 | #endif |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 1723 | |
| 1724 | return NULL; |
| 1725 | } |
| 1726 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1727 | /* Move to (x, y) in win, and display a line of n spaces with the |
| 1728 | * current attributes. */ |
Benno Schulenberg | f7d320d | 2017-01-12 17:48:33 +0100 | [diff] [blame] | 1729 | void blank_row(WINDOW *win, int y, int x, int n) |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1730 | { |
| 1731 | wmove(win, y, x); |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 1732 | |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1733 | for (; n > 0; n--) |
| 1734 | waddch(win, ' '); |
| 1735 | } |
| 1736 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1737 | /* Blank the first line of the top portion of the window. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1738 | void blank_titlebar(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1739 | { |
Benno Schulenberg | f7d320d | 2017-01-12 17:48:33 +0100 | [diff] [blame] | 1740 | blank_row(topwin, 0, 0, COLS); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
David Lawrence Ramsey | b159f94 | 2006-07-28 17:06:27 +0000 | [diff] [blame] | 1743 | /* 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] | 1744 | * edit window. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1745 | void blank_edit(void) |
| 1746 | { |
Benno Schulenberg | f7d320d | 2017-01-12 17:48:33 +0100 | [diff] [blame] | 1747 | int row; |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 1748 | |
Benno Schulenberg | f7d320d | 2017-01-12 17:48:33 +0100 | [diff] [blame] | 1749 | for (row = 0; row < editwinrows; row++) |
| 1750 | blank_row(edit, row, 0, COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1753 | /* Blank the first line of the bottom portion of the window. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1754 | void blank_statusbar(void) |
| 1755 | { |
Benno Schulenberg | f7d320d | 2017-01-12 17:48:33 +0100 | [diff] [blame] | 1756 | blank_row(bottomwin, 0, 0, COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1759 | /* If the NO_HELP flag isn't set, blank the last two lines of the bottom |
| 1760 | * portion of the window. */ |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 1761 | void blank_bottombars(void) |
| 1762 | { |
Benno Schulenberg | 76a960d | 2016-08-15 19:44:49 +0200 | [diff] [blame] | 1763 | if (!ISSET(NO_HELP) && LINES > 4) { |
Benno Schulenberg | f7d320d | 2017-01-12 17:48:33 +0100 | [diff] [blame] | 1764 | blank_row(bottomwin, 1, 0, COLS); |
| 1765 | blank_row(bottomwin, 2, 0, COLS); |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 1766 | } |
| 1767 | } |
| 1768 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 1769 | /* Check if the number of keystrokes needed to blank the statusbar has |
| 1770 | * been pressed. If so, blank the statusbar, unless constant cursor |
Benno Schulenberg | 2503503 | 2016-05-15 11:36:51 +0200 | [diff] [blame] | 1771 | * position display is on and we are in the editing screen. */ |
David Lawrence Ramsey | e5d8f32 | 2004-09-30 22:07:21 +0000 | [diff] [blame] | 1772 | void check_statusblank(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1773 | { |
Benno Schulenberg | 2503503 | 2016-05-15 11:36:51 +0200 | [diff] [blame] | 1774 | if (statusblank == 0) |
| 1775 | return; |
David Lawrence Ramsey | bf51aa4 | 2005-06-17 21:52:59 +0000 | [diff] [blame] | 1776 | |
Benno Schulenberg | 2503503 | 2016-05-15 11:36:51 +0200 | [diff] [blame] | 1777 | statusblank--; |
| 1778 | |
| 1779 | /* When editing and 'constantshow' is active, skip the blanking. */ |
| 1780 | if (currmenu == MMAIN && ISSET(CONST_UPDATE)) |
| 1781 | return; |
| 1782 | |
| 1783 | if (statusblank == 0) { |
| 1784 | blank_statusbar(); |
| 1785 | wnoutrefresh(bottomwin); |
| 1786 | reset_cursor(); |
| 1787 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1788 | } |
Benno Schulenberg | 76a960d | 2016-08-15 19:44:49 +0200 | [diff] [blame] | 1789 | |
| 1790 | /* If the subwindows overlap, make sure to show the edit window now. */ |
| 1791 | if (LINES == 1) |
| 1792 | edit_refresh(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1795 | /* Convert buf into a string that can be displayed on screen. The |
| 1796 | * caller wants to display buf starting with column start_col, and |
Benno Schulenberg | a37cd9f | 2016-06-14 19:56:16 +0200 | [diff] [blame] | 1797 | * extending for at most span columns. start_col is zero-based. span |
| 1798 | * is one-based, so span == 0 means you get "" returned. The returned |
Benno Schulenberg | eafae5d | 2016-12-18 09:40:09 +0100 | [diff] [blame] | 1799 | * string is dynamically allocated, and should be freed. If isdata is |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1800 | * TRUE, the caller might put "$" at the beginning or end of the line if |
| 1801 | * it's too long. */ |
Benno Schulenberg | a37cd9f | 2016-06-14 19:56:16 +0200 | [diff] [blame] | 1802 | char *display_string(const char *buf, size_t start_col, size_t span, |
Benno Schulenberg | eafae5d | 2016-12-18 09:40:09 +0100 | [diff] [blame] | 1803 | bool isdata) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1804 | { |
| 1805 | size_t start_index; |
David Lawrence Ramsey | 61a7140 | 2004-12-24 15:45:36 +0000 | [diff] [blame] | 1806 | /* Index in buf of the first character shown. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1807 | size_t column; |
David Lawrence Ramsey | 61a7140 | 2004-12-24 15:45:36 +0000 | [diff] [blame] | 1808 | /* Screen column that start_index corresponds to. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1809 | char *converted; |
| 1810 | /* The string we return. */ |
| 1811 | size_t index; |
| 1812 | /* Current position in converted. */ |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1813 | |
Benno Schulenberg | eafae5d | 2016-12-18 09:40:09 +0100 | [diff] [blame] | 1814 | /* If this is data, make room for the "$" at the end of the line. */ |
| 1815 | if (isdata && !ISSET(SOFTWRAP) && strlenpt(buf) > start_col + span) |
Benno Schulenberg | a37cd9f | 2016-06-14 19:56:16 +0200 | [diff] [blame] | 1816 | span--; |
David Lawrence Ramsey | 9dffac9 | 2005-01-05 06:09:34 +0000 | [diff] [blame] | 1817 | |
Benno Schulenberg | a37cd9f | 2016-06-14 19:56:16 +0200 | [diff] [blame] | 1818 | if (span == 0) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1819 | return mallocstrcpy(NULL, ""); |
| 1820 | |
| 1821 | start_index = actual_x(buf, start_col); |
| 1822 | column = strnlenpt(buf, start_index); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1823 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1824 | assert(column <= start_col); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1825 | |
Benno Schulenberg | cf0eed6 | 2016-06-05 12:53:02 +0200 | [diff] [blame] | 1826 | /* Allocate enough space to hold the entire converted buffer. */ |
| 1827 | converted = charalloc(strlen(buf) * (mb_cur_max() + tabsize) + 1); |
David Lawrence Ramsey | bbd63e1 | 2005-01-05 16:59:49 +0000 | [diff] [blame] | 1828 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1829 | index = 0; |
Benno Schulenberg | 8c7a385 | 2016-07-12 21:05:09 +0200 | [diff] [blame] | 1830 | #ifdef USING_OLD_NCURSES |
Benno Schulenberg | 954d04b | 2015-09-05 09:14:24 +0000 | [diff] [blame] | 1831 | seen_wide = FALSE; |
Benno Schulenberg | 8c7a385 | 2016-07-12 21:05:09 +0200 | [diff] [blame] | 1832 | #endif |
Benno Schulenberg | d6f43bd | 2016-06-05 21:10:07 +0200 | [diff] [blame] | 1833 | buf += start_index; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1834 | |
Benno Schulenberg | 407f2d5 | 2017-02-17 12:01:25 +0100 | [diff] [blame] | 1835 | /* If the first character starts before the left edge, or would be |
| 1836 | * overwritten by a "$" token, then show spaces instead. */ |
| 1837 | if (*buf != '\0' && *buf != '\t' && (column < start_col || |
| 1838 | (column > 0 && isdata && !ISSET(SOFTWRAP)))) { |
Benno Schulenberg | d6f43bd | 2016-06-05 21:10:07 +0200 | [diff] [blame] | 1839 | if (is_cntrl_mbchar(buf)) { |
David Lawrence Ramsey | fe3627d | 2004-12-24 17:52:17 +0000 | [diff] [blame] | 1840 | if (column < start_col) { |
Benno Schulenberg | eafae5d | 2016-12-18 09:40:09 +0100 | [diff] [blame] | 1841 | converted[index++] = control_mbrep(buf, isdata); |
Benno Schulenberg | 622995f | 2016-06-29 20:37:28 +0200 | [diff] [blame] | 1842 | start_col++; |
Benno Schulenberg | d6f43bd | 2016-06-05 21:10:07 +0200 | [diff] [blame] | 1843 | buf += parse_mbchar(buf, NULL, NULL); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1844 | } |
David Lawrence Ramsey | 956da0d | 2005-01-03 06:56:38 +0000 | [diff] [blame] | 1845 | } |
David Lawrence Ramsey | 7eb30a8 | 2005-07-17 02:40:07 +0000 | [diff] [blame] | 1846 | #ifdef ENABLE_UTF8 |
Benno Schulenberg | d6f43bd | 2016-06-05 21:10:07 +0200 | [diff] [blame] | 1847 | else if (using_utf8() && mbwidth(buf) == 2) { |
David Lawrence Ramsey | d99b0e1 | 2006-05-19 17:50:01 +0000 | [diff] [blame] | 1848 | if (column >= start_col) { |
| 1849 | converted[index++] = ' '; |
| 1850 | start_col++; |
| 1851 | } |
| 1852 | |
David Lawrence Ramsey | 9dffac9 | 2005-01-05 06:09:34 +0000 | [diff] [blame] | 1853 | converted[index++] = ' '; |
David Lawrence Ramsey | a9b9913 | 2004-12-27 23:35:25 +0000 | [diff] [blame] | 1854 | start_col++; |
David Lawrence Ramsey | b54155c | 2005-01-12 03:25:57 +0000 | [diff] [blame] | 1855 | |
Benno Schulenberg | d6f43bd | 2016-06-05 21:10:07 +0200 | [diff] [blame] | 1856 | buf += parse_mbchar(buf, NULL, NULL); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1857 | } |
David Lawrence Ramsey | 956da0d | 2005-01-03 06:56:38 +0000 | [diff] [blame] | 1858 | #endif |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
Benno Schulenberg | d6f43bd | 2016-06-05 21:10:07 +0200 | [diff] [blame] | 1861 | while (*buf != '\0') { |
Benno Schulenberg | e33a0b6 | 2016-06-06 13:20:04 +0200 | [diff] [blame] | 1862 | int charlength, charwidth = 1; |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1863 | |
Benno Schulenberg | d6f43bd | 2016-06-05 21:10:07 +0200 | [diff] [blame] | 1864 | if (*buf == ' ') { |
Benno Schulenberg | 3ac3764 | 2016-05-30 10:41:11 +0200 | [diff] [blame] | 1865 | /* Show a space as a visible character, or as a space. */ |
| 1866 | #ifndef NANO_TINY |
| 1867 | if (ISSET(WHITESPACE_DISPLAY)) { |
| 1868 | int i = whitespace_len[0]; |
| 1869 | |
| 1870 | while (i < whitespace_len[0] + whitespace_len[1]) |
| 1871 | converted[index++] = whitespace[i++]; |
| 1872 | } else |
| 1873 | #endif |
| 1874 | converted[index++] = ' '; |
| 1875 | start_col++; |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1876 | buf++; |
| 1877 | continue; |
Benno Schulenberg | d6f43bd | 2016-06-05 21:10:07 +0200 | [diff] [blame] | 1878 | } else if (*buf == '\t') { |
Benno Schulenberg | 5864d97 | 2016-05-30 10:45:46 +0200 | [diff] [blame] | 1879 | /* Show a tab as a visible character, or as as a space. */ |
Benno Schulenberg | 90798fb | 2015-08-09 16:05:50 +0000 | [diff] [blame] | 1880 | #ifndef NANO_TINY |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 1881 | if (ISSET(WHITESPACE_DISPLAY)) { |
Benno Schulenberg | 5864d97 | 2016-05-30 10:45:46 +0200 | [diff] [blame] | 1882 | int i = 0; |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 1883 | |
Benno Schulenberg | 5864d97 | 2016-05-30 10:45:46 +0200 | [diff] [blame] | 1884 | while (i < whitespace_len[0]) |
| 1885 | converted[index++] = whitespace[i++]; |
David Lawrence Ramsey | 6e60db6 | 2005-03-10 22:52:21 +0000 | [diff] [blame] | 1886 | } else |
David Lawrence Ramsey | 483ea32 | 2004-05-29 16:25:30 +0000 | [diff] [blame] | 1887 | #endif |
David Lawrence Ramsey | b94d51a | 2007-04-19 03:15:04 +0000 | [diff] [blame] | 1888 | converted[index++] = ' '; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1889 | start_col++; |
Benno Schulenberg | 5864d97 | 2016-05-30 10:45:46 +0200 | [diff] [blame] | 1890 | /* Fill the tab up with the required number of spaces. */ |
David Lawrence Ramsey | c195820 | 2004-12-27 23:21:34 +0000 | [diff] [blame] | 1891 | while (start_col % tabsize != 0) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1892 | converted[index++] = ' '; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1893 | start_col++; |
| 1894 | } |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1895 | buf++; |
| 1896 | continue; |
| 1897 | } |
| 1898 | |
Benno Schulenberg | e33a0b6 | 2016-06-06 13:20:04 +0200 | [diff] [blame] | 1899 | charlength = length_of_char(buf, &charwidth); |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1900 | |
Benno Schulenberg | 622995f | 2016-06-29 20:37:28 +0200 | [diff] [blame] | 1901 | /* If buf contains a control character, represent it. */ |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1902 | if (is_cntrl_mbchar(buf)) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1903 | converted[index++] = '^'; |
Benno Schulenberg | eafae5d | 2016-12-18 09:40:09 +0100 | [diff] [blame] | 1904 | converted[index++] = control_mbrep(buf, isdata); |
Benno Schulenberg | 622995f | 2016-06-29 20:37:28 +0200 | [diff] [blame] | 1905 | start_col += 2; |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1906 | buf += charlength; |
| 1907 | continue; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1910 | /* If buf contains a valid non-control character, simply copy it. */ |
| 1911 | if (charlength > 0) { |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1912 | for (; charlength > 0; charlength--) |
| 1913 | converted[index++] = *(buf++); |
| 1914 | |
Benno Schulenberg | e33a0b6 | 2016-06-06 13:20:04 +0200 | [diff] [blame] | 1915 | start_col += charwidth; |
Benno Schulenberg | 8c7a385 | 2016-07-12 21:05:09 +0200 | [diff] [blame] | 1916 | #ifdef USING_OLD_NCURSES |
Benno Schulenberg | e33a0b6 | 2016-06-06 13:20:04 +0200 | [diff] [blame] | 1917 | if (charwidth > 1) |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1918 | seen_wide = TRUE; |
Benno Schulenberg | 8c7a385 | 2016-07-12 21:05:09 +0200 | [diff] [blame] | 1919 | #endif |
Benno Schulenberg | 0894587 | 2016-06-06 12:48:26 +0200 | [diff] [blame] | 1920 | continue; |
| 1921 | } |
| 1922 | |
| 1923 | /* Represent an invalid sequence with the Replacement Character. */ |
| 1924 | converted[index++] = '\xEF'; |
| 1925 | converted[index++] = '\xBF'; |
| 1926 | converted[index++] = '\xBD'; |
| 1927 | |
| 1928 | start_col += 1; |
| 1929 | buf++; |
| 1930 | |
| 1931 | /* For invalid codepoints, skip extra bytes. */ |
| 1932 | if (charlength < -1) |
| 1933 | buf += charlength + 7; |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
David Lawrence Ramsey | e54f1c4 | 2006-10-29 21:14:53 +0000 | [diff] [blame] | 1936 | /* Null-terminate converted. */ |
David Lawrence Ramsey | 114cfb6 | 2006-02-03 03:58:49 +0000 | [diff] [blame] | 1937 | converted[index] = '\0'; |
David Lawrence Ramsey | 0251bdb | 2005-01-05 19:05:04 +0000 | [diff] [blame] | 1938 | |
Benno Schulenberg | a37cd9f | 2016-06-14 19:56:16 +0200 | [diff] [blame] | 1939 | /* Make sure converted takes up no more than span columns. */ |
| 1940 | index = actual_x(converted, span); |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1941 | null_at(&converted, index); |
David Lawrence Ramsey | 0251bdb | 2005-01-05 19:05:04 +0000 | [diff] [blame] | 1942 | |
David Lawrence Ramsey | fc69321 | 2004-12-23 17:43:27 +0000 | [diff] [blame] | 1943 | return converted; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
David Lawrence Ramsey | 4ea2eac | 2006-07-09 00:52:16 +0000 | [diff] [blame] | 1946 | /* If path is NULL, we're in normal editing mode, so display the current |
| 1947 | * version of nano, the current filename, and whether the current file |
| 1948 | * has been modified on the titlebar. If path isn't NULL, we're in the |
| 1949 | * file browser, and path contains the directory to start the file |
| 1950 | * browser in, so display the current version of nano and the contents |
| 1951 | * of path on the titlebar. */ |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 1952 | void titlebar(const char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1953 | { |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 1954 | size_t verlen, prefixlen, pathlen, statelen; |
| 1955 | /* The width of the different titlebar elements, in columns. */ |
| 1956 | size_t pluglen = 0; |
| 1957 | /* The width that "Modified" would take up. */ |
| 1958 | size_t offset = 0; |
| 1959 | /* The position at which the center part of the titlebar starts. */ |
| 1960 | const char *prefix = ""; |
| 1961 | /* What is shown before the path -- "File:", "DIR:", or "". */ |
| 1962 | const char *state = ""; |
| 1963 | /* The state of the current buffer -- "Modified", "View", or "". */ |
Benno Schulenberg | dfff78d | 2016-12-17 21:54:36 +0100 | [diff] [blame] | 1964 | char *caption; |
| 1965 | /* The presentable form of the pathname. */ |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 1966 | |
Benno Schulenberg | 76a960d | 2016-08-15 19:44:49 +0200 | [diff] [blame] | 1967 | /* If the screen is too small, there is no titlebar. */ |
| 1968 | if (topwin == NULL) |
| 1969 | return; |
| 1970 | |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 1971 | assert(path != NULL || openfile->filename != NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1972 | |
Benno Schulenberg | 960e848 | 2016-07-12 09:35:48 +0200 | [diff] [blame] | 1973 | wattron(topwin, interface_color_pair[TITLE_BAR]); |
David Lawrence Ramsey | 85ffaee | 2006-07-02 18:29:49 +0000 | [diff] [blame] | 1974 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1975 | blank_titlebar(); |
Benno Schulenberg | eef7d10 | 2016-12-20 19:27:41 +0100 | [diff] [blame] | 1976 | as_an_at = FALSE; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1977 | |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 1978 | /* Do as Pico: if there is not enough width available for all items, |
| 1979 | * first sacrifice the version string, then eat up the side spaces, |
| 1980 | * then sacrifice the prefix, and only then start dottifying. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1981 | |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 1982 | /* Figure out the path, prefix and state strings. */ |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1983 | #ifndef DISABLE_BROWSER |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1984 | if (path != NULL) |
| 1985 | prefix = _("DIR:"); |
| 1986 | else |
| 1987 | #endif |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 1988 | { |
| 1989 | if (openfile->filename[0] == '\0') |
| 1990 | path = _("New Buffer"); |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 1991 | else { |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 1992 | path = openfile->filename; |
| 1993 | prefix = _("File:"); |
| 1994 | } |
David Lawrence Ramsey | cb4f14b | 2005-03-24 22:28:25 +0000 | [diff] [blame] | 1995 | |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 1996 | if (openfile->modified) |
| 1997 | state = _("Modified"); |
| 1998 | else if (ISSET(VIEW_MODE)) |
| 1999 | state = _("View"); |
| 2000 | |
| 2001 | pluglen = strlenpt(_("Modified")) + 1; |
| 2002 | } |
| 2003 | |
| 2004 | /* Determine the widths of the four elements, including their padding. */ |
| 2005 | verlen = strlenpt(BRANDING) + 3; |
| 2006 | prefixlen = strlenpt(prefix); |
| 2007 | if (prefixlen > 0) |
| 2008 | prefixlen++; |
| 2009 | pathlen= strlenpt(path); |
| 2010 | statelen = strlenpt(state) + 2; |
| 2011 | if (statelen > 2) { |
| 2012 | pathlen++; |
| 2013 | pluglen = 0; |
| 2014 | } |
| 2015 | |
| 2016 | /* Only print the version message when there is room for it. */ |
| 2017 | if (verlen + prefixlen + pathlen + pluglen + statelen <= COLS) |
| 2018 | mvwaddstr(topwin, 0, 2, BRANDING); |
| 2019 | else { |
| 2020 | verlen = 2; |
| 2021 | /* If things don't fit yet, give up the placeholder. */ |
| 2022 | if (verlen + prefixlen + pathlen + pluglen + statelen > COLS) |
| 2023 | pluglen = 0; |
| 2024 | /* If things still don't fit, give up the side spaces. */ |
| 2025 | if (verlen + prefixlen + pathlen + pluglen + statelen > COLS) { |
| 2026 | verlen = 0; |
| 2027 | statelen -= 2; |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 2028 | } |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2029 | } |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2030 | |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 2031 | /* If we have side spaces left, center the path name. */ |
| 2032 | if (verlen > 0) |
| 2033 | offset = verlen + (COLS - (verlen + pluglen + statelen) - |
| 2034 | (prefixlen + pathlen)) / 2; |
| 2035 | |
| 2036 | /* Only print the prefix when there is room for it. */ |
| 2037 | if (verlen + prefixlen + pathlen + pluglen + statelen <= COLS) { |
| 2038 | mvwaddstr(topwin, 0, offset, prefix); |
| 2039 | if (prefixlen > 0) |
| 2040 | waddstr(topwin, " "); |
| 2041 | } else |
| 2042 | wmove(topwin, 0, offset); |
| 2043 | |
| 2044 | /* Print the full path if there's room; otherwise, dottify it. */ |
Benno Schulenberg | dfff78d | 2016-12-17 21:54:36 +0100 | [diff] [blame] | 2045 | if (pathlen + pluglen + statelen <= COLS) { |
| 2046 | caption = display_string(path, 0, pathlen, FALSE); |
| 2047 | waddstr(topwin, caption); |
| 2048 | free(caption); |
| 2049 | } else if (5 + statelen <= COLS) { |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 2050 | waddstr(topwin, "..."); |
Benno Schulenberg | dfff78d | 2016-12-17 21:54:36 +0100 | [diff] [blame] | 2051 | caption = display_string(path, 3 + pathlen - COLS + statelen, |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 2052 | COLS - statelen, FALSE); |
Benno Schulenberg | dfff78d | 2016-12-17 21:54:36 +0100 | [diff] [blame] | 2053 | waddstr(topwin, caption); |
| 2054 | free(caption); |
Benno Schulenberg | 577f7fa | 2016-04-29 10:42:20 +0200 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | /* Right-align the state if there's room; otherwise, trim it. */ |
| 2058 | if (statelen > 0 && statelen <= COLS) |
| 2059 | mvwaddstr(topwin, 0, COLS - statelen, state); |
| 2060 | else if (statelen > 0) |
| 2061 | mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS)); |
| 2062 | |
Benno Schulenberg | 960e848 | 2016-07-12 09:35:48 +0200 | [diff] [blame] | 2063 | wattroff(topwin, interface_color_pair[TITLE_BAR]); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2064 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2065 | wnoutrefresh(topwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2066 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 2067 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
Benno Schulenberg | 2535f51 | 2016-04-30 17:31:43 +0200 | [diff] [blame] | 2070 | /* Display a normal message on the statusbar, quietly. */ |
| 2071 | void statusbar(const char *msg) |
| 2072 | { |
| 2073 | statusline(HUSH, msg); |
| 2074 | } |
| 2075 | |
David Lawrence Ramsey | e4d4524 | 2016-11-27 15:01:54 -0600 | [diff] [blame] | 2076 | /* Warn the user on the statusbar and pause for a moment, so that the |
| 2077 | * message can be noticed and read. */ |
| 2078 | void warn_and_shortly_pause(const char *msg) |
| 2079 | { |
| 2080 | statusbar(msg); |
| 2081 | beep(); |
| 2082 | napms(1800); |
David Lawrence Ramsey | e4d4524 | 2016-11-27 15:01:54 -0600 | [diff] [blame] | 2083 | } |
| 2084 | |
Benno Schulenberg | 9d6d5b6 | 2016-05-04 12:18:21 +0200 | [diff] [blame] | 2085 | /* Display a message on the statusbar, and set suppress_cursorpos to |
David Lawrence Ramsey | 5593e20 | 2005-06-28 19:49:15 +0000 | [diff] [blame] | 2086 | * TRUE, so that the message won't be immediately overwritten if |
| 2087 | * constant cursor position display is on. */ |
Benno Schulenberg | c8f530a | 2016-05-19 20:43:08 +0200 | [diff] [blame] | 2088 | void statusline(message_type importance, const char *msg, ...) |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2089 | { |
| 2090 | va_list ap; |
Benno Schulenberg | 23c3fd9 | 2017-02-21 12:57:11 +0100 | [diff] [blame] | 2091 | static int alerts = 0; |
Benno Schulenberg | 21cb01e | 2016-08-22 10:50:51 +0200 | [diff] [blame] | 2092 | char *compound, *message; |
Benno Schulenberg | 8f21d25 | 2017-01-08 12:05:42 +0100 | [diff] [blame] | 2093 | size_t start_col; |
Benno Schulenberg | ea9aaee | 2016-08-15 22:25:52 +0200 | [diff] [blame] | 2094 | bool bracketed; |
Benno Schulenberg | 90798fb | 2015-08-09 16:05:50 +0000 | [diff] [blame] | 2095 | #ifndef NANO_TINY |
| 2096 | bool old_whitespace = ISSET(WHITESPACE_DISPLAY); |
| 2097 | |
| 2098 | UNSET(WHITESPACE_DISPLAY); |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2099 | #endif |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2100 | |
| 2101 | va_start(ap, msg); |
| 2102 | |
| 2103 | /* Curses mode is turned off. If we use wmove() now, it will muck |
| 2104 | * up the terminal settings. So we just use vfprintf(). */ |
David Lawrence Ramsey | f70f67b | 2006-06-03 17:31:52 +0000 | [diff] [blame] | 2105 | if (isendwin()) { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2106 | vfprintf(stderr, msg, ap); |
| 2107 | va_end(ap); |
| 2108 | return; |
| 2109 | } |
| 2110 | |
Benno Schulenberg | c8f530a | 2016-05-19 20:43:08 +0200 | [diff] [blame] | 2111 | /* If there already was an alert message, ignore lesser ones. */ |
| 2112 | if ((lastmessage == ALERT && importance != ALERT) || |
| 2113 | (lastmessage == MILD && importance == HUSH)) |
| 2114 | return; |
Benno Schulenberg | 2535f51 | 2016-04-30 17:31:43 +0200 | [diff] [blame] | 2115 | |
Benno Schulenberg | 23c3fd9 | 2017-02-21 12:57:11 +0100 | [diff] [blame] | 2116 | /* If the ALERT status has been reset, reset the counter. */ |
| 2117 | if (lastmessage == HUSH) |
| 2118 | alerts = 0; |
| 2119 | |
| 2120 | /* Shortly pause after each of the first three alert messages, |
| 2121 | * to give the user time to read them. */ |
| 2122 | if (lastmessage == ALERT && alerts < 4) |
Benno Schulenberg | c8f530a | 2016-05-19 20:43:08 +0200 | [diff] [blame] | 2123 | napms(1200); |
| 2124 | |
Benno Schulenberg | 23c3fd9 | 2017-02-21 12:57:11 +0100 | [diff] [blame] | 2125 | if (importance == ALERT) { |
| 2126 | if (++alerts > 3) |
| 2127 | msg = "Some warnings were suppressed"; |
Benno Schulenberg | 2535f51 | 2016-04-30 17:31:43 +0200 | [diff] [blame] | 2128 | beep(); |
Benno Schulenberg | 23c3fd9 | 2017-02-21 12:57:11 +0100 | [diff] [blame] | 2129 | } |
Benno Schulenberg | c8f530a | 2016-05-19 20:43:08 +0200 | [diff] [blame] | 2130 | |
| 2131 | lastmessage = importance; |
Benno Schulenberg | 2535f51 | 2016-04-30 17:31:43 +0200 | [diff] [blame] | 2132 | |
Benno Schulenberg | 97dcd37 | 2016-02-06 11:18:27 +0000 | [diff] [blame] | 2133 | /* Turn the cursor off while fiddling in the statusbar. */ |
| 2134 | curs_set(0); |
| 2135 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2136 | blank_statusbar(); |
| 2137 | |
Benno Schulenberg | 21cb01e | 2016-08-22 10:50:51 +0200 | [diff] [blame] | 2138 | /* Construct the message out of all the arguments. */ |
| 2139 | compound = charalloc(mb_cur_max() * (COLS + 1)); |
| 2140 | vsnprintf(compound, mb_cur_max() * (COLS + 1), msg, ap); |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2141 | va_end(ap); |
Benno Schulenberg | 21cb01e | 2016-08-22 10:50:51 +0200 | [diff] [blame] | 2142 | message = display_string(compound, 0, COLS, FALSE); |
| 2143 | free(compound); |
Benno Schulenberg | 90798fb | 2015-08-09 16:05:50 +0000 | [diff] [blame] | 2144 | |
Benno Schulenberg | 8f21d25 | 2017-01-08 12:05:42 +0100 | [diff] [blame] | 2145 | start_col = (COLS - strlenpt(message)) / 2; |
| 2146 | bracketed = (start_col > 1); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2147 | |
Benno Schulenberg | 8f21d25 | 2017-01-08 12:05:42 +0100 | [diff] [blame] | 2148 | wmove(bottomwin, 0, (bracketed ? start_col - 2 : start_col)); |
Benno Schulenberg | 960e848 | 2016-07-12 09:35:48 +0200 | [diff] [blame] | 2149 | wattron(bottomwin, interface_color_pair[STATUS_BAR]); |
Benno Schulenberg | ea9aaee | 2016-08-15 22:25:52 +0200 | [diff] [blame] | 2150 | if (bracketed) |
| 2151 | waddstr(bottomwin, "[ "); |
Benno Schulenberg | 21cb01e | 2016-08-22 10:50:51 +0200 | [diff] [blame] | 2152 | waddstr(bottomwin, message); |
| 2153 | free(message); |
Benno Schulenberg | ea9aaee | 2016-08-15 22:25:52 +0200 | [diff] [blame] | 2154 | if (bracketed) |
| 2155 | waddstr(bottomwin, " ]"); |
Benno Schulenberg | 960e848 | 2016-07-12 09:35:48 +0200 | [diff] [blame] | 2156 | wattroff(bottomwin, interface_color_pair[STATUS_BAR]); |
Benno Schulenberg | f5eb316 | 2016-02-23 12:37:10 +0000 | [diff] [blame] | 2157 | |
Benno Schulenberg | e0e788e | 2016-05-23 21:34:02 +0200 | [diff] [blame] | 2158 | /* Push the message to the screen straightaway. */ |
David Lawrence Ramsey | 874703b | 2005-10-27 03:35:42 +0000 | [diff] [blame] | 2159 | wnoutrefresh(bottomwin); |
Benno Schulenberg | e0e788e | 2016-05-23 21:34:02 +0200 | [diff] [blame] | 2160 | doupdate(); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2161 | |
Benno Schulenberg | 9d6d5b6 | 2016-05-04 12:18:21 +0200 | [diff] [blame] | 2162 | suppress_cursorpos = TRUE; |
David Lawrence Ramsey | c661853 | 2005-06-17 22:33:15 +0000 | [diff] [blame] | 2163 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2164 | #ifndef NANO_TINY |
Benno Schulenberg | 21cb01e | 2016-08-22 10:50:51 +0200 | [diff] [blame] | 2165 | if (old_whitespace) |
| 2166 | SET(WHITESPACE_DISPLAY); |
| 2167 | |
| 2168 | /* If doing quick blanking, blank the statusbar after just one keystroke. |
| 2169 | * Otherwise, blank it after twenty-six keystrokes, as Pico does. */ |
Benno Schulenberg | 681f042 | 2016-05-15 10:57:25 +0200 | [diff] [blame] | 2170 | if (ISSET(QUICK_BLANK)) |
| 2171 | statusblank = 1; |
| 2172 | else |
David Lawrence Ramsey | e29111f | 2005-06-17 19:06:25 +0000 | [diff] [blame] | 2173 | #endif |
Benno Schulenberg | 681f042 | 2016-05-15 10:57:25 +0200 | [diff] [blame] | 2174 | statusblank = 26; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
Benno Schulenberg | f2da466 | 2015-12-04 21:11:10 +0000 | [diff] [blame] | 2177 | /* Display the shortcut list corresponding to menu on the last two rows |
| 2178 | * of the bottom portion of the window. */ |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2179 | void bottombars(int menu) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2180 | { |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2181 | size_t number, itemwidth, i; |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2182 | subnfunc *f; |
| 2183 | const sc *s; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2184 | |
Benno Schulenberg | d8b6dbf | 2015-04-07 14:16:07 +0000 | [diff] [blame] | 2185 | /* Set the global variable to the given menu. */ |
| 2186 | currmenu = menu; |
| 2187 | |
Benno Schulenberg | 76a960d | 2016-08-15 19:44:49 +0200 | [diff] [blame] | 2188 | if (ISSET(NO_HELP) || LINES < 5) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2189 | return; |
| 2190 | |
Benno Schulenberg | c19f0c7 | 2016-08-27 10:03:34 +0200 | [diff] [blame] | 2191 | /* Determine how many shortcuts there are to show. */ |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2192 | number = length_of_list(menu); |
Benno Schulenberg | c19f0c7 | 2016-08-27 10:03:34 +0200 | [diff] [blame] | 2193 | |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2194 | if (number > MAIN_VISIBLE) |
| 2195 | number = MAIN_VISIBLE; |
David Lawrence Ramsey | 31b159c | 2005-05-26 05:17:13 +0000 | [diff] [blame] | 2196 | |
Benno Schulenberg | 0dd2a55 | 2016-08-15 12:55:03 +0200 | [diff] [blame] | 2197 | /* Compute the width of each keyname-plus-explanation pair. */ |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2198 | itemwidth = COLS / ((number / 2) + (number % 2)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2199 | |
Benno Schulenberg | 0dd2a55 | 2016-08-15 12:55:03 +0200 | [diff] [blame] | 2200 | /* If there is no room, don't print anything. */ |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2201 | if (itemwidth == 0) |
Benno Schulenberg | 0dd2a55 | 2016-08-15 12:55:03 +0200 | [diff] [blame] | 2202 | return; |
| 2203 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2204 | blank_bottombars(); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2205 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2206 | #ifdef DEBUG |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2207 | fprintf(stderr, "In bottombars, number of items == \"%d\"\n", (int) number); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2208 | #endif |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 2209 | |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2210 | for (f = allfuncs, i = 0; i < number && f != NULL; f = f->next) { |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2211 | #ifdef DEBUG |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 2212 | fprintf(stderr, "Checking menu items...."); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2213 | #endif |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 2214 | if ((f->menus & menu) == 0) |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2215 | continue; |
David Lawrence Ramsey | 0ff01a9 | 2004-10-25 15:00:38 +0000 | [diff] [blame] | 2216 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2217 | #ifdef DEBUG |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 2218 | 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] | 2219 | #endif |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 2220 | s = first_sc_for(menu, f->scfunc); |
| 2221 | if (s == NULL) { |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2222 | #ifdef DEBUG |
| 2223 | fprintf(stderr, "Whoops, guess not, no shortcut key found for func!\n"); |
| 2224 | #endif |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 2225 | continue; |
| 2226 | } |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2227 | |
| 2228 | wmove(bottomwin, 1 + i % 2, (i / 2) * itemwidth); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 2229 | #ifdef DEBUG |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 2230 | 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] | 2231 | #endif |
Benno Schulenberg | c05c914 | 2016-08-27 10:12:05 +0200 | [diff] [blame] | 2232 | onekey(s->keystr, _(f->desc), itemwidth + (COLS % itemwidth)); |
Benno Schulenberg | 26de2dd | 2014-06-27 20:01:27 +0000 | [diff] [blame] | 2233 | i++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
Benno Schulenberg | 0a18d89 | 2016-10-12 13:56:48 +0200 | [diff] [blame] | 2236 | /* Defeat a VTE bug by moving the cursor and forcing a screen update. */ |
| 2237 | wmove(bottomwin, 0, 0); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2238 | wnoutrefresh(bottomwin); |
Benno Schulenberg | 0a18d89 | 2016-10-12 13:56:48 +0200 | [diff] [blame] | 2239 | doupdate(); |
| 2240 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2241 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 2242 | wnoutrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2245 | /* Write a shortcut key to the help area at the bottom of the window. |
| 2246 | * keystroke is e.g. "^G" and desc is e.g. "Get Help". We are careful |
Benno Schulenberg | 7f3dc2d | 2016-03-23 20:21:36 +0000 | [diff] [blame] | 2247 | * to write at most length characters, even if length is very small and |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2248 | * keystroke and desc are long. Note that waddnstr(,,(size_t)-1) adds |
| 2249 | * the whole string! We do not bother padding the entry with blanks. */ |
Benno Schulenberg | 7f3dc2d | 2016-03-23 20:21:36 +0000 | [diff] [blame] | 2250 | void onekey(const char *keystroke, const char *desc, int length) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2251 | { |
David Lawrence Ramsey | 12054fe | 2005-01-07 22:37:01 +0000 | [diff] [blame] | 2252 | assert(keystroke != NULL && desc != NULL); |
| 2253 | |
Benno Schulenberg | 960e848 | 2016-07-12 09:35:48 +0200 | [diff] [blame] | 2254 | wattron(bottomwin, interface_color_pair[KEY_COMBO]); |
Benno Schulenberg | 7f3dc2d | 2016-03-23 20:21:36 +0000 | [diff] [blame] | 2255 | waddnstr(bottomwin, keystroke, actual_x(keystroke, length)); |
Benno Schulenberg | 960e848 | 2016-07-12 09:35:48 +0200 | [diff] [blame] | 2256 | wattroff(bottomwin, interface_color_pair[KEY_COMBO]); |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2257 | |
Benno Schulenberg | 7f3dc2d | 2016-03-23 20:21:36 +0000 | [diff] [blame] | 2258 | length -= strlenpt(keystroke) + 1; |
David Lawrence Ramsey | 1903ace | 2004-12-24 00:43:41 +0000 | [diff] [blame] | 2259 | |
Benno Schulenberg | 7f3dc2d | 2016-03-23 20:21:36 +0000 | [diff] [blame] | 2260 | if (length > 0) { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2261 | waddch(bottomwin, ' '); |
Benno Schulenberg | 960e848 | 2016-07-12 09:35:48 +0200 | [diff] [blame] | 2262 | wattron(bottomwin, interface_color_pair[FUNCTION_TAG]); |
Benno Schulenberg | 7f3dc2d | 2016-03-23 20:21:36 +0000 | [diff] [blame] | 2263 | waddnstr(bottomwin, desc, actual_x(desc, length)); |
Benno Schulenberg | 960e848 | 2016-07-12 09:35:48 +0200 | [diff] [blame] | 2264 | wattroff(bottomwin, interface_color_pair[FUNCTION_TAG]); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
Benno Schulenberg | 344fe55 | 2016-03-23 20:04:33 +0000 | [diff] [blame] | 2268 | /* Redetermine current_y from the position of current relative to edittop, |
| 2269 | * and put the cursor in the edit window at (current_y, current_x). */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2270 | void reset_cursor(void) |
| 2271 | { |
Benno Schulenberg | 6fc70cc | 2016-03-23 19:48:44 +0000 | [diff] [blame] | 2272 | size_t xpt = xplustabs(); |
David Lawrence Ramsey | 964722a | 2006-05-26 03:02:50 +0000 | [diff] [blame] | 2273 | |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2274 | #ifndef NANO_TINY |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2275 | if (ISSET(SOFTWRAP)) { |
Benno Schulenberg | 344fe55 | 2016-03-23 20:04:33 +0000 | [diff] [blame] | 2276 | filestruct *line = openfile->edittop; |
Chris Allegretta | 6f08332 | 2009-11-11 06:00:33 +0000 | [diff] [blame] | 2277 | openfile->current_y = 0; |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2278 | |
Benno Schulenberg | 344fe55 | 2016-03-23 20:04:33 +0000 | [diff] [blame] | 2279 | while (line != NULL && line != openfile->current) { |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2280 | openfile->current_y += strlenpt(line->data) / editwincols + 1; |
Benno Schulenberg | 344fe55 | 2016-03-23 20:04:33 +0000 | [diff] [blame] | 2281 | line = line->next; |
| 2282 | } |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2283 | openfile->current_y += xpt / editwincols; |
Benno Schulenberg | 344fe55 | 2016-03-23 20:04:33 +0000 | [diff] [blame] | 2284 | |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2285 | if (openfile->current_y < editwinrows) |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2286 | wmove(edit, openfile->current_y, xpt % editwincols + margin); |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2287 | } else |
| 2288 | #endif |
| 2289 | { |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2290 | openfile->current_y = openfile->current->lineno - |
Benno Schulenberg | 344fe55 | 2016-03-23 20:04:33 +0000 | [diff] [blame] | 2291 | openfile->edittop->lineno; |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2292 | |
| 2293 | if (openfile->current_y < editwinrows) |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2294 | wmove(edit, openfile->current_y, xpt - get_page_start(xpt) + margin); |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2295 | } |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 2296 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2297 | |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2298 | /* edit_draw() takes care of the job of actually painting a line into |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2299 | * the edit window. fileptr is the line to be painted, at row row of |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2300 | * the window. converted is the actual string to be written to the |
| 2301 | * window, with tabs and control characters replaced by strings of |
Benno Schulenberg | 6103c47 | 2017-01-08 10:20:57 +0100 | [diff] [blame] | 2302 | * regular characters. from_col is the column number of the first |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2303 | * character of this page. That is, the first character of converted |
Benno Schulenberg | 6103c47 | 2017-01-08 10:20:57 +0100 | [diff] [blame] | 2304 | * corresponds to character number actual_x(fileptr->data, from_col) of the |
David Lawrence Ramsey | a0aff67 | 2005-10-27 20:10:45 +0000 | [diff] [blame] | 2305 | * line. */ |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2306 | void edit_draw(filestruct *fileptr, const char *converted, |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2307 | int row, size_t from_col) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2308 | { |
Benno Schulenberg | 0038992 | 2014-04-04 11:59:03 +0000 | [diff] [blame] | 2309 | #if !defined(NANO_TINY) || !defined(DISABLE_COLOR) |
Benno Schulenberg | 6103c47 | 2017-01-08 10:20:57 +0100 | [diff] [blame] | 2310 | size_t from_x = actual_x(fileptr->data, from_col); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2311 | /* The position in fileptr->data of the leftmost character |
| 2312 | * that displays at least partially on the window. */ |
Benno Schulenberg | 6103c47 | 2017-01-08 10:20:57 +0100 | [diff] [blame] | 2313 | size_t till_x = actual_x(fileptr->data, from_col + editwincols - 1) + 1; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2314 | /* The position in fileptr->data of the first character that is |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2315 | * completely off the window to the right. Note that till_x |
| 2316 | * might be beyond the null terminator of the string. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2317 | #endif |
| 2318 | |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2319 | assert(openfile != NULL && fileptr != NULL && converted != NULL); |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2320 | assert(strlenpt(converted) <= editwincols); |
| 2321 | |
| 2322 | #ifdef ENABLE_LINENUMBERS |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2323 | /* If line numbering is switched on, put a line number in front of |
Benno Schulenberg | 023edff | 2016-10-21 14:31:37 +0200 | [diff] [blame] | 2324 | * the text -- but only for the parts that are not softwrapped. */ |
| 2325 | if (margin > 0) { |
Benno Schulenberg | de2aa4f | 2016-10-20 10:07:48 +0200 | [diff] [blame] | 2326 | wattron(edit, interface_color_pair[LINE_NUMBER]); |
David Lawrence Ramsey | c9f743f | 2016-12-09 11:51:41 -0600 | [diff] [blame] | 2327 | #ifndef NANO_TINY |
Benno Schulenberg | 08cfdbc | 2017-01-08 11:49:59 +0100 | [diff] [blame] | 2328 | if (ISSET(SOFTWRAP) && from_x != 0) |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2329 | mvwprintw(edit, row, 0, "%*s", margin - 1, " "); |
David Lawrence Ramsey | c9f743f | 2016-12-09 11:51:41 -0600 | [diff] [blame] | 2330 | else |
| 2331 | #endif |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2332 | mvwprintw(edit, row, 0, "%*ld", margin - 1, (long)fileptr->lineno); |
Benno Schulenberg | de2aa4f | 2016-10-20 10:07:48 +0200 | [diff] [blame] | 2333 | wattroff(edit, interface_color_pair[LINE_NUMBER]); |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2334 | } |
| 2335 | #endif |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2336 | |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2337 | /* First simply write the converted line -- afterward we'll add colors |
| 2338 | * and the marking highlight on just the pieces that need it. */ |
| 2339 | mvwaddstr(edit, row, margin, converted); |
Benno Schulenberg | 1de337d | 2014-06-04 16:02:51 +0000 | [diff] [blame] | 2340 | |
Benno Schulenberg | 8c7a385 | 2016-07-12 21:05:09 +0200 | [diff] [blame] | 2341 | #ifdef USING_OLD_NCURSES |
Benno Schulenberg | 1de337d | 2014-06-04 16:02:51 +0000 | [diff] [blame] | 2342 | /* Tell ncurses to really redraw the line without trying to optimize |
| 2343 | * for what it thinks is already there, because it gets it wrong in |
| 2344 | * the case of a wide character in column zero. See bug #31743. */ |
Benno Schulenberg | 954d04b | 2015-09-05 09:14:24 +0000 | [diff] [blame] | 2345 | if (seen_wide) |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2346 | wredrawln(edit, row, 1); |
Chris Allegretta | cfa2976 | 2014-05-28 01:35:51 +0000 | [diff] [blame] | 2347 | #endif |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2348 | |
Benno Schulenberg | 0038992 | 2014-04-04 11:59:03 +0000 | [diff] [blame] | 2349 | #ifndef DISABLE_COLOR |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2350 | /* If color syntaxes are available and turned on, apply them. */ |
David Lawrence Ramsey | db95802 | 2005-07-13 20:18:46 +0000 | [diff] [blame] | 2351 | if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) { |
Benno Schulenberg | 8fea347 | 2016-03-13 20:13:16 +0000 | [diff] [blame] | 2352 | const colortype *varnish = openfile->colorstrings; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2353 | |
Benno Schulenberg | ee33503 | 2015-11-29 13:20:08 +0000 | [diff] [blame] | 2354 | /* If there are multiline regexes, make sure there is a cache. */ |
| 2355 | if (openfile->syntax->nmultis > 0) |
| 2356 | alloc_multidata_if_needed(fileptr); |
| 2357 | |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2358 | /* Iterate through all the coloring regexes. */ |
Benno Schulenberg | 8fea347 | 2016-03-13 20:13:16 +0000 | [diff] [blame] | 2359 | for (; varnish != NULL; varnish = varnish->next) { |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2360 | size_t index = 0; |
| 2361 | /* Where in the line we currently begin looking for a match. */ |
Benno Schulenberg | 5dbd288 | 2017-01-08 12:32:24 +0100 | [diff] [blame] | 2362 | int start_col; |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2363 | /* The starting column of a piece to paint. Zero-based. */ |
Benno Schulenberg | 26ae9db | 2015-06-14 18:06:36 +0000 | [diff] [blame] | 2364 | int paintlen = 0; |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2365 | /* The number of characters to paint. */ |
| 2366 | const char *thetext; |
| 2367 | /* The place in converted from where painting starts. */ |
Benno Schulenberg | af7201f | 2017-01-20 21:32:43 +0100 | [diff] [blame] | 2368 | regmatch_t match; |
| 2369 | /* The match positions of a single-line regex. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2370 | |
David Lawrence Ramsey | b0e04c0 | 2005-12-08 07:24:54 +0000 | [diff] [blame] | 2371 | /* Two notes about regexec(). A return value of zero means |
| 2372 | * that there is a match. Also, rm_eo is the first |
| 2373 | * non-matching character after the match. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2374 | |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2375 | wattron(edit, varnish->attributes); |
| 2376 | |
Benno Schulenberg | 8fea347 | 2016-03-13 20:13:16 +0000 | [diff] [blame] | 2377 | /* First case: varnish is a single-line expression. */ |
| 2378 | if (varnish->end == NULL) { |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2379 | /* We increment index by rm_eo, to move past the end of the |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2380 | * last match. Even though two matches may overlap, we |
David Lawrence Ramsey | 2ef7dae | 2006-05-26 11:58:37 +0000 | [diff] [blame] | 2381 | * want to ignore them, so that we can highlight e.g. C |
| 2382 | * strings correctly. */ |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2383 | while (index < till_x) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2384 | /* Note the fifth parameter to regexec(). It says |
| 2385 | * not to match the beginning-of-line character |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2386 | * unless index is zero. If regexec() returns |
David Lawrence Ramsey | 2ef7dae | 2006-05-26 11:58:37 +0000 | [diff] [blame] | 2387 | * REG_NOMATCH, there are no more matches in the |
| 2388 | * line. */ |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2389 | if (regexec(varnish->start, &fileptr->data[index], 1, |
Benno Schulenberg | 23595c8 | 2017-01-20 19:44:46 +0100 | [diff] [blame] | 2390 | &match, (index == 0) ? 0 : REG_NOTBOL) != 0) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2391 | break; |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2392 | |
Benno Schulenberg | 6694535 | 2017-01-20 19:20:30 +0100 | [diff] [blame] | 2393 | /* If the match is of length zero, skip it. */ |
Benno Schulenberg | 23595c8 | 2017-01-20 19:44:46 +0100 | [diff] [blame] | 2394 | if (match.rm_so == match.rm_eo) { |
Benno Schulenberg | 6694535 | 2017-01-20 19:20:30 +0100 | [diff] [blame] | 2395 | index = move_mbright(fileptr->data, |
Benno Schulenberg | 23595c8 | 2017-01-20 19:44:46 +0100 | [diff] [blame] | 2396 | index + match.rm_eo); |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2397 | continue; |
| 2398 | } |
| 2399 | |
| 2400 | /* Translate the match to the beginning of the line. */ |
Benno Schulenberg | 23595c8 | 2017-01-20 19:44:46 +0100 | [diff] [blame] | 2401 | match.rm_so += index; |
| 2402 | match.rm_eo += index; |
| 2403 | index = match.rm_eo; |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2404 | |
Benno Schulenberg | 23595c8 | 2017-01-20 19:44:46 +0100 | [diff] [blame] | 2405 | /* If the matching part is not visible, skip it. */ |
| 2406 | if (match.rm_eo <= from_x || match.rm_so >= till_x) |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2407 | continue; |
| 2408 | |
Benno Schulenberg | 23595c8 | 2017-01-20 19:44:46 +0100 | [diff] [blame] | 2409 | start_col = (match.rm_so <= from_x) ? |
| 2410 | 0 : strnlenpt(fileptr->data, |
| 2411 | match.rm_so) - from_col; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2412 | |
Benno Schulenberg | 26683a9 | 2017-01-08 21:31:49 +0100 | [diff] [blame] | 2413 | thetext = converted + actual_x(converted, start_col); |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2414 | |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2415 | paintlen = actual_x(thetext, strnlenpt(fileptr->data, |
Benno Schulenberg | 23595c8 | 2017-01-20 19:44:46 +0100 | [diff] [blame] | 2416 | match.rm_eo) - from_col - start_col); |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2417 | |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2418 | mvwaddnstr(edit, row, margin + start_col, |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2419 | thetext, paintlen); |
| 2420 | } |
| 2421 | goto tail_of_loop; |
| 2422 | } |
| 2423 | |
| 2424 | /* Second case: varnish is a multiline expression. */ |
| 2425 | const filestruct *start_line = fileptr->prev; |
| 2426 | /* The first line before fileptr that matches 'start'. */ |
| 2427 | const filestruct *end_line = fileptr; |
| 2428 | /* The line that matches 'end'. */ |
Benno Schulenberg | af7201f | 2017-01-20 21:32:43 +0100 | [diff] [blame] | 2429 | regmatch_t startmatch, endmatch; |
| 2430 | /* The match positions of the start and end regexes. */ |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2431 | |
Benno Schulenberg | fccfccc | 2017-02-13 17:28:38 +0100 | [diff] [blame] | 2432 | /* Assume nothing gets painted until proven otherwise below. */ |
| 2433 | fileptr->multidata[varnish->id] = CNONE; |
| 2434 | |
Benno Schulenberg | b3bcc8e | 2017-01-23 14:41:25 +0100 | [diff] [blame] | 2435 | /* First check the multidata of the preceding line -- it tells |
| 2436 | * us about the situation so far, and thus what to do here. */ |
| 2437 | if (start_line != NULL && start_line->multidata != NULL) { |
| 2438 | if (start_line->multidata[varnish->id] == CWHOLELINE || |
Benno Schulenberg | fccfccc | 2017-02-13 17:28:38 +0100 | [diff] [blame] | 2439 | start_line->multidata[varnish->id] == CENDAFTER || |
| 2440 | start_line->multidata[varnish->id] == CWOULDBE) |
Benno Schulenberg | b3bcc8e | 2017-01-23 14:41:25 +0100 | [diff] [blame] | 2441 | goto seek_an_end; |
Benno Schulenberg | b3bcc8e | 2017-01-23 14:41:25 +0100 | [diff] [blame] | 2442 | if (start_line->multidata[varnish->id] == CNONE || |
| 2443 | start_line->multidata[varnish->id] == CBEGINBEFORE || |
Benno Schulenberg | fccfccc | 2017-02-13 17:28:38 +0100 | [diff] [blame] | 2444 | start_line->multidata[varnish->id] == CSTARTENDHERE) |
Benno Schulenberg | b3bcc8e | 2017-01-23 14:41:25 +0100 | [diff] [blame] | 2445 | goto step_two; |
Benno Schulenberg | b3bcc8e | 2017-01-23 14:41:25 +0100 | [diff] [blame] | 2446 | } |
| 2447 | |
Benno Schulenberg | 6bd9404 | 2017-02-12 20:28:14 +0100 | [diff] [blame] | 2448 | /* The preceding line has no precalculated multidata. So, do |
| 2449 | * some backtracking to find out what to paint. */ |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2450 | |
Benno Schulenberg | fccfccc | 2017-02-13 17:28:38 +0100 | [diff] [blame] | 2451 | /* First step: see if there is a line before current that |
| 2452 | * matches 'start' and is not complemented by an 'end'. */ |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2453 | while (start_line != NULL && regexec(varnish->start, |
| 2454 | start_line->data, 1, &startmatch, 0) == REG_NOMATCH) { |
Benno Schulenberg | fccfccc | 2017-02-13 17:28:38 +0100 | [diff] [blame] | 2455 | /* There is no start on this line; but if there is an end, |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2456 | * there is no need to look for starts on earlier lines. */ |
| 2457 | if (regexec(varnish->end, start_line->data, 0, NULL, 0) == 0) |
| 2458 | goto step_two; |
| 2459 | start_line = start_line->prev; |
| 2460 | } |
| 2461 | |
| 2462 | /* If no start was found, skip to the next step. */ |
| 2463 | if (start_line == NULL) |
| 2464 | goto step_two; |
| 2465 | |
| 2466 | /* If a found start has been qualified as an end earlier, |
| 2467 | * believe it and skip to the next step. */ |
| 2468 | if (start_line->multidata != NULL && |
| 2469 | (start_line->multidata[varnish->id] == CBEGINBEFORE || |
| 2470 | start_line->multidata[varnish->id] == CSTARTENDHERE)) |
| 2471 | goto step_two; |
| 2472 | |
Benno Schulenberg | fccfccc | 2017-02-13 17:28:38 +0100 | [diff] [blame] | 2473 | /* Is there an uncomplemented start on the found line? */ |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2474 | while (TRUE) { |
Benno Schulenberg | 94907aa | 2017-01-20 13:31:18 +0100 | [diff] [blame] | 2475 | /* Begin searching for an end after the start match. */ |
Benno Schulenberg | 7e5524b | 2017-01-20 10:58:15 +0100 | [diff] [blame] | 2476 | index += startmatch.rm_eo; |
Benno Schulenberg | 94907aa | 2017-01-20 13:31:18 +0100 | [diff] [blame] | 2477 | /* If there is no end after this last start, good. */ |
Benno Schulenberg | 1d10d79 | 2017-01-22 10:12:27 +0100 | [diff] [blame] | 2478 | if (regexec(varnish->end, start_line->data + index, 1, &endmatch, |
| 2479 | (index == 0) ? 0 : REG_NOTBOL) == REG_NOMATCH) |
Benno Schulenberg | 94907aa | 2017-01-20 13:31:18 +0100 | [diff] [blame] | 2480 | break; |
Benno Schulenberg | 9a4a545 | 2017-01-21 11:58:00 +0100 | [diff] [blame] | 2481 | /* Begin searching for a new start after the end match. */ |
| 2482 | index += endmatch.rm_eo; |
Benno Schulenberg | 8441887 | 2017-01-21 19:35:11 +0100 | [diff] [blame] | 2483 | /* If both start and end match are mere anchors, advance. */ |
| 2484 | if (startmatch.rm_so == startmatch.rm_eo && |
| 2485 | endmatch.rm_so == endmatch.rm_eo) { |
Benno Schulenberg | 775f007 | 2017-01-21 18:18:34 +0100 | [diff] [blame] | 2486 | if (start_line->data[index] == '\0') |
Benno Schulenberg | 9a4a545 | 2017-01-21 11:58:00 +0100 | [diff] [blame] | 2487 | break; |
Benno Schulenberg | 775f007 | 2017-01-21 18:18:34 +0100 | [diff] [blame] | 2488 | index = move_mbright(start_line->data, index); |
Benno Schulenberg | 9a4a545 | 2017-01-21 11:58:00 +0100 | [diff] [blame] | 2489 | } |
Benno Schulenberg | 94907aa | 2017-01-20 13:31:18 +0100 | [diff] [blame] | 2490 | /* If there is no later start on this line, next step. */ |
| 2491 | if (regexec(varnish->start, start_line->data + index, |
| 2492 | 1, &startmatch, REG_NOTBOL) == REG_NOMATCH) |
| 2493 | goto step_two; |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2494 | } |
| 2495 | /* Indeed, there is a start without an end on that line. */ |
| 2496 | |
Benno Schulenberg | b3bcc8e | 2017-01-23 14:41:25 +0100 | [diff] [blame] | 2497 | seek_an_end: |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2498 | /* We've already checked that there is no end between the start |
| 2499 | * and the current line. But is there an end after the start |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2500 | * at all? We don't paint unterminated starts. */ |
| 2501 | while (end_line != NULL && regexec(varnish->end, end_line->data, |
| 2502 | 1, &endmatch, 0) == REG_NOMATCH) |
| 2503 | end_line = end_line->next; |
| 2504 | |
Benno Schulenberg | a898fa5 | 2017-01-09 19:14:51 +0100 | [diff] [blame] | 2505 | /* If there is no end, there is nothing to paint. */ |
Benno Schulenberg | 7ef5c53 | 2017-02-12 22:34:31 +0100 | [diff] [blame] | 2506 | if (end_line == NULL) { |
| 2507 | fileptr->multidata[varnish->id] = CWOULDBE; |
Benno Schulenberg | a898fa5 | 2017-01-09 19:14:51 +0100 | [diff] [blame] | 2508 | goto tail_of_loop; |
Benno Schulenberg | 7ef5c53 | 2017-02-12 22:34:31 +0100 | [diff] [blame] | 2509 | } |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2510 | |
Benno Schulenberg | 2f80193 | 2017-01-20 21:27:49 +0100 | [diff] [blame] | 2511 | /* If the end is on a later line, paint whole line, and be done. */ |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2512 | if (end_line != fileptr) { |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2513 | mvwaddnstr(edit, row, margin, converted, -1); |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2514 | fileptr->multidata[varnish->id] = CWHOLELINE; |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2515 | goto tail_of_loop; |
Benno Schulenberg | 2f80193 | 2017-01-20 21:27:49 +0100 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | /* Only if it is visible, paint the part to be coloured. */ |
| 2519 | if (endmatch.rm_eo > from_x) { |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2520 | paintlen = actual_x(converted, strnlenpt(fileptr->data, |
| 2521 | endmatch.rm_eo) - from_col); |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2522 | mvwaddnstr(edit, row, margin, converted, paintlen); |
Benno Schulenberg | 2f80193 | 2017-01-20 21:27:49 +0100 | [diff] [blame] | 2523 | } |
| 2524 | fileptr->multidata[varnish->id] = CBEGINBEFORE; |
Benno Schulenberg | 0314880 | 2017-02-13 17:09:17 +0100 | [diff] [blame] | 2525 | |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2526 | step_two: |
| 2527 | /* Second step: look for starts on this line, but begin |
| 2528 | * looking only after an end match, if there is one. */ |
| 2529 | index = (paintlen == 0) ? 0 : endmatch.rm_eo; |
| 2530 | |
| 2531 | while (regexec(varnish->start, fileptr->data + index, |
| 2532 | 1, &startmatch, (index == 0) ? |
Benno Schulenberg | 07e806e | 2015-12-01 13:33:45 +0000 | [diff] [blame] | 2533 | 0 : REG_NOTBOL) == 0) { |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2534 | /* Translate the match to be relative to the |
| 2535 | * beginning of the line. */ |
| 2536 | startmatch.rm_so += index; |
| 2537 | startmatch.rm_eo += index; |
| 2538 | |
| 2539 | start_col = (startmatch.rm_so <= from_x) ? |
| 2540 | 0 : strnlenpt(fileptr->data, |
| 2541 | startmatch.rm_so) - from_col; |
| 2542 | |
| 2543 | thetext = converted + actual_x(converted, start_col); |
| 2544 | |
| 2545 | if (regexec(varnish->end, fileptr->data + startmatch.rm_eo, |
| 2546 | 1, &endmatch, (startmatch.rm_eo == 0) ? |
| 2547 | 0 : REG_NOTBOL) == 0) { |
| 2548 | /* Translate the end match to be relative to |
| 2549 | * the beginning of the line. */ |
| 2550 | endmatch.rm_so += startmatch.rm_eo; |
| 2551 | endmatch.rm_eo += startmatch.rm_eo; |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2552 | /* Only paint the match if it is visible on screen and |
| 2553 | * it is more than zero characters long. */ |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2554 | if (endmatch.rm_eo > from_x && |
Benno Schulenberg | 88cf22f | 2017-01-07 20:42:37 +0100 | [diff] [blame] | 2555 | endmatch.rm_eo > startmatch.rm_so) { |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2556 | paintlen = actual_x(thetext, strnlenpt(fileptr->data, |
Benno Schulenberg | 5dbd288 | 2017-01-08 12:32:24 +0100 | [diff] [blame] | 2557 | endmatch.rm_eo) - from_col - start_col); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2558 | |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2559 | mvwaddnstr(edit, row, margin + start_col, |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2560 | thetext, paintlen); |
Benno Schulenberg | 8177e62 | 2017-01-03 21:18:24 +0100 | [diff] [blame] | 2561 | |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2562 | fileptr->multidata[varnish->id] = CSTARTENDHERE; |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2563 | } |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2564 | index = endmatch.rm_eo; |
Benno Schulenberg | 8441887 | 2017-01-21 19:35:11 +0100 | [diff] [blame] | 2565 | /* If both start and end match are anchors, advance. */ |
| 2566 | if (startmatch.rm_so == startmatch.rm_eo && |
| 2567 | endmatch.rm_so == endmatch.rm_eo) { |
Benno Schulenberg | 775f007 | 2017-01-21 18:18:34 +0100 | [diff] [blame] | 2568 | if (fileptr->data[index] == '\0') |
Benno Schulenberg | 6694535 | 2017-01-20 19:20:30 +0100 | [diff] [blame] | 2569 | break; |
Benno Schulenberg | 775f007 | 2017-01-21 18:18:34 +0100 | [diff] [blame] | 2570 | index = move_mbright(fileptr->data, index); |
Benno Schulenberg | 6694535 | 2017-01-20 19:20:30 +0100 | [diff] [blame] | 2571 | } |
| 2572 | continue; |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2573 | } |
Benno Schulenberg | 38d7362 | 2017-01-08 22:04:43 +0100 | [diff] [blame] | 2574 | |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2575 | /* There is no end on this line. But maybe on later lines? */ |
| 2576 | end_line = fileptr->next; |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2577 | |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2578 | while (end_line != NULL && regexec(varnish->end, end_line->data, |
| 2579 | 0, NULL, 0) == REG_NOMATCH) |
| 2580 | end_line = end_line->next; |
David Lawrence Ramsey | 14ace17 | 2005-01-24 21:51:07 +0000 | [diff] [blame] | 2581 | |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2582 | /* If there is no end, we're done with this regex. */ |
Benno Schulenberg | 7ef5c53 | 2017-02-12 22:34:31 +0100 | [diff] [blame] | 2583 | if (end_line == NULL) { |
| 2584 | fileptr->multidata[varnish->id] = CWOULDBE; |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2585 | break; |
Benno Schulenberg | 7ef5c53 | 2017-02-12 22:34:31 +0100 | [diff] [blame] | 2586 | } |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2587 | |
Benno Schulenberg | 0314880 | 2017-02-13 17:09:17 +0100 | [diff] [blame] | 2588 | /* Paint the rest of the line, and we're done. */ |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2589 | mvwaddnstr(edit, row, margin + start_col, thetext, -1); |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2590 | fileptr->multidata[varnish->id] = CENDAFTER; |
Benno Schulenberg | f6fbc15 | 2017-01-09 11:49:35 +0100 | [diff] [blame] | 2591 | break; |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2592 | } |
Benno Schulenberg | eee07d5 | 2015-12-01 12:49:17 +0000 | [diff] [blame] | 2593 | tail_of_loop: |
Rishabh Dave | 4c566c7 | 2016-07-17 18:59:07 +0530 | [diff] [blame] | 2594 | wattroff(edit, varnish->attributes); |
David Lawrence Ramsey | 202d3c2 | 2005-03-10 20:55:11 +0000 | [diff] [blame] | 2595 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2596 | } |
Benno Schulenberg | 0038992 | 2014-04-04 11:59:03 +0000 | [diff] [blame] | 2597 | #endif /* !DISABLE_COLOR */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2598 | |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2599 | #ifndef NANO_TINY |
Benno Schulenberg | 95f417f | 2016-06-14 11:06:04 +0200 | [diff] [blame] | 2600 | /* If the mark is on, and fileptr is at least partially selected, we |
| 2601 | * need to paint it. */ |
| 2602 | if (openfile->mark_set && |
| 2603 | (fileptr->lineno <= openfile->mark_begin->lineno || |
| 2604 | fileptr->lineno <= openfile->current->lineno) && |
| 2605 | (fileptr->lineno >= openfile->mark_begin->lineno || |
| 2606 | fileptr->lineno >= openfile->current->lineno)) { |
| 2607 | const filestruct *top, *bot; |
| 2608 | /* The lines where the marked region begins and ends. */ |
| 2609 | size_t top_x, bot_x; |
| 2610 | /* The x positions where the marked region begins and ends. */ |
Benno Schulenberg | 5dbd288 | 2017-01-08 12:32:24 +0100 | [diff] [blame] | 2611 | int start_col; |
Benno Schulenberg | a894372 | 2017-01-08 13:01:45 +0100 | [diff] [blame] | 2612 | /* The column where painting starts. Zero-based. */ |
| 2613 | const char *thetext; |
| 2614 | /* The place in converted from where painting starts. */ |
| 2615 | int paintlen = -1; |
| 2616 | /* The number of characters to paint. Negative means "all". */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2617 | |
David Lawrence Ramsey | 90e59c1 | 2004-11-05 23:03:03 +0000 | [diff] [blame] | 2618 | mark_order(&top, &top_x, &bot, &bot_x, NULL); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2619 | |
Benno Schulenberg | 6103c47 | 2017-01-08 10:20:57 +0100 | [diff] [blame] | 2620 | if (top->lineno < fileptr->lineno || top_x < from_x) |
| 2621 | top_x = from_x; |
| 2622 | if (bot->lineno > fileptr->lineno || bot_x > till_x) |
| 2623 | bot_x = till_x; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2624 | |
Benno Schulenberg | 5dbd288 | 2017-01-08 12:32:24 +0100 | [diff] [blame] | 2625 | /* Only paint if the marked part of the line is on this page. */ |
Benno Schulenberg | 6103c47 | 2017-01-08 10:20:57 +0100 | [diff] [blame] | 2626 | if (top_x < till_x && bot_x > from_x) { |
Benno Schulenberg | 5dbd288 | 2017-01-08 12:32:24 +0100 | [diff] [blame] | 2627 | /* Compute on which screen column to start painting. */ |
| 2628 | start_col = strnlenpt(fileptr->data, top_x) - from_col; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2629 | |
Benno Schulenberg | a894372 | 2017-01-08 13:01:45 +0100 | [diff] [blame] | 2630 | thetext = converted + actual_x(converted, start_col); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2631 | |
Benno Schulenberg | a894372 | 2017-01-08 13:01:45 +0100 | [diff] [blame] | 2632 | /* If the end of the mark is onscreen, compute how many |
| 2633 | * characters to paint. Otherwise, just paint all. */ |
| 2634 | if (bot_x < till_x) { |
| 2635 | size_t end_col = strnlenpt(fileptr->data, bot_x) - from_col; |
| 2636 | paintlen = actual_x(thetext, end_col - start_col); |
| 2637 | } |
David Lawrence Ramsey | 68e3016 | 2005-01-03 22:23:00 +0000 | [diff] [blame] | 2638 | |
Benno Schulenberg | c970035 | 2014-05-04 08:53:06 +0000 | [diff] [blame] | 2639 | wattron(edit, hilite_attribute); |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2640 | mvwaddnstr(edit, row, margin + start_col, thetext, paintlen); |
Benno Schulenberg | c970035 | 2014-05-04 08:53:06 +0000 | [diff] [blame] | 2641 | wattroff(edit, hilite_attribute); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2642 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 2643 | } |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2644 | #endif /* !NANO_TINY */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2645 | } |
| 2646 | |
David Lawrence Ramsey | c67c431 | 2017-01-12 17:55:22 -0600 | [diff] [blame] | 2647 | /* Redraw the line at fileptr. The line will be displayed so that the |
| 2648 | * character with the given index is visible -- if necessary, the line |
| 2649 | * will be horizontally scrolled. In softwrap mode, however, the entire |
| 2650 | * line will be displayed. Likely values of index are current_x or zero. |
| 2651 | * Return the number of additional rows consumed (when softwrapping). */ |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2652 | int update_line(filestruct *fileptr, size_t index) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2653 | { |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2654 | int row = 0; |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2655 | /* The row in the edit window we will be updating. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2656 | char *converted; |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2657 | /* The data of the line with tabs and control characters expanded. */ |
Benno Schulenberg | b7c2513 | 2017-01-12 18:25:50 +0100 | [diff] [blame] | 2658 | size_t from_col = 0; |
| 2659 | /* From which column a horizontally scrolled line is displayed. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2660 | |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2661 | #ifndef NANO_TINY |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2662 | if (ISSET(SOFTWRAP)) { |
Benno Schulenberg | b7c2513 | 2017-01-12 18:25:50 +0100 | [diff] [blame] | 2663 | filestruct *line = openfile->edittop; |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2664 | |
Benno Schulenberg | 9bb64fc | 2017-01-13 17:47:55 +0100 | [diff] [blame] | 2665 | /* Find out on which screen row the target line should be shown. */ |
Benno Schulenberg | b7c2513 | 2017-01-12 18:25:50 +0100 | [diff] [blame] | 2666 | while (line != fileptr && line != NULL) { |
| 2667 | row += (strlenpt(line->data) / editwincols) + 1; |
| 2668 | line = line->next; |
| 2669 | } |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2670 | } else |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2671 | #endif |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2672 | row = fileptr->lineno - openfile->edittop->lineno; |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2673 | |
David Lawrence Ramsey | 6e3adf3 | 2016-12-28 10:22:05 -0600 | [diff] [blame] | 2674 | /* If the line is offscreen, don't even try to display it. */ |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2675 | if (row < 0 || row >= editwinrows) |
David Lawrence Ramsey | 6e3adf3 | 2016-12-28 10:22:05 -0600 | [diff] [blame] | 2676 | return 0; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2677 | |
Benno Schulenberg | 980e334 | 2017-01-13 19:11:11 +0100 | [diff] [blame] | 2678 | #ifndef NANO_TINY |
Benno Schulenberg | 5d5666f | 2017-01-13 19:18:08 +0100 | [diff] [blame] | 2679 | if (ISSET(SOFTWRAP)) { |
Benno Schulenberg | 53435b0 | 2014-06-10 19:07:47 +0000 | [diff] [blame] | 2680 | size_t full_length = strlenpt(fileptr->data); |
Benno Schulenberg | 9f88481 | 2017-01-13 19:25:16 +0100 | [diff] [blame] | 2681 | int starting_row = row; |
Benno Schulenberg | b7c2513 | 2017-01-12 18:25:50 +0100 | [diff] [blame] | 2682 | |
Benno Schulenberg | 980e334 | 2017-01-13 19:11:11 +0100 | [diff] [blame] | 2683 | for (from_col = 0; from_col <= full_length && |
| 2684 | row < editwinrows; from_col += editwincols) { |
David Lawrence Ramsey | c67c431 | 2017-01-12 17:55:22 -0600 | [diff] [blame] | 2685 | /* First, blank out the row. */ |
Benno Schulenberg | 980e334 | 2017-01-13 19:11:11 +0100 | [diff] [blame] | 2686 | blank_row(edit, row, 0, COLS); |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2687 | |
| 2688 | /* Expand the line, replacing tabs with spaces, and control |
Benno Schulenberg | 71c9a52 | 2014-05-13 20:14:01 +0000 | [diff] [blame] | 2689 | * characters with their displayed forms. */ |
Benno Schulenberg | b7c2513 | 2017-01-12 18:25:50 +0100 | [diff] [blame] | 2690 | converted = display_string(fileptr->data, from_col, editwincols, TRUE); |
Benno Schulenberg | 9bb64fc | 2017-01-13 17:47:55 +0100 | [diff] [blame] | 2691 | |
Benno Schulenberg | 892762d | 2017-01-12 18:00:54 +0100 | [diff] [blame] | 2692 | /* Draw the line. */ |
Benno Schulenberg | 980e334 | 2017-01-13 19:11:11 +0100 | [diff] [blame] | 2693 | edit_draw(fileptr, converted, row++, from_col); |
Benno Schulenberg | 71c9a52 | 2014-05-13 20:14:01 +0000 | [diff] [blame] | 2694 | free(converted); |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2695 | } |
Benno Schulenberg | 980e334 | 2017-01-13 19:11:11 +0100 | [diff] [blame] | 2696 | |
Benno Schulenberg | 9f88481 | 2017-01-13 19:25:16 +0100 | [diff] [blame] | 2697 | return (row - starting_row); |
Chris Allegretta | 05417a2 | 2009-08-17 07:52:10 +0000 | [diff] [blame] | 2698 | } |
Benno Schulenberg | 9bb64fc | 2017-01-13 17:47:55 +0100 | [diff] [blame] | 2699 | #endif |
David Lawrence Ramsey | c67c431 | 2017-01-12 17:55:22 -0600 | [diff] [blame] | 2700 | |
Benno Schulenberg | 5d5666f | 2017-01-13 19:18:08 +0100 | [diff] [blame] | 2701 | /* First, blank out the row. */ |
| 2702 | blank_row(edit, row, 0, COLS); |
| 2703 | |
| 2704 | /* Next, find out from which column to start displaying the line. */ |
| 2705 | from_col = get_page_start(strnlenpt(fileptr->data, index)); |
| 2706 | |
| 2707 | /* Expand the line, replacing tabs with spaces, and control |
| 2708 | * characters with their displayed forms. */ |
| 2709 | converted = display_string(fileptr->data, from_col, editwincols, TRUE); |
| 2710 | |
| 2711 | /* Draw the line. */ |
| 2712 | edit_draw(fileptr, converted, row, from_col); |
| 2713 | free(converted); |
| 2714 | |
| 2715 | if (from_col > 0) |
| 2716 | mvwaddch(edit, row, margin, '$'); |
| 2717 | if (strlenpt(fileptr->data) > from_col + editwincols) |
| 2718 | mvwaddch(edit, row, COLS - 1, '$'); |
| 2719 | |
Benno Schulenberg | 9f88481 | 2017-01-13 19:25:16 +0100 | [diff] [blame] | 2720 | return 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
Benno Schulenberg | 2f66476 | 2016-07-26 19:47:00 +0200 | [diff] [blame] | 2723 | /* Check whether old_column and new_column are on different "pages" (or that |
| 2724 | * the mark is on), which means that the relevant line needs to be redrawn. */ |
| 2725 | bool need_horizontal_scroll(const size_t old_column, const size_t new_column) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2726 | { |
David Lawrence Ramsey | ebe3425 | 2005-11-15 03:17:35 +0000 | [diff] [blame] | 2727 | #ifndef NANO_TINY |
Benno Schulenberg | 2f66476 | 2016-07-26 19:47:00 +0200 | [diff] [blame] | 2728 | if (openfile->mark_set) |
| 2729 | return TRUE; |
| 2730 | else |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2731 | #endif |
Benno Schulenberg | 2f66476 | 2016-07-26 19:47:00 +0200 | [diff] [blame] | 2732 | return (get_page_start(old_column) != get_page_start(new_column)); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
Benno Schulenberg | bf0268d | 2017-01-12 21:31:08 +0100 | [diff] [blame] | 2735 | /* Determine how many file lines we can display, accounting for softwraps. */ |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2736 | void compute_maxlines(void) |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2737 | { |
David Lawrence Ramsey | c8c6340 | 2016-12-08 09:56:16 -0600 | [diff] [blame] | 2738 | #ifndef NANO_TINY |
| 2739 | if (ISSET(SOFTWRAP)) { |
Benno Schulenberg | 2fa93ae | 2016-12-09 12:47:00 +0100 | [diff] [blame] | 2740 | filestruct *line = openfile->edittop; |
Benno Schulenberg | bf0268d | 2017-01-12 21:31:08 +0100 | [diff] [blame] | 2741 | int row = 0; |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2742 | |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2743 | maxlines = 0; |
Benno Schulenberg | 2fa93ae | 2016-12-09 12:47:00 +0100 | [diff] [blame] | 2744 | |
Benno Schulenberg | bf0268d | 2017-01-12 21:31:08 +0100 | [diff] [blame] | 2745 | while (row < editwinrows && line != NULL) { |
| 2746 | row += (strlenpt(line->data) / editwincols) + 1; |
Benno Schulenberg | 2fa93ae | 2016-12-09 12:47:00 +0100 | [diff] [blame] | 2747 | line = line->next; |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2748 | maxlines++; |
David Lawrence Ramsey | c8c6340 | 2016-12-08 09:56:16 -0600 | [diff] [blame] | 2749 | } |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 2750 | |
Benno Schulenberg | bf0268d | 2017-01-12 21:31:08 +0100 | [diff] [blame] | 2751 | if (row < editwinrows) |
| 2752 | maxlines += (editwinrows - row); |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2753 | #ifdef DEBUG |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2754 | fprintf(stderr, "recomputed: maxlines = %d\n", maxlines); |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2755 | #endif |
David Lawrence Ramsey | c8c6340 | 2016-12-08 09:56:16 -0600 | [diff] [blame] | 2756 | } else |
| 2757 | #endif /* !NANO_TINY */ |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2758 | maxlines = editwinrows; |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2761 | /* Scroll the edit window in the given direction and the given number of rows, |
| 2762 | * and draw new lines on the blank lines left after the scrolling. We change |
| 2763 | * edittop, and assume that current and current_x are up to date. */ |
| 2764 | void edit_scroll(scroll_dir direction, int nrows) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2765 | { |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2766 | int i; |
David Lawrence Ramsey | 7803783 | 2016-12-30 02:09:14 -0600 | [diff] [blame] | 2767 | filestruct *line; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2768 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2769 | /* Part 1: nrows is the number of rows we're going to scroll the text of |
| 2770 | * the edit window. */ |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2771 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2772 | /* Move the top line of the edit window up or down (depending on the value |
| 2773 | * of direction) nrows rows, or as many rows as we can if there are fewer |
| 2774 | * than nrows rows available. */ |
| 2775 | for (i = nrows; i > 0; i--) { |
Benno Schulenberg | ce0ea44 | 2014-06-23 18:20:12 +0000 | [diff] [blame] | 2776 | if (direction == UPWARD) { |
David Lawrence Ramsey | e99223d | 2005-11-10 04:27:30 +0000 | [diff] [blame] | 2777 | if (openfile->edittop == openfile->fileage) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2778 | break; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2779 | openfile->edittop = openfile->edittop->prev; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2780 | } else { |
David Lawrence Ramsey | e99223d | 2005-11-10 04:27:30 +0000 | [diff] [blame] | 2781 | if (openfile->edittop == openfile->filebot) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2782 | break; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2783 | openfile->edittop = openfile->edittop->next; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2784 | } |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2785 | |
| 2786 | #ifndef NANO_TINY |
Benno Schulenberg | f876ee1 | 2014-04-15 11:25:29 +0000 | [diff] [blame] | 2787 | /* Don't over-scroll on long lines. */ |
Benno Schulenberg | ce0ea44 | 2014-06-23 18:20:12 +0000 | [diff] [blame] | 2788 | if (ISSET(SOFTWRAP) && direction == UPWARD) { |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2789 | ssize_t len = strlenpt(openfile->edittop->data) / editwincols; |
Benno Schulenberg | 52e3533 | 2014-05-16 11:03:04 +0000 | [diff] [blame] | 2790 | i -= len; |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 2791 | if (len > 0) |
Benno Schulenberg | 53f4a9f | 2016-04-25 21:14:18 +0200 | [diff] [blame] | 2792 | refresh_needed = TRUE; |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 2793 | } |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2794 | #endif |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2797 | /* Limit nrows to the number of rows we could scroll. */ |
| 2798 | nrows -= i; |
David Lawrence Ramsey | 258497f | 2005-08-01 21:17:38 +0000 | [diff] [blame] | 2799 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2800 | /* Don't bother scrolling zero rows, nor more than the window can hold. */ |
| 2801 | if (nrows == 0) |
David Lawrence Ramsey | 258497f | 2005-08-01 21:17:38 +0000 | [diff] [blame] | 2802 | return; |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2803 | if (nrows >= editwinrows) |
Benno Schulenberg | 53f4a9f | 2016-04-25 21:14:18 +0200 | [diff] [blame] | 2804 | refresh_needed = TRUE; |
Benno Schulenberg | 2246029 | 2016-04-13 13:14:36 +0200 | [diff] [blame] | 2805 | |
Benno Schulenberg | 53f4a9f | 2016-04-25 21:14:18 +0200 | [diff] [blame] | 2806 | if (refresh_needed == TRUE) |
Benno Schulenberg | 2246029 | 2016-04-13 13:14:36 +0200 | [diff] [blame] | 2807 | return; |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2808 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2809 | /* Scroll the text of the edit window a number of rows up or down. */ |
David Lawrence Ramsey | 47bb888 | 2005-07-22 22:56:03 +0000 | [diff] [blame] | 2810 | scrollok(edit, TRUE); |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2811 | wscrl(edit, (direction == UPWARD) ? -nrows : nrows); |
David Lawrence Ramsey | 47bb888 | 2005-07-22 22:56:03 +0000 | [diff] [blame] | 2812 | scrollok(edit, FALSE); |
| 2813 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2814 | /* Part 2: nrows is now the number of rows in the scrolled region of the |
| 2815 | * edit window that we need to draw. */ |
David Lawrence Ramsey | c009759 | 2005-07-22 23:17:19 +0000 | [diff] [blame] | 2816 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2817 | /* If the scrolled region contains only one row, and the row before it is |
| 2818 | * visible in the edit window, we need to draw it too. If the scrolled |
| 2819 | * region is more than one row, and the rows before and after it are |
| 2820 | * visible in the edit window, we need to draw them too. */ |
| 2821 | nrows += (nrows == 1) ? 1 : 2; |
David Lawrence Ramsey | c25ed53 | 2005-08-01 21:53:54 +0000 | [diff] [blame] | 2822 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2823 | if (nrows > editwinrows) |
| 2824 | nrows = editwinrows; |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 2825 | |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2826 | /* If we scrolled up, we're on the line before the scrolled region. */ |
David Lawrence Ramsey | 7803783 | 2016-12-30 02:09:14 -0600 | [diff] [blame] | 2827 | line = openfile->edittop; |
David Lawrence Ramsey | 1458891 | 2005-07-14 20:37:01 +0000 | [diff] [blame] | 2828 | |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2829 | /* If we scrolled down, move down to the line before the scrolled region. */ |
Benno Schulenberg | ce0ea44 | 2014-06-23 18:20:12 +0000 | [diff] [blame] | 2830 | if (direction == DOWNWARD) { |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2831 | for (i = editwinrows - nrows; i > 0 && line != NULL; i--) |
David Lawrence Ramsey | 7803783 | 2016-12-30 02:09:14 -0600 | [diff] [blame] | 2832 | line = line->next; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
David Lawrence Ramsey | b1b9770 | 2017-01-15 12:17:19 -0600 | [diff] [blame] | 2835 | /* Draw new lines on any blank rows before or inside the scrolled region. |
| 2836 | * If we scrolled down and we're on the top row, or if we scrolled up and |
| 2837 | * we're on the bottom row, the row won't be blank, so we don't need to |
| 2838 | * draw it unless the mark is on or we're not on the first "page". */ |
| 2839 | for (i = nrows; i > 0 && line != NULL; i--) { |
| 2840 | if ((i == nrows && direction == DOWNWARD) || |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2841 | (i == 1 && direction == UPWARD)) { |
Benno Schulenberg | 2f66476 | 2016-07-26 19:47:00 +0200 | [diff] [blame] | 2842 | if (need_horizontal_scroll(openfile->placewewant, 0)) |
David Lawrence Ramsey | 7803783 | 2016-12-30 02:09:14 -0600 | [diff] [blame] | 2843 | update_line(line, (line == openfile->current) ? |
David Lawrence Ramsey | 2786530 | 2005-07-23 20:39:41 +0000 | [diff] [blame] | 2844 | openfile->current_x : 0); |
| 2845 | } else |
David Lawrence Ramsey | 7803783 | 2016-12-30 02:09:14 -0600 | [diff] [blame] | 2846 | update_line(line, (line == openfile->current) ? |
David Lawrence Ramsey | 4d46437 | 2005-07-16 22:50:30 +0000 | [diff] [blame] | 2847 | openfile->current_x : 0); |
David Lawrence Ramsey | 7803783 | 2016-12-30 02:09:14 -0600 | [diff] [blame] | 2848 | line = line->next; |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2849 | } |
Benno Schulenberg | c0aa5ad | 2017-01-09 18:25:25 +0100 | [diff] [blame] | 2850 | |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2851 | compute_maxlines(); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | /* 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] | 2855 | * updated. Use this if we've moved without changing any text. */ |
Benno Schulenberg | aa1ae0a | 2016-04-10 21:16:19 +0200 | [diff] [blame] | 2856 | void edit_redraw(filestruct *old_current) |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2857 | { |
Benno Schulenberg | aa1ae0a | 2016-04-10 21:16:19 +0200 | [diff] [blame] | 2858 | size_t was_pww = openfile->placewewant; |
| 2859 | |
| 2860 | openfile->placewewant = xplustabs(); |
| 2861 | |
Benno Schulenberg | b8d32d8 | 2016-01-24 15:32:13 +0000 | [diff] [blame] | 2862 | /* If the current line is offscreen, scroll until it's onscreen. */ |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2863 | if (openfile->current->lineno >= openfile->edittop->lineno + maxlines || |
Benno Schulenberg | fc9c7b4 | 2016-09-13 10:26:08 +0200 | [diff] [blame] | 2864 | #ifndef NANO_TINY |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2865 | (openfile->current->lineno == openfile->edittop->lineno + maxlines - 1 && |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2866 | ISSET(SOFTWRAP) && strlenpt(openfile->current->data) >= editwincols) || |
Benno Schulenberg | fc9c7b4 | 2016-09-13 10:26:08 +0200 | [diff] [blame] | 2867 | #endif |
Benno Schulenberg | b97c36c | 2016-04-25 20:05:21 +0200 | [diff] [blame] | 2868 | openfile->current->lineno < openfile->edittop->lineno) { |
Benno Schulenberg | 01bbf7e | 2016-10-20 21:11:11 +0200 | [diff] [blame] | 2869 | adjust_viewport((focusing || !ISSET(SMOOTH_SCROLL)) ? CENTERING : FLOWING); |
Benno Schulenberg | 53f4a9f | 2016-04-25 21:14:18 +0200 | [diff] [blame] | 2870 | refresh_needed = TRUE; |
Benno Schulenberg | 9d5ee16 | 2016-10-20 21:18:17 +0200 | [diff] [blame] | 2871 | return; |
Benno Schulenberg | b97c36c | 2016-04-25 20:05:21 +0200 | [diff] [blame] | 2872 | } |
David Lawrence Ramsey | 107e816 | 2005-08-01 21:05:29 +0000 | [diff] [blame] | 2873 | |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 2874 | #ifndef NANO_TINY |
Benno Schulenberg | b8d32d8 | 2016-01-24 15:32:13 +0000 | [diff] [blame] | 2875 | /* If the mark is on, update all lines between old_current and current. */ |
| 2876 | if (openfile->mark_set) { |
David Lawrence Ramsey | 34e086f | 2017-01-19 01:15:43 -0600 | [diff] [blame] | 2877 | filestruct *line = old_current; |
David Lawrence Ramsey | d5228b3 | 2006-05-26 03:04:24 +0000 | [diff] [blame] | 2878 | |
David Lawrence Ramsey | 34e086f | 2017-01-19 01:15:43 -0600 | [diff] [blame] | 2879 | while (line != openfile->current) { |
| 2880 | update_line(line, 0); |
David Lawrence Ramsey | e5806be | 2005-07-16 02:12:18 +0000 | [diff] [blame] | 2881 | |
David Lawrence Ramsey | 34e086f | 2017-01-19 01:15:43 -0600 | [diff] [blame] | 2882 | line = (line->lineno > openfile->current->lineno) ? |
| 2883 | line->prev : line->next; |
Benno Schulenberg | b8d32d8 | 2016-01-24 15:32:13 +0000 | [diff] [blame] | 2884 | } |
Benno Schulenberg | b26aaa7 | 2016-04-27 17:45:36 +0200 | [diff] [blame] | 2885 | } else |
| 2886 | #endif |
| 2887 | /* Otherwise, update old_current only if it differs from current |
| 2888 | * and was horizontally scrolled. */ |
| 2889 | if (old_current != openfile->current && get_page_start(was_pww) > 0) |
| 2890 | update_line(old_current, 0); |
Benno Schulenberg | 4b5b66a | 2016-04-11 20:40:21 +0200 | [diff] [blame] | 2891 | |
David Lawrence Ramsey | f2ac201 | 2016-12-28 09:43:23 -0600 | [diff] [blame] | 2892 | /* Update current if the mark is on or it has changed "page", or if it |
| 2893 | * differs from old_current and needs to be horizontally scrolled. */ |
Benno Schulenberg | 2f66476 | 2016-07-26 19:47:00 +0200 | [diff] [blame] | 2894 | if (need_horizontal_scroll(was_pww, openfile->placewewant) || |
Benno Schulenberg | c9e9964 | 2016-07-26 11:47:53 +0200 | [diff] [blame] | 2895 | (old_current != openfile->current && |
Benno Schulenberg | 4b5b66a | 2016-04-11 20:40:21 +0200 | [diff] [blame] | 2896 | get_page_start(openfile->placewewant) > 0)) |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2897 | update_line(openfile->current, openfile->current_x); |
David Lawrence Ramsey | 2ed225f | 2004-05-28 20:44:09 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
David Lawrence Ramsey | 75a29b7 | 2005-07-26 14:26:47 +0000 | [diff] [blame] | 2900 | /* Refresh the screen without changing the position of lines. Use this |
| 2901 | * if we've moved and changed text. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2902 | void edit_refresh(void) |
| 2903 | { |
Benno Schulenberg | c92b9be | 2016-12-23 12:51:04 +0100 | [diff] [blame] | 2904 | filestruct *line; |
| 2905 | int row = 0; |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2906 | |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2907 | /* Figure out what maxlines should really be. */ |
| 2908 | compute_maxlines(); |
Chris Allegretta | 99c8d40 | 2009-11-13 13:48:56 +0000 | [diff] [blame] | 2909 | |
Benno Schulenberg | 55b1403 | 2016-10-20 22:04:38 +0200 | [diff] [blame] | 2910 | /* If the current line is out of view, get it back on screen. */ |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 2911 | if (openfile->current->lineno < openfile->edittop->lineno || |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2912 | openfile->current->lineno >= openfile->edittop->lineno + maxlines) { |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 2913 | #ifdef DEBUG |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2914 | fprintf(stderr, "edit-refresh: line = %ld, edittop = %ld and maxlines = %d\n", |
| 2915 | (long)openfile->current->lineno, (long)openfile->edittop->lineno, maxlines); |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 2916 | #endif |
Benno Schulenberg | 01bbf7e | 2016-10-20 21:11:11 +0200 | [diff] [blame] | 2917 | adjust_viewport((focusing || !ISSET(SMOOTH_SCROLL)) ? CENTERING : STATIONARY); |
Chris Allegretta | 8c1edd1 | 2009-11-16 04:28:40 +0000 | [diff] [blame] | 2918 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2919 | |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2920 | #ifdef DEBUG |
Benno Schulenberg | 0f3e303 | 2016-12-02 17:37:11 +0100 | [diff] [blame] | 2921 | fprintf(stderr, "edit-refresh: now edittop = %ld\n", (long)openfile->edittop->lineno); |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2922 | #endif |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2923 | |
Benno Schulenberg | c92b9be | 2016-12-23 12:51:04 +0100 | [diff] [blame] | 2924 | line = openfile->edittop; |
| 2925 | |
| 2926 | while (row < editwinrows && line != NULL) { |
| 2927 | if (line == openfile->current) |
Benno Schulenberg | 9f88481 | 2017-01-13 19:25:16 +0100 | [diff] [blame] | 2928 | row += update_line(line, openfile->current_x); |
Benno Schulenberg | c92b9be | 2016-12-23 12:51:04 +0100 | [diff] [blame] | 2929 | else |
Benno Schulenberg | 9f88481 | 2017-01-13 19:25:16 +0100 | [diff] [blame] | 2930 | row += update_line(line, 0); |
Benno Schulenberg | c92b9be | 2016-12-23 12:51:04 +0100 | [diff] [blame] | 2931 | line = line->next; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2932 | } |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2933 | |
Benno Schulenberg | c92b9be | 2016-12-23 12:51:04 +0100 | [diff] [blame] | 2934 | while (row < editwinrows) |
Benno Schulenberg | f7d320d | 2017-01-12 17:48:33 +0100 | [diff] [blame] | 2935 | blank_row(edit, row++, 0, COLS); |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2936 | |
| 2937 | reset_cursor(); |
David Lawrence Ramsey | 6d8e495 | 2005-07-26 14:42:57 +0000 | [diff] [blame] | 2938 | wnoutrefresh(edit); |
Benno Schulenberg | 2789bb0 | 2016-10-21 13:52:40 +0200 | [diff] [blame] | 2939 | |
| 2940 | refresh_needed = FALSE; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2941 | } |
| 2942 | |
Benno Schulenberg | cb17732 | 2016-04-07 13:58:51 +0200 | [diff] [blame] | 2943 | /* Move edittop so that current is on the screen. manner says how it |
| 2944 | * should be moved: CENTERING means that current should end up in the |
| 2945 | * middle of the screen, STATIONARY means that it should stay at the |
| 2946 | * same vertical position, and FLOWING means that it should scroll no |
| 2947 | * more than needed to bring current into view. */ |
Benno Schulenberg | 01bbf7e | 2016-10-20 21:11:11 +0200 | [diff] [blame] | 2948 | void adjust_viewport(update_type manner) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2949 | { |
Benno Schulenberg | 0bffd99 | 2016-04-16 11:38:39 +0200 | [diff] [blame] | 2950 | int goal = 0; |
David Lawrence Ramsey | 20b8350 | 2004-08-26 18:07:58 +0000 | [diff] [blame] | 2951 | |
David Lawrence Ramsey | f2ac201 | 2016-12-28 09:43:23 -0600 | [diff] [blame] | 2952 | /* If manner is CENTERING, move edittop half the number of window rows |
| 2953 | * back from current. If manner is FLOWING, move edittop back 0 rows |
| 2954 | * or (editwinrows - 1) rows, depending on where current has moved. |
| 2955 | * This puts the cursor on the first or the last row. If manner is |
| 2956 | * STATIONARY, move edittop back current_y rows if current_y is in range |
| 2957 | * of the screen, 0 rows if current_y is below zero, or (editwinrows - 1) |
| 2958 | * rows if current_y is too big. This puts current at the same place on |
| 2959 | * the screen as before, or... at some undefined place. */ |
Benno Schulenberg | cb17732 | 2016-04-07 13:58:51 +0200 | [diff] [blame] | 2960 | if (manner == CENTERING) |
Chris Allegretta | 374216f | 2010-01-04 19:00:55 +0000 | [diff] [blame] | 2961 | goal = editwinrows / 2; |
Benno Schulenberg | cb17732 | 2016-04-07 13:58:51 +0200 | [diff] [blame] | 2962 | else if (manner == FLOWING) { |
Benno Schulenberg | 598e0af | 2016-09-15 10:43:49 +0200 | [diff] [blame] | 2963 | if (openfile->current->lineno >= openfile->edittop->lineno) { |
Benno Schulenberg | cb17732 | 2016-04-07 13:58:51 +0200 | [diff] [blame] | 2964 | goal = editwinrows - 1; |
Benno Schulenberg | 598e0af | 2016-09-15 10:43:49 +0200 | [diff] [blame] | 2965 | #ifndef NANO_TINY |
| 2966 | if (ISSET(SOFTWRAP)) |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2967 | goal -= strlenpt(openfile->current->data) / editwincols; |
Benno Schulenberg | 598e0af | 2016-09-15 10:43:49 +0200 | [diff] [blame] | 2968 | #endif |
| 2969 | } |
Benno Schulenberg | cb17732 | 2016-04-07 13:58:51 +0200 | [diff] [blame] | 2970 | } else { |
David Lawrence Ramsey | 5b44f37 | 2005-07-16 22:47:12 +0000 | [diff] [blame] | 2971 | goal = openfile->current_y; |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 2972 | |
David Lawrence Ramsey | f2ac201 | 2016-12-28 09:43:23 -0600 | [diff] [blame] | 2973 | /* Limit goal to (editwinrows - 1) rows maximum. */ |
Chris Allegretta | 374216f | 2010-01-04 19:00:55 +0000 | [diff] [blame] | 2974 | if (goal > editwinrows - 1) |
| 2975 | goal = editwinrows - 1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2976 | } |
David Lawrence Ramsey | 50c7f2d | 2004-08-27 17:02:05 +0000 | [diff] [blame] | 2977 | |
Benno Schulenberg | 0bffd99 | 2016-04-16 11:38:39 +0200 | [diff] [blame] | 2978 | openfile->edittop = openfile->current; |
| 2979 | |
| 2980 | while (goal > 0 && openfile->edittop->prev != NULL) { |
| 2981 | openfile->edittop = openfile->edittop->prev; |
Benno Schulenberg | 55b1403 | 2016-10-20 22:04:38 +0200 | [diff] [blame] | 2982 | goal--; |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2983 | #ifndef NANO_TINY |
Benno Schulenberg | 598e0af | 2016-09-15 10:43:49 +0200 | [diff] [blame] | 2984 | if (ISSET(SOFTWRAP)) { |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 2985 | goal -= strlenpt(openfile->edittop->data) / editwincols; |
Benno Schulenberg | 598e0af | 2016-09-15 10:43:49 +0200 | [diff] [blame] | 2986 | if (goal < 0) |
| 2987 | openfile->edittop = openfile->edittop->next; |
| 2988 | } |
Benno Schulenberg | 1102aaa | 2014-06-09 20:26:54 +0000 | [diff] [blame] | 2989 | #endif |
Chris Allegretta | 35afab5 | 2009-09-13 04:50:44 +0000 | [diff] [blame] | 2990 | } |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 2991 | #ifdef DEBUG |
Benno Schulenberg | 01bbf7e | 2016-10-20 21:11:11 +0200 | [diff] [blame] | 2992 | fprintf(stderr, "adjust_viewport(): setting edittop to lineno %ld\n", (long)openfile->edittop->lineno); |
Chris Allegretta | 1a7a91b | 2010-01-13 03:21:19 +0000 | [diff] [blame] | 2993 | #endif |
Benno Schulenberg | 0208ae7 | 2017-01-12 17:33:46 +0100 | [diff] [blame] | 2994 | compute_maxlines(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2995 | } |
| 2996 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 2997 | /* Unconditionally redraw the entire screen. */ |
David Lawrence Ramsey | c54c4d1 | 2005-06-18 15:49:17 +0000 | [diff] [blame] | 2998 | void total_redraw(void) |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2999 | { |
David Lawrence Ramsey | f78bc85 | 2007-12-18 15:55:48 +0000 | [diff] [blame] | 3000 | #ifdef USE_SLANG |
| 3001 | /* Slang curses emulation brain damage, part 4: Slang doesn't define |
| 3002 | * curscr. */ |
| 3003 | SLsmg_touch_screen(); |
| 3004 | SLsmg_refresh(); |
| 3005 | #else |
David Lawrence Ramsey | b386a90 | 2005-07-10 02:37:38 +0000 | [diff] [blame] | 3006 | wrefresh(curscr); |
David Lawrence Ramsey | f78bc85 | 2007-12-18 15:55:48 +0000 | [diff] [blame] | 3007 | #endif |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 3008 | } |
| 3009 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 3010 | /* Unconditionally redraw the entire screen, and then refresh it using |
| 3011 | * the current file. */ |
David Lawrence Ramsey | b9ddb80 | 2005-03-17 17:56:48 +0000 | [diff] [blame] | 3012 | void total_refresh(void) |
| 3013 | { |
David Lawrence Ramsey | c54c4d1 | 2005-06-18 15:49:17 +0000 | [diff] [blame] | 3014 | total_redraw(); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3015 | titlebar(NULL); |
David Lawrence Ramsey | 7483571 | 2004-12-04 17:41:52 +0000 | [diff] [blame] | 3016 | edit_refresh(); |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 3017 | bottombars(currmenu); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 3020 | /* Display the main shortcut list on the last two rows of the bottom |
| 3021 | * portion of the window. */ |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3022 | void display_main_list(void) |
| 3023 | { |
Benno Schulenberg | 0038992 | 2014-04-04 11:59:03 +0000 | [diff] [blame] | 3024 | #ifndef DISABLE_COLOR |
Benno Schulenberg | 17cf833 | 2016-05-30 09:09:36 +0200 | [diff] [blame] | 3025 | if (openfile->syntax && |
| 3026 | (openfile->syntax->formatter || openfile->syntax->linter)) |
Chris Allegretta | 4b3f277 | 2015-01-03 07:24:17 +0000 | [diff] [blame] | 3027 | set_lint_or_format_shortcuts(); |
Chris Allegretta | 5575bfa | 2014-02-24 10:18:15 +0000 | [diff] [blame] | 3028 | else |
| 3029 | set_spell_shortcuts(); |
| 3030 | #endif |
| 3031 | |
Chris Allegretta | 79a33bb | 2008-03-05 07:34:01 +0000 | [diff] [blame] | 3032 | bottombars(MMAIN); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 3033 | } |
| 3034 | |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3035 | /* If constant is TRUE, we display the current cursor position only if |
Benno Schulenberg | 9d6d5b6 | 2016-05-04 12:18:21 +0200 | [diff] [blame] | 3036 | * suppress_cursorpos is FALSE. If constant is FALSE, we display the |
| 3037 | * position always. In any case we reset suppress_cursorpos to FALSE. */ |
David Lawrence Ramsey | a0b5ba2 | 2004-08-25 15:39:10 +0000 | [diff] [blame] | 3038 | void do_cursorpos(bool constant) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3039 | { |
Benno Schulenberg | a772194 | 2016-12-11 11:24:48 +0100 | [diff] [blame] | 3040 | char saved_byte; |
| 3041 | size_t sum, cur_xpt = xplustabs() + 1; |
David Lawrence Ramsey | 6ad59cd | 2005-07-08 20:09:16 +0000 | [diff] [blame] | 3042 | size_t cur_lenpt = strlenpt(openfile->current->data) + 1; |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3043 | int linepct, colpct, charpct; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3044 | |
David Lawrence Ramsey | 4ab8015 | 2005-07-31 18:51:51 +0000 | [diff] [blame] | 3045 | assert(openfile->fileage != NULL && openfile->current != NULL); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3046 | |
Benno Schulenberg | 9d6d5b6 | 2016-05-04 12:18:21 +0200 | [diff] [blame] | 3047 | /* Determine the size of the file up to the cursor. */ |
Benno Schulenberg | a772194 | 2016-12-11 11:24:48 +0100 | [diff] [blame] | 3048 | saved_byte = openfile->current->data[openfile->current_x]; |
David Lawrence Ramsey | 15d6857 | 2005-07-31 20:15:01 +0000 | [diff] [blame] | 3049 | openfile->current->data[openfile->current_x] = '\0'; |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 3050 | |
Benno Schulenberg | a772194 | 2016-12-11 11:24:48 +0100 | [diff] [blame] | 3051 | sum = get_totsize(openfile->fileage, openfile->current); |
David Lawrence Ramsey | 04f65f2 | 2005-08-01 02:18:05 +0000 | [diff] [blame] | 3052 | |
Benno Schulenberg | a772194 | 2016-12-11 11:24:48 +0100 | [diff] [blame] | 3053 | openfile->current->data[openfile->current_x] = saved_byte; |
Benno Schulenberg | faf77fb | 2016-12-11 11:18:28 +0100 | [diff] [blame] | 3054 | |
| 3055 | /* When not at EOF, subtract 1 for an overcounted newline. */ |
| 3056 | if (openfile->current != openfile->filebot) |
Benno Schulenberg | a772194 | 2016-12-11 11:24:48 +0100 | [diff] [blame] | 3057 | sum--; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 3058 | |
Benno Schulenberg | 9d6d5b6 | 2016-05-04 12:18:21 +0200 | [diff] [blame] | 3059 | /* If the position needs to be suppressed, don't suppress it next time. */ |
Benno Schulenberg | 6698659 | 2016-05-14 21:49:19 +0200 | [diff] [blame] | 3060 | if (suppress_cursorpos && constant) { |
Benno Schulenberg | 9d6d5b6 | 2016-05-04 12:18:21 +0200 | [diff] [blame] | 3061 | suppress_cursorpos = FALSE; |
Benno Schulenberg | 6698659 | 2016-05-14 21:49:19 +0200 | [diff] [blame] | 3062 | return; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3063 | } |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 3064 | |
Benno Schulenberg | 9d6d5b6 | 2016-05-04 12:18:21 +0200 | [diff] [blame] | 3065 | /* Display the current cursor position on the statusbar. */ |
Benno Schulenberg | 08d9f57 | 2015-07-10 17:25:51 +0000 | [diff] [blame] | 3066 | linepct = 100 * openfile->current->lineno / openfile->filebot->lineno; |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3067 | colpct = 100 * cur_xpt / cur_lenpt; |
Benno Schulenberg | a772194 | 2016-12-11 11:24:48 +0100 | [diff] [blame] | 3068 | charpct = (openfile->totsize == 0) ? 0 : 100 * sum / openfile->totsize; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 3069 | |
Benno Schulenberg | 2535f51 | 2016-04-30 17:31:43 +0200 | [diff] [blame] | 3070 | statusline(HUSH, |
David Lawrence Ramsey | 520a90c | 2005-07-25 21:23:11 +0000 | [diff] [blame] | 3071 | _("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] | 3072 | (long)openfile->current->lineno, |
David Lawrence Ramsey | 520a90c | 2005-07-25 21:23:11 +0000 | [diff] [blame] | 3073 | (long)openfile->filebot->lineno, linepct, |
David Lawrence Ramsey | 4e05b75 | 2005-06-28 20:04:14 +0000 | [diff] [blame] | 3074 | (unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct, |
Benno Schulenberg | a772194 | 2016-12-11 11:24:48 +0100 | [diff] [blame] | 3075 | (unsigned long)sum, (unsigned long)openfile->totsize, charpct); |
Benno Schulenberg | 6698659 | 2016-05-14 21:49:19 +0200 | [diff] [blame] | 3076 | |
| 3077 | /* Displaying the cursor position should not suppress it next time. */ |
| 3078 | suppress_cursorpos = FALSE; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
David Lawrence Ramsey | 6d6a36c | 2005-12-08 07:09:08 +0000 | [diff] [blame] | 3081 | /* Unconditionally display the current cursor position. */ |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3082 | void do_cursorpos_void(void) |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3083 | { |
David Lawrence Ramsey | 72e51ab | 2004-07-02 14:31:03 +0000 | [diff] [blame] | 3084 | do_cursorpos(FALSE); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 3087 | void enable_nodelay(void) |
| 3088 | { |
Benno Schulenberg | 492e9f6 | 2014-06-20 10:48:26 +0000 | [diff] [blame] | 3089 | nodelay_mode = TRUE; |
| 3090 | nodelay(edit, TRUE); |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | void disable_nodelay(void) |
| 3094 | { |
Benno Schulenberg | 492e9f6 | 2014-06-20 10:48:26 +0000 | [diff] [blame] | 3095 | nodelay_mode = FALSE; |
| 3096 | nodelay(edit, FALSE); |
Chris Allegretta | 0dc26dc | 2009-01-24 22:40:41 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3099 | /* Highlight the current word being replaced or spell checked. We |
| 3100 | * expect word to have tabs and control characters expanded. */ |
Benno Schulenberg | c98afde | 2016-03-30 12:09:39 +0000 | [diff] [blame] | 3101 | void spotlight(bool active, const char *word) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3102 | { |
Benno Schulenberg | 29cac04 | 2016-03-30 12:18:22 +0000 | [diff] [blame] | 3103 | size_t word_len = strlenpt(word), room; |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3104 | |
Benno Schulenberg | 17cf833 | 2016-05-30 09:09:36 +0200 | [diff] [blame] | 3105 | /* Compute the number of columns that are available for the word. */ |
Faissal Bensefia | de95ca6 | 2016-10-20 09:44:29 +0100 | [diff] [blame] | 3106 | room = editwincols + get_page_start(xplustabs()) - xplustabs(); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3107 | |
Benno Schulenberg | 29cac04 | 2016-03-30 12:18:22 +0000 | [diff] [blame] | 3108 | assert(room > 0); |
David Lawrence Ramsey | 913db83 | 2005-01-05 05:08:14 +0000 | [diff] [blame] | 3109 | |
Benno Schulenberg | 29cac04 | 2016-03-30 12:18:22 +0000 | [diff] [blame] | 3110 | if (word_len > room) |
| 3111 | room--; |
David Lawrence Ramsey | 913db83 | 2005-01-05 05:08:14 +0000 | [diff] [blame] | 3112 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3113 | reset_cursor(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3114 | |
Benno Schulenberg | c98afde | 2016-03-30 12:09:39 +0000 | [diff] [blame] | 3115 | if (active) |
Benno Schulenberg | c970035 | 2014-05-04 08:53:06 +0000 | [diff] [blame] | 3116 | wattron(edit, hilite_attribute); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3117 | |
David Lawrence Ramsey | 21b946e | 2006-11-10 20:13:38 +0000 | [diff] [blame] | 3118 | /* This is so we can show zero-length matches. */ |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 3119 | if (word_len == 0) |
David Lawrence Ramsey | 5b9f522 | 2005-06-13 02:22:44 +0000 | [diff] [blame] | 3120 | waddch(edit, ' '); |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 3121 | else |
Benno Schulenberg | 29cac04 | 2016-03-30 12:18:22 +0000 | [diff] [blame] | 3122 | waddnstr(edit, word, actual_x(word, room)); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3123 | |
Benno Schulenberg | 29cac04 | 2016-03-30 12:18:22 +0000 | [diff] [blame] | 3124 | if (word_len > room) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 3125 | waddch(edit, '$'); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3126 | |
Benno Schulenberg | c98afde | 2016-03-30 12:09:39 +0000 | [diff] [blame] | 3127 | if (active) |
Benno Schulenberg | c970035 | 2014-05-04 08:53:06 +0000 | [diff] [blame] | 3128 | wattroff(edit, hilite_attribute); |
Benno Schulenberg | c6512a9 | 2016-12-01 15:14:41 +0100 | [diff] [blame] | 3129 | |
| 3130 | wnoutrefresh(edit); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
Benno Schulenberg | d17438b | 2014-04-03 20:57:44 +0000 | [diff] [blame] | 3133 | #ifndef DISABLE_EXTRA |
Benno Schulenberg | 8d53aa3 | 2015-02-01 09:19:58 +0000 | [diff] [blame] | 3134 | #define CREDIT_LEN 54 |
| 3135 | #define XLCREDIT_LEN 9 |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 3136 | |
David Lawrence Ramsey | 8ad58bc | 2005-08-16 03:02:46 +0000 | [diff] [blame] | 3137 | /* Easter egg: Display credits. Assume nodelay(edit) and scrollok(edit) |
| 3138 | * are FALSE. */ |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3139 | void do_credits(void) |
| 3140 | { |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3141 | bool old_more_space = ISSET(MORE_SPACE); |
| 3142 | bool old_no_help = ISSET(NO_HELP); |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3143 | int kbinput = ERR, crpos = 0, xlpos = 0; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3144 | const char *credits[CREDIT_LEN] = { |
| 3145 | NULL, /* "The nano text editor" */ |
| 3146 | NULL, /* "version" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3147 | VERSION, |
| 3148 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3149 | NULL, /* "Brought to you by:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3150 | "Chris Allegretta", |
| 3151 | "Jordi Mallach", |
| 3152 | "Adam Rogoyski", |
| 3153 | "Rob Siemborski", |
| 3154 | "Rocco Corsi", |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 3155 | "David Lawrence Ramsey", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 3156 | "David Benbennick", |
Benno Schulenberg | a44def0 | 2014-12-28 22:27:56 +0000 | [diff] [blame] | 3157 | "Mark Majeres", |
David Lawrence Ramsey | 47daf02 | 2005-08-29 18:29:02 +0000 | [diff] [blame] | 3158 | "Mike Frysinger", |
Chris Allegretta | 34b7f1c | 2014-02-24 15:15:51 +0000 | [diff] [blame] | 3159 | "Benno Schulenberg", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3160 | "Ken Tyler", |
| 3161 | "Sven Guckes", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3162 | "Bill Soudan", |
| 3163 | "Christian Weisgerber", |
| 3164 | "Erik Andersen", |
| 3165 | "Big Gaute", |
| 3166 | "Joshua Jensen", |
| 3167 | "Ryan Krebs", |
| 3168 | "Albert Chin", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3169 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3170 | NULL, /* "Special thanks to:" */ |
Chris Allegretta | 34b7f1c | 2014-02-24 15:15:51 +0000 | [diff] [blame] | 3171 | "Monique, Brielle & Joseph", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3172 | "Plattsburgh State University", |
| 3173 | "Benet Laboratories", |
| 3174 | "Amy Allegretta", |
| 3175 | "Linda Young", |
| 3176 | "Jeremy Robichaud", |
| 3177 | "Richard Kolb II", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3178 | NULL, /* "The Free Software Foundation" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3179 | "Linus Torvalds", |
Benno Schulenberg | 8d53aa3 | 2015-02-01 09:19:58 +0000 | [diff] [blame] | 3180 | NULL, /* "the many translators and the TP" */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3181 | NULL, /* "For ncurses:" */ |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 3182 | "Thomas Dickey", |
| 3183 | "Pavel Curtis", |
| 3184 | "Zeyd Ben-Halim", |
| 3185 | "Eric S. Raymond", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3186 | NULL, /* "and anyone else we forgot..." */ |
| 3187 | NULL, /* "Thank you for using nano!" */ |
| 3188 | "", |
| 3189 | "", |
| 3190 | "", |
| 3191 | "", |
Benno Schulenberg | 1b293ff | 2016-01-10 16:18:43 +0000 | [diff] [blame] | 3192 | "(C) 1999 - 2016", |
David Lawrence Ramsey | d8a1d37 | 2007-10-11 05:01:32 +0000 | [diff] [blame] | 3193 | "Free Software Foundation, Inc.", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3194 | "", |
| 3195 | "", |
| 3196 | "", |
| 3197 | "", |
Jordi Mallach | c2b199e | 2016-06-20 19:44:56 +0200 | [diff] [blame] | 3198 | "https://nano-editor.org/" |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3199 | }; |
| 3200 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3201 | const char *xlcredits[XLCREDIT_LEN] = { |
David Lawrence Ramsey | 576bf33 | 2004-07-12 03:10:30 +0000 | [diff] [blame] | 3202 | N_("The nano text editor"), |
| 3203 | N_("version"), |
| 3204 | N_("Brought to you by:"), |
| 3205 | N_("Special thanks to:"), |
| 3206 | N_("The Free Software Foundation"), |
Benno Schulenberg | 8d53aa3 | 2015-02-01 09:19:58 +0000 | [diff] [blame] | 3207 | N_("the many translators and the TP"), |
David Lawrence Ramsey | 576bf33 | 2004-07-12 03:10:30 +0000 | [diff] [blame] | 3208 | N_("For ncurses:"), |
| 3209 | N_("and anyone else we forgot..."), |
| 3210 | N_("Thank you for using nano!") |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3211 | }; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 3212 | |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3213 | if (!old_more_space || !old_no_help) { |
| 3214 | SET(MORE_SPACE); |
| 3215 | SET(NO_HELP); |
| 3216 | window_init(); |
| 3217 | } |
| 3218 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3219 | curs_set(0); |
| 3220 | nodelay(edit, TRUE); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3221 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3222 | blank_titlebar(); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 3223 | blank_edit(); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3224 | blank_statusbar(); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3225 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3226 | wrefresh(topwin); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 3227 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3228 | wrefresh(bottomwin); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3229 | napms(700); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3230 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3231 | for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) { |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3232 | if ((kbinput = wgetch(edit)) != ERR) |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3233 | break; |
David Lawrence Ramsey | 0099a8f | 2005-03-15 06:34:09 +0000 | [diff] [blame] | 3234 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3235 | if (crpos < CREDIT_LEN) { |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3236 | const char *what; |
Benno Schulenberg | 8f21d25 | 2017-01-08 12:05:42 +0100 | [diff] [blame] | 3237 | size_t start_col; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3238 | |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3239 | if (credits[crpos] == NULL) { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3240 | assert(0 <= xlpos && xlpos < XLCREDIT_LEN); |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3241 | |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3242 | what = _(xlcredits[xlpos]); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3243 | xlpos++; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3244 | } else |
David Lawrence Ramsey | 9905b6a | 2005-06-28 07:26:11 +0000 | [diff] [blame] | 3245 | what = credits[crpos]; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3246 | |
Benno Schulenberg | 8f21d25 | 2017-01-08 12:05:42 +0100 | [diff] [blame] | 3247 | start_col = COLS / 2 - strlenpt(what) / 2 - 1; |
David Lawrence Ramsey | 4dc5838 | 2005-03-15 06:58:02 +0000 | [diff] [blame] | 3248 | mvwaddstr(edit, editwinrows - 1 - (editwinrows % 2), |
Benno Schulenberg | 8f21d25 | 2017-01-08 12:05:42 +0100 | [diff] [blame] | 3249 | start_col, what); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3250 | } |
David Lawrence Ramsey | 0099a8f | 2005-03-15 06:34:09 +0000 | [diff] [blame] | 3251 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3252 | wrefresh(edit); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3253 | |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3254 | if ((kbinput = wgetch(edit)) != ERR) |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3255 | break; |
| 3256 | napms(700); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3257 | |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3258 | scrollok(edit, TRUE); |
David Lawrence Ramsey | c71e031 | 2005-08-14 21:17:37 +0000 | [diff] [blame] | 3259 | wscrl(edit, 1); |
| 3260 | scrollok(edit, FALSE); |
| 3261 | wrefresh(edit); |
| 3262 | |
| 3263 | if ((kbinput = wgetch(edit)) != ERR) |
| 3264 | break; |
| 3265 | napms(700); |
| 3266 | |
| 3267 | scrollok(edit, TRUE); |
| 3268 | wscrl(edit, 1); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3269 | scrollok(edit, FALSE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 3270 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
David Lawrence Ramsey | 3925bda | 2005-06-07 03:20:35 +0000 | [diff] [blame] | 3273 | if (kbinput != ERR) |
| 3274 | ungetch(kbinput); |
| 3275 | |
Benno Schulenberg | c916ca8 | 2016-01-02 16:33:03 +0000 | [diff] [blame] | 3276 | if (!old_more_space) |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3277 | UNSET(MORE_SPACE); |
Benno Schulenberg | c916ca8 | 2016-01-02 16:33:03 +0000 | [diff] [blame] | 3278 | if (!old_no_help) |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3279 | UNSET(NO_HELP); |
Benno Schulenberg | c916ca8 | 2016-01-02 16:33:03 +0000 | [diff] [blame] | 3280 | window_init(); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3281 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3282 | nodelay(edit, FALSE); |
David Lawrence Ramsey | 31de105 | 2005-08-14 19:25:16 +0000 | [diff] [blame] | 3283 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 3284 | total_refresh(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 3285 | } |
Benno Schulenberg | d17438b | 2014-04-03 20:57:44 +0000 | [diff] [blame] | 3286 | #endif /* !DISABLE_EXTRA */ |