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