Chris Allegretta | 11b0011 | 2000-08-06 21:13:45 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * winio.c * |
| 4 | * * |
David Lawrence Ramsey | f28f50e | 2004-01-09 23:04:55 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 Chris Allegretta * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
Chris Allegretta | 3a24f3f | 2001-10-24 11:33:54 +0000 | [diff] [blame] | 8 | * the Free Software Foundation; either version 2, or (at your option) * |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 9 | * any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * |
| 19 | * * |
| 20 | **************************************************************************/ |
| 21 | |
David Lawrence Ramsey | e21adfa | 2002-09-13 18:14:04 +0000 | [diff] [blame] | 22 | #include "config.h" |
| 23 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 24 | #include <stdarg.h> |
| 25 | #include <string.h> |
Chris Allegretta | dba37ae | 2000-07-07 05:13:09 +0000 | [diff] [blame] | 26 | #include <stdlib.h> |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 27 | #include <unistd.h> |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 28 | #include <ctype.h> |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 29 | #include <assert.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 30 | #include "proto.h" |
| 31 | #include "nano.h" |
| 32 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 33 | static int statblank = 0; /* Number of keystrokes left after |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 34 | we call statusbar(), before we |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 35 | actually blank the statusbar */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 36 | |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 37 | /* Control character compatibility: |
| 38 | * |
| 39 | * - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI, |
| 40 | * VT100, and VT220. |
| 41 | * - NANO_TAB_KEY is Ctrl-I, which is Tab under ASCII, ANSI, VT100, |
| 42 | * VT220, and VT320. |
| 43 | * - NANO_ENTER_KEY is Ctrl-M, which is Enter under ASCII, ANSI, VT100, |
| 44 | * VT220, and VT320. |
| 45 | * - NANO_XON_KEY is Ctrl-Q, which is XON under ASCII, ANSI, VT100, |
| 46 | * VT220, and VT320. |
| 47 | * - NANO_XOFF_KEY is Ctrl-S, which is XOFF under ASCII, ANSI, VT100, |
| 48 | * VT220, and VT320. |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 49 | * - NANO_CONTROL_8 is Ctrl-8 (Ctrl-?), which is Delete under ASCII, |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 50 | * ANSI, VT100, and VT220, and which is Backspace under VT320. |
| 51 | * |
| 52 | * Note: VT220s and VT320s also generate Esc [ 3 ~ for Delete. By |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 53 | * default, xterm assumes it's running on a VT320 and generates Ctrl-8 |
| 54 | * (Ctrl-?) for Backspace and Esc [ 3 ~ for Delete. This causes |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 55 | * problems for VT100-derived terminals such as the FreeBSD console, |
David Lawrence Ramsey | a849ab1 | 2004-05-01 04:13:06 +0000 | [diff] [blame] | 56 | * 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] | 57 | * on which the VT320 sequences are translated by the keypad to KEY_DC |
| 58 | * and [nothing]. We work around this conflict via the REBIND_DELETE |
| 59 | * flag: if it's not set, we assume VT320 compatibility, and if it is, |
| 60 | * we assume VT100 compatibility. Thanks to Lee Nelson and Wouter van |
| 61 | * Hemel for helping work this conflict out. |
| 62 | * |
| 63 | * Escape sequence compatibility: |
| 64 | * |
| 65 | * We support escape sequences for ANSI, VT100, VT220, VT320, the Linux |
| 66 | * console, the FreeBSD console, the Hurd console (a.k.a. the Mach |
| 67 | * console), xterm, rxvt, and Eterm. Among these, there are several |
| 68 | * conflicts and omissions, outlined as follows: |
| 69 | * |
| 70 | * - Tab on ANSI == PageUp on FreeBSD console; the former is omitted. |
| 71 | * (Ctrl-I is also Tab on ANSI, which we already support.) |
| 72 | * - PageDown on FreeBSD console == Center (5) on numeric keypad with |
| 73 | * NumLock off on Linux console; the latter is omitted. (The editing |
| 74 | * keypad key is more important to have working than the numeric |
| 75 | * keypad key, because the latter actually has no value when NumLock |
| 76 | * is off.) |
| 77 | * - F1 on FreeBSD console == the mouse key on xterm/rxvt/Eterm; the |
| 78 | * latter is omitted. (Mouse input will only work properly if the |
| 79 | * extended keypad value KEY_MOUSE is generated on mouse events |
| 80 | * instead of the escape sequence.) |
| 81 | * - F9 on FreeBSD console == PageDown on Hurd console; the former is |
| 82 | * omitted. (The editing keypad is more important to have working |
| 83 | * than the function keys, because the functions of the former are not |
| 84 | * arbitrary and the functions of the latter are.) |
| 85 | * - F10 on FreeBSD console == PageUp on Hurd console; the former is |
| 86 | * omitted. (Same as above.) |
| 87 | * - F13 on FreeBSD console == End on Hurd console; the former is |
| 88 | * omitted. (Same as above.) |
| 89 | * - The Hurd console has no escape sequences for F11, F12, F13, F14, or |
| 90 | * Center (5) on the numeric keypad with NumLock off. |
| 91 | * |
| 92 | * Note that Center (5) on the numeric keypad with NumLock off can also |
| 93 | * be the Begin key. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 94 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 95 | /* Read in a single input character. If it's ignored, swallow it and go |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 96 | * on. Otherwise, try to translate it from ASCII, extended keypad |
| 97 | * values, and/or escape sequences. Supported extended keypad values |
| 98 | * consist of [arrow key], Ctrl-[arrow key], Shift-[arrow key], Enter, |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 99 | * Backspace, the editing keypad (Insert, Delete, Home, End, PageUp, and |
| 100 | * PageDown), the function keypad (F1-F14), and the numeric keypad with |
| 101 | * NumLock off. Assume nodelay(win) is FALSE. */ |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 102 | int get_kbinput(WINDOW *win, int *meta_key) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 103 | { |
| 104 | int kbinput, retval; |
| 105 | |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 106 | #ifndef NANO_SMALL |
| 107 | allow_pending_sigwinch(TRUE); |
| 108 | #endif |
| 109 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 110 | kbinput = get_ignored_kbinput(win); |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 111 | retval = get_accepted_kbinput(win, kbinput, meta_key); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 112 | |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 113 | #ifndef NANO_SMALL |
| 114 | allow_pending_sigwinch(FALSE); |
| 115 | #endif |
| 116 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 117 | return retval; |
| 118 | } |
| 119 | |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 120 | /* Read in a string of input characters (e.g. an escape sequence) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 121 | * verbatim, and return the length of the string in kbinput_len. Assume |
| 122 | * nodelay(win) is FALSE. */ |
David Lawrence Ramsey | 805547f | 2004-04-22 03:41:04 +0000 | [diff] [blame] | 123 | int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len, int |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 124 | allow_ascii) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 125 | { |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 126 | int kbinput, *verbatim_kbinput; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 127 | |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 128 | #ifndef NANO_SMALL |
| 129 | allow_pending_sigwinch(TRUE); |
| 130 | #endif |
| 131 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 132 | /* Turn off flow control characters if necessary so that we can type |
| 133 | * them in verbatim, and turn the keypad off so that we don't get |
| 134 | * extended keypad values outside the ASCII range. */ |
| 135 | if (ISSET(PRESERVE)) |
| 136 | disable_flow_control(); |
David Lawrence Ramsey | ce991bb | 2004-03-29 18:36:39 +0000 | [diff] [blame] | 137 | keypad(win, FALSE); |
David Lawrence Ramsey | 58f6d83 | 2004-01-27 07:12:47 +0000 | [diff] [blame] | 138 | |
| 139 | kbinput = wgetch(win); |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 140 | verbatim_kbinput = (int *)nmalloc(sizeof(int)); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 141 | verbatim_kbinput[0] = kbinput; |
| 142 | *kbinput_len = 1; |
| 143 | |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 144 | if (allow_ascii && kbinput >= '0' && kbinput <= '2') |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 145 | /* Entering a three-digit decimal ASCII code from 000-255 in |
| 146 | * verbatim mode will produce the corresponding ASCII |
| 147 | * character. */ |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 148 | verbatim_kbinput[0] = get_ascii_kbinput(win, kbinput); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 149 | else { |
| 150 | nodelay(win, TRUE); |
David Lawrence Ramsey | e1e7cb2 | 2004-04-15 06:15:55 +0000 | [diff] [blame] | 151 | #ifdef DEBUG |
| 152 | fprintf(stderr, "get_verbatim_kbinput(): kbinput = %d\n", kbinput); |
| 153 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 154 | while ((kbinput = wgetch(win)) != ERR) { |
David Lawrence Ramsey | da8fd8f | 2003-09-16 01:22:31 +0000 | [diff] [blame] | 155 | (*kbinput_len)++; |
David Lawrence Ramsey | 805547f | 2004-04-22 03:41:04 +0000 | [diff] [blame] | 156 | verbatim_kbinput = (int *)nrealloc(verbatim_kbinput, *kbinput_len * sizeof(int)); |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 157 | verbatim_kbinput[*kbinput_len - 1] = kbinput; |
David Lawrence Ramsey | e1e7cb2 | 2004-04-15 06:15:55 +0000 | [diff] [blame] | 158 | #ifdef DEBUG |
| 159 | fprintf(stderr, "get_verbatim_kbinput(): kbinput = %d\n", kbinput); |
| 160 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 161 | } |
| 162 | nodelay(win, FALSE); |
| 163 | } |
| 164 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 165 | /* Turn flow control characters back on if necessary and turn the |
| 166 | * keypad back on now that we're done. */ |
| 167 | if (ISSET(PRESERVE)) |
| 168 | enable_flow_control(); |
David Lawrence Ramsey | ce991bb | 2004-03-29 18:36:39 +0000 | [diff] [blame] | 169 | keypad(win, TRUE); |
David Lawrence Ramsey | 58f6d83 | 2004-01-27 07:12:47 +0000 | [diff] [blame] | 170 | |
David Lawrence Ramsey | 369732f | 2004-02-16 20:32:40 +0000 | [diff] [blame] | 171 | #ifndef NANO_SMALL |
| 172 | allow_pending_sigwinch(FALSE); |
| 173 | #endif |
| 174 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 175 | return verbatim_kbinput; |
| 176 | } |
| 177 | |
| 178 | /* Swallow input characters that should be quietly ignored, and return |
| 179 | * the first input character that shouldn't be. */ |
| 180 | int get_ignored_kbinput(WINDOW *win) |
| 181 | { |
| 182 | int kbinput; |
| 183 | |
David Lawrence Ramsey | 6aec4b8 | 2004-03-15 20:26:30 +0000 | [diff] [blame] | 184 | while (TRUE) { |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 185 | kbinput = wgetch(win); |
| 186 | switch (kbinput) { |
| 187 | case ERR: |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 188 | #ifdef KEY_RESIZE |
| 189 | /* Slang and SunOS 5.7-5.9 don't support KEY_RESIZE. */ |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 190 | case KEY_RESIZE: |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 191 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 192 | #ifdef PDCURSES |
| 193 | case KEY_SHIFT_L: |
| 194 | case KEY_SHIFT_R: |
| 195 | case KEY_CONTROL_L: |
| 196 | case KEY_CONTROL_R: |
| 197 | case KEY_ALT_L: |
| 198 | case KEY_ALT_R: |
| 199 | #endif |
| 200 | #ifdef DEBUG |
| 201 | fprintf(stderr, "get_ignored_kbinput(): kbinput = %d\n", kbinput); |
| 202 | #endif |
| 203 | break; |
| 204 | default: |
| 205 | return kbinput; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 210 | /* Translate acceptable ASCII, extended keypad values, and/or escape |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 211 | * sequences. Set meta_key to 1 if we get a Meta sequence. Assume |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 212 | * nodelay(win) is FALSE. */ |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 213 | int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta_key) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 214 | { |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 215 | *meta_key = FALSE; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 216 | |
| 217 | switch (kbinput) { |
| 218 | case NANO_CONTROL_3: /* Escape */ |
David Lawrence Ramsey | 2506136 | 2004-01-16 19:12:46 +0000 | [diff] [blame] | 219 | kbinput = wgetch(win); |
| 220 | switch (kbinput) { |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 221 | case NANO_CONTROL_3: /* Escape */ |
| 222 | kbinput = wgetch(win); |
| 223 | /* Esc Esc [three-digit decimal ASCII code from |
| 224 | * 000-255] == [corresponding ASCII character]; |
David Lawrence Ramsey | d390dd8 | 2004-02-07 03:38:02 +0000 | [diff] [blame] | 225 | * Esc Esc 2 obviously can't be Ctrl-2 here */ |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 226 | if (kbinput >= '0' && kbinput <= '2') |
| 227 | kbinput = get_ascii_kbinput(win, kbinput); |
| 228 | /* Esc Esc [character] == Ctrl-[character]; |
| 229 | * Ctrl-Space (Ctrl-2) == Ctrl-@ == Ctrl-` */ |
| 230 | else if (kbinput == ' ' || kbinput == '@' || kbinput == '`') |
| 231 | kbinput = NANO_CONTROL_SPACE; |
| 232 | /* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-_) */ |
| 233 | else if (kbinput >= '3' && kbinput <= '7') |
| 234 | kbinput -= 24; |
| 235 | /* Ctrl-8 (Ctrl-?) */ |
| 236 | else if (kbinput == '8' || kbinput == '?') |
| 237 | kbinput = NANO_CONTROL_8; |
| 238 | /* Ctrl-A to Ctrl-_ */ |
| 239 | else if (kbinput >= 'A' && kbinput <= '_') |
| 240 | kbinput -= 64; |
David Lawrence Ramsey | da8fd8f | 2003-09-16 01:22:31 +0000 | [diff] [blame] | 241 | /* Ctrl-A to Ctrl-~ */ |
| 242 | else if (kbinput >= 'a' && kbinput <= '~') |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 243 | kbinput -= 96; |
| 244 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 245 | case 'O': |
| 246 | case 'o': |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 247 | case '[': |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 248 | { |
David Lawrence Ramsey | 805547f | 2004-04-22 03:41:04 +0000 | [diff] [blame] | 249 | int old_kbinput = kbinput, *escape_seq; |
| 250 | size_t escape_seq_len; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 251 | nodelay(win, TRUE); |
| 252 | kbinput = wgetch(win); |
| 253 | switch (kbinput) { |
| 254 | case ERR: |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 255 | kbinput = tolower(old_kbinput); |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 256 | *meta_key = TRUE; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 257 | break; |
| 258 | default: |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 259 | ungetch(kbinput); |
| 260 | ungetch(old_kbinput); |
| 261 | escape_seq = get_verbatim_kbinput(win, &escape_seq_len, 0); |
| 262 | kbinput = get_escape_seq_kbinput(win, escape_seq, escape_seq_len); |
| 263 | free(escape_seq); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 264 | } |
| 265 | nodelay(win, FALSE); |
| 266 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 267 | } |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 268 | default: |
| 269 | /* Esc [character] == Meta-[character] */ |
David Lawrence Ramsey | da8fd8f | 2003-09-16 01:22:31 +0000 | [diff] [blame] | 270 | kbinput = tolower(kbinput); |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 271 | *meta_key = TRUE; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 272 | } |
| 273 | break; |
David Lawrence Ramsey | 7776ef9 | 2003-11-04 18:32:35 +0000 | [diff] [blame] | 274 | case NANO_CONTROL_8: |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 275 | kbinput = ISSET(REBIND_DELETE) ? NANO_DELETE_KEY : NANO_BACKSPACE_KEY; |
David Lawrence Ramsey | 7776ef9 | 2003-11-04 18:32:35 +0000 | [diff] [blame] | 276 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 277 | case KEY_DOWN: |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 278 | kbinput = NANO_NEXTLINE_KEY; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 279 | break; |
| 280 | case KEY_UP: |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 281 | kbinput = NANO_PREVLINE_KEY; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 282 | break; |
| 283 | case KEY_LEFT: |
| 284 | kbinput = NANO_BACK_KEY; |
| 285 | break; |
| 286 | case KEY_RIGHT: |
| 287 | kbinput = NANO_FORWARD_KEY; |
| 288 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 289 | #ifdef KEY_HOME |
| 290 | /* HP-UX 10 and 11 don't support KEY_HOME. */ |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 291 | case KEY_HOME: |
| 292 | kbinput = NANO_HOME_KEY; |
| 293 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 294 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 295 | case KEY_BACKSPACE: |
| 296 | kbinput = NANO_BACKSPACE_KEY; |
| 297 | break; |
| 298 | case KEY_DC: |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 299 | kbinput = ISSET(REBIND_DELETE) ? NANO_BACKSPACE_KEY : NANO_DELETE_KEY; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 300 | break; |
| 301 | case KEY_IC: |
| 302 | kbinput = NANO_INSERTFILE_KEY; |
| 303 | break; |
| 304 | case KEY_NPAGE: |
| 305 | kbinput = NANO_NEXTPAGE_KEY; |
| 306 | break; |
| 307 | case KEY_PPAGE: |
| 308 | kbinput = NANO_PREVPAGE_KEY; |
| 309 | break; |
| 310 | case KEY_ENTER: |
| 311 | kbinput = NANO_ENTER_KEY; |
| 312 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 313 | case KEY_B2: /* Center (5) on numeric keypad with NumLock off |
| 314 | * on xterm. */ |
| 315 | #ifdef KEY_BEG |
| 316 | /* Slang doesn't support KEY_BEG. */ |
| 317 | case KEY_BEG: /* Center (5) on numeric keypad with NumLock off |
| 318 | * on Eterm. */ |
| 319 | #endif |
| 320 | kbinput = '5'; |
| 321 | break; |
| 322 | #ifdef KEY_END |
| 323 | /* HP-UX 10 and 11 don't support KEY_END. */ |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 324 | case KEY_END: |
| 325 | kbinput = NANO_END_KEY; |
| 326 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 327 | #endif |
| 328 | #ifdef KEY_SUSPEND |
| 329 | /* Slang doesn't support KEY_SUSPEND. */ |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 330 | case KEY_SUSPEND: |
| 331 | kbinput = NANO_SUSPEND_KEY; |
| 332 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 333 | #endif |
| 334 | #ifdef KEY_SLEFT |
| 335 | /* Slang doesn't support KEY_SLEFT. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 336 | case KEY_SLEFT: |
| 337 | kbinput = NANO_BACK_KEY; |
| 338 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 339 | #endif |
| 340 | #ifdef KEY_SRIGHT |
| 341 | /* Slang doesn't support KEY_SRIGHT. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 342 | case KEY_SRIGHT: |
| 343 | kbinput = NANO_FORWARD_KEY; |
| 344 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 345 | #endif |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 346 | } |
| 347 | #ifdef DEBUG |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 348 | fprintf(stderr, "get_accepted_kbinput(): kbinput = %d, meta_key = %d\n", kbinput, *meta_key); |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 349 | #endif |
| 350 | return kbinput; |
| 351 | } |
| 352 | |
| 353 | /* Translate a three-digit decimal ASCII code from 000-255 into the |
| 354 | * corresponding ASCII character. */ |
| 355 | int get_ascii_kbinput(WINDOW *win, int kbinput) |
| 356 | { |
| 357 | int retval; |
| 358 | |
| 359 | switch (kbinput) { |
| 360 | case '0': |
| 361 | case '1': |
| 362 | case '2': |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 363 | retval = (kbinput - '0') * 100; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 364 | break; |
| 365 | default: |
| 366 | return kbinput; |
| 367 | } |
| 368 | |
| 369 | kbinput = wgetch(win); |
| 370 | switch (kbinput) { |
| 371 | case '0': |
| 372 | case '1': |
| 373 | case '2': |
| 374 | case '3': |
| 375 | case '4': |
| 376 | case '5': |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 377 | retval += (kbinput - '0') * 10; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 378 | break; |
| 379 | case '6': |
| 380 | case '7': |
| 381 | case '8': |
| 382 | case '9': |
| 383 | if (retval < 200) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 384 | retval += (kbinput - '0') * 10; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 385 | break; |
| 386 | } |
| 387 | default: |
| 388 | return kbinput; |
| 389 | } |
| 390 | |
| 391 | kbinput = wgetch(win); |
| 392 | switch (kbinput) { |
| 393 | case '0': |
| 394 | case '1': |
| 395 | case '2': |
| 396 | case '3': |
| 397 | case '4': |
| 398 | case '5': |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 399 | retval += kbinput - '0'; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 400 | break; |
| 401 | case '6': |
| 402 | case '7': |
| 403 | case '8': |
| 404 | case '9': |
| 405 | if (retval < 250) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 406 | retval += kbinput - '0'; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | default: |
| 410 | return kbinput; |
| 411 | } |
| 412 | |
| 413 | #ifdef DEBUG |
| 414 | fprintf(stderr, "get_ascii_kbinput(): kbinput = %d\n", kbinput); |
| 415 | #endif |
| 416 | return retval; |
| 417 | } |
| 418 | |
David Lawrence Ramsey | 58f6d83 | 2004-01-27 07:12:47 +0000 | [diff] [blame] | 419 | /* Translate escape sequences, most of which correspond to extended |
| 420 | * keypad values. These sequences are generated when the terminal |
| 421 | * doesn't support the needed keys. Assume that Escape has already been |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 422 | * read in, and that nodelay(win) is TRUE. */ |
David Lawrence Ramsey | 805547f | 2004-04-22 03:41:04 +0000 | [diff] [blame] | 423 | int get_escape_seq_kbinput(WINDOW *win, int *escape_seq, size_t |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 424 | escape_seq_len) |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 425 | { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 426 | int kbinput = ERR; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 427 | |
| 428 | if (escape_seq_len > 1) { |
| 429 | switch (escape_seq[0]) { |
| 430 | case 'O': |
| 431 | switch (escape_seq[1]) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 432 | case '2': |
| 433 | if (escape_seq_len >= 3) { |
| 434 | switch (escape_seq[2]) { |
| 435 | case 'P': /* Esc O 2 P == F13 on |
| 436 | * xterm. */ |
| 437 | kbinput = KEY_F(13); |
| 438 | break; |
| 439 | case 'Q': /* Esc O 2 Q == F14 on |
| 440 | * xterm. */ |
| 441 | kbinput = KEY_F(14); |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 446 | case 'A': /* Esc O A == Up on VT100/VT320/xterm. */ |
| 447 | case 'B': /* Esc O B == Down on |
| 448 | * VT100/VT320/xterm. */ |
| 449 | case 'C': /* Esc O C == Right on |
| 450 | * VT100/VT320/xterm. */ |
| 451 | case 'D': /* Esc O D == Left on |
| 452 | * VT100/VT320/xterm. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 453 | kbinput = get_escape_seq_abcd(escape_seq[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 454 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 455 | case 'E': /* Esc O E == Center (5) on numeric keypad |
| 456 | * with NumLock off on xterm. */ |
| 457 | kbinput = '5'; |
| 458 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 459 | case 'F': /* Esc O F == End on xterm. */ |
| 460 | kbinput = NANO_END_KEY; |
| 461 | break; |
| 462 | case 'H': /* Esc O H == Home on xterm. */ |
| 463 | kbinput = NANO_HOME_KEY; |
| 464 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 465 | case 'M': /* Esc O M == Enter on numeric keypad with |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 466 | * NumLock off on |
| 467 | * VT100/VT220/VT320/xterm/Eterm. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 468 | kbinput = NANO_ENTER_KEY; |
| 469 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 470 | case 'P': /* Esc O P == F1 on VT100/VT220/VT320/Hurd |
| 471 | * console. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 472 | kbinput = KEY_F(1); |
| 473 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 474 | case 'Q': /* Esc O Q == F2 on VT100/VT220/VT320/Hurd |
| 475 | * console. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 476 | kbinput = KEY_F(2); |
| 477 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 478 | case 'R': /* Esc O R == F3 on VT100/VT220/VT320/Hurd |
| 479 | * console. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 480 | kbinput = KEY_F(3); |
| 481 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 482 | case 'S': /* Esc O S == F4 on VT100/VT220/VT320/Hurd |
| 483 | * console. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 484 | kbinput = KEY_F(4); |
| 485 | break; |
| 486 | case 'T': /* Esc O T == F5 on Hurd console. */ |
| 487 | kbinput = KEY_F(5); |
| 488 | break; |
| 489 | case 'U': /* Esc O U == F6 on Hurd console. */ |
| 490 | kbinput = KEY_F(6); |
| 491 | break; |
| 492 | case 'V': /* Esc O V == F7 on Hurd console. */ |
| 493 | kbinput = KEY_F(7); |
| 494 | break; |
| 495 | case 'W': /* Esc O W == F8 on Hurd console. */ |
| 496 | kbinput = KEY_F(8); |
| 497 | break; |
| 498 | case 'X': /* Esc O X == F9 on Hurd console. */ |
| 499 | kbinput = KEY_F(9); |
| 500 | break; |
| 501 | case 'Y': /* Esc O Y == F10 on Hurd console. */ |
| 502 | kbinput = KEY_F(10); |
| 503 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 504 | case 'a': /* Esc O a == Ctrl-Up on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 505 | case 'b': /* Esc O b == Ctrl-Down on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 506 | case 'c': /* Esc O c == Ctrl-Right on rxvt. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 507 | case 'd': /* Esc O d == Ctrl-Left on rxvt. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 508 | kbinput = get_escape_seq_abcd(escape_seq[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 509 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 510 | case 'j': /* Esc O j == '*' on numeric keypad with |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 511 | * NumLock off on |
| 512 | * VT100/VT220/VT320/xterm/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 513 | kbinput = '*'; |
| 514 | break; |
| 515 | case 'k': /* Esc O k == '+' on numeric keypad with |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 516 | * NumLock off on |
| 517 | * VT100/VT220/VT320/xterm/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 518 | kbinput = '+'; |
| 519 | break; |
| 520 | case 'l': /* Esc O l == ',' on numeric keypad with |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 521 | * NumLock off on |
| 522 | * VT100/VT220/VT320/xterm/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 523 | kbinput = '+'; |
| 524 | break; |
| 525 | case 'm': /* Esc O m == '-' on numeric keypad with |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 526 | * NumLock off on |
| 527 | * VT100/VT220/VT320/xterm/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 528 | kbinput = '-'; |
| 529 | break; |
| 530 | case 'n': /* Esc O n == Delete (.) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 531 | * with NumLock off on |
| 532 | * VT100/VT220/VT320/xterm/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 533 | kbinput = NANO_DELETE_KEY; |
| 534 | break; |
| 535 | case 'o': /* Esc O o == '/' on numeric keypad with |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 536 | * NumLock off on |
| 537 | * VT100/VT220/VT320/xterm/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 538 | kbinput = '/'; |
| 539 | break; |
| 540 | case 'p': /* Esc O p == Insert (0) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 541 | * with NumLock off on |
| 542 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 543 | kbinput = NANO_INSERTFILE_KEY; |
| 544 | break; |
| 545 | case 'q': /* Esc O q == End (1) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 546 | * with NumLock off on |
| 547 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 548 | kbinput = NANO_END_KEY; |
| 549 | break; |
| 550 | case 'r': /* Esc O r == Down (2) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 551 | * with NumLock off on |
| 552 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 553 | kbinput = NANO_NEXTLINE_KEY; |
| 554 | break; |
| 555 | case 's': /* Esc O s == PageDown (3) on numeric |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 556 | * keypad with NumLock off on |
| 557 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 558 | kbinput = NANO_NEXTPAGE_KEY; |
| 559 | break; |
| 560 | case 't': /* Esc O t == Left (4) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 561 | * with NumLock off on |
| 562 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 563 | kbinput = NANO_BACK_KEY; |
| 564 | break; |
| 565 | case 'u': /* Esc O u == Center (5) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 566 | * with NumLock off on |
| 567 | * VT100/VT220/VT320/rxvt/Eterm. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 568 | kbinput = '5'; |
| 569 | break; |
| 570 | case 'v': /* Esc O v == Right (6) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 571 | * with NumLock off on |
| 572 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 573 | kbinput = NANO_FORWARD_KEY; |
| 574 | break; |
| 575 | case 'w': /* Esc O w == Home (7) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 576 | * with NumLock off on |
| 577 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 578 | kbinput = NANO_HOME_KEY; |
| 579 | break; |
| 580 | case 'x': /* Esc O x == Up (8) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 581 | * with NumLock off on |
| 582 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 583 | kbinput = NANO_PREVLINE_KEY; |
| 584 | break; |
| 585 | case 'y': /* Esc O y == PageUp (9) on numeric keypad |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 586 | * with NumLock off on |
| 587 | * VT100/VT220/VT320/rxvt. */ |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 588 | kbinput = NANO_PREVPAGE_KEY; |
| 589 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 590 | } |
| 591 | break; |
| 592 | case 'o': |
| 593 | switch (escape_seq[1]) { |
| 594 | case 'a': /* Esc o a == Ctrl-Up on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 595 | case 'b': /* Esc o b == Ctrl-Down on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 596 | case 'c': /* Esc o c == Ctrl-Right on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 597 | case 'd': /* Esc o d == Ctrl-Left on Eterm. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 598 | kbinput = get_escape_seq_abcd(escape_seq[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 599 | break; |
| 600 | } |
| 601 | break; |
| 602 | case '[': |
| 603 | switch (escape_seq[1]) { |
| 604 | case '1': |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 605 | if (escape_seq_len >= 3) { |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 606 | switch (escape_seq[2]) { |
| 607 | case '1': /* Esc [ 1 1 ~ == F1 on |
| 608 | * rxvt/Eterm. */ |
| 609 | kbinput = KEY_F(1); |
| 610 | break; |
| 611 | case '2': /* Esc [ 1 2 ~ == F2 on |
| 612 | * rxvt/Eterm. */ |
| 613 | kbinput = KEY_F(2); |
| 614 | break; |
| 615 | case '3': /* Esc [ 1 3 ~ == F3 on |
| 616 | * rxvt/Eterm. */ |
| 617 | kbinput = KEY_F(3); |
| 618 | break; |
| 619 | case '4': /* Esc [ 1 4 ~ == F4 on |
| 620 | * rxvt/Eterm. */ |
| 621 | kbinput = KEY_F(4); |
| 622 | break; |
| 623 | case '5': /* Esc [ 1 5 ~ == F5 on |
| 624 | * xterm/rxvt/Eterm. */ |
| 625 | kbinput = KEY_F(5); |
| 626 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 627 | case '7': /* Esc [ 1 7 ~ == F6 on |
| 628 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 629 | * console/xterm/rxvt/Eterm. */ |
| 630 | kbinput = KEY_F(6); |
| 631 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 632 | case '8': /* Esc [ 1 8 ~ == F7 on |
| 633 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 634 | * console/xterm/rxvt/Eterm. */ |
| 635 | kbinput = KEY_F(7); |
| 636 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 637 | case '9': /* Esc [ 1 9 ~ == F8 on |
| 638 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 639 | * console/xterm/rxvt/Eterm. */ |
| 640 | kbinput = KEY_F(8); |
| 641 | break; |
David Lawrence Ramsey | ee383db | 2004-02-06 03:07:10 +0000 | [diff] [blame] | 642 | case ';': |
| 643 | if (escape_seq_len >= 4) { |
| 644 | switch (escape_seq[3]) { |
| 645 | case '2': |
| 646 | if (escape_seq_len >= 5) { |
| 647 | switch (escape_seq[4]) { |
| 648 | case 'A': /* Esc [ 1 ; 2 A == Shift-Up on |
| 649 | * xterm. */ |
| 650 | case 'B': /* Esc [ 1 ; 2 B == Shift-Down on |
| 651 | * xterm. */ |
| 652 | case 'C': /* Esc [ 1 ; 2 C == Shift-Right on |
| 653 | * xterm. */ |
| 654 | case 'D': /* Esc [ 1 ; 2 D == Shift-Left on |
| 655 | * xterm. */ |
| 656 | kbinput = get_escape_seq_abcd(escape_seq[4]); |
| 657 | break; |
| 658 | } |
| 659 | } |
| 660 | break; |
| 661 | case '5': |
| 662 | if (escape_seq_len >= 5) { |
| 663 | switch (escape_seq[4]) { |
| 664 | case 'A': /* Esc [ 1 ; 5 A == Ctrl-Up on |
| 665 | * xterm. */ |
| 666 | case 'B': /* Esc [ 1 ; 5 B == Ctrl-Down on |
| 667 | * xterm. */ |
| 668 | case 'C': /* Esc [ 1 ; 5 C == Ctrl-Right on |
| 669 | * xterm. */ |
| 670 | case 'D': /* Esc [ 1 ; 5 D == Ctrl-Left on |
| 671 | * xterm. */ |
| 672 | kbinput = get_escape_seq_abcd(escape_seq[4]); |
| 673 | break; |
| 674 | } |
| 675 | } |
| 676 | break; |
| 677 | } |
| 678 | } |
| 679 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 680 | default: /* Esc [ 1 ~ == Home on |
| 681 | * VT320/Linux console. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 682 | kbinput = NANO_HOME_KEY; |
| 683 | break; |
| 684 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 685 | } |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 686 | break; |
| 687 | case '2': |
| 688 | if (escape_seq_len >= 3) { |
| 689 | switch (escape_seq[2]) { |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 690 | case '0': /* Esc [ 2 0 ~ == F9 on |
| 691 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 692 | * console/xterm/rxvt/Eterm. */ |
| 693 | kbinput = KEY_F(9); |
| 694 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 695 | case '1': /* Esc [ 2 1 ~ == F10 on |
| 696 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 697 | * console/xterm/rxvt/Eterm. */ |
| 698 | kbinput = KEY_F(10); |
| 699 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 700 | case '3': /* Esc [ 2 3 ~ == F11 on |
| 701 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 702 | * console/xterm/rxvt/Eterm. */ |
| 703 | kbinput = KEY_F(11); |
| 704 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 705 | case '4': /* Esc [ 2 4 ~ == F12 on |
| 706 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 707 | * console/xterm/rxvt/Eterm. */ |
| 708 | kbinput = KEY_F(12); |
| 709 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 710 | case '5': /* Esc [ 2 5 ~ == F13 on |
| 711 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 712 | * console/rxvt/Eterm. */ |
| 713 | kbinput = KEY_F(13); |
| 714 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 715 | case '6': /* Esc [ 2 6 ~ == F14 on |
| 716 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 717 | * console/rxvt/Eterm. */ |
| 718 | kbinput = KEY_F(14); |
| 719 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 720 | default: /* Esc [ 2 ~ == Insert on |
| 721 | * VT220/VT320/Linux |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 722 | * console/xterm. */ |
| 723 | kbinput = NANO_INSERTFILE_KEY; |
| 724 | break; |
| 725 | } |
| 726 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 727 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 728 | case '3': /* Esc [ 3 ~ == Delete on |
| 729 | * VT220/VT320/Linux console/xterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 730 | kbinput = NANO_DELETE_KEY; |
| 731 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 732 | case '4': /* Esc [ 4 ~ == End on VT220/VT320/Linux |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 733 | * console/xterm. */ |
| 734 | kbinput = NANO_END_KEY; |
| 735 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 736 | case '5': /* Esc [ 5 ~ == PageUp on |
| 737 | * VT220/VT320/Linux console/xterm; Esc [ |
| 738 | * 5 ^ == PageUp on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 739 | kbinput = NANO_PREVPAGE_KEY; |
| 740 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 741 | case '6': /* Esc [ 6 ~ == PageDown on |
| 742 | * VT220/VT320/Linux console/xterm; Esc [ |
| 743 | * 6 ^ == PageDown on Eterm. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 744 | kbinput = NANO_NEXTPAGE_KEY; |
| 745 | break; |
| 746 | case '7': /* Esc [ 7 ~ == Home on rxvt. */ |
| 747 | kbinput = NANO_HOME_KEY; |
| 748 | break; |
| 749 | case '8': /* Esc [ 8 ~ == End on rxvt. */ |
| 750 | kbinput = NANO_END_KEY; |
| 751 | break; |
| 752 | case '9': /* Esc [ 9 == Delete on Hurd console. */ |
| 753 | kbinput = NANO_DELETE_KEY; |
| 754 | break; |
| 755 | case '@': /* Esc [ @ == Insert on Hurd console. */ |
| 756 | kbinput = NANO_INSERTFILE_KEY; |
| 757 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 758 | case 'A': /* Esc [ A == Up on ANSI/VT220/Linux |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 759 | * console/FreeBSD console/Hurd |
| 760 | * console/rxvt/Eterm. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 761 | case 'B': /* Esc [ B == Down on ANSI/VT220/Linux |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 762 | * console/FreeBSD console/Hurd |
| 763 | * console/rxvt/Eterm. */ |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 764 | case 'C': /* Esc [ C == Right on ANSI/VT220/Linux |
| 765 | * console/FreeBSD console/Hurd |
| 766 | * console/rxvt/Eterm. */ |
| 767 | case 'D': /* Esc [ D == Left on ANSI/VT220/Linux |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 768 | * console/FreeBSD console/Hurd |
| 769 | * console/rxvt/Eterm. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 770 | kbinput = get_escape_seq_abcd(escape_seq[1]); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 771 | break; |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 772 | case 'E': /* Esc [ E == Center (5) on numeric keypad |
| 773 | * with NumLock off on FreeBSD console. */ |
| 774 | kbinput = '5'; |
| 775 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 776 | case 'F': /* Esc [ F == End on FreeBSD |
| 777 | * console/Eterm. */ |
| 778 | kbinput = NANO_END_KEY; |
| 779 | break; |
| 780 | case 'G': /* Esc [ G == PageDown on FreeBSD |
David Lawrence Ramsey | 0a25808 | 2004-04-23 18:02:37 +0000 | [diff] [blame] | 781 | * console. */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 782 | kbinput = NANO_NEXTPAGE_KEY; |
| 783 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 784 | case 'H': /* Esc [ H == Home on ANSI/VT220/FreeBSD |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 785 | * console/Hurd console/Eterm. */ |
| 786 | kbinput = NANO_HOME_KEY; |
| 787 | break; |
| 788 | case 'I': /* Esc [ I == PageUp on FreeBSD |
| 789 | * console. */ |
| 790 | kbinput = NANO_PREVPAGE_KEY; |
| 791 | break; |
David Lawrence Ramsey | 0381c21 | 2004-05-01 01:21:38 +0000 | [diff] [blame] | 792 | case 'L': /* Esc [ L == Insert on ANSI/FreeBSD |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 793 | * console. */ |
| 794 | kbinput = NANO_INSERTFILE_KEY; |
| 795 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 796 | case 'M': /* Esc [ M == F1 on FreeBSD console. */ |
| 797 | kbinput = KEY_F(1); |
| 798 | break; |
| 799 | case 'N': /* Esc [ N == F2 on FreeBSD console. */ |
| 800 | kbinput = KEY_F(2); |
| 801 | break; |
| 802 | case 'O': |
| 803 | if (escape_seq_len >= 3) { |
| 804 | switch (escape_seq[2]) { |
| 805 | case 'P': /* Esc [ O P == F1 on |
| 806 | * xterm. */ |
| 807 | kbinput = KEY_F(1); |
| 808 | break; |
| 809 | case 'Q': /* Esc [ O Q == F2 on |
| 810 | * xterm. */ |
| 811 | kbinput = KEY_F(2); |
| 812 | break; |
| 813 | case 'R': /* Esc [ O R == F3 on |
| 814 | * xterm. */ |
| 815 | kbinput = KEY_F(3); |
| 816 | break; |
| 817 | case 'S': /* Esc [ O S == F4 on |
| 818 | * xterm. */ |
| 819 | kbinput = KEY_F(4); |
| 820 | break; |
| 821 | default: /* Esc [ O == F3 on |
| 822 | * FreeBSD console. */ |
| 823 | kbinput = KEY_F(3); |
| 824 | break; |
| 825 | } |
| 826 | } |
| 827 | break; |
| 828 | case 'P': /* Esc [ P == F4 on FreeBSD console. */ |
| 829 | kbinput = KEY_F(4); |
| 830 | break; |
| 831 | case 'Q': /* Esc [ Q == F5 on FreeBSD console. */ |
| 832 | kbinput = KEY_F(5); |
| 833 | break; |
| 834 | case 'R': /* Esc [ R == F6 on FreeBSD console. */ |
| 835 | kbinput = KEY_F(6); |
| 836 | break; |
| 837 | case 'S': /* Esc [ S == F7 on FreeBSD console. */ |
| 838 | kbinput = KEY_F(7); |
| 839 | break; |
| 840 | case 'T': /* Esc [ T == F8 on FreeBSD console. */ |
| 841 | kbinput = KEY_F(8); |
| 842 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 843 | case 'U': /* Esc [ U == PageDown on Hurd console. */ |
| 844 | kbinput = NANO_NEXTPAGE_KEY; |
| 845 | break; |
| 846 | case 'V': /* Esc [ V == PageUp on Hurd console. */ |
| 847 | kbinput = NANO_PREVPAGE_KEY; |
| 848 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 849 | case 'W': /* Esc [ W == F11 on FreeBSD console. */ |
| 850 | kbinput = KEY_F(11); |
| 851 | break; |
| 852 | case 'X': /* Esc [ X == F12 on FreeBSD console. */ |
| 853 | kbinput = KEY_F(12); |
| 854 | break; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 855 | case 'Y': /* Esc [ Y == End on Hurd console. */ |
| 856 | kbinput = NANO_END_KEY; |
| 857 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 858 | case 'Z': /* Esc [ Z == F14 on FreeBSD console. */ |
| 859 | kbinput = KEY_F(14); |
| 860 | break; |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 861 | case 'a': /* Esc [ a == Shift-Up on rxvt/Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 862 | case 'b': /* Esc [ b == Shift-Down on rxvt/Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 863 | case 'c': /* Esc [ c == Shift-Right on |
| 864 | * rxvt/Eterm. */ |
David Lawrence Ramsey | 9b5bd42 | 2004-01-06 01:45:04 +0000 | [diff] [blame] | 865 | case 'd': /* Esc [ d == Shift-Left on rxvt/Eterm. */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 866 | kbinput = get_escape_seq_abcd(escape_seq[1]); |
| 867 | break; |
| 868 | case '[': |
| 869 | if (escape_seq_len >= 3) { |
| 870 | switch (escape_seq[2]) { |
| 871 | case 'A': /* Esc [ [ A == F1 on Linux |
| 872 | * console. */ |
| 873 | kbinput = KEY_F(1); |
| 874 | break; |
| 875 | case 'B': /* Esc [ [ B == F2 on Linux |
| 876 | * console. */ |
| 877 | kbinput = KEY_F(2); |
| 878 | break; |
| 879 | case 'C': /* Esc [ [ C == F3 on Linux |
| 880 | * console. */ |
| 881 | kbinput = KEY_F(3); |
| 882 | break; |
| 883 | case 'D': /* Esc [ [ D == F4 on Linux |
| 884 | * console. */ |
| 885 | kbinput = KEY_F(4); |
| 886 | break; |
| 887 | case 'E': /* Esc [ [ E == F5 on Linux |
| 888 | * console. */ |
| 889 | kbinput = KEY_F(5); |
| 890 | break; |
| 891 | } |
| 892 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 893 | break; |
| 894 | } |
| 895 | break; |
| 896 | } |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 897 | } |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 898 | |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 899 | if (kbinput == ERR) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 900 | /* This escape sequence is unrecognized; send it back. */ |
| 901 | for (; escape_seq_len > 1; escape_seq_len--) |
| 902 | ungetch(escape_seq[escape_seq_len - 1]); |
| 903 | kbinput = escape_seq[0]; |
| 904 | } |
| 905 | |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 906 | return kbinput; |
| 907 | } |
| 908 | |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 909 | /* Return the equivalent arrow key value for the case-insensitive |
David Lawrence Ramsey | b7e5cf6 | 2004-02-07 03:39:48 +0000 | [diff] [blame] | 910 | * letters A (up), B (down), C (right), and D (left). These are common |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 911 | * to many escape sequences. */ |
| 912 | int get_escape_seq_abcd(int kbinput) |
| 913 | { |
| 914 | switch (tolower(kbinput)) { |
| 915 | case 'a': |
| 916 | return NANO_PREVLINE_KEY; |
| 917 | case 'b': |
| 918 | return NANO_NEXTLINE_KEY; |
| 919 | case 'c': |
| 920 | return NANO_FORWARD_KEY; |
| 921 | case 'd': |
| 922 | return NANO_BACK_KEY; |
| 923 | default: |
| 924 | return ERR; |
| 925 | } |
| 926 | } |
| 927 | |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 928 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 929 | /* Check for a mouse event, and if one's taken place, save the |
| 930 | * coordinates where it took place in mouse_x and mouse_y. After that, |
| 931 | * if allow_shortcuts is zero, return 0. Otherwise, if the mouse event |
| 932 | * took place on the shortcut list on the bottom two lines of the screen |
| 933 | * (assuming that the shortcut list is visible), figure out which |
| 934 | * shortcut was clicked and ungetch() the equivalent keystroke(s). |
| 935 | * Return 0 if no keystrokes were ungetch()ed, or 1 if at least one was. |
| 936 | * Assume that KEY_MOUSE has already been read in. */ |
| 937 | int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts) |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 938 | { |
| 939 | MEVENT mevent; |
| 940 | |
| 941 | *mouse_x = -1; |
| 942 | *mouse_y = -1; |
| 943 | |
| 944 | /* First, get the actual mouse event. */ |
| 945 | if (getmouse(&mevent) == ERR) |
| 946 | return 0; |
| 947 | |
| 948 | /* Save the screen coordinates where the mouse event took place. */ |
| 949 | *mouse_x = mevent.x; |
| 950 | *mouse_y = mevent.y; |
| 951 | |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 952 | /* If we're not allowing shortcuts' we're done now. */ |
| 953 | if (!allow_shortcuts) |
| 954 | return 0; |
| 955 | |
| 956 | /* Otherwise, if the current shortcut list is being displayed on the |
| 957 | * last two lines of the screen and the mouse event took place |
| 958 | * inside it, we need to figure out which shortcut was clicked and |
| 959 | * ungetch() the equivalent keystroke(s) for it. */ |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 960 | if (!ISSET(NO_HELP) && wenclose(bottomwin, *mouse_y, *mouse_x)) { |
| 961 | int i, j; |
| 962 | int currslen; |
| 963 | /* The number of shortcuts in the current shortcut list. */ |
| 964 | const shortcut *s = currshortcut; |
| 965 | /* The actual shortcut we clicked on, starting at the first |
| 966 | * one in the current shortcut list. */ |
| 967 | |
| 968 | /* Get the shortcut lists' length. */ |
| 969 | if (currshortcut == main_list) |
| 970 | currslen = MAIN_VISIBLE; |
| 971 | else |
| 972 | currslen = length_of_list(currshortcut); |
| 973 | |
| 974 | /* Calculate the width of each shortcut in the list (it's the |
| 975 | * same for all of them). */ |
| 976 | if (currslen < 2) |
| 977 | i = COLS / 6; |
| 978 | else |
| 979 | i = COLS / ((currslen / 2) + (currslen % 2)); |
| 980 | |
| 981 | /* Calculate the y-coordinates relative to the beginning of |
| 982 | * bottomwin, i.e, the bottom three lines of the screen. */ |
| 983 | j = *mouse_y - (editwinrows + 3); |
| 984 | |
| 985 | /* If we're on the statusbar, beyond the end of the shortcut |
| 986 | * list, or beyond the end of a shortcut on the right side of |
| 987 | * the screen, don't do anything. */ |
| 988 | if (j < 0 || (*mouse_x / i) >= currslen) |
| 989 | return 0; |
| 990 | j = (*mouse_x / i) * 2 + j; |
| 991 | if (j >= currslen) |
| 992 | return 0; |
| 993 | |
| 994 | /* Go through the shortcut list to determine which shortcut was |
| 995 | * clicked. */ |
| 996 | for (; j > 0; j--) |
| 997 | s = s->next; |
| 998 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 999 | /* And ungetch() the equivalent control key. If it's a Meta key |
| 1000 | * sequence, we need to ungetch() Escape too. Assume that the |
| 1001 | * shortcut has an equivalent control key, meta key sequence, or |
| 1002 | * both. */ |
| 1003 | if (s->ctrlval != NANO_NO_KEY) |
| 1004 | ungetch(s->ctrlval); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1005 | else if (s->ctrlval != NANO_NO_KEY) { |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1006 | ungetch(s->metaval); |
| 1007 | ungetch(NANO_CONTROL_3); |
| 1008 | } |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1009 | |
| 1010 | return 1; |
| 1011 | } |
| 1012 | return 0; |
| 1013 | } |
| 1014 | #endif |
| 1015 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1016 | int do_first_line(void) |
| 1017 | { |
| 1018 | current = fileage; |
| 1019 | placewewant = 0; |
| 1020 | current_x = 0; |
David Lawrence Ramsey | d91ab6e | 2003-09-07 23:57:24 +0000 | [diff] [blame] | 1021 | edit_update(current, TOP); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1022 | return 1; |
| 1023 | } |
| 1024 | |
| 1025 | int do_last_line(void) |
| 1026 | { |
| 1027 | current = filebot; |
| 1028 | placewewant = 0; |
| 1029 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 1030 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1031 | return 1; |
| 1032 | } |
| 1033 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1034 | /* Return the placewewant associated with current_x. That is, xplustabs |
| 1035 | * is the zero-based column position of the cursor. Value is no smaller |
| 1036 | * than current_x. */ |
| 1037 | size_t xplustabs(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1038 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1039 | return strnlenpt(current->data, current_x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1042 | /* actual_x() gives the index in str of the character displayed at |
| 1043 | * column xplus. That is, actual_x() is the largest value such that |
| 1044 | * strnlenpt(str, actual_x(str, xplus)) <= xplus. */ |
| 1045 | size_t actual_x(const char *str, size_t xplus) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1046 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1047 | size_t i = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1048 | /* the position in str, returned */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1049 | size_t length = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1050 | /* the screen display width to str[i] */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1051 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1052 | assert(str != NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1053 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1054 | for (; length < xplus && *str != '\0'; i++, str++) { |
| 1055 | if (*str == '\t') |
David Lawrence Ramsey | 0362c58 | 2003-09-30 03:31:56 +0000 | [diff] [blame] | 1056 | length += tabsize - (length % tabsize); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1057 | else if (is_cntrl_char((int)*str)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1058 | length += 2; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1059 | else |
| 1060 | length++; |
| 1061 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1062 | assert(length == strnlenpt(str - i, i)); |
| 1063 | assert(i <= strlen(str - i)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1064 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1065 | if (length > xplus) |
| 1066 | i--; |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1067 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1068 | return i; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
David Lawrence Ramsey | a3370c4 | 2004-04-05 01:08:14 +0000 | [diff] [blame] | 1071 | /* A strlen() with tabs factored in, similar to xplustabs(). How many |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame] | 1072 | * columns wide are the first size characters of buf? */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1073 | size_t strnlenpt(const char *buf, size_t size) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1074 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1075 | size_t length = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1076 | |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame] | 1077 | assert(buf != NULL); |
| 1078 | for (; *buf != '\0' && size != 0; size--, buf++) { |
| 1079 | if (*buf == '\t') |
| 1080 | length += tabsize - (length % tabsize); |
| 1081 | else if (is_cntrl_char((int)*buf)) |
| 1082 | length += 2; |
| 1083 | else |
| 1084 | length++; |
| 1085 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1086 | return length; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
David Lawrence Ramsey | 5dcba30 | 2003-09-28 19:15:18 +0000 | [diff] [blame] | 1089 | /* How many columns wide is buf? */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1090 | size_t strlenpt(const char *buf) |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 1091 | { |
David Lawrence Ramsey | 0b047c5 | 2004-03-29 23:09:08 +0000 | [diff] [blame] | 1092 | return strnlenpt(buf, (size_t)-1); |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1095 | void blank_titlebar(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1096 | { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1097 | mvwaddstr(topwin, 0, 0, hblank); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1100 | void blank_edit(void) |
| 1101 | { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1102 | size_t i; |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 1103 | for (i = 0; i < editwinrows; i++) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1104 | mvwaddstr(edit, i, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1107 | void blank_statusbar(void) |
| 1108 | { |
| 1109 | mvwaddstr(bottomwin, 0, 0, hblank); |
| 1110 | } |
| 1111 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1112 | void check_statblank(void) |
| 1113 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1114 | if (statblank > 1) |
| 1115 | statblank--; |
| 1116 | else if (statblank == 1 && !ISSET(CONSTUPDATE)) { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1117 | statblank = 0; |
| 1118 | blank_statusbar(); |
| 1119 | wnoutrefresh(bottomwin); |
| 1120 | reset_cursor(); |
| 1121 | wrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1122 | } |
| 1123 | } |
| 1124 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1125 | void blank_bottombars(void) |
| 1126 | { |
| 1127 | if (!ISSET(NO_HELP)) { |
| 1128 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 1129 | mvwaddstr(bottomwin, 2, 0, hblank); |
| 1130 | } |
| 1131 | } |
| 1132 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1133 | /* Convert buf into a string that can be displayed on screen. The |
| 1134 | * caller wants to display buf starting with column start_col, and |
| 1135 | * extending for at most len columns. start_col is zero-based. len is |
| 1136 | * one-based, so len == 0 means you get "" returned. The returned |
| 1137 | * string is dynamically allocated, and should be freed. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1138 | char *display_string(const char *buf, size_t start_col, size_t len) |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1139 | { |
| 1140 | size_t start_index; |
| 1141 | /* Index in buf of first character shown in return value. */ |
| 1142 | size_t column; |
| 1143 | /* Screen column start_index corresponds to. */ |
| 1144 | size_t end_index; |
| 1145 | /* Index in buf of last character shown in return value. */ |
| 1146 | size_t alloc_len; |
| 1147 | /* The length of memory allocated for converted. */ |
| 1148 | char *converted; |
| 1149 | /* The string we return. */ |
| 1150 | size_t index; |
| 1151 | /* Current position in converted. */ |
| 1152 | |
| 1153 | if (len == 0) |
| 1154 | return mallocstrcpy(NULL, ""); |
| 1155 | |
| 1156 | start_index = actual_x(buf, start_col); |
| 1157 | column = strnlenpt(buf, start_index); |
| 1158 | assert(column <= start_col); |
| 1159 | end_index = actual_x(buf, start_col + len - 1); |
| 1160 | alloc_len = strnlenpt(buf, end_index + 1) - column; |
| 1161 | if (len > alloc_len + column - start_col) |
| 1162 | len = alloc_len + column - start_col; |
| 1163 | converted = charalloc(alloc_len + 1); |
| 1164 | buf += start_index; |
| 1165 | index = 0; |
| 1166 | |
| 1167 | for (; index < alloc_len; buf++) { |
| 1168 | if (*buf == '\t') |
| 1169 | do { |
| 1170 | converted[index++] = ' '; |
| 1171 | } while ((column + index) % tabsize); |
| 1172 | else if (is_cntrl_char(*buf)) { |
| 1173 | converted[index++] = '^'; |
| 1174 | if (*buf == '\n') |
| 1175 | /* Treat newlines embedded in a line as encoded nulls; |
| 1176 | * the line in question should be run through unsunder() |
| 1177 | * before reaching here. */ |
| 1178 | converted[index++] = '@'; |
| 1179 | else if (*buf == NANO_CONTROL_8) |
| 1180 | converted[index++] = '?'; |
| 1181 | else |
| 1182 | converted[index++] = *buf + 64; |
| 1183 | } else |
| 1184 | converted[index++] = *buf; |
| 1185 | } |
| 1186 | assert(len <= alloc_len + column - start_col); |
| 1187 | charmove(converted, converted + start_col - column, len); |
| 1188 | null_at(&converted, len); |
| 1189 | |
| 1190 | return charealloc(converted, len + 1); |
| 1191 | } |
| 1192 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1193 | /* Repaint the statusbar when getting a character in nanogetstr(). buf |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1194 | * should be no longer than max(0, COLS - 4). |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1195 | * |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1196 | * Note that we must turn on A_REVERSE here, since do_help() turns it |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1197 | * off! */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1198 | void nanoget_repaint(const char *buf, const char *inputbuf, size_t x) |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 1199 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1200 | size_t x_real = strnlenpt(inputbuf, x); |
| 1201 | int wid = COLS - strlen(buf) - 2; |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 1202 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1203 | assert(0 <= x && x <= strlen(inputbuf)); |
| 1204 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1205 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 1206 | blank_statusbar(); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1207 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1208 | mvwaddstr(bottomwin, 0, 0, buf); |
| 1209 | waddch(bottomwin, ':'); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1210 | |
| 1211 | if (COLS > 1) |
| 1212 | waddch(bottomwin, x_real < wid ? ' ' : '$'); |
| 1213 | if (COLS > 2) { |
| 1214 | size_t page_start = x_real - x_real % wid; |
| 1215 | char *expanded = display_string(inputbuf, page_start, wid); |
| 1216 | |
| 1217 | assert(wid > 0); |
| 1218 | assert(strlen(expanded) <= wid); |
| 1219 | waddstr(bottomwin, expanded); |
| 1220 | free(expanded); |
| 1221 | wmove(bottomwin, 0, COLS - wid + x_real - page_start); |
| 1222 | } else |
| 1223 | wmove(bottomwin, 0, COLS - 1); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1224 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
David Lawrence Ramsey | 6aec4b8 | 2004-03-15 20:26:30 +0000 | [diff] [blame] | 1227 | /* Get the input from the keyboard; this should only be called from |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1228 | * statusq(). */ |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 1229 | int nanogetstr(int allowtabs, const char *buf, const char *def, |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1230 | #ifndef NANO_SMALL |
| 1231 | historyheadtype *history_list, |
| 1232 | #endif |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1233 | const shortcut *s |
Rocco Corsi | 06aca1c | 2001-01-11 05:30:31 +0000 | [diff] [blame] | 1234 | #ifndef DISABLE_TABCOMP |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1235 | , int *list |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 1236 | #endif |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 1237 | ) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1238 | { |
| 1239 | int kbinput; |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1240 | int meta_key; |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1241 | static int x = -1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1242 | /* the cursor position in 'answer' */ |
| 1243 | int xend; |
| 1244 | /* length of 'answer', the status bar text */ |
| 1245 | int tabbed = 0; |
| 1246 | /* used by input_tab() */ |
| 1247 | const shortcut *t; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1248 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1249 | #ifndef NANO_SMALL |
| 1250 | /* for history */ |
| 1251 | char *history = NULL; |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 1252 | char *currentbuf = NULL; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1253 | char *complete = NULL; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1254 | int last_kbinput = 0; |
| 1255 | |
| 1256 | /* This variable is used in the search history code. use_cb == 0 |
| 1257 | means that we're using the existing history and ignoring |
| 1258 | currentbuf. use_cb == 1 means that the entry in answer should be |
| 1259 | moved to currentbuf or restored from currentbuf to answer. |
| 1260 | use_cb == 2 means that the entry in currentbuf should be moved to |
| 1261 | answer or restored from answer to currentbuf. */ |
| 1262 | int use_cb = 0; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1263 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1264 | xend = strlen(def); |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1265 | |
| 1266 | /* Only put x at the end of the string if it's uninitialized or if |
| 1267 | it would be past the end of the string as it is. Otherwise, |
| 1268 | leave it alone. This is so the cursor position stays at the same |
| 1269 | place if a prompt-changing toggle is pressed. */ |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 1270 | if (x == -1 || x > xend || resetstatuspos) |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1271 | x = xend; |
| 1272 | |
Chris Allegretta | e1e0fd6 | 2003-04-15 01:15:09 +0000 | [diff] [blame] | 1273 | answer = charealloc(answer, xend + 1); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1274 | if (xend > 0) |
| 1275 | strcpy(answer, def); |
| 1276 | else |
| 1277 | answer[0] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1278 | |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 1279 | #if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE) |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1280 | currshortcut = s; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 1281 | #endif |
| 1282 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1283 | /* Get the input! */ |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 1284 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1285 | nanoget_repaint(buf, answer, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1286 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1287 | /* Make sure any editor screen updates are displayed before getting |
| 1288 | input */ |
Chris Allegretta | 022b96f | 2000-11-14 17:47:58 +0000 | [diff] [blame] | 1289 | wrefresh(edit); |
| 1290 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1291 | while ((kbinput = get_kbinput(bottomwin, &meta_key)) != NANO_ENTER_KEY) { |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1292 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1293 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1294 | fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput); |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1295 | #endif |
| 1296 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1297 | /* Temporary hack to interpret NANO_HELP_FKEY correctly. */ |
| 1298 | if (kbinput == t->funcval) |
| 1299 | kbinput = t->ctrlval; |
David Lawrence Ramsey | d7f5ad9 | 2004-03-04 19:30:53 +0000 | [diff] [blame] | 1300 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1301 | if (kbinput == t->ctrlval && is_cntrl_char(kbinput)) { |
Chris Allegretta | 5bf51d3 | 2000-11-16 06:01:10 +0000 | [diff] [blame] | 1302 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1303 | #ifndef DISABLE_HELP |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1304 | /* Have to do this here, it would be too late to do it |
| 1305 | in statusq() */ |
David Lawrence Ramsey | d7f5ad9 | 2004-03-04 19:30:53 +0000 | [diff] [blame] | 1306 | if (kbinput == NANO_HELP_KEY) { |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1307 | do_help(); |
| 1308 | break; |
| 1309 | } |
| 1310 | #endif |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1311 | #ifndef NANO_SMALL |
| 1312 | /* Have to handle these here too, for the time being */ |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1313 | if (kbinput == NANO_PREVLINE_KEY || kbinput == NANO_NEXTLINE_KEY) |
David Lawrence Ramsey | a593f53 | 2003-11-28 19:47:42 +0000 | [diff] [blame] | 1314 | break; |
| 1315 | #endif |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 1316 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1317 | return t->ctrlval; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1318 | } |
| 1319 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1320 | assert(0 <= x && x <= xend && xend == strlen(answer)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1321 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1322 | if (kbinput != '\t') |
| 1323 | tabbed = 0; |
| 1324 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1325 | switch (kbinput) { |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 1326 | #ifndef DISABLE_MOUSE |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1327 | case KEY_MOUSE: |
| 1328 | do_mouse(); |
| 1329 | break; |
| 1330 | #endif |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1331 | case NANO_HOME_KEY: |
David Lawrence Ramsey | c7acf69 | 2004-05-22 20:15:20 +0000 | [diff] [blame] | 1332 | #ifndef NANO_SMALL |
| 1333 | if (ISSET(SMART_HOME)) { |
| 1334 | int old_x = x; |
| 1335 | |
| 1336 | for (x = 0; isblank(answer[x]) && x < xend; x++) |
| 1337 | ; |
| 1338 | |
| 1339 | if (x == old_x || x == xend) |
| 1340 | x = 0; |
| 1341 | } else |
| 1342 | #endif |
| 1343 | x = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1344 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1345 | case NANO_END_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1346 | x = xend; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1347 | break; |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 1348 | case NANO_FORWARD_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1349 | if (x < xend) |
| 1350 | x++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1351 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1352 | case NANO_DELETE_KEY: |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 1353 | if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) { |
| 1354 | if (x < xend) { |
| 1355 | charmove(answer + x, answer + x + 1, xend - x); |
| 1356 | xend--; |
| 1357 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1358 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1359 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1360 | case NANO_CUT_KEY: |
| 1361 | case NANO_UNCUT_KEY: |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 1362 | if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) { |
| 1363 | null_at(&answer, 0); |
| 1364 | xend = 0; |
| 1365 | x = 0; |
| 1366 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1367 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1368 | case NANO_BACKSPACE_KEY: |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 1369 | if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) { |
| 1370 | if (x > 0) { |
| 1371 | charmove(answer + x - 1, answer + x, xend - x + 1); |
| 1372 | x--; |
| 1373 | xend--; |
| 1374 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1375 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1376 | break; |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1377 | case NANO_TAB_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1378 | #ifndef NANO_SMALL |
| 1379 | /* tab history completion */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1380 | if (history_list != NULL) { |
David Lawrence Ramsey | 4d7c260 | 2003-08-17 02:48:43 +0000 | [diff] [blame] | 1381 | if (!complete || last_kbinput != NANO_TAB_KEY) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1382 | history_list->current = (historytype *)history_list; |
| 1383 | history_list->len = strlen(answer); |
| 1384 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1385 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1386 | if (history_list->len > 0) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1387 | complete = get_history_completion(history_list, answer); |
| 1388 | xend = strlen(complete); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1389 | x = xend; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1390 | answer = mallocstrcpy(answer, complete); |
| 1391 | } |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 1392 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1393 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 1394 | else |
| 1395 | #endif |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 1396 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1397 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 1398 | if (allowtabs) { |
| 1399 | int shift = 0; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1400 | |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 1401 | answer = input_tab(answer, x, &tabbed, &shift, list); |
| 1402 | xend = strlen(answer); |
| 1403 | x += shift; |
| 1404 | if (x > xend) |
| 1405 | x = xend; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1406 | } |
| 1407 | #endif |
| 1408 | break; |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 1409 | case NANO_BACK_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1410 | if (x > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1411 | x--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1412 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1413 | case NANO_PREVLINE_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1414 | #ifndef NANO_SMALL |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1415 | if (history_list != NULL) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 1416 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1417 | /* if currentbuf is NULL, or if use_cb is 1, currentbuf |
| 1418 | isn't NULL, and currentbuf is different from answer, |
| 1419 | it means that we're scrolling up at the top of the |
| 1420 | search history, and we need to save the current |
| 1421 | answer in currentbuf; do this and reset use_cb to |
| 1422 | 0 */ |
| 1423 | if (currentbuf == NULL || (use_cb == 1 && strcmp(currentbuf, answer))) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 1424 | currentbuf = mallocstrcpy(currentbuf, answer); |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1425 | use_cb = 0; |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1428 | /* if currentbuf isn't NULL, use_cb is 2, and currentbuf |
| 1429 | is different from answer, it means that we're |
| 1430 | scrolling up at the bottom of the search history, and |
| 1431 | we need to make the string in currentbuf the current |
| 1432 | answer; do this, blow away currentbuf since we don't |
| 1433 | need it anymore, and reset use_cb to 0 */ |
| 1434 | if (currentbuf != NULL && use_cb == 2 && strcmp(currentbuf, answer)) { |
| 1435 | answer = mallocstrcpy(answer, currentbuf); |
| 1436 | free(currentbuf); |
| 1437 | currentbuf = NULL; |
| 1438 | xend = strlen(answer); |
| 1439 | use_cb = 0; |
| 1440 | |
| 1441 | /* else get older search from the history list and save |
| 1442 | it in answer; if there is no older search, blank out |
| 1443 | answer */ |
| 1444 | } else if ((history = get_history_older(history_list)) != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1445 | answer = mallocstrcpy(answer, history); |
| 1446 | xend = strlen(history); |
| 1447 | } else { |
| 1448 | answer = mallocstrcpy(answer, ""); |
| 1449 | xend = 0; |
| 1450 | } |
| 1451 | x = xend; |
| 1452 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1453 | #endif |
Chris Allegretta | 54abd94 | 2003-01-09 23:43:12 +0000 | [diff] [blame] | 1454 | break; |
David Lawrence Ramsey | c2c5a51 | 2004-01-23 19:26:17 +0000 | [diff] [blame] | 1455 | case NANO_NEXTLINE_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1456 | #ifndef NANO_SMALL |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1457 | if (history_list != NULL) { |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1458 | |
| 1459 | /* get newer search from the history list and save it |
| 1460 | in answer */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1461 | if ((history = get_history_newer(history_list)) != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1462 | answer = mallocstrcpy(answer, history); |
| 1463 | xend = strlen(history); |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 1464 | |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1465 | /* if there is no newer search, we're here */ |
| 1466 | |
| 1467 | /* if currentbuf isn't NULL and use_cb isn't 2, it means |
| 1468 | that we're scrolling down at the bottom of the search |
| 1469 | history and we need to make the string in currentbuf |
| 1470 | the current answer; do this, blow away currentbuf |
| 1471 | since we don't need it anymore, and set use_cb to |
| 1472 | 1 */ |
| 1473 | } else if (currentbuf != NULL && use_cb != 2) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 1474 | answer = mallocstrcpy(answer, currentbuf); |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 1475 | free(currentbuf); |
| 1476 | currentbuf = NULL; |
| 1477 | xend = strlen(answer); |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1478 | use_cb = 1; |
| 1479 | |
| 1480 | /* otherwise, if currentbuf is NULL and use_cb isn't 2, |
| 1481 | it means that we're scrolling down at the bottom of |
Chris Allegretta | c30fc24 | 2003-08-11 00:32:45 +0000 | [diff] [blame] | 1482 | the search history and the current answer (if it's |
| 1483 | not blank) needs to be saved in currentbuf; do this, |
| 1484 | blank out answer (if necessary), and set use_cb to |
| 1485 | 2 */ |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1486 | } else if (use_cb != 2) { |
Chris Allegretta | c30fc24 | 2003-08-11 00:32:45 +0000 | [diff] [blame] | 1487 | if (answer[0] != '\0') { |
| 1488 | currentbuf = mallocstrcpy(currentbuf, answer); |
| 1489 | answer = mallocstrcpy(answer, ""); |
| 1490 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1491 | xend = 0; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1492 | use_cb = 2; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1493 | } |
| 1494 | x = xend; |
| 1495 | } |
| 1496 | #endif |
| 1497 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1498 | default: |
| 1499 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1500 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1501 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1502 | fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1503 | kbinput); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1504 | #endif |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 1505 | if (meta_key == TRUE && (kbinput == t->metaval || kbinput == t->miscval)) |
David Lawrence Ramsey | 8213850 | 2003-12-24 08:03:54 +0000 | [diff] [blame] | 1506 | /* We hit a Meta key. Do like above. We don't |
| 1507 | * just ungetch() the letter and let it get |
| 1508 | * caught above cause that screws the |
| 1509 | * keypad... */ |
| 1510 | return kbinput; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1511 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1512 | |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 1513 | if (is_cntrl_char(kbinput) || (ISSET(RESTRICTED) && filename[0] != '\0' && s == writefile_list)) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1514 | break; |
David Lawrence Ramsey | 70047ee | 2003-06-14 20:41:34 +0000 | [diff] [blame] | 1515 | answer = charealloc(answer, xend + 2); |
David Lawrence Ramsey | 9eff746 | 2003-09-16 02:04:00 +0000 | [diff] [blame] | 1516 | charmove(answer + x + 1, answer + x, xend - x + 1); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1517 | xend++; |
| 1518 | answer[x] = kbinput; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1519 | x++; |
| 1520 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1521 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 1522 | fprintf(stderr, "input \'%c\' (%d)\n", kbinput, kbinput); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1523 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1524 | } /* switch (kbinput) */ |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 1525 | #ifndef NANO_SMALL |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1526 | last_kbinput = kbinput; |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 1527 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1528 | nanoget_repaint(buf, answer, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1529 | wrefresh(bottomwin); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1530 | } /* while (kbinput ...) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1531 | |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 1532 | /* We finished putting in an answer; reset x */ |
| 1533 | x = -1; |
| 1534 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1535 | /* Just check for a blank answer here */ |
Chris Allegretta | 15c28f8 | 2003-01-05 21:47:06 +0000 | [diff] [blame] | 1536 | if (answer[0] == '\0') |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1537 | return -2; |
| 1538 | else |
| 1539 | return 0; |
| 1540 | } |
| 1541 | |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 1542 | void titlebar(const char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1543 | { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1544 | size_t space; |
| 1545 | /* The space we have available for display. */ |
| 1546 | size_t verlen = strlen(VERMSG) + 1; |
| 1547 | /* The length of the version message. */ |
| 1548 | const char *prefix; |
| 1549 | /* "File:", "Dir:", or "New Buffer". Goes before filename. */ |
| 1550 | size_t prefixlen; |
| 1551 | /* strlen(prefix) + 1. */ |
| 1552 | const char *state; |
| 1553 | /* "Modified", "View", or spaces the length of "Modified". |
| 1554 | * Tells the state of this buffer. */ |
| 1555 | size_t statelen = 0; |
| 1556 | /* strlen(state) + 1. */ |
| 1557 | char *exppath = NULL; |
| 1558 | /* The file name, expanded for display. */ |
| 1559 | size_t explen = 0; |
| 1560 | /* strlen(exppath) + 1. */ |
| 1561 | int newbuffer = FALSE; |
| 1562 | /* Do we say "New Buffer"? */ |
| 1563 | int dots = FALSE; |
| 1564 | /* Do we put an ellipsis before the path? */ |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 1565 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1566 | assert(path != NULL || filename != NULL); |
| 1567 | assert(COLS >= 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1568 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1569 | wattron(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1570 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1571 | blank_titlebar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1572 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1573 | if (COLS <= 5 || COLS - 5 < verlen) |
| 1574 | space = 0; |
| 1575 | else { |
| 1576 | space = COLS - 5 - verlen; |
| 1577 | /* Reserve 2/3 of the screen for after the version message. */ |
| 1578 | if (space < COLS - (COLS / 3)) |
| 1579 | space = COLS - (COLS / 3); |
| 1580 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1581 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1582 | if (COLS > 4) { |
| 1583 | /* The version message should only take up 1/3 of the screen. */ |
| 1584 | mvwaddnstr(topwin, 0, 2, VERMSG, COLS / 3); |
| 1585 | waddstr(topwin, " "); |
| 1586 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1587 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1588 | if (ISSET(MODIFIED)) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1589 | state = _("Modified"); |
| 1590 | else if (path == NULL && ISSET(VIEW_MODE)) |
| 1591 | state = _("View"); |
| 1592 | else { |
| 1593 | if (space > 0) |
| 1594 | statelen = strnlen(_("Modified"), space - 1) + 1; |
| 1595 | state = &hblank[COLS - statelen]; |
| 1596 | } |
| 1597 | statelen = strnlen(state, COLS); |
| 1598 | /* We need a space before state. */ |
| 1599 | if ((ISSET(MODIFIED) || ISSET(VIEW_MODE)) && statelen < COLS) |
| 1600 | statelen++; |
| 1601 | |
| 1602 | assert(space >= 0); |
| 1603 | if (space == 0 || statelen >= space) |
| 1604 | goto the_end; |
| 1605 | |
| 1606 | #ifndef DISABLE_BROWSER |
| 1607 | if (path != NULL) |
| 1608 | prefix = _("DIR:"); |
| 1609 | else |
| 1610 | #endif |
| 1611 | if (filename[0] == '\0') { |
| 1612 | prefix = _("New Buffer"); |
| 1613 | newbuffer = TRUE; |
| 1614 | } else |
| 1615 | prefix = _("File:"); |
| 1616 | assert(statelen < space); |
| 1617 | prefixlen = strnlen(prefix, space - statelen); |
| 1618 | /* If newbuffer is FALSE, we need a space after prefix. */ |
| 1619 | if (!newbuffer && prefixlen + statelen < space) |
| 1620 | prefixlen++; |
| 1621 | |
| 1622 | if (path == NULL) |
| 1623 | path = filename; |
David Lawrence Ramsey | 1dcf36a | 2004-05-23 21:17:56 +0000 | [diff] [blame] | 1624 | space -= prefixlen + statelen; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1625 | /* space is now the room we have for the file name. */ |
| 1626 | if (!newbuffer) { |
| 1627 | size_t lenpt = strlenpt(path), start_col; |
| 1628 | |
| 1629 | if (lenpt > space) |
| 1630 | start_col = actual_x(path, lenpt - space); |
| 1631 | else |
| 1632 | start_col = 0; |
| 1633 | exppath = display_string(path, start_col, space); |
| 1634 | dots = (lenpt > space); |
| 1635 | explen = strlen(exppath); |
| 1636 | } |
| 1637 | |
| 1638 | if (!dots) { |
| 1639 | /* There is room for the whole filename, so we center it. */ |
| 1640 | waddnstr(topwin, hblank, (space - explen) / 3); |
| 1641 | waddnstr(topwin, prefix, prefixlen); |
| 1642 | if (!newbuffer) { |
| 1643 | assert(strlen(prefix) + 1 == prefixlen); |
| 1644 | waddch(topwin, ' '); |
| 1645 | waddstr(topwin, exppath); |
| 1646 | } |
| 1647 | } else { |
| 1648 | /* We will say something like "File: ...ename". */ |
| 1649 | waddnstr(topwin, prefix, prefixlen); |
David Lawrence Ramsey | 1dcf36a | 2004-05-23 21:17:56 +0000 | [diff] [blame] | 1650 | if (space <= 0 || newbuffer) |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1651 | goto the_end; |
| 1652 | waddch(topwin, ' '); |
| 1653 | waddnstr(topwin, "...", space); |
| 1654 | if (space <= 3) |
| 1655 | goto the_end; |
| 1656 | space -= 3; |
| 1657 | assert(explen = space + 3); |
| 1658 | waddnstr(topwin, exppath + 3, space); |
| 1659 | } |
| 1660 | |
| 1661 | the_end: |
| 1662 | |
| 1663 | free(exppath); |
| 1664 | |
| 1665 | if (COLS <= 1 || statelen >= COLS - 1) |
| 1666 | mvwaddnstr(topwin, 0, 0, state, COLS); |
| 1667 | else { |
| 1668 | assert(COLS - statelen - 2 >= 0); |
| 1669 | mvwaddch(topwin, 0, COLS - statelen - 2, ' '); |
| 1670 | mvwaddnstr(topwin, 0, COLS - statelen - 1, state, statelen); |
| 1671 | } |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1672 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1673 | wattroff(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1674 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1675 | wnoutrefresh(topwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1676 | reset_cursor(); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1677 | wrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1680 | /* If modified is not already set, set it and update titlebar. */ |
| 1681 | void set_modified(void) |
| 1682 | { |
| 1683 | if (!ISSET(MODIFIED)) { |
| 1684 | SET(MODIFIED); |
| 1685 | titlebar(NULL); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | void statusbar(const char *msg, ...) |
| 1690 | { |
| 1691 | va_list ap; |
| 1692 | |
| 1693 | va_start(ap, msg); |
| 1694 | |
| 1695 | /* Curses mode is turned off. If we use wmove() now, it will muck |
| 1696 | * up the terminal settings. So we just use vfprintf(). */ |
| 1697 | if (curses_ended) { |
| 1698 | vfprintf(stderr, msg, ap); |
| 1699 | va_end(ap); |
| 1700 | return; |
| 1701 | } |
| 1702 | |
| 1703 | /* Blank out the line. */ |
| 1704 | blank_statusbar(); |
| 1705 | |
| 1706 | if (COLS >= 4) { |
| 1707 | char *bar; |
| 1708 | char *foo; |
| 1709 | size_t start_x = 0, foo_len; |
| 1710 | bar = charalloc(COLS - 3); |
| 1711 | vsnprintf(bar, COLS - 3, msg, ap); |
| 1712 | va_end(ap); |
| 1713 | foo = display_string(bar, 0, COLS - 4); |
| 1714 | free(bar); |
| 1715 | foo_len = strlen(foo); |
| 1716 | start_x = (COLS - foo_len - 4) / 2; |
| 1717 | |
| 1718 | wmove(bottomwin, 0, start_x); |
| 1719 | wattron(bottomwin, A_REVERSE); |
| 1720 | |
| 1721 | waddstr(bottomwin, "[ "); |
| 1722 | waddstr(bottomwin, foo); |
| 1723 | free(foo); |
| 1724 | waddstr(bottomwin, " ]"); |
| 1725 | wattroff(bottomwin, A_REVERSE); |
| 1726 | wnoutrefresh(bottomwin); |
| 1727 | reset_cursor(); |
| 1728 | wrefresh(edit); |
| 1729 | /* Leave the cursor at its position in the edit window, not |
| 1730 | * in the statusbar. */ |
| 1731 | } |
| 1732 | |
| 1733 | SET(DISABLE_CURPOS); |
| 1734 | statblank = 26; |
| 1735 | } |
| 1736 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1737 | void bottombars(const shortcut *s) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1738 | { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1739 | size_t i, colwidth, slen; |
| 1740 | char *keystr; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1741 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1742 | if (ISSET(NO_HELP)) |
| 1743 | return; |
| 1744 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1745 | if (s == main_list) { |
| 1746 | slen = MAIN_VISIBLE; |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1747 | assert(slen <= length_of_list(s)); |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 1748 | } else { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1749 | slen = length_of_list(s); |
| 1750 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1751 | /* Don't show any more shortcuts than the main list does. */ |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 1752 | if (slen > MAIN_VISIBLE) |
| 1753 | slen = MAIN_VISIBLE; |
| 1754 | } |
| 1755 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1756 | /* There will be this many characters per column. We need at least |
| 1757 | * 3 to display anything properly.*/ |
| 1758 | colwidth = COLS / ((slen / 2) + (slen % 2)); |
| 1759 | keystr = charalloc(colwidth); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1760 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 1761 | blank_bottombars(); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1762 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1763 | for (i = 0; i < slen; i++, s = s->next) { |
| 1764 | wmove(bottomwin, 1 + i % 2, (i / 2) * colwidth); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1765 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1766 | /* Yucky sentinel values we can't handle a better way. */ |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 1767 | #ifndef NANO_SMALL |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1768 | if (s->ctrlval == NANO_HISTORY_KEY) |
| 1769 | strncpy(keystr, _("Up"), colwidth); |
| 1770 | else |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 1771 | #endif |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1772 | if (s->ctrlval == NANO_CONTROL_SPACE) |
| 1773 | strncpy(keystr, "^ ", colwidth); |
| 1774 | else if (s->ctrlval == NANO_CONTROL_8) |
| 1775 | strncpy(keystr, "^?", colwidth); |
| 1776 | /* Normal values. Assume that the shortcut has an equivalent |
| 1777 | * control key, meta key sequence, or both. */ |
| 1778 | else if (s->ctrlval != NANO_NO_KEY) |
| 1779 | snprintf(keystr, colwidth, "^%c", s->ctrlval + 64); |
| 1780 | else if (s->metaval != NANO_NO_KEY) |
| 1781 | snprintf(keystr, colwidth, "M-%c", toupper(s->metaval)); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 1782 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1783 | onekey(keystr, s->desc, colwidth); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1786 | free(keystr); |
| 1787 | |
| 1788 | wnoutrefresh(bottomwin); |
| 1789 | reset_cursor(); |
| 1790 | wrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1793 | /* Write a shortcut key to the help area at the bottom of the window. |
| 1794 | * keystroke is e.g. "^G" and desc is e.g. "Get Help". We are careful |
| 1795 | * to write at most len characters, even if len is very small and |
| 1796 | * keystroke and desc are long. Note that waddnstr(,,(size_t)-1) adds |
| 1797 | * the whole string! We do not bother padding the entry with blanks. */ |
| 1798 | void onekey(const char *keystroke, const char *desc, size_t len) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1799 | { |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1800 | assert(keystroke != NULL && desc != NULL && len >= 0); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1801 | wattron(bottomwin, A_REVERSE); |
| 1802 | waddnstr(bottomwin, keystroke, len); |
| 1803 | wattroff(bottomwin, A_REVERSE); |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 1804 | len -= strlen(keystroke) + 1; |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1805 | if (len > 0) { |
| 1806 | waddch(bottomwin, ' '); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1807 | waddnstr(bottomwin, desc, len); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1811 | /* And so start the display update routines. */ |
| 1812 | |
| 1813 | #ifndef NDEBUG |
| 1814 | int check_linenumbers(const filestruct *fileptr) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1815 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1816 | int check_line = 0; |
| 1817 | const filestruct *filetmp; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1818 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1819 | for (filetmp = edittop; filetmp != fileptr; filetmp = filetmp->next) |
| 1820 | check_line++; |
| 1821 | return check_line; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1822 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1823 | #endif |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1824 | |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 1825 | /* nano scrolls horizontally within a line in chunks. This function |
| 1826 | * returns the column number of the first character displayed in the |
| 1827 | * window when the cursor is at the given column. Note that |
| 1828 | * 0 <= column - get_page_start(column) < COLS. */ |
| 1829 | size_t get_page_start(size_t column) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1830 | { |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 1831 | assert(COLS > 0); |
| 1832 | if (column == 0 || column < COLS - 1) |
| 1833 | return 0; |
| 1834 | else if (COLS > 9) |
David Lawrence Ramsey | 66081d4 | 2004-01-22 07:25:31 +0000 | [diff] [blame] | 1835 | return column - 7 - (column - 7) % (COLS - 8); |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 1836 | else if (COLS > 2) |
| 1837 | return column - (COLS - 2); |
| 1838 | else |
| 1839 | return column - (COLS - 1); |
| 1840 | /* The parentheses are necessary to avoid overflow. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 1843 | /* Resets current_y, based on the position of current, and puts the |
| 1844 | * cursor at (current_y, current_x). */ |
| 1845 | void reset_cursor(void) |
| 1846 | { |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1847 | /* Yuck. This condition can be true after open_file() when opening |
| 1848 | * the first file. */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 1849 | if (edittop == NULL) |
| 1850 | return; |
| 1851 | |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 1852 | current_y = current->lineno - edittop->lineno; |
| 1853 | if (current_y < editwinrows) { |
| 1854 | size_t x = xplustabs(); |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 1855 | |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 1856 | wmove(edit, current_y, x - get_page_start(x)); |
| 1857 | } |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 1858 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1859 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1860 | /* edit_add() takes care of the job of actually painting a line into the |
| 1861 | * edit window. fileptr is the line to be painted, at row yval of the |
| 1862 | * window. converted is the actual string to be written to the window, |
| 1863 | * with tabs and control characters replaced by strings of regular |
David Lawrence Ramsey | 4178db0 | 2004-05-23 21:23:23 +0000 | [diff] [blame^] | 1864 | * characters. start is the column number of the first character of |
| 1865 | * this page. That is, the first character of converted corresponds to |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1866 | * character number actual_x(fileptr->data, start) of the line. */ |
David Lawrence Ramsey | 07d3feb | 2004-04-16 05:15:11 +0000 | [diff] [blame] | 1867 | void edit_add(const filestruct *fileptr, const char *converted, int |
| 1868 | yval, size_t start) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1869 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1870 | #if defined(ENABLE_COLOR) || !defined(NANO_SMALL) |
| 1871 | size_t startpos = actual_x(fileptr->data, start); |
| 1872 | /* The position in fileptr->data of the leftmost character |
| 1873 | * that displays at least partially on the window. */ |
| 1874 | size_t endpos = actual_x(fileptr->data, start + COLS - 1) + 1; |
| 1875 | /* The position in fileptr->data of the first character that is |
| 1876 | * completely off the window to the right. |
| 1877 | * |
| 1878 | * Note that endpos might be beyond the null terminator of the |
| 1879 | * string. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1880 | #endif |
| 1881 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1882 | assert(fileptr != NULL && converted != NULL); |
| 1883 | assert(strlen(converted) <= COLS); |
| 1884 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1885 | /* Just paint the string in any case (we'll add color or reverse on |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1886 | * just the text that needs it). */ |
| 1887 | mvwaddstr(edit, yval, 0, converted); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1888 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 1889 | #ifdef ENABLE_COLOR |
Chris Allegretta | 1dd0bc9 | 2002-10-13 18:43:45 +0000 | [diff] [blame] | 1890 | if (colorstrings != NULL && ISSET(COLOR_SYNTAX)) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1891 | const colortype *tmpcolor = colorstrings; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1892 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1893 | for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { |
| 1894 | int x_start; |
| 1895 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 1896 | int paintlen; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1897 | /* Number of chars to paint on this line. There are COLS |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1898 | * characters on a whole line. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1899 | regmatch_t startmatch; /* match position for start_regexp */ |
| 1900 | regmatch_t endmatch; /* match position for end_regexp */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1901 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1902 | if (tmpcolor->bright) |
| 1903 | wattron(edit, A_BOLD); |
| 1904 | wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1905 | /* Two notes about regexec(). Return value 0 means there is |
| 1906 | * a match. Also, rm_eo is the first non-matching character |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1907 | * after the match. */ |
| 1908 | |
| 1909 | /* First case, tmpcolor is a single-line expression. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1910 | if (tmpcolor->end == NULL) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1911 | size_t k = 0; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1912 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1913 | /* We increment k by rm_eo, to move past the end of the |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1914 | * last match. Even though two matches may overlap, we |
| 1915 | * want to ignore them, so that we can highlight |
| 1916 | * C-strings correctly. */ |
| 1917 | while (k < endpos) { |
| 1918 | /* Note the fifth parameter to regexec(). It says |
| 1919 | * not to match the beginning-of-line character |
| 1920 | * unless k is 0. If regexec() returns REG_NOMATCH, |
| 1921 | * there are no more matches in the line. */ |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1922 | if (regexec(&tmpcolor->start, &fileptr->data[k], 1, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1923 | &startmatch, k == 0 ? 0 : REG_NOTBOL) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1924 | break; |
| 1925 | /* Translate the match to the beginning of the line. */ |
| 1926 | startmatch.rm_so += k; |
| 1927 | startmatch.rm_eo += k; |
David Lawrence Ramsey | 2ab03f6 | 2002-10-17 02:19:31 +0000 | [diff] [blame] | 1928 | if (startmatch.rm_so == startmatch.rm_eo) { |
| 1929 | startmatch.rm_eo++; |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 1930 | statusbar(_("Refusing 0 length regex match")); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1931 | } else if (startmatch.rm_so < endpos && |
| 1932 | startmatch.rm_eo > startpos) { |
| 1933 | if (startmatch.rm_so <= startpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1934 | x_start = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1935 | else |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 1936 | x_start = strnlenpt(fileptr->data, |
| 1937 | startmatch.rm_so) - start; |
| 1938 | paintlen = strnlenpt(fileptr->data, |
| 1939 | startmatch.rm_eo) - start - x_start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1940 | if (paintlen > COLS - x_start) |
| 1941 | paintlen = COLS - x_start; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1942 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1943 | assert(0 <= x_start && 0 < paintlen && |
| 1944 | x_start + paintlen <= COLS); |
| 1945 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1946 | converted + x_start, paintlen); |
| 1947 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1948 | k = startmatch.rm_eo; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1949 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1950 | } else { |
| 1951 | /* This is a multi-line regexp. There are two steps. |
| 1952 | * First, we have to see if the beginning of the line is |
| 1953 | * colored by a start on an earlier line, and an end on |
| 1954 | * this line or later. |
| 1955 | * |
| 1956 | * We find the first line before fileptr matching the |
| 1957 | * start. If every match on that line is followed by an |
| 1958 | * end, then go to step two. Otherwise, find the next line |
| 1959 | * after start_line matching the end. If that line is not |
| 1960 | * before fileptr, then paint the beginning of this line. */ |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 1961 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1962 | const filestruct *start_line = fileptr->prev; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1963 | /* the first line before fileptr matching start */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1964 | regoff_t start_col; |
| 1965 | /* where it starts in that line */ |
| 1966 | const filestruct *end_line; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1967 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1968 | while (start_line != NULL && |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1969 | regexec(&tmpcolor->start, start_line->data, 1, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1970 | &startmatch, 0) == REG_NOMATCH) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1971 | /* If there is an end on this line, there is no need |
| 1972 | * to look for starts on earlier lines. */ |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 1973 | if (regexec(tmpcolor->end, start_line->data, 0, |
| 1974 | NULL, 0) == 0) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1975 | goto step_two; |
| 1976 | start_line = start_line->prev; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1977 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1978 | /* No start found, so skip to the next step. */ |
| 1979 | if (start_line == NULL) |
| 1980 | goto step_two; |
| 1981 | /* Now start_line is the first line before fileptr |
| 1982 | * containing a start match. Is there a start on this |
| 1983 | * line not followed by an end on this line? */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 1984 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1985 | start_col = 0; |
David Lawrence Ramsey | 6aec4b8 | 2004-03-15 20:26:30 +0000 | [diff] [blame] | 1986 | while (TRUE) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1987 | start_col += startmatch.rm_so; |
| 1988 | startmatch.rm_eo -= startmatch.rm_so; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1989 | if (regexec(tmpcolor->end, |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 1990 | start_line->data + start_col + startmatch.rm_eo, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 1991 | 0, NULL, start_col + startmatch.rm_eo == 0 ? 0 : |
| 1992 | REG_NOTBOL) == REG_NOMATCH) |
| 1993 | /* No end found after this start. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1994 | break; |
| 1995 | start_col++; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 1996 | if (regexec(&tmpcolor->start, |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 1997 | start_line->data + start_col, 1, |
| 1998 | &startmatch, REG_NOTBOL) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1999 | /* No later start on this line. */ |
| 2000 | goto step_two; |
| 2001 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2002 | /* Indeed, there is a start not followed on this line by |
| 2003 | * an end. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2004 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2005 | /* We have already checked that there is no end before |
| 2006 | * fileptr and after the start. Is there an end after |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2007 | * the start at all? We don't paint unterminated |
| 2008 | * starts. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2009 | end_line = fileptr; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 2010 | while (end_line != NULL && |
| 2011 | regexec(tmpcolor->end, end_line->data, 1, &endmatch, 0)) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2012 | end_line = end_line->next; |
| 2013 | |
| 2014 | /* No end found, or it is too early. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2015 | if (end_line == NULL || |
| 2016 | (end_line == fileptr && endmatch.rm_eo <= startpos)) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2017 | goto step_two; |
| 2018 | |
| 2019 | /* Now paint the start of fileptr. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2020 | paintlen = end_line != fileptr ? COLS : |
| 2021 | strnlenpt(fileptr->data, endmatch.rm_eo) - start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2022 | if (paintlen > COLS) |
| 2023 | paintlen = COLS; |
| 2024 | |
| 2025 | assert(0 < paintlen && paintlen <= COLS); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2026 | mvwaddnstr(edit, yval, 0, converted, paintlen); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2027 | |
| 2028 | /* We have already painted the whole line. */ |
| 2029 | if (paintlen == COLS) |
| 2030 | goto skip_step_two; |
| 2031 | |
David Lawrence Ramsey | 94e7094 | 2004-05-13 18:04:31 +0000 | [diff] [blame] | 2032 | step_two: |
| 2033 | /* Second step, we look for starts on this line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2034 | start_col = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2035 | while (start_col < endpos) { |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2036 | if (regexec(&tmpcolor->start, |
| 2037 | fileptr->data + start_col, 1, &startmatch, |
| 2038 | start_col == 0 ? 0 : REG_NOTBOL) == REG_NOMATCH || |
| 2039 | start_col + startmatch.rm_so >= endpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2040 | /* No more starts on this line. */ |
| 2041 | break; |
| 2042 | /* Translate the match to be relative to the |
| 2043 | * beginning of the line. */ |
| 2044 | startmatch.rm_so += start_col; |
| 2045 | startmatch.rm_eo += start_col; |
| 2046 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2047 | if (startmatch.rm_so <= startpos) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2048 | x_start = 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2049 | else |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2050 | x_start = strnlenpt(fileptr->data, |
| 2051 | startmatch.rm_so) - start; |
| 2052 | if (regexec(tmpcolor->end, |
| 2053 | fileptr->data + startmatch.rm_eo, 1, &endmatch, |
| 2054 | startmatch.rm_eo == 0 ? 0 : REG_NOTBOL) == 0) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2055 | /* Translate the end match to be relative to the |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2056 | * beginning of the line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2057 | endmatch.rm_so += startmatch.rm_eo; |
| 2058 | endmatch.rm_eo += startmatch.rm_eo; |
| 2059 | /* There is an end on this line. But does it |
David Lawrence Ramsey | 94e7094 | 2004-05-13 18:04:31 +0000 | [diff] [blame] | 2060 | * appear on this page, and is the match more |
| 2061 | * than zero characters long? */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2062 | if (endmatch.rm_eo > startpos && |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2063 | endmatch.rm_eo > startmatch.rm_so) { |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2064 | paintlen = strnlenpt(fileptr->data, |
| 2065 | endmatch.rm_eo) - start - x_start; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2066 | if (x_start + paintlen > COLS) |
| 2067 | paintlen = COLS - x_start; |
| 2068 | |
| 2069 | assert(0 <= x_start && 0 < paintlen && |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2070 | x_start + paintlen <= COLS); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2071 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2072 | converted + x_start, paintlen); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2073 | } |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2074 | } else { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2075 | /* There is no end on this line. But we haven't |
| 2076 | * yet looked for one on later lines. */ |
| 2077 | end_line = fileptr->next; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2078 | while (end_line != NULL && |
| 2079 | regexec(tmpcolor->end, end_line->data, 0, |
| 2080 | NULL, 0) == REG_NOMATCH) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2081 | end_line = end_line->next; |
| 2082 | if (end_line != NULL) { |
| 2083 | assert(0 <= x_start && x_start < COLS); |
| 2084 | mvwaddnstr(edit, yval, x_start, |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2085 | converted + x_start, COLS - x_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2086 | /* We painted to the end of the line, so |
| 2087 | * don't bother checking any more starts. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2088 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 2089 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2090 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2091 | start_col = startmatch.rm_so + 1; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2092 | } /* while start_col < endpos */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2093 | } /* if (tmp_color->end != NULL) */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 2094 | |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 2095 | skip_step_two: |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2096 | wattroff(edit, A_BOLD); |
| 2097 | wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); |
| 2098 | } /* for tmpcolor in colorstrings */ |
| 2099 | } |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2100 | #endif /* ENABLE_COLOR */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2101 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 2102 | #ifndef NANO_SMALL |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2103 | if (ISSET(MARK_ISSET) |
| 2104 | && (fileptr->lineno <= mark_beginbuf->lineno |
| 2105 | || fileptr->lineno <= current->lineno) |
| 2106 | && (fileptr->lineno >= mark_beginbuf->lineno |
| 2107 | || fileptr->lineno >= current->lineno)) { |
| 2108 | /* fileptr is at least partially selected. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 2109 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2110 | const filestruct *top; |
| 2111 | /* Either current or mark_beginbuf, whichever is first. */ |
| 2112 | size_t top_x; |
| 2113 | /* current_x or mark_beginx, corresponding to top. */ |
| 2114 | const filestruct *bot; |
| 2115 | size_t bot_x; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2116 | int x_start; |
| 2117 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 2118 | int paintlen; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2119 | /* Number of chars to paint on this line. There are COLS |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2120 | * characters on a whole line. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2121 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2122 | mark_order(&top, &top_x, &bot, &bot_x); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2123 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2124 | if (top->lineno < fileptr->lineno || top_x < startpos) |
| 2125 | top_x = startpos; |
| 2126 | if (bot->lineno > fileptr->lineno || bot_x > endpos) |
| 2127 | bot_x = endpos; |
| 2128 | |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2129 | /* The selected bit of fileptr is on this page. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2130 | if (top_x < endpos && bot_x > startpos) { |
| 2131 | assert(startpos <= top_x); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2132 | |
| 2133 | /* x_start is the expanded location of the beginning of the |
| 2134 | * mark minus the beginning of the page. */ |
| 2135 | x_start = strnlenpt(fileptr->data, top_x) - start; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2136 | |
| 2137 | if (bot_x >= endpos) |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2138 | /* If the end of the mark is off the page, paintlen is |
| 2139 | * -1, meaning that everything on the line gets |
| 2140 | * painted. */ |
| 2141 | paintlen = -1; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2142 | else |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2143 | /* Otherwise, paintlen is the expanded location of the |
| 2144 | * end of the mark minus the expanded location of the |
| 2145 | * beginning of the mark. */ |
David Lawrence Ramsey | e5b2f83 | 2004-04-29 06:30:36 +0000 | [diff] [blame] | 2146 | paintlen = strnlenpt(fileptr->data, bot_x) |
| 2147 | - (x_start + start); |
David Lawrence Ramsey | 4dcd070 | 2003-10-03 04:20:28 +0000 | [diff] [blame] | 2148 | |
| 2149 | /* If x_start is before the beginning of the page, shift |
| 2150 | * paintlen x_start characters to compensate, and put |
| 2151 | * x_start at the beginning of the page. */ |
| 2152 | if (x_start < 0) { |
| 2153 | paintlen += x_start; |
| 2154 | x_start = 0; |
| 2155 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2156 | |
| 2157 | assert(x_start >= 0 && x_start <= strlen(converted)); |
| 2158 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2159 | wattron(edit, A_REVERSE); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2160 | mvwaddnstr(edit, yval, x_start, converted + x_start, paintlen); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2161 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2162 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 2163 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2164 | #endif /* !NANO_SMALL */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2167 | /* Just update one line in the edit buffer. Basically a wrapper for |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2168 | * edit_add(). |
| 2169 | * |
David Lawrence Ramsey | 07d3feb | 2004-04-16 05:15:11 +0000 | [diff] [blame] | 2170 | * If fileptr != current, then index is considered 0. The line will be |
| 2171 | * displayed starting with fileptr->data[index]. Likely args are |
| 2172 | * current_x or 0. */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2173 | void update_line(const filestruct *fileptr, size_t index) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2174 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2175 | int line; |
| 2176 | /* line in the edit window for CURSES calls */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2177 | char *converted; |
| 2178 | /* fileptr->data converted to have tabs and control characters |
| 2179 | * expanded. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2180 | size_t page_start; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2181 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2182 | assert(fileptr != NULL); |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 2183 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2184 | line = fileptr->lineno - edittop->lineno; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2185 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2186 | /* We assume the line numbers are valid. Is that really true? */ |
| 2187 | assert(line < 0 || line == check_linenumbers(fileptr)); |
| 2188 | |
| 2189 | if (line < 0 || line >= editwinrows) |
| 2190 | return; |
| 2191 | |
| 2192 | /* First, blank out the line (at a minimum) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2193 | mvwaddstr(edit, line, 0, hblank); |
| 2194 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2195 | /* Next, convert variables that index the line to their equivalent |
| 2196 | * positions in the expanded line. */ |
David Lawrence Ramsey | 2dd7ed1 | 2003-09-29 05:15:24 +0000 | [diff] [blame] | 2197 | index = (fileptr == current) ? strnlenpt(fileptr->data, index) : 0; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2198 | page_start = get_page_start(index); |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2199 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2200 | /* Expand the line, replacing Tab by spaces, and control characters |
| 2201 | * by their display form. */ |
| 2202 | converted = display_string(fileptr->data, page_start, COLS); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 2203 | |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 2204 | /* Now, paint the line */ |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2205 | edit_add(fileptr, converted, line, page_start); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2206 | free(converted); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2207 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2208 | if (page_start > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2209 | mvwaddch(edit, line, 0, '$'); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2210 | if (strlenpt(fileptr->data) > page_start + COLS) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 2211 | mvwaddch(edit, line, COLS - 1, '$'); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2214 | /* This function updates current, based on where current_y is; |
| 2215 | * reset_cursor() does the opposite. */ |
| 2216 | void update_cursor(void) |
| 2217 | { |
| 2218 | int i = 0; |
| 2219 | |
| 2220 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 2221 | fprintf(stderr, "Moved to (%d, %d) in edit buffer\n", current_y, |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2222 | current_x); |
| 2223 | #endif |
| 2224 | |
| 2225 | current = edittop; |
| 2226 | while (i < current_y && current->next != NULL) { |
| 2227 | current = current->next; |
| 2228 | i++; |
| 2229 | } |
| 2230 | |
| 2231 | #ifdef DEBUG |
Chris Allegretta | 0e86e60 | 2003-01-23 04:27:23 +0000 | [diff] [blame] | 2232 | fprintf(stderr, "current->data = \"%s\"\n", current->data); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2233 | #endif |
| 2234 | } |
| 2235 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2236 | void center_cursor(void) |
| 2237 | { |
| 2238 | current_y = editwinrows / 2; |
| 2239 | wmove(edit, current_y, current_x); |
| 2240 | } |
| 2241 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2242 | /* Refresh the screen without changing the position of lines. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2243 | void edit_refresh(void) |
| 2244 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2245 | /* Neither of these conditions should occur, but they do. edittop |
| 2246 | * is NULL when you open an existing file on the command line, and |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2247 | * ENABLE_COLOR is defined. Yuck. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2248 | if (current == NULL) |
| 2249 | return; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2250 | if (edittop == NULL) |
| 2251 | edittop = current; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2252 | |
Chris Allegretta | 63d0b48 | 2003-01-26 19:47:10 +0000 | [diff] [blame] | 2253 | if (current->lineno < edittop->lineno || |
| 2254 | current->lineno >= edittop->lineno + editwinrows) |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2255 | /* Note that edit_update() changes edittop so that |
| 2256 | * current->lineno = edittop->lineno + editwinrows / 2. Thus |
| 2257 | * when it then calls edit_refresh(), there is no danger of |
| 2258 | * getting an infinite loop. */ |
Chris Allegretta | da721be | 2000-07-31 01:26:42 +0000 | [diff] [blame] | 2259 | edit_update(current, CENTER); |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2260 | else { |
| 2261 | int nlines = 0; |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2262 | const filestruct *foo = edittop; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2263 | |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2264 | #ifdef DEBUG |
| 2265 | fprintf(stderr, "edit_refresh(): edittop->lineno = %ld\n", edittop->lineno); |
| 2266 | #endif |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2267 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2268 | while (nlines < editwinrows) { |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2269 | update_line(foo, current_x); |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2270 | nlines++; |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2271 | if (foo->next == NULL) |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2272 | break; |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2273 | foo = foo->next; |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2274 | } |
| 2275 | while (nlines < editwinrows) { |
| 2276 | mvwaddstr(edit, nlines, 0, hblank); |
| 2277 | nlines++; |
| 2278 | } |
David Lawrence Ramsey | 1044d74 | 2004-02-24 20:41:39 +0000 | [diff] [blame] | 2279 | reset_cursor(); |
David Lawrence Ramsey | 07d3feb | 2004-04-16 05:15:11 +0000 | [diff] [blame] | 2280 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2281 | /* What the hell are we expecting to update the screen if this |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2282 | * isn't here? Luck? */ |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2283 | wrefresh(edit); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2284 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2285 | } |
| 2286 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 2287 | /* Same as above, but touch the window first, so everything is |
| 2288 | * redrawn. */ |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 2289 | void edit_refresh_clearok(void) |
| 2290 | { |
| 2291 | clearok(edit, TRUE); |
| 2292 | edit_refresh(); |
| 2293 | clearok(edit, FALSE); |
| 2294 | } |
| 2295 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2296 | /* Nice generic routine to update the edit buffer, given a pointer to the |
| 2297 | * file struct =) */ |
David Lawrence Ramsey | 1356a0a | 2003-09-10 20:31:02 +0000 | [diff] [blame] | 2298 | void edit_update(filestruct *fileptr, topmidnone location) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2299 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2300 | if (fileptr == NULL) |
| 2301 | return; |
| 2302 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2303 | if (location != TOP) { |
David Lawrence Ramsey | 07d3feb | 2004-04-16 05:15:11 +0000 | [diff] [blame] | 2304 | int goal = (location == NONE) ? current_y : editwinrows / 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2305 | |
David Lawrence Ramsey | d91ab6e | 2003-09-07 23:57:24 +0000 | [diff] [blame] | 2306 | for (; goal > 0 && fileptr->prev != NULL; goal--) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2307 | fileptr = fileptr->prev; |
| 2308 | } |
| 2309 | edittop = fileptr; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2310 | edit_refresh(); |
| 2311 | } |
| 2312 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2313 | /* Ask a question on the statusbar. Answer will be stored in answer |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2314 | * global. Returns -1 on aborted enter, -2 on a blank string, and 0 |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 2315 | * otherwise, the valid shortcut key caught. Def is any editable text we |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2316 | * want to put up by default. |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 2317 | * |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2318 | * New arg tabs tells whether or not to allow tab completion. */ |
David Lawrence Ramsey | 6aec4b8 | 2004-03-15 20:26:30 +0000 | [diff] [blame] | 2319 | int statusq(int allowtabs, const shortcut *s, const char *def, |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2320 | #ifndef NANO_SMALL |
| 2321 | historyheadtype *which_history, |
| 2322 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2323 | const char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2324 | { |
| 2325 | va_list ap; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2326 | char *foo = charalloc(COLS - 3); |
Chris Allegretta | 9caa193 | 2002-02-15 20:08:05 +0000 | [diff] [blame] | 2327 | int ret; |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2328 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | a16e4e9 | 2002-01-05 18:59:54 +0000 | [diff] [blame] | 2329 | int list = 0; |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2330 | #endif |
| 2331 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2332 | bottombars(s); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2333 | |
| 2334 | va_start(ap, msg); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2335 | vsnprintf(foo, COLS - 4, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2336 | va_end(ap); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2337 | foo[COLS - 4] = '\0'; |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2338 | |
David Lawrence Ramsey | 6aec4b8 | 2004-03-15 20:26:30 +0000 | [diff] [blame] | 2339 | ret = nanogetstr(allowtabs, foo, def, |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2340 | #ifndef NANO_SMALL |
| 2341 | which_history, |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2342 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 2343 | s |
| 2344 | #ifndef DISABLE_TABCOMP |
| 2345 | , &list |
| 2346 | #endif |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 2347 | ); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2348 | free(foo); |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 2349 | resetstatuspos = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2350 | |
| 2351 | switch (ret) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2352 | case NANO_FIRSTLINE_KEY: |
David Lawrence Ramsey | d7f5ad9 | 2004-03-04 19:30:53 +0000 | [diff] [blame] | 2353 | case NANO_FIRSTLINE_FKEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2354 | do_first_line(); |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 2355 | resetstatuspos = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2356 | break; |
| 2357 | case NANO_LASTLINE_KEY: |
David Lawrence Ramsey | d7f5ad9 | 2004-03-04 19:30:53 +0000 | [diff] [blame] | 2358 | case NANO_LASTLINE_FKEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2359 | do_last_line(); |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 2360 | resetstatuspos = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2361 | break; |
David Lawrence Ramsey | 8faf305 | 2003-09-04 20:25:29 +0000 | [diff] [blame] | 2362 | #ifndef DISABLE_JUSTIFY |
| 2363 | case NANO_PARABEGIN_KEY: |
| 2364 | do_para_begin(); |
| 2365 | resetstatuspos = 1; |
| 2366 | break; |
| 2367 | case NANO_PARAEND_KEY: |
| 2368 | do_para_end(); |
| 2369 | resetstatuspos = 1; |
| 2370 | break; |
David Lawrence Ramsey | 8d3e7f3 | 2004-05-13 17:28:03 +0000 | [diff] [blame] | 2371 | case NANO_FULLJUSTIFY_KEY: |
| 2372 | do_full_justify(); |
| 2373 | resetstatuspos = 1; |
| 2374 | break; |
David Lawrence Ramsey | 8faf305 | 2003-09-04 20:25:29 +0000 | [diff] [blame] | 2375 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2376 | case NANO_CANCEL_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2377 | ret = -1; |
Chris Allegretta | 65f075d | 2003-02-13 03:03:49 +0000 | [diff] [blame] | 2378 | resetstatuspos = 1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2379 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2380 | } |
Chris Allegretta | a90d0cf | 2003-02-10 02:55:03 +0000 | [diff] [blame] | 2381 | blank_statusbar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2382 | |
| 2383 | #ifdef DEBUG |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 2384 | fprintf(stderr, "I got \"%s\"\n", answer); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2385 | #endif |
| 2386 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2387 | #ifndef DISABLE_TABCOMP |
| 2388 | /* if we've done tab completion, there might be a list of |
| 2389 | filename matches on the edit window at this point; make sure |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2390 | they're cleared off. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2391 | if (list) |
| 2392 | edit_refresh(); |
| 2393 | #endif |
| 2394 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2395 | return ret; |
| 2396 | } |
| 2397 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2398 | /* Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 2399 | * for N, 2 for All (if all is nonzero when passed in) and -1 for abort |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2400 | * (^C). */ |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2401 | int do_yesno(int all, const char *msg) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2402 | { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2403 | int ok = -2, width = 16; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2404 | const char *yesstr; /* String of yes characters accepted */ |
| 2405 | const char *nostr; /* Same for no */ |
| 2406 | const char *allstr; /* And all, surprise! */ |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 2407 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2408 | /* Yes, no and all are strings of any length. Each string consists |
| 2409 | * of all characters accepted as a valid character for that value. |
| 2410 | * The first value will be the one displayed in the shortcuts. */ |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2411 | yesstr = _("Yy"); |
| 2412 | nostr = _("Nn"); |
| 2413 | allstr = _("Aa"); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2414 | |
David Lawrence Ramsey | fa39404 | 2004-05-23 21:11:14 +0000 | [diff] [blame] | 2415 | /* Remove gettext() call for keybindings until we clear the thing |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2416 | * up. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2417 | if (!ISSET(NO_HELP)) { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2418 | char shortstr[3]; /* Temp string for Y, N, A. */ |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2419 | |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2420 | if (COLS < 32) |
| 2421 | width = COLS / 2; |
| 2422 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2423 | /* Write the bottom of the screen. */ |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2424 | blank_bottombars(); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2425 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2426 | sprintf(shortstr, " %c", yesstr[0]); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2427 | wmove(bottomwin, 1, 0); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2428 | onekey(shortstr, _("Yes"), width); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2429 | |
| 2430 | if (all) { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2431 | wmove(bottomwin, 1, width); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2432 | shortstr[1] = allstr[0]; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2433 | onekey(shortstr, _("All"), width); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2434 | } |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2435 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2436 | wmove(bottomwin, 2, 0); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 2437 | shortstr[1] = nostr[0]; |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2438 | onekey(shortstr, _("No"), width); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2439 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2440 | wmove(bottomwin, 2, 16); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2441 | onekey("^C", _("Cancel"), width); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2442 | } |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2443 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2444 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2445 | |
| 2446 | blank_statusbar(); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2447 | mvwaddnstr(bottomwin, 0, 0, msg, COLS - 1); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2448 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2449 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 2450 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2451 | wrefresh(bottomwin); |
| 2452 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2453 | do { |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2454 | int kbinput; |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 2455 | int meta_key; |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 2456 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2457 | int mouse_x, mouse_y; |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 2458 | #endif |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2459 | |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 2460 | kbinput = get_kbinput(edit, &meta_key); |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2461 | |
| 2462 | if (kbinput == NANO_CANCEL_KEY) |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2463 | ok = -1; |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 2464 | #ifndef DISABLE_MOUSE |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2465 | /* Look ma! We get to duplicate lots of code from |
| 2466 | * do_mouse()!! */ |
| 2467 | else if (kbinput == KEY_MOUSE) { |
| 2468 | kbinput = get_mouseinput(&mouse_x, &mouse_y, 0); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2469 | |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2470 | if (mouse_x != -1 && mouse_y != -1 && !ISSET(NO_HELP) && |
| 2471 | wenclose(bottomwin, mouse_y, mouse_x) && mouse_x < |
| 2472 | (width * 2) && mouse_y >= editwinrows + 3) { |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 2473 | |
David Lawrence Ramsey | f427694 | 2003-12-24 03:33:09 +0000 | [diff] [blame] | 2474 | int x = mouse_x / width; |
| 2475 | /* Did we click in the first column of shortcuts, or |
| 2476 | * the second? */ |
| 2477 | int y = mouse_y - editwinrows - 3; |
| 2478 | /* Did we click in the first row of shortcuts? */ |
| 2479 | |
| 2480 | assert(0 <= x && x <= 1 && 0 <= y && y <= 1); |
| 2481 | |
| 2482 | /* x = 0 means they clicked Yes or No. |
| 2483 | * y = 0 means Yes or All. */ |
| 2484 | ok = -2 * x * y + x - y + 1; |
| 2485 | |
| 2486 | if (ok == 2 && !all) |
| 2487 | ok = -2; |
| 2488 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2489 | } |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2490 | #endif |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2491 | /* Look for the kbinput in the yes, no and (optionally) all |
| 2492 | * str. */ |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2493 | else if (strchr(yesstr, kbinput) != NULL) |
| 2494 | ok = 1; |
| 2495 | else if (strchr(nostr, kbinput) != NULL) |
| 2496 | ok = 0; |
| 2497 | else if (all && strchr(allstr, kbinput) != NULL) |
| 2498 | ok = 2; |
| 2499 | } while (ok == -2); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2500 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 2501 | return ok; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2504 | int total_refresh(void) |
| 2505 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2506 | clearok(topwin, TRUE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2507 | clearok(edit, TRUE); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2508 | clearok(bottomwin, TRUE); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2509 | wnoutrefresh(topwin); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2510 | wnoutrefresh(edit); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2511 | wnoutrefresh(bottomwin); |
| 2512 | doupdate(); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2513 | clearok(topwin, FALSE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2514 | clearok(edit, FALSE); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2515 | clearok(bottomwin, FALSE); |
| 2516 | edit_refresh(); |
| 2517 | titlebar(NULL); |
| 2518 | return 1; |
| 2519 | } |
| 2520 | |
| 2521 | void display_main_list(void) |
| 2522 | { |
| 2523 | bottombars(main_list); |
| 2524 | } |
| 2525 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2526 | /* If constant is FALSE, the user typed ^C so we unconditionally display |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2527 | * the cursor position. Otherwise, we display it only if the character |
| 2528 | * position changed, and DISABLE_CURPOS is not set. |
| 2529 | * |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2530 | * If constant is TRUE and DISABLE_CURPOS is set, we unset it and update |
| 2531 | * old_i and old_totsize. That way, we leave the current statusbar |
| 2532 | * alone, but next time we will display. */ |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2533 | int do_cursorpos(int constant) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2534 | { |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2535 | const filestruct *fileptr; |
| 2536 | unsigned long i = 0; |
| 2537 | static unsigned long old_i = 0; |
| 2538 | static long old_totsize = -1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2539 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2540 | assert(current != NULL && fileage != NULL && totlines != 0); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2541 | |
| 2542 | if (old_totsize == -1) |
| 2543 | old_totsize = totsize; |
| 2544 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2545 | for (fileptr = fileage; fileptr != current; fileptr = fileptr->next) { |
| 2546 | assert(fileptr != NULL); |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 2547 | i += strlen(fileptr->data) + 1; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2548 | } |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 2549 | i += current_x; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 2550 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2551 | if (constant && ISSET(DISABLE_CURPOS)) { |
| 2552 | UNSET(DISABLE_CURPOS); |
| 2553 | old_i = i; |
| 2554 | old_totsize = totsize; |
| 2555 | return 0; |
| 2556 | } |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 2557 | |
David Lawrence Ramsey | 4178db0 | 2004-05-23 21:23:23 +0000 | [diff] [blame^] | 2558 | /* If constant is FALSE, display the position on the statusbar |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2559 | * unconditionally; otherwise, only display the position when the |
| 2560 | * character values have changed. */ |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2561 | if (!constant || old_i != i || old_totsize != totsize) { |
| 2562 | unsigned long xpt = xplustabs() + 1; |
| 2563 | unsigned long cur_len = strlenpt(current->data) + 1; |
| 2564 | int linepct = 100 * current->lineno / totlines; |
| 2565 | int colpct = 100 * xpt / cur_len; |
| 2566 | int bytepct = totsize == 0 ? 0 : 100 * i / totsize; |
| 2567 | |
| 2568 | statusbar( |
| 2569 | _("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%ld (%d%%)"), |
| 2570 | current->lineno, totlines, linepct, |
| 2571 | xpt, cur_len, colpct, |
| 2572 | i, totsize, bytepct); |
| 2573 | UNSET(DISABLE_CURPOS); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | old_i = i; |
| 2577 | old_totsize = totsize; |
| 2578 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2579 | reset_cursor(); |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 2580 | return 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 2583 | int do_cursorpos_void(void) |
| 2584 | { |
| 2585 | return do_cursorpos(0); |
| 2586 | } |
| 2587 | |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 2588 | /* Calculate the next line of help_text, starting at ptr. */ |
| 2589 | int line_len(const char *ptr) |
| 2590 | { |
| 2591 | int j = 0; |
| 2592 | |
| 2593 | while (*ptr != '\n' && *ptr != '\0' && j < COLS - 5) { |
| 2594 | ptr++; |
| 2595 | j++; |
| 2596 | } |
| 2597 | if (j == COLS - 5) { |
| 2598 | /* Don't wrap at the first of two spaces following a period. */ |
| 2599 | if (*ptr == ' ' && *(ptr + 1) == ' ') |
| 2600 | j++; |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2601 | /* Don't print half a word if we've run out of space. */ |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 2602 | while (*ptr != ' ' && j > 0) { |
| 2603 | ptr--; |
| 2604 | j--; |
| 2605 | } |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2606 | /* Word longer than COLS - 5 chars just gets broken. */ |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 2607 | if (j == 0) |
| 2608 | j = COLS - 5; |
| 2609 | } |
| 2610 | assert(j >= 0 && j <= COLS - 4 && (j > 0 || *ptr == '\n')); |
| 2611 | return j; |
| 2612 | } |
| 2613 | |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 2614 | #ifndef DISABLE_HELP |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2615 | /* Our shortcut-list-compliant help function, which is better than |
| 2616 | * nothing, and dynamic! */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2617 | int do_help(void) |
| 2618 | { |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 2619 | int i, page = 0, kbinput = ERR, meta_key, no_more = 0; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2620 | int no_help_flag = FALSE; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2621 | const shortcut *oldshortcut; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2622 | |
| 2623 | blank_edit(); |
| 2624 | curs_set(0); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 2625 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2626 | blank_statusbar(); |
| 2627 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2628 | /* Set help_text as the string to display. */ |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 2629 | help_init(); |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 2630 | assert(help_text != NULL); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 2631 | |
| 2632 | oldshortcut = currshortcut; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 2633 | |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 2634 | currshortcut = help_list; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 2635 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2636 | if (ISSET(NO_HELP)) { |
| 2637 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2638 | /* Well, if we're going to do this, we should at least do it the |
| 2639 | * right way. */ |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2640 | no_help_flag = TRUE; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 2641 | UNSET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 2642 | window_init(); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2643 | bottombars(help_list); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 2644 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 2645 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2646 | bottombars(help_list); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2647 | |
| 2648 | do { |
Chris Allegretta | f717f98 | 2003-02-13 22:25:01 +0000 | [diff] [blame] | 2649 | const char *ptr = help_text; |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 2650 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2651 | switch (kbinput) { |
David Lawrence Ramsey | f5b256b | 2003-10-03 20:26:25 +0000 | [diff] [blame] | 2652 | #ifndef DISABLE_MOUSE |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2653 | case KEY_MOUSE: |
| 2654 | do_mouse(); |
| 2655 | break; |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 2656 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2657 | case NANO_NEXTPAGE_KEY: |
| 2658 | case NANO_NEXTPAGE_FKEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2659 | if (!no_more) { |
| 2660 | blank_edit(); |
| 2661 | page++; |
| 2662 | } |
| 2663 | break; |
| 2664 | case NANO_PREVPAGE_KEY: |
| 2665 | case NANO_PREVPAGE_FKEY: |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 2666 | if (page > 0) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2667 | no_more = 0; |
| 2668 | blank_edit(); |
| 2669 | page--; |
| 2670 | } |
| 2671 | break; |
| 2672 | } |
| 2673 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2674 | /* Calculate where in the text we should be, based on the |
| 2675 | * page. */ |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 2676 | for (i = 1; i < page * (editwinrows - 1); i++) { |
| 2677 | ptr += line_len(ptr); |
| 2678 | if (*ptr == '\n') |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2679 | ptr++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 2682 | for (i = 0; i < editwinrows && *ptr != '\0'; i++) { |
| 2683 | int j = line_len(ptr); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2684 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2685 | mvwaddnstr(edit, i, 0, ptr, j); |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 2686 | ptr += j; |
| 2687 | if (*ptr == '\n') |
| 2688 | ptr++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2689 | } |
Chris Allegretta | 4640fe3 | 2003-02-10 03:10:03 +0000 | [diff] [blame] | 2690 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2691 | if (*ptr == '\0') { |
| 2692 | no_more = 1; |
| 2693 | continue; |
| 2694 | } |
David Lawrence Ramsey | 1576d53 | 2004-03-19 21:46:34 +0000 | [diff] [blame] | 2695 | } while ((kbinput = get_kbinput(edit, &meta_key)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY); |
Chris Allegretta | d1627cf | 2000-12-18 05:03:16 +0000 | [diff] [blame] | 2696 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 2697 | currshortcut = oldshortcut; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 2698 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2699 | if (no_help_flag) { |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 2700 | blank_bottombars(); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 2701 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2702 | SET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 2703 | window_init(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2704 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2705 | bottombars(currshortcut); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2706 | |
| 2707 | curs_set(1); |
| 2708 | edit_refresh(); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 2709 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 2710 | /* The help_init() at the beginning allocated help_text, which has |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2711 | * now been written to the screen. */ |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 2712 | free(help_text); |
| 2713 | help_text = NULL; |
| 2714 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2715 | return 1; |
| 2716 | } |
David Lawrence Ramsey | d893fa9 | 2004-04-30 04:49:02 +0000 | [diff] [blame] | 2717 | #endif /* !DISABLE_HELP */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2718 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2719 | /* Highlight the current word being replaced or spell checked. We |
| 2720 | * expect word to have tabs and control characters expanded. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 2721 | void do_replace_highlight(int highlight_flag, const char *word) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 2722 | { |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2723 | int y = xplustabs(); |
| 2724 | size_t word_len = strlen(word); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 2725 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2726 | y = get_page_start(y) + COLS - y; |
| 2727 | /* Now y is the number of characters we can display on this |
| 2728 | * line. */ |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 2729 | |
| 2730 | reset_cursor(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2731 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 2732 | if (highlight_flag) |
| 2733 | wattron(edit, A_REVERSE); |
| 2734 | |
David Lawrence Ramsey | 2a4ab6d | 2003-12-24 08:29:49 +0000 | [diff] [blame] | 2735 | #ifdef HAVE_REGEX_H |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 2736 | /* This is so we can show zero-length regexes. */ |
| 2737 | if (word_len == 0) |
| 2738 | waddstr(edit, " "); |
| 2739 | else |
David Lawrence Ramsey | 2a4ab6d | 2003-12-24 08:29:49 +0000 | [diff] [blame] | 2740 | #endif |
David Lawrence Ramsey | 76c4b33 | 2003-12-24 08:17:54 +0000 | [diff] [blame] | 2741 | waddnstr(edit, word, y - 1); |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2742 | |
| 2743 | if (word_len > y) |
| 2744 | waddch(edit, '$'); |
| 2745 | else if (word_len == y) |
| 2746 | waddch(edit, word[word_len - 1]); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 2747 | |
| 2748 | if (highlight_flag) |
| 2749 | wattroff(edit, A_REVERSE); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2752 | #ifdef DEBUG |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2753 | /* Dump the passed-in file structure to stderr. */ |
| 2754 | void dump_buffer(const filestruct *inptr) |
| 2755 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2756 | if (inptr == fileage) |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 2757 | fprintf(stderr, "Dumping file buffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2758 | else if (inptr == cutbuffer) |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 2759 | fprintf(stderr, "Dumping cutbuffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2760 | else |
Jordi Mallach | f9390af | 2003-08-05 19:31:12 +0000 | [diff] [blame] | 2761 | fprintf(stderr, "Dumping a buffer to stderr...\n"); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2762 | |
| 2763 | while (inptr != NULL) { |
| 2764 | fprintf(stderr, "(%d) %s\n", inptr->lineno, inptr->data); |
| 2765 | inptr = inptr->next; |
| 2766 | } |
| 2767 | } |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2768 | |
David Lawrence Ramsey | 5ffbec5 | 2003-09-16 01:16:49 +0000 | [diff] [blame] | 2769 | /* Dump the file structure to stderr in reverse. */ |
David Lawrence Ramsey | aaad3af | 2003-08-31 16:44:10 +0000 | [diff] [blame] | 2770 | void dump_buffer_reverse(void) |
| 2771 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 2772 | const filestruct *fileptr = filebot; |
| 2773 | |
| 2774 | while (fileptr != NULL) { |
| 2775 | fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data); |
| 2776 | fileptr = fileptr->prev; |
| 2777 | } |
| 2778 | } |
| 2779 | #endif /* DEBUG */ |
| 2780 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2781 | #ifdef NANO_EXTRA |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 2782 | #define CREDIT_LEN 53 |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 2783 | #define XLCREDIT_LEN 8 |
| 2784 | |
David Lawrence Ramsey | fdece46 | 2004-01-19 18:15:03 +0000 | [diff] [blame] | 2785 | /* Easter egg: Display credits. Assume nodelay(edit) is FALSE. */ |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2786 | void do_credits(void) |
| 2787 | { |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2788 | int crpos = 0, xlpos = 0; |
| 2789 | const char *credits[CREDIT_LEN] = { |
| 2790 | NULL, /* "The nano text editor" */ |
| 2791 | NULL, /* "version" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2792 | VERSION, |
| 2793 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2794 | NULL, /* "Brought to you by:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2795 | "Chris Allegretta", |
| 2796 | "Jordi Mallach", |
| 2797 | "Adam Rogoyski", |
| 2798 | "Rob Siemborski", |
| 2799 | "Rocco Corsi", |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2800 | "David Lawrence Ramsey", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 2801 | "David Benbennick", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2802 | "Ken Tyler", |
| 2803 | "Sven Guckes", |
| 2804 | "Florian König", |
| 2805 | "Pauli Virtanen", |
| 2806 | "Daniele Medri", |
| 2807 | "Clement Laforet", |
| 2808 | "Tedi Heriyanto", |
| 2809 | "Bill Soudan", |
| 2810 | "Christian Weisgerber", |
| 2811 | "Erik Andersen", |
| 2812 | "Big Gaute", |
| 2813 | "Joshua Jensen", |
| 2814 | "Ryan Krebs", |
| 2815 | "Albert Chin", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2816 | "", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2817 | NULL, /* "Special thanks to:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2818 | "Plattsburgh State University", |
| 2819 | "Benet Laboratories", |
| 2820 | "Amy Allegretta", |
| 2821 | "Linda Young", |
| 2822 | "Jeremy Robichaud", |
| 2823 | "Richard Kolb II", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2824 | NULL, /* "The Free Software Foundation" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2825 | "Linus Torvalds", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2826 | NULL, /* "For ncurses:" */ |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 2827 | "Thomas Dickey", |
| 2828 | "Pavel Curtis", |
| 2829 | "Zeyd Ben-Halim", |
| 2830 | "Eric S. Raymond", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2831 | NULL, /* "and anyone else we forgot..." */ |
| 2832 | NULL, /* "Thank you for using nano!" */ |
| 2833 | "", |
| 2834 | "", |
| 2835 | "", |
| 2836 | "", |
David Lawrence Ramsey | 6481c3f | 2004-01-09 23:06:54 +0000 | [diff] [blame] | 2837 | "(c) 1999-2004 Chris Allegretta", |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2838 | "", |
| 2839 | "", |
| 2840 | "", |
| 2841 | "", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 2842 | "http://www.nano-editor.org/" |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2843 | }; |
| 2844 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2845 | const char *xlcredits[XLCREDIT_LEN] = { |
David Lawrence Ramsey | 837a02b | 2004-05-18 15:23:31 +0000 | [diff] [blame] | 2846 | "The nano text editor", |
| 2847 | "version", |
| 2848 | "Brought to you by:", |
| 2849 | "Special thanks to:", |
| 2850 | "The Free Software Foundation", |
| 2851 | "For ncurses:", |
| 2852 | "and anyone else we forgot...", |
| 2853 | "Thank you for using nano!" |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2854 | }; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 2855 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2856 | curs_set(0); |
| 2857 | nodelay(edit, TRUE); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2858 | scrollok(edit, TRUE); |
| 2859 | blank_titlebar(); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2860 | blank_edit(); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2861 | blank_statusbar(); |
| 2862 | blank_bottombars(); |
| 2863 | wrefresh(topwin); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2864 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2865 | wrefresh(bottomwin); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2866 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2867 | for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) { |
| 2868 | if (wgetch(edit) != ERR) |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2869 | break; |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2870 | if (crpos < CREDIT_LEN) { |
| 2871 | const char *what = credits[crpos]; |
| 2872 | size_t start_x; |
| 2873 | |
| 2874 | if (what == NULL) { |
| 2875 | assert(0 <= xlpos && xlpos < XLCREDIT_LEN); |
David Lawrence Ramsey | 837a02b | 2004-05-18 15:23:31 +0000 | [diff] [blame] | 2876 | what = _(xlcredits[xlpos]); |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2877 | xlpos++; |
| 2878 | } |
| 2879 | start_x = COLS / 2 - strlen(what) / 2 - 1; |
| 2880 | mvwaddstr(edit, editwinrows - 1 - editwinrows % 2, start_x, what); |
| 2881 | } |
| 2882 | napms(700); |
| 2883 | scroll(edit); |
| 2884 | wrefresh(edit); |
| 2885 | if (wgetch(edit) != ERR) |
| 2886 | break; |
| 2887 | napms(700); |
| 2888 | scroll(edit); |
| 2889 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
David Lawrence Ramsey | d7fd200 | 2004-05-18 01:20:36 +0000 | [diff] [blame] | 2892 | scrollok(edit, FALSE); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2893 | nodelay(edit, FALSE); |
| 2894 | curs_set(1); |
| 2895 | display_main_list(); |
| 2896 | total_refresh(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2897 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2898 | #endif |