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