Chris Allegretta | 11b0011 | 2000-08-06 21:13:45 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * winio.c * |
| 4 | * * |
Chris Allegretta | d757e25 | 2003-01-15 19:33:27 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2003 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 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 37 | int do_first_line(void) |
| 38 | { |
| 39 | current = fileage; |
| 40 | placewewant = 0; |
| 41 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 42 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 43 | return 1; |
| 44 | } |
| 45 | |
| 46 | int do_last_line(void) |
| 47 | { |
| 48 | current = filebot; |
| 49 | placewewant = 0; |
| 50 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 51 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 52 | return 1; |
| 53 | } |
| 54 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 55 | /* Return the placewewant associated with current_x. That is, xplustabs |
| 56 | * is the zero-based column position of the cursor. Value is no smaller |
| 57 | * than current_x. */ |
| 58 | size_t xplustabs(void) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 59 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 60 | return strnlenpt(current->data, current_x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 63 | /* Return what current_x should be, given xplustabs() for the line. */ |
| 64 | size_t actual_x(const filestruct *fileptr, size_t xplus) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 65 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 66 | size_t i = 0; |
| 67 | /* the position in fileptr->data, returned */ |
| 68 | size_t length = 0; |
| 69 | /* the screen display width to data[i] */ |
| 70 | char *c; |
| 71 | /* fileptr->data + i */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 72 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 73 | assert(fileptr != NULL && fileptr->data != NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 74 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 75 | for (c = fileptr->data; length < xplus && *c != '\0'; i++, c++) { |
| 76 | if (*c == '\t') |
| 77 | length += tabsize - length % tabsize; |
Chris Allegretta | cf287c8 | 2002-07-20 13:57:41 +0000 | [diff] [blame] | 78 | else if (is_cntrl_char((int)*c)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 79 | length += 2; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 80 | else |
| 81 | length++; |
| 82 | } |
| 83 | assert(length == strnlenpt(fileptr->data, i)); |
| 84 | assert(i <= strlen(fileptr->data)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 85 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 86 | if (length > xplus) |
| 87 | i--; |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 88 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 89 | #ifdef DEBUG |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 90 | fprintf(stderr, _("actual_x for xplus=%d returns %d\n"), xplus, i); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 91 | #endif |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 92 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 93 | return i; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 96 | /* A strlen with tabs factored in, similar to xplustabs(). */ |
| 97 | size_t strnlenpt(const char *buf, size_t size) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 98 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 99 | size_t length = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 100 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 101 | if (buf != NULL) |
| 102 | for (; *buf != '\0' && size != 0; size--, buf++) { |
| 103 | if (*buf == '\t') |
| 104 | length += tabsize - (length % tabsize); |
Chris Allegretta | cf287c8 | 2002-07-20 13:57:41 +0000 | [diff] [blame] | 105 | else if (is_cntrl_char((int)*buf)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 106 | length += 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 107 | else |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 108 | length++; |
| 109 | } |
| 110 | return length; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 113 | size_t strlenpt(const char *buf) |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 114 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 115 | return strnlenpt(buf, -1); |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 118 | void blank_bottombars(void) |
| 119 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 120 | if (!no_help()) { |
| 121 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 122 | mvwaddstr(bottomwin, 2, 0, hblank); |
| 123 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 124 | } |
| 125 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 126 | void blank_bottomwin(void) |
| 127 | { |
| 128 | if (ISSET(NO_HELP)) |
| 129 | return; |
| 130 | |
| 131 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 132 | mvwaddstr(bottomwin, 2, 0, hblank); |
| 133 | } |
| 134 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 135 | void blank_edit(void) |
| 136 | { |
| 137 | int i; |
| 138 | for (i = 0; i <= editwinrows - 1; i++) |
| 139 | mvwaddstr(edit, i, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | |
| 143 | void blank_statusbar(void) |
| 144 | { |
| 145 | mvwaddstr(bottomwin, 0, 0, hblank); |
| 146 | } |
| 147 | |
| 148 | void blank_statusbar_refresh(void) |
| 149 | { |
| 150 | blank_statusbar(); |
| 151 | wrefresh(bottomwin); |
| 152 | } |
| 153 | |
| 154 | void check_statblank(void) |
| 155 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 156 | if (statblank > 1) |
| 157 | statblank--; |
| 158 | else if (statblank == 1 && !ISSET(CONSTUPDATE)) { |
| 159 | statblank--; |
| 160 | blank_statusbar_refresh(); |
| 161 | } |
| 162 | } |
| 163 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 164 | /* Repaint the statusbar when getting a character in nanogetstr(). buf |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 165 | * should be no longer than COLS - 4. |
| 166 | * |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 167 | * 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] | 168 | * off! */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 169 | void nanoget_repaint(const char *buf, const char *inputbuf, int x) |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 170 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 171 | int len = strlen(buf) + 2; |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 172 | int wid = COLS - len; |
| 173 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 174 | assert(wid >= 2); |
| 175 | assert(0 <= x && x <= strlen(inputbuf)); |
| 176 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 177 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 178 | blank_statusbar(); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 179 | mvwaddstr(bottomwin, 0, 0, buf); |
| 180 | waddch(bottomwin, ':'); |
| 181 | waddch(bottomwin, x < wid ? ' ' : '$'); |
| 182 | waddnstr(bottomwin, &inputbuf[wid * (x / wid)], wid); |
| 183 | wmove(bottomwin, 0, (x % wid) + len); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 184 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 187 | /* Get the input from the kb; this should only be called from |
| 188 | * statusq(). */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 189 | int nanogetstr(int allowtabs, const char *buf, const char *def, |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 190 | #ifndef NANO_SMALL |
| 191 | historyheadtype *history_list, |
| 192 | #endif |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 193 | const shortcut *s |
Rocco Corsi | 06aca1c | 2001-01-11 05:30:31 +0000 | [diff] [blame] | 194 | #ifndef DISABLE_TABCOMP |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 195 | , int *list |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 196 | #endif |
Chris Allegretta | 47fcfe5 | 2003-01-26 21:01:16 +0000 | [diff] [blame] | 197 | , int resetpos) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 198 | { |
| 199 | int kbinput; |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 200 | static int x = -1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 201 | /* the cursor position in 'answer' */ |
| 202 | int xend; |
| 203 | /* length of 'answer', the status bar text */ |
| 204 | int tabbed = 0; |
| 205 | /* used by input_tab() */ |
| 206 | const shortcut *t; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 207 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 208 | #ifndef NANO_SMALL |
| 209 | /* for history */ |
| 210 | char *history = NULL; |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 211 | char *currentbuf = NULL; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 212 | char *complete = NULL; |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 213 | int last_kbinput = 0, ret2cb = 0; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 214 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 215 | xend = strlen(def); |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 216 | |
| 217 | /* Only put x at the end of the string if it's uninitialized or if |
| 218 | it would be past the end of the string as it is. Otherwise, |
| 219 | leave it alone. This is so the cursor position stays at the same |
| 220 | place if a prompt-changing toggle is pressed. */ |
Chris Allegretta | 47fcfe5 | 2003-01-26 21:01:16 +0000 | [diff] [blame] | 221 | if (x == -1 || x > xend || resetpos) |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 222 | x = xend; |
| 223 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 224 | answer = (char *)nrealloc(answer, xend + 1); |
| 225 | if (xend > 0) |
| 226 | strcpy(answer, def); |
| 227 | else |
| 228 | answer[0] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 229 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 230 | #if !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)) |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 231 | currshortcut = s; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 232 | #endif |
| 233 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 234 | /* Get the input! */ |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 235 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 236 | nanoget_repaint(buf, answer, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 237 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 238 | /* Make sure any editor screen updates are displayed before getting |
| 239 | input */ |
Chris Allegretta | 022b96f | 2000-11-14 17:47:58 +0000 | [diff] [blame] | 240 | wrefresh(edit); |
| 241 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 242 | while ((kbinput = wgetch(bottomwin)) != 13) { |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 243 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 244 | #ifdef DEBUG |
| 245 | fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput); |
| 246 | #endif |
| 247 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 248 | if (kbinput == t->val && kbinput < 32) { |
Chris Allegretta | 5bf51d3 | 2000-11-16 06:01:10 +0000 | [diff] [blame] | 249 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 250 | #ifndef DISABLE_HELP |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 251 | /* Have to do this here, it would be too late to do it |
| 252 | in statusq() */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 253 | if (kbinput == NANO_HELP_KEY || kbinput == NANO_HELP_FKEY) { |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 254 | do_help(); |
| 255 | break; |
| 256 | } |
| 257 | #endif |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 258 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 259 | return t->val; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 260 | } |
| 261 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 262 | assert(0 <= x && x <= xend && xend == strlen(answer)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 263 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 264 | if (kbinput != '\t') |
| 265 | tabbed = 0; |
| 266 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 267 | switch (kbinput) { |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 268 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 269 | /* Stuff we want to equate with <enter>, ASCII 13 */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 270 | case 343: |
Chris Allegretta | f9b6c9b | 2000-10-18 19:35:59 +0000 | [diff] [blame] | 271 | ungetch(13); /* Enter on iris-ansi $TERM, sometimes */ |
| 272 | break; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 273 | /* Stuff we want to ignore */ |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 274 | #ifdef PDCURSES |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 275 | case 541: |
| 276 | case 542: |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 277 | case 543: /* Right ctrl again */ |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 278 | case 544: |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 279 | case 545: /* Right alt again */ |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 280 | break; |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 281 | #endif |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 282 | #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION) |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 283 | case KEY_MOUSE: |
| 284 | do_mouse(); |
| 285 | break; |
| 286 | #endif |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 287 | case NANO_HOME_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 288 | case KEY_HOME: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 289 | x = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 290 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 291 | case NANO_END_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 292 | case KEY_END: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 293 | x = xend; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 294 | break; |
| 295 | case KEY_RIGHT: |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 296 | case NANO_FORWARD_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 297 | if (x < xend) |
| 298 | x++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 299 | break; |
| 300 | case NANO_CONTROL_D: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 301 | if (x < xend) { |
| 302 | memmove(answer + x, answer + x + 1, xend - x); |
| 303 | xend--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 304 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 305 | break; |
| 306 | case NANO_CONTROL_K: |
| 307 | case NANO_CONTROL_U: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 308 | null_at(&answer, 0); |
| 309 | xend = 0; |
| 310 | x = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 311 | break; |
| 312 | case KEY_BACKSPACE: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 313 | case 127: |
| 314 | case NANO_CONTROL_H: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 315 | if (x > 0) { |
| 316 | memmove(answer + x - 1, answer + x, xend - x + 1); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 317 | x--; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 318 | xend--; |
| 319 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 320 | break; |
| 321 | case NANO_CONTROL_I: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 322 | #ifndef NANO_SMALL |
| 323 | /* tab history completion */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 324 | if (history_list != NULL) { |
| 325 | if (!complete || last_kbinput != NANO_CONTROL_I) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 326 | history_list->current = (historytype *)history_list; |
| 327 | history_list->len = strlen(answer); |
| 328 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 329 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 330 | if (history_list->len > 0) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 331 | complete = get_history_completion(history_list, answer); |
| 332 | xend = strlen(complete); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 333 | x = xend; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 334 | answer = mallocstrcpy(answer, complete); |
| 335 | } |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 336 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 337 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 338 | else |
| 339 | #endif |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 340 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 341 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 342 | if (allowtabs) { |
| 343 | int shift = 0; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 344 | |
Chris Allegretta | 327abda | 2003-01-17 05:04:17 +0000 | [diff] [blame] | 345 | answer = input_tab(answer, x, &tabbed, &shift, list); |
| 346 | xend = strlen(answer); |
| 347 | x += shift; |
| 348 | if (x > xend) |
| 349 | x = xend; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 350 | } |
| 351 | #endif |
| 352 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 353 | case KEY_LEFT: |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 354 | case NANO_BACK_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 355 | if (x > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 356 | x--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 357 | break; |
| 358 | case KEY_UP: |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 359 | case NANO_UP_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 360 | #ifndef NANO_SMALL |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 361 | if (history_list != NULL) { |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 362 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 363 | /* If there's no previous temp holder, or if we already |
| 364 | arrowed back down to it and (possibly edited it), |
| 365 | update the holder */ |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 366 | if (currentbuf == NULL || (ret2cb == 1 && strcmp(currentbuf, answer))) { |
| 367 | currentbuf = mallocstrcpy(currentbuf, answer); |
| 368 | ret2cb = 0; |
| 369 | } |
| 370 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 371 | /* get older search from the history list */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 372 | if ((history = get_history_older(history_list)) != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 373 | answer = mallocstrcpy(answer, history); |
| 374 | xend = strlen(history); |
| 375 | } else { |
| 376 | answer = mallocstrcpy(answer, ""); |
| 377 | xend = 0; |
| 378 | } |
| 379 | x = xend; |
| 380 | } |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 381 | #endif |
Chris Allegretta | 54abd94 | 2003-01-09 23:43:12 +0000 | [diff] [blame] | 382 | break; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 383 | case KEY_DOWN: |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 384 | case NANO_DOWN_KEY: |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 385 | #ifndef NANO_SMALL |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 386 | if (history_list != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 387 | /* get newer search from the history list */ |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 388 | if ((history = get_history_newer(history_list)) != NULL) { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 389 | answer = mallocstrcpy(answer, history); |
| 390 | xend = strlen(history); |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 391 | |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 392 | /* else if we ran out of history, regurgitate the temporary |
| 393 | buffer and blow away currentbuf */ |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 394 | } else if (currentbuf != NULL) { |
| 395 | answer = mallocstrcpy(answer, currentbuf); |
Chris Allegretta | 09fc430 | 2003-01-16 22:16:38 +0000 | [diff] [blame] | 396 | free(currentbuf); |
| 397 | currentbuf = NULL; |
| 398 | xend = strlen(answer); |
Chris Allegretta | 8031f83 | 2003-01-09 05:29:58 +0000 | [diff] [blame] | 399 | ret2cb = 1; |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 400 | } else { |
| 401 | answer = mallocstrcpy(answer, ""); |
| 402 | xend = 0; |
| 403 | } |
| 404 | x = xend; |
| 405 | } |
| 406 | #endif |
| 407 | break; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 408 | case KEY_DC: |
| 409 | goto do_deletekey; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 410 | case 27: |
| 411 | switch (kbinput = wgetch(edit)) { |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 412 | case 'O': |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 413 | switch (kbinput = wgetch(edit)) { |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 414 | case 'F': |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 415 | x = xend; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 416 | break; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 417 | case 'H': |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 418 | x = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 419 | break; |
| 420 | } |
| 421 | break; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 422 | case '[': |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 423 | switch (kbinput = wgetch(edit)) { |
| 424 | case 'C': |
| 425 | if (x < xend) |
| 426 | x++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 427 | break; |
| 428 | case 'D': |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 429 | if (x > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 430 | x--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 431 | break; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 432 | case '1': |
| 433 | case '7': |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 434 | x = 0; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 435 | goto skip_tilde; |
| 436 | case '3': |
| 437 | do_deletekey: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 438 | if (x < xend) { |
| 439 | memmove(answer + x, answer + x + 1, xend - x); |
| 440 | xend--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 441 | } |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 442 | goto skip_tilde; |
| 443 | case '4': |
| 444 | case '8': |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 445 | x = xend; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 446 | skip_tilde: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 447 | nodelay(edit, TRUE); |
| 448 | kbinput = wgetch(edit); |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 449 | if (kbinput == '~' || kbinput == ERR) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 450 | kbinput = -1; |
| 451 | nodelay(edit, FALSE); |
| 452 | break; |
| 453 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 454 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 455 | default: |
| 456 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 457 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 458 | #ifdef DEBUG |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 459 | fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, |
| 460 | kbinput); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 461 | #endif |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 462 | if (kbinput == t->val || kbinput == t->val - 32) |
| 463 | /* We hit an Alt key. Do like above. We don't |
| 464 | just ungetch() the letter and let it get |
| 465 | caught above cause that screws the |
| 466 | keypad... */ |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 467 | return t->val; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 468 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 469 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 470 | break; |
| 471 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 472 | default: |
| 473 | if (kbinput < 32) |
| 474 | break; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 475 | answer = nrealloc(answer, xend + 2); |
| 476 | memmove(answer + x + 1, answer + x, xend - x + 1); |
| 477 | xend++; |
| 478 | answer[x] = kbinput; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 479 | x++; |
| 480 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 481 | #ifdef DEBUG |
| 482 | fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput); |
| 483 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 484 | } /* switch (kbinput) */ |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 485 | #ifndef NANO_SMALL |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 486 | last_kbinput = kbinput; |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 487 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 488 | nanoget_repaint(buf, answer, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 489 | wrefresh(bottomwin); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 490 | } /* while (kbinput ...) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 491 | |
Chris Allegretta | 5af5889 | 2003-01-17 21:07:38 +0000 | [diff] [blame] | 492 | /* We finished putting in an answer; reset x */ |
| 493 | x = -1; |
| 494 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 495 | /* Just check for a blank answer here */ |
Chris Allegretta | 15c28f8 | 2003-01-05 21:47:06 +0000 | [diff] [blame] | 496 | if (answer[0] == '\0') |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 497 | return -2; |
| 498 | else |
| 499 | return 0; |
| 500 | } |
| 501 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 502 | /* If modified is not already set, set it and update titlebar. */ |
| 503 | void set_modified(void) |
| 504 | { |
| 505 | if (!ISSET(MODIFIED)) { |
| 506 | SET(MODIFIED); |
| 507 | titlebar(NULL); |
| 508 | wrefresh(topwin); |
| 509 | } |
| 510 | } |
| 511 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 512 | void titlebar(const char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 513 | { |
| 514 | int namelen, space; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 515 | const char *what = path; |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 516 | |
| 517 | if (path == NULL) |
| 518 | what = filename; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 519 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 520 | wattron(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 521 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 522 | mvwaddstr(topwin, 0, 0, hblank); |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 523 | mvwaddnstr(topwin, 0, 2, VERMSG, COLS - 3); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 524 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 525 | space = COLS - sizeof(VERMSG) - 22; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 526 | |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 527 | namelen = strlen(what); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 528 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 529 | if (space > 0) { |
| 530 | if (what[0] == '\0') |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 531 | mvwaddnstr(topwin, 0, COLS / 2 - 6, _("New Buffer"), |
| 532 | COLS / 2 + COLS % 2 - 6); |
| 533 | else if (namelen > space) { |
| 534 | if (path == NULL) |
| 535 | waddstr(topwin, _(" File: ...")); |
| 536 | else |
| 537 | waddstr(topwin, _(" DIR: ...")); |
| 538 | waddstr(topwin, &what[namelen - space]); |
| 539 | } else { |
| 540 | if (path == NULL) |
| 541 | mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), |
| 542 | _("File: ")); |
| 543 | else |
| 544 | mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), |
| 545 | _(" DIR: ")); |
| 546 | waddstr(topwin, what); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 547 | } |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 548 | } /* If we don't have space, we shouldn't bother */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 549 | if (ISSET(MODIFIED)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 550 | mvwaddnstr(topwin, 0, COLS - 11, _(" Modified "), 11); |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 551 | else if (ISSET(VIEW_MODE)) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 552 | mvwaddnstr(topwin, 0, COLS - 11, _(" View "), 11); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 553 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 554 | wattroff(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 555 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 556 | wrefresh(topwin); |
| 557 | reset_cursor(); |
| 558 | } |
| 559 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 560 | void bottombars(const shortcut *s) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 561 | { |
Chris Allegretta | bc72e36 | 2002-02-16 20:03:44 +0000 | [diff] [blame] | 562 | int i, j, numcols; |
Chris Allegretta | 3bbc416 | 2003-01-23 00:46:12 +0000 | [diff] [blame] | 563 | char keystr[9]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 564 | int slen; |
| 565 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 566 | if (ISSET(NO_HELP)) |
| 567 | return; |
| 568 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 569 | if (s == main_list) { |
| 570 | slen = MAIN_VISIBLE; |
| 571 | assert(MAIN_VISIBLE <= length_of_list(s)); |
| 572 | } else |
| 573 | slen = length_of_list(s); |
| 574 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 575 | /* There will be this many columns of shortcuts */ |
| 576 | numcols = (slen + (slen % 2)) / 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 577 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 578 | blank_bottomwin(); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 579 | |
Chris Allegretta | bc72e36 | 2002-02-16 20:03:44 +0000 | [diff] [blame] | 580 | for (i = 0; i < numcols; i++) { |
| 581 | for (j = 0; j <= 1; j++) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 582 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 583 | wmove(bottomwin, 1 + j, i * (COLS / numcols)); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 584 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 585 | /* Yucky sentinel values we can't handle a better way */ |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 586 | if (s->val == NANO_CONTROL_SPACE) |
| 587 | strcpy(keystr, "^ "); |
Chris Allegretta | a65ba51 | 2003-01-05 20:57:07 +0000 | [diff] [blame] | 588 | #ifndef NANO_SMALL |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 589 | else if (s->val == KEY_UP) |
Chris Allegretta | 3bbc416 | 2003-01-23 00:46:12 +0000 | [diff] [blame] | 590 | strncpy(keystr, _("Up"), 8); |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 591 | #endif /* NANO_SMALL */ |
| 592 | else if (s->val > 0) { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 593 | if (s->val < 64) |
| 594 | sprintf(keystr, "^%c", s->val + 64); |
| 595 | else |
| 596 | sprintf(keystr, "M-%c", s->val - 32); |
| 597 | } else if (s->altval > 0) |
| 598 | sprintf(keystr, "M-%c", s->altval); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 599 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 600 | onekey(keystr, s->desc, COLS / numcols); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 601 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 602 | s = s->next; |
| 603 | if (s == NULL) |
| 604 | goto break_completely_out; |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 605 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 608 | break_completely_out: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 609 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 610 | } |
| 611 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 612 | /* Write a shortcut key to the help area at the bottom of the window. |
| 613 | * keystroke is e.g. "^G" and desc is e.g. "Get Help". |
| 614 | * We are careful to write exactly len characters, even if len is |
| 615 | * very small and keystroke and desc are long. */ |
| 616 | void onekey(const char *keystroke, const char *desc, int len) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 617 | { |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 618 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 619 | wattron(bottomwin, A_REVERSE); |
| 620 | waddnstr(bottomwin, keystroke, len); |
| 621 | wattroff(bottomwin, A_REVERSE); |
| 622 | len -= strlen(keystroke); |
| 623 | if (len > 0) { |
| 624 | waddch(bottomwin, ' '); |
| 625 | len--; |
| 626 | waddnstr(bottomwin, desc, len); |
| 627 | len -= strlen(desc); |
| 628 | for (; len > 0; len--) |
| 629 | waddch(bottomwin, ' '); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 633 | /* And so start the display update routines. */ |
| 634 | |
| 635 | #ifndef NDEBUG |
| 636 | int check_linenumbers(const filestruct *fileptr) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 637 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 638 | int check_line = 0; |
| 639 | const filestruct *filetmp; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 640 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 641 | for (filetmp = edittop; filetmp != fileptr; filetmp = filetmp->next) |
| 642 | check_line++; |
| 643 | return check_line; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 644 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 645 | #endif |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 646 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 647 | /* nano scrolls horizontally within a line in chunks. This function |
| 648 | * returns the column number of the first character displayed in the |
| 649 | * window when the cursor is at the given column. */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 650 | int get_page_start(int column) |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 651 | { |
| 652 | assert(COLS > 9); |
| 653 | return column < COLS - 1 ? 0 : column - 7 - (column - 8) % (COLS - 9); |
| 654 | } |
| 655 | |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 656 | /* Resets current_y, based on the position of current, and puts the |
| 657 | * cursor at (current_y, current_x). */ |
| 658 | void reset_cursor(void) |
| 659 | { |
| 660 | const filestruct *ptr = edittop; |
| 661 | size_t x; |
| 662 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 663 | /* Yuck. This condition can be true after open_file() when opening |
| 664 | * the first file. */ |
David Lawrence Ramsey | 0341b58 | 2002-08-21 16:10:37 +0000 | [diff] [blame] | 665 | if (edittop == NULL) |
| 666 | return; |
| 667 | |
| 668 | current_y = 0; |
| 669 | |
| 670 | while (ptr != current && ptr != editbot && ptr->next != NULL) { |
| 671 | ptr = ptr->next; |
| 672 | current_y++; |
| 673 | } |
| 674 | |
| 675 | x = xplustabs(); |
| 676 | wmove(edit, current_y, x - get_page_start(x)); |
| 677 | } |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 678 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 679 | /* edit_add() takes care of the job of actually painting a line into |
| 680 | * the edit window. Called only from update_line(). Expects a |
| 681 | * converted-to-not-have-tabs line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 682 | void edit_add(const filestruct *fileptr, int yval, int start |
| 683 | #ifndef NANO_SMALL |
| 684 | , int virt_mark_beginx, int virt_cur_x |
| 685 | #endif |
| 686 | ) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 687 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 688 | #ifdef DEBUG |
| 689 | fprintf(stderr, "Painting line %d, current is %d\n", fileptr->lineno, |
| 690 | current->lineno); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 691 | #endif |
| 692 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 693 | /* Just paint the string in any case (we'll add color or reverse on |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 694 | just the text that needs it */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 695 | mvwaddnstr(edit, yval, 0, &fileptr->data[start], COLS); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 696 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 697 | #ifdef ENABLE_COLOR |
Chris Allegretta | 1dd0bc9 | 2002-10-13 18:43:45 +0000 | [diff] [blame] | 698 | if (colorstrings != NULL && ISSET(COLOR_SYNTAX)) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 699 | const colortype *tmpcolor = colorstrings; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 700 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 701 | for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { |
| 702 | int x_start; |
| 703 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 704 | int paintlen; |
| 705 | /* number of chars to paint on this line. There are COLS |
| 706 | * characters on a whole line. */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 707 | regmatch_t startmatch; /* match position for start_regexp*/ |
| 708 | regmatch_t endmatch; /* match position for end_regexp*/ |
| 709 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 710 | if (tmpcolor->bright) |
| 711 | wattron(edit, A_BOLD); |
| 712 | wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); |
| 713 | /* Two notes about regexec. Return value 0 means there is a |
| 714 | * match. Also, rm_eo is the first non-matching character |
| 715 | * after the match. */ |
| 716 | |
| 717 | /* First case, tmpcolor is a single-line expression. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 718 | if (tmpcolor->end == NULL) { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 719 | size_t k = 0; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 720 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 721 | /* We increment k by rm_eo, to move past the end of the |
| 722 | last match. Even though two matches may overlap, we |
| 723 | want to ignore them, so that we can highlight C-strings |
| 724 | correctly. */ |
| 725 | while (k < start + COLS) { |
| 726 | /* Note the fifth parameter to regexec. It says not to |
| 727 | * match the beginning-of-line character unless |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 728 | * k == 0. If regexec returns nonzero, there are no |
| 729 | * more matches in the line. */ |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 730 | if (regexec(&tmpcolor->start, &fileptr->data[k], 1, |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 731 | &startmatch, k == 0 ? 0 : REG_NOTBOL)) |
| 732 | break; |
| 733 | /* Translate the match to the beginning of the line. */ |
| 734 | startmatch.rm_so += k; |
| 735 | startmatch.rm_eo += k; |
David Lawrence Ramsey | 2ab03f6 | 2002-10-17 02:19:31 +0000 | [diff] [blame] | 736 | if (startmatch.rm_so == startmatch.rm_eo) { |
| 737 | startmatch.rm_eo++; |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 738 | statusbar(_("Refusing 0 length regex match")); |
David Lawrence Ramsey | 2ab03f6 | 2002-10-17 02:19:31 +0000 | [diff] [blame] | 739 | } else if (startmatch.rm_so < start + COLS && |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 740 | startmatch.rm_eo > start) { |
| 741 | x_start = startmatch.rm_so - start; |
| 742 | if (x_start < 0) |
| 743 | x_start = 0; |
| 744 | paintlen = startmatch.rm_eo - start - x_start; |
| 745 | if (paintlen > COLS - x_start) |
| 746 | paintlen = COLS - x_start; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 747 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 748 | assert(0 <= x_start && 0 < paintlen && |
| 749 | x_start + paintlen <= COLS); |
| 750 | mvwaddnstr(edit, yval, x_start, |
| 751 | fileptr->data + start + x_start, paintlen); |
| 752 | } |
| 753 | k = startmatch.rm_eo; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 754 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 755 | } else { |
| 756 | /* This is a multi-line regexp. There are two steps. |
| 757 | * First, we have to see if the beginning of the line is |
| 758 | * colored by a start on an earlier line, and an end on |
| 759 | * this line or later. |
| 760 | * |
| 761 | * We find the first line before fileptr matching the |
| 762 | * start. If every match on that line is followed by an |
| 763 | * end, then go to step two. Otherwise, find the next line |
| 764 | * after start_line matching the end. If that line is not |
| 765 | * before fileptr, then paint the beginning of this line. */ |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 766 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 767 | const filestruct *start_line = fileptr->prev; |
| 768 | /* the first line before fileptr matching start*/ |
| 769 | regoff_t start_col; |
| 770 | /* where it starts in that line */ |
| 771 | const filestruct *end_line; |
| 772 | int searched_later_lines = 0; |
| 773 | /* Used in step 2. Have we looked for an end on |
| 774 | * lines after fileptr? */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 775 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 776 | while (start_line != NULL && |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 777 | regexec(&tmpcolor->start, start_line->data, 1, |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 778 | &startmatch, 0)) { |
| 779 | /* If there is an end on this line, there is no need |
| 780 | * to look for starts on earlier lines. */ |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 781 | if (!regexec(tmpcolor->end, start_line->data, 1, |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 782 | &endmatch, 0)) |
| 783 | goto step_two; |
| 784 | start_line = start_line->prev; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 785 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 786 | /* No start found, so skip to the next step. */ |
| 787 | if (start_line == NULL) |
| 788 | goto step_two; |
| 789 | /* Now start_line is the first line before fileptr |
| 790 | * containing a start match. Is there a start on this |
| 791 | * line not followed by an end on this line? */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 792 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 793 | start_col = 0; |
| 794 | while (1) { |
| 795 | start_col += startmatch.rm_so; |
| 796 | startmatch.rm_eo -= startmatch.rm_so; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 797 | if (regexec(tmpcolor->end, |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 798 | start_line->data + start_col + startmatch.rm_eo, |
| 799 | 1, &endmatch, |
| 800 | start_col + startmatch.rm_eo == 0 ? 0 : REG_NOTBOL)) |
| 801 | /* No end found after this start */ |
| 802 | break; |
| 803 | start_col++; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 804 | if (regexec(&tmpcolor->start, |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 805 | start_line->data + start_col, 1, &startmatch, |
| 806 | REG_NOTBOL)) |
| 807 | /* No later start on this line. */ |
| 808 | goto step_two; |
| 809 | } |
| 810 | /* Indeed, there is a start not followed on this line by an |
| 811 | * end. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 812 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 813 | /* We have already checked that there is no end before |
| 814 | * fileptr and after the start. Is there an end after |
| 815 | * the start at all? We don't paint unterminated starts. */ |
| 816 | end_line = fileptr; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 817 | while (end_line != NULL && |
| 818 | regexec(tmpcolor->end, end_line->data, 1, &endmatch, 0)) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 819 | end_line = end_line->next; |
| 820 | |
| 821 | /* No end found, or it is too early. */ |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 822 | if (end_line == NULL || end_line->lineno < fileptr->lineno || |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 823 | (end_line == fileptr && endmatch.rm_eo <= start)) |
| 824 | goto step_two; |
| 825 | |
| 826 | /* Now paint the start of fileptr. */ |
| 827 | paintlen = end_line != fileptr |
| 828 | ? COLS : endmatch.rm_eo - start; |
| 829 | if (paintlen > COLS) |
| 830 | paintlen = COLS; |
| 831 | |
| 832 | assert(0 < paintlen && paintlen <= COLS); |
| 833 | mvwaddnstr(edit, yval, 0, fileptr->data + start, paintlen); |
| 834 | |
| 835 | /* We have already painted the whole line. */ |
| 836 | if (paintlen == COLS) |
| 837 | goto skip_step_two; |
| 838 | |
| 839 | |
| 840 | step_two: /* Second step, we look for starts on this line. */ |
| 841 | start_col = 0; |
| 842 | while (start_col < start + COLS) { |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 843 | if (regexec(&tmpcolor->start, fileptr->data + start_col, 1, |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 844 | &startmatch, start_col == 0 ? 0 : REG_NOTBOL) |
| 845 | || start_col + startmatch.rm_so >= start + COLS) |
| 846 | /* No more starts on this line. */ |
| 847 | break; |
| 848 | /* Translate the match to be relative to the |
| 849 | * beginning of the line. */ |
| 850 | startmatch.rm_so += start_col; |
| 851 | startmatch.rm_eo += start_col; |
| 852 | |
| 853 | x_start = startmatch.rm_so - start; |
| 854 | if (x_start < 0) { |
| 855 | x_start = 0; |
| 856 | startmatch.rm_so = start; |
| 857 | } |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 858 | if (!regexec(tmpcolor->end, fileptr->data + startmatch.rm_eo, |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 859 | 1, &endmatch, |
| 860 | startmatch.rm_eo == 0 ? 0 : REG_NOTBOL)) { |
| 861 | /* Translate the end match to be relative to the |
| 862 | beginning of the line. */ |
| 863 | endmatch.rm_so += startmatch.rm_eo; |
| 864 | endmatch.rm_eo += startmatch.rm_eo; |
| 865 | /* There is an end on this line. But does it |
| 866 | appear on this page, and is the match more than |
| 867 | zero characters long? */ |
| 868 | if (endmatch.rm_eo > start && |
| 869 | endmatch.rm_eo > startmatch.rm_so) { |
| 870 | paintlen = endmatch.rm_eo - start - x_start; |
| 871 | if (x_start + paintlen > COLS) |
| 872 | paintlen = COLS - x_start; |
| 873 | |
| 874 | assert(0 <= x_start && 0 < paintlen && |
| 875 | x_start + paintlen <= COLS); |
| 876 | mvwaddnstr(edit, yval, x_start, |
| 877 | fileptr->data + start + x_start, paintlen); |
| 878 | } |
| 879 | } else if (!searched_later_lines) { |
| 880 | searched_later_lines = 1; |
| 881 | /* There is no end on this line. But we haven't |
| 882 | * yet looked for one on later lines. */ |
| 883 | end_line = fileptr->next; |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 884 | while (end_line != NULL && regexec(tmpcolor->end, |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 885 | end_line->data, 1, &endmatch, 0)) |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 886 | end_line = end_line->next; |
| 887 | if (end_line != NULL) { |
| 888 | assert(0 <= x_start && x_start < COLS); |
| 889 | mvwaddnstr(edit, yval, x_start, |
| 890 | fileptr->data + start + x_start, |
| 891 | COLS - x_start); |
| 892 | /* We painted to the end of the line, so |
| 893 | * don't bother checking any more starts. */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 894 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 895 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 896 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 897 | start_col = startmatch.rm_so + 1; |
| 898 | } /* while start_col < start + COLS */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 899 | } /* if (tmp_color->end != NULL) */ |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 900 | |
Chris Allegretta | ce452fb | 2003-02-03 02:56:44 +0000 | [diff] [blame] | 901 | skip_step_two: |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 902 | wattroff(edit, A_BOLD); |
| 903 | wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); |
| 904 | } /* for tmpcolor in colorstrings */ |
| 905 | } |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 906 | #endif /* ENABLE_COLOR */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 907 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 908 | #ifndef NANO_SMALL |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 909 | if (ISSET(MARK_ISSET) |
| 910 | && (fileptr->lineno <= mark_beginbuf->lineno |
| 911 | || fileptr->lineno <= current->lineno) |
| 912 | && (fileptr->lineno >= mark_beginbuf->lineno |
| 913 | || fileptr->lineno >= current->lineno)) { |
| 914 | /* fileptr is at least partially selected. */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 915 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 916 | int x_start; |
| 917 | /* Starting column for mvwaddnstr. Zero-based. */ |
| 918 | int paintlen; |
| 919 | /* number of chars to paint on this line. There are COLS |
| 920 | * characters on a whole line. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 921 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 922 | if (mark_beginbuf == fileptr && current == fileptr) { |
| 923 | x_start = virt_mark_beginx < virt_cur_x ? virt_mark_beginx |
| 924 | : virt_cur_x; |
| 925 | paintlen = abs(virt_mark_beginx - virt_cur_x); |
| 926 | } else { |
| 927 | if (mark_beginbuf->lineno < fileptr->lineno || |
| 928 | current->lineno < fileptr->lineno) |
| 929 | x_start = 0; |
| 930 | else |
| 931 | x_start = mark_beginbuf == fileptr ? virt_mark_beginx |
| 932 | : virt_cur_x; |
| 933 | |
| 934 | if (mark_beginbuf->lineno > fileptr->lineno || |
| 935 | current->lineno > fileptr->lineno) |
| 936 | paintlen = start + COLS; |
| 937 | else |
| 938 | paintlen = mark_beginbuf == fileptr ? virt_mark_beginx |
| 939 | : virt_cur_x; |
| 940 | } |
| 941 | x_start -= start; |
| 942 | if (x_start < 0) { |
| 943 | paintlen += x_start; |
| 944 | x_start = 0; |
| 945 | } |
| 946 | if (x_start + paintlen > COLS) |
| 947 | paintlen = COLS - x_start; |
| 948 | if (paintlen > 0) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 949 | wattron(edit, A_REVERSE); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 950 | assert(x_start >= 0 && paintlen > 0 && x_start + paintlen <= COLS); |
| 951 | mvwaddnstr(edit, yval, x_start, |
| 952 | fileptr->data + start + x_start, paintlen); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 953 | wattroff(edit, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 954 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 955 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 956 | #endif /* !NANO_SMALL */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 957 | } |
| 958 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 959 | /* Just update one line in the edit buffer. Basically a wrapper for |
| 960 | * edit_add(). If fileptr != current, then index is considered 0. |
| 961 | * The line will be displayed starting with fileptr->data[index]. |
| 962 | * Likely args are current_x or 0. */ |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 963 | void update_line(filestruct *fileptr, int index) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 964 | { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 965 | int line; |
| 966 | /* line in the edit window for CURSES calls */ |
| 967 | #ifndef NANO_SMALL |
| 968 | int virt_cur_x; |
| 969 | int virt_mark_beginx; |
| 970 | #endif |
| 971 | char *original; |
| 972 | /* The original string fileptr->data. */ |
| 973 | char *converted; |
| 974 | /* fileptr->data converted to have tabs and control characters |
| 975 | * expanded. */ |
| 976 | size_t pos; |
| 977 | size_t page_start; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 978 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 979 | if (fileptr == NULL) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 980 | return; |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 981 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 982 | line = fileptr->lineno - edittop->lineno; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 983 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 984 | /* We assume the line numbers are valid. Is that really true? */ |
| 985 | assert(line < 0 || line == check_linenumbers(fileptr)); |
| 986 | |
| 987 | if (line < 0 || line >= editwinrows) |
| 988 | return; |
| 989 | |
| 990 | /* First, blank out the line (at a minimum) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 991 | mvwaddstr(edit, line, 0, hblank); |
| 992 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 993 | original = fileptr->data; |
| 994 | converted = charalloc(strlenpt(original) + 1); |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 995 | |
| 996 | /* Next, convert all the tabs to spaces, so everything else is easy. |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 997 | * Note the internal speller sends us index == -1. */ |
| 998 | index = fileptr == current && index > 0 ? strnlenpt(original, index) : 0; |
| 999 | #ifndef NANO_SMALL |
| 1000 | virt_cur_x = fileptr == current ? strnlenpt(original, current_x) : current_x; |
| 1001 | virt_mark_beginx = fileptr == mark_beginbuf ? strnlenpt(original, mark_beginx) : mark_beginx; |
| 1002 | #endif |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1003 | |
| 1004 | pos = 0; |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1005 | for (; *original != '\0'; original++) { |
| 1006 | if (*original == '\t') |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1007 | do { |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1008 | converted[pos++] = ' '; |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 1009 | } while (pos % tabsize); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1010 | else if (is_cntrl_char(*original)) { |
| 1011 | converted[pos++] = '^'; |
| 1012 | if (*original == 127) |
| 1013 | converted[pos++] = '?'; |
| 1014 | else if (*original == '\n') |
| 1015 | /* Treat newlines (ASCII 10's) embedded in a line as encoded |
| 1016 | * nulls (ASCII 0's); the line in question should be run |
| 1017 | * through unsunder() before reaching here */ |
| 1018 | converted[pos++] = '@'; |
| 1019 | else |
| 1020 | converted[pos++] = *original + 64; |
| 1021 | } else |
| 1022 | converted[pos++] = *original; |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1023 | } |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1024 | converted[pos] = '\0'; |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1025 | |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 1026 | /* Now, paint the line */ |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1027 | original = fileptr->data; |
| 1028 | fileptr->data = converted; |
| 1029 | page_start = get_page_start(index); |
| 1030 | edit_add(fileptr, line, page_start |
| 1031 | #ifndef NANO_SMALL |
| 1032 | , virt_mark_beginx, virt_cur_x |
| 1033 | #endif |
| 1034 | ); |
| 1035 | free(converted); |
| 1036 | fileptr->data = original; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1037 | |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1038 | if (page_start > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1039 | mvwaddch(edit, line, 0, '$'); |
David Lawrence Ramsey | 1f28b8f | 2002-09-27 14:21:59 +0000 | [diff] [blame] | 1040 | if (pos > page_start + COLS) |
| 1041 | mvwaddch(edit, line, COLS - 1, '$'); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1044 | /* This function updates current, based on where current_y is; |
| 1045 | * reset_cursor() does the opposite. */ |
| 1046 | void update_cursor(void) |
| 1047 | { |
| 1048 | int i = 0; |
| 1049 | |
| 1050 | #ifdef DEBUG |
| 1051 | fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y, |
| 1052 | current_x); |
| 1053 | #endif |
| 1054 | |
| 1055 | current = edittop; |
| 1056 | while (i < current_y && current->next != NULL) { |
| 1057 | current = current->next; |
| 1058 | i++; |
| 1059 | } |
| 1060 | |
| 1061 | #ifdef DEBUG |
Chris Allegretta | 0e86e60 | 2003-01-23 04:27:23 +0000 | [diff] [blame] | 1062 | fprintf(stderr, "current->data = \"%s\"\n", current->data); |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1063 | #endif |
| 1064 | } |
| 1065 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1066 | void center_cursor(void) |
| 1067 | { |
| 1068 | current_y = editwinrows / 2; |
| 1069 | wmove(edit, current_y, current_x); |
| 1070 | } |
| 1071 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1072 | /* Refresh the screen without changing the position of lines. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1073 | void edit_refresh(void) |
| 1074 | { |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1075 | /* Neither of these conditions should occur, but they do. edittop is |
| 1076 | * NULL when you open an existing file on the command line, and |
| 1077 | * ENABLE_COLOR is defined. Yuck. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1078 | if (current == NULL) |
| 1079 | return; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1080 | if (edittop == NULL) |
| 1081 | edittop = current; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1082 | |
Chris Allegretta | 63d0b48 | 2003-01-26 19:47:10 +0000 | [diff] [blame] | 1083 | if (current->lineno < edittop->lineno || |
| 1084 | current->lineno >= edittop->lineno + editwinrows) |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1085 | /* Note that edit_update() changes edittop so that |
| 1086 | * current->lineno = edittop->lineno + editwinrows / 2. Thus |
| 1087 | * when it then calls edit_refresh(), there is no danger of |
| 1088 | * getting an infinite loop. */ |
Chris Allegretta | da721be | 2000-07-31 01:26:42 +0000 | [diff] [blame] | 1089 | edit_update(current, CENTER); |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1090 | else { |
| 1091 | int nlines = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1092 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1093 | /* Don't make the cursor jump around the screen whilst updating */ |
| 1094 | leaveok(edit, TRUE); |
| 1095 | |
| 1096 | editbot = edittop; |
| 1097 | while (nlines < editwinrows) { |
| 1098 | update_line(editbot, current_x); |
| 1099 | nlines++; |
| 1100 | if (editbot->next == NULL) |
| 1101 | break; |
| 1102 | editbot = editbot->next; |
| 1103 | } |
| 1104 | while (nlines < editwinrows) { |
| 1105 | mvwaddstr(edit, nlines, 0, hblank); |
| 1106 | nlines++; |
| 1107 | } |
| 1108 | /* What the hell are we expecting to update the screen if this |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1109 | isn't here? Luck? */ |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1110 | wrefresh(edit); |
| 1111 | leaveok(edit, FALSE); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1112 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Chris Allegretta | 7662c86 | 2003-01-13 01:35:15 +0000 | [diff] [blame] | 1115 | /* Same as above, but touch the window first, so everything is |
| 1116 | * redrawn. */ |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 1117 | void edit_refresh_clearok(void) |
| 1118 | { |
| 1119 | clearok(edit, TRUE); |
| 1120 | edit_refresh(); |
| 1121 | clearok(edit, FALSE); |
| 1122 | } |
| 1123 | |
| 1124 | /* |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1125 | * Nice generic routine to update the edit buffer, given a pointer to the |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1126 | * file struct =) |
| 1127 | */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1128 | void edit_update(filestruct *fileptr, topmidbotnone location) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1129 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1130 | if (fileptr == NULL) |
| 1131 | return; |
| 1132 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1133 | if (location != TOP) { |
| 1134 | int goal = location == NONE ? current_y - 1 : editwinrows / 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1135 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1136 | for (; goal >= 0 && fileptr->prev != NULL; goal--) |
| 1137 | fileptr = fileptr->prev; |
| 1138 | } |
| 1139 | edittop = fileptr; |
Robert Siemborski | 29e9a76 | 2000-07-05 03:16:04 +0000 | [diff] [blame] | 1140 | fix_editbot(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1141 | |
| 1142 | edit_refresh(); |
| 1143 | } |
| 1144 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1145 | /* |
| 1146 | * Ask a question on the statusbar. Answer will be stored in answer |
| 1147 | * 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] | 1148 | * otherwise, the valid shortcut key caught. Def is any editable text we |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1149 | * want to put up by default. |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 1150 | * |
| 1151 | * New arg tabs tells whether or not to allow tab completion. |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1152 | */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1153 | int statusq(int tabs, const shortcut *s, const char *def, |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1154 | #ifndef NANO_SMALL |
| 1155 | historyheadtype *which_history, |
| 1156 | #endif |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1157 | const char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1158 | { |
| 1159 | va_list ap; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1160 | char *foo = charalloc(COLS - 3); |
Chris Allegretta | 9caa193 | 2002-02-15 20:08:05 +0000 | [diff] [blame] | 1161 | int ret; |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1162 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | a16e4e9 | 2002-01-05 18:59:54 +0000 | [diff] [blame] | 1163 | int list = 0; |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1164 | #endif |
Chris Allegretta | 47fcfe5 | 2003-01-26 21:01:16 +0000 | [diff] [blame] | 1165 | static int resetpos = 0; /* Do we need to scrap the cursor position |
| 1166 | on the statusbar? */ |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1167 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1168 | bottombars(s); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1169 | |
| 1170 | va_start(ap, msg); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1171 | vsnprintf(foo, COLS - 4, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1172 | va_end(ap); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1173 | foo[COLS - 4] = '\0'; |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1174 | |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1175 | ret = nanogetstr(tabs, foo, def, |
| 1176 | #ifndef NANO_SMALL |
| 1177 | which_history, |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1178 | #endif |
Chris Allegretta | 5beed50 | 2003-01-05 20:41:21 +0000 | [diff] [blame] | 1179 | s |
| 1180 | #ifndef DISABLE_TABCOMP |
| 1181 | , &list |
| 1182 | #endif |
Chris Allegretta | 47fcfe5 | 2003-01-26 21:01:16 +0000 | [diff] [blame] | 1183 | , resetpos); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1184 | free(foo); |
Chris Allegretta | 47fcfe5 | 2003-01-26 21:01:16 +0000 | [diff] [blame] | 1185 | resetpos = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1186 | |
| 1187 | switch (ret) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1188 | case NANO_FIRSTLINE_KEY: |
| 1189 | do_first_line(); |
Chris Allegretta | 47fcfe5 | 2003-01-26 21:01:16 +0000 | [diff] [blame] | 1190 | resetpos = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1191 | break; |
| 1192 | case NANO_LASTLINE_KEY: |
| 1193 | do_last_line(); |
Chris Allegretta | 47fcfe5 | 2003-01-26 21:01:16 +0000 | [diff] [blame] | 1194 | resetpos = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1195 | break; |
| 1196 | case NANO_CANCEL_KEY: |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1197 | ret = -1; |
Chris Allegretta | 47fcfe5 | 2003-01-26 21:01:16 +0000 | [diff] [blame] | 1198 | resetpos = 1; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1199 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1200 | } |
Chris Allegretta | a90d0cf | 2003-02-10 02:55:03 +0000 | [diff] [blame^] | 1201 | blank_statusbar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1202 | |
| 1203 | #ifdef DEBUG |
| 1204 | fprintf(stderr, _("I got \"%s\"\n"), answer); |
| 1205 | #endif |
| 1206 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1207 | #ifndef DISABLE_TABCOMP |
| 1208 | /* if we've done tab completion, there might be a list of |
| 1209 | filename matches on the edit window at this point; make sure |
| 1210 | they're cleared off */ |
| 1211 | if (list) |
| 1212 | edit_refresh(); |
| 1213 | #endif |
| 1214 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1215 | return ret; |
| 1216 | } |
| 1217 | |
| 1218 | /* |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1219 | * 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] | 1220 | * for N, 2 for All (if all is nonzero when passed in) and -1 for abort |
| 1221 | * (^C). |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1222 | */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1223 | int do_yesno(int all, int leavecursor, const char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1224 | { |
| 1225 | va_list ap; |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1226 | char *foo; |
| 1227 | int ok = -2; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1228 | const char *yesstr; /* String of yes characters accepted */ |
| 1229 | const char *nostr; /* Same for no */ |
| 1230 | const char *allstr; /* And all, surprise! */ |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1231 | |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1232 | /* Yes, no and all are strings of any length. Each string consists of |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1233 | all characters accepted as a valid character for that value. |
| 1234 | The first value will be the one displayed in the shortcuts. */ |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1235 | yesstr = _("Yy"); |
| 1236 | nostr = _("Nn"); |
| 1237 | allstr = _("Aa"); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1238 | |
Jordi Mallach | 0b0fc49 | 2000-06-23 01:00:13 +0000 | [diff] [blame] | 1239 | /* Remove gettext call for keybindings until we clear the thing up */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1240 | if (!ISSET(NO_HELP)) { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1241 | char shortstr[3]; /* Temp string for Y, N, A */ |
| 1242 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1243 | /* Write the bottom of the screen */ |
| 1244 | blank_bottombars(); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1245 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1246 | sprintf(shortstr, " %c", yesstr[0]); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1247 | wmove(bottomwin, 1, 0); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1248 | onekey(shortstr, _("Yes"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1249 | |
| 1250 | if (all) { |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1251 | wmove(bottomwin, 1, 16); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1252 | shortstr[1] = allstr[0]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1253 | onekey(shortstr, _("All"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1254 | } |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1255 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1256 | wmove(bottomwin, 2, 0); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1257 | shortstr[1] = nostr[0]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1258 | onekey(shortstr, _("No"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1259 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1260 | wmove(bottomwin, 2, 16); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1261 | onekey("^C", _("Cancel"), 16); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1262 | } |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1263 | |
| 1264 | foo = charalloc(COLS); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1265 | va_start(ap, msg); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1266 | vsnprintf(foo, COLS, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1267 | va_end(ap); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1268 | foo[COLS - 1] = '\0'; |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1269 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1270 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1271 | |
| 1272 | blank_statusbar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1273 | mvwaddstr(bottomwin, 0, 0, foo); |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1274 | free(foo); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1275 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1276 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1277 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1278 | wrefresh(bottomwin); |
| 1279 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1280 | do { |
| 1281 | int kbinput = wgetch(edit); |
| 1282 | #ifndef DISABLE_MOUSE |
| 1283 | MEVENT mevent; |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1284 | #endif |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1285 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1286 | if (kbinput == NANO_CONTROL_C) |
| 1287 | ok = -1; |
| 1288 | #ifndef DISABLE_MOUSE |
| 1289 | /* Look ma! We get to duplicate lots of code from do_mouse!! */ |
| 1290 | else if (kbinput == KEY_MOUSE && getmouse(&mevent) != ERR && |
| 1291 | wenclose(bottomwin, mevent.y, mevent.x) && |
| 1292 | !ISSET(NO_HELP) && mevent.x < 32 && |
| 1293 | mevent.y >= editwinrows + 3) { |
| 1294 | int x = mevent.x /= 16; |
| 1295 | /* Did we click in the first column of shortcuts, or the |
| 1296 | second? */ |
| 1297 | int y = mevent.y - editwinrows - 3; |
| 1298 | /* Did we click in the first row of shortcuts? */ |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1299 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1300 | assert(0 <= x && x <= 1 && 0 <= y && y <= 1); |
| 1301 | /* x = 0 means they clicked Yes or No. |
| 1302 | y = 0 means Yes or All. */ |
| 1303 | ok = -2 * x * y + x - y + 1; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1304 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1305 | if (ok == 2 && !all) |
| 1306 | ok = -2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1307 | } |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1308 | #endif |
| 1309 | /* Look for the kbinput in the yes, no and (optionally) all str */ |
| 1310 | else if (strchr(yesstr, kbinput) != NULL) |
| 1311 | ok = 1; |
| 1312 | else if (strchr(nostr, kbinput) != NULL) |
| 1313 | ok = 0; |
| 1314 | else if (all && strchr(allstr, kbinput) != NULL) |
| 1315 | ok = 2; |
| 1316 | } while (ok == -2); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1317 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1318 | /* Then blank the statusbar. */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1319 | blank_statusbar_refresh(); |
| 1320 | |
Chris Allegretta | db28e96 | 2003-01-28 01:23:40 +0000 | [diff] [blame] | 1321 | return ok; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1324 | int total_refresh(void) |
| 1325 | { |
| 1326 | clearok(edit, TRUE); |
| 1327 | clearok(topwin, TRUE); |
| 1328 | clearok(bottomwin, TRUE); |
| 1329 | wnoutrefresh(edit); |
| 1330 | wnoutrefresh(topwin); |
| 1331 | wnoutrefresh(bottomwin); |
| 1332 | doupdate(); |
| 1333 | clearok(edit, FALSE); |
| 1334 | clearok(topwin, FALSE); |
| 1335 | clearok(bottomwin, FALSE); |
| 1336 | edit_refresh(); |
| 1337 | titlebar(NULL); |
| 1338 | return 1; |
| 1339 | } |
| 1340 | |
| 1341 | void display_main_list(void) |
| 1342 | { |
| 1343 | bottombars(main_list); |
| 1344 | } |
| 1345 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1346 | void statusbar(const char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1347 | { |
| 1348 | va_list ap; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1349 | char *foo; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1350 | int start_x = 0; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1351 | size_t foo_len; |
| 1352 | |
Chris Allegretta | a0d8997 | 2003-02-03 03:32:08 +0000 | [diff] [blame] | 1353 | va_start(ap, msg); |
| 1354 | |
| 1355 | /* Curses mode is turned off. If we use wmove() now, it will muck up |
| 1356 | the terminal settings. So we just use vfprintf(). */ |
| 1357 | if (curses_ended) { |
| 1358 | vfprintf(stderr, msg, ap); |
| 1359 | va_end(ap); |
| 1360 | return; |
| 1361 | } |
| 1362 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1363 | assert(COLS >= 4); |
| 1364 | foo = charalloc(COLS - 3); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1365 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1366 | vsnprintf(foo, COLS - 3, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1367 | va_end(ap); |
| 1368 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1369 | foo[COLS - 4] = '\0'; |
| 1370 | foo_len = strlen(foo); |
| 1371 | start_x = (COLS - foo_len - 4) / 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1372 | |
| 1373 | /* Blank out line */ |
| 1374 | blank_statusbar(); |
| 1375 | |
| 1376 | wmove(bottomwin, 0, start_x); |
| 1377 | |
| 1378 | wattron(bottomwin, A_REVERSE); |
| 1379 | |
| 1380 | waddstr(bottomwin, "[ "); |
| 1381 | waddstr(bottomwin, foo); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1382 | free(foo); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1383 | waddstr(bottomwin, " ]"); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1384 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1385 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1386 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1387 | wrefresh(bottomwin); |
| 1388 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1389 | SET(DISABLE_CURPOS); |
| 1390 | statblank = 26; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1393 | /* |
| 1394 | * If constant is false, the user typed ^C so we unconditionally display |
| 1395 | * the cursor position. Otherwise, we display it only if the character |
| 1396 | * position changed, and DISABLE_CURPOS is not set. |
| 1397 | * |
| 1398 | * If constant and DISABLE_CURPOS is set, we unset it and update old_i and |
| 1399 | * old_totsize. That way, we leave the current statusbar alone, but next |
| 1400 | * time we will display. */ |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1401 | int do_cursorpos(int constant) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1402 | { |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1403 | const filestruct *fileptr; |
| 1404 | unsigned long i = 0; |
| 1405 | static unsigned long old_i = 0; |
| 1406 | static long old_totsize = -1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1407 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1408 | assert(current != NULL && fileage != NULL && totlines != 0); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1409 | |
| 1410 | if (old_totsize == -1) |
| 1411 | old_totsize = totsize; |
| 1412 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1413 | for (fileptr = fileage; fileptr != current; fileptr = fileptr->next) { |
| 1414 | assert(fileptr != NULL); |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1415 | i += strlen(fileptr->data) + 1; |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1416 | } |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1417 | i += current_x; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1418 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1419 | if (constant && ISSET(DISABLE_CURPOS)) { |
| 1420 | UNSET(DISABLE_CURPOS); |
| 1421 | old_i = i; |
| 1422 | old_totsize = totsize; |
| 1423 | return 0; |
| 1424 | } |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1425 | |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1426 | /* if constant is false, display the position on the statusbar |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1427 | unconditionally; otherwise, only display the position when the |
| 1428 | character values have changed */ |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1429 | if (!constant || old_i != i || old_totsize != totsize) { |
| 1430 | unsigned long xpt = xplustabs() + 1; |
| 1431 | unsigned long cur_len = strlenpt(current->data) + 1; |
| 1432 | int linepct = 100 * current->lineno / totlines; |
| 1433 | int colpct = 100 * xpt / cur_len; |
| 1434 | int bytepct = totsize == 0 ? 0 : 100 * i / totsize; |
| 1435 | |
| 1436 | statusbar( |
| 1437 | _("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%ld (%d%%)"), |
| 1438 | current->lineno, totlines, linepct, |
| 1439 | xpt, cur_len, colpct, |
| 1440 | i, totsize, bytepct); |
| 1441 | UNSET(DISABLE_CURPOS); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | old_i = i; |
| 1445 | old_totsize = totsize; |
| 1446 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1447 | reset_cursor(); |
Chris Allegretta | d26ab91 | 2003-01-28 01:16:47 +0000 | [diff] [blame] | 1448 | return 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1451 | int do_cursorpos_void(void) |
| 1452 | { |
| 1453 | return do_cursorpos(0); |
| 1454 | } |
| 1455 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1456 | /* Our shortcut-list-compliant help function, which is |
| 1457 | * better than nothing, and dynamic! */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1458 | int do_help(void) |
| 1459 | { |
Rocco Corsi | af5c302 | 2001-01-12 07:51:05 +0000 | [diff] [blame] | 1460 | #ifndef DISABLE_HELP |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1461 | int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1462 | int no_help_flag = 0; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1463 | const shortcut *oldshortcut; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1464 | |
| 1465 | blank_edit(); |
| 1466 | curs_set(0); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1467 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1468 | blank_statusbar(); |
| 1469 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1470 | /* set help_text as the string to display */ |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1471 | help_init(); |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1472 | assert(help_text != NULL); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1473 | |
| 1474 | oldshortcut = currshortcut; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1475 | |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1476 | currshortcut = help_list; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 1477 | |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1478 | kp = keypad_on(edit, 1); |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1479 | kp2 = keypad_on(bottomwin, 1); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1480 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1481 | if (ISSET(NO_HELP)) { |
| 1482 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1483 | /* Well, if we're going to do this, we should at least |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1484 | do it the right way */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1485 | no_help_flag = 1; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1486 | UNSET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1487 | window_init(); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1488 | bottombars(help_list); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1489 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1490 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1491 | bottombars(help_list); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1492 | |
| 1493 | do { |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1494 | const char *ptr = help_text; |
| 1495 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1496 | switch (kbinput) { |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1497 | #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION) |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1498 | case KEY_MOUSE: |
| 1499 | do_mouse(); |
| 1500 | break; |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1501 | #endif |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1502 | case 27: |
| 1503 | kbinput = wgetch(edit); |
| 1504 | switch(kbinput) { |
| 1505 | case '[': |
| 1506 | kbinput = wgetch(edit); |
| 1507 | switch(kbinput) { |
| 1508 | case '5': /* Alt-[-5 = Page Up */ |
| 1509 | wgetch(edit); |
| 1510 | goto do_pageupkey; |
| 1511 | break; |
| 1512 | case 'V': /* Alt-[-V = Page Up in Hurd Console */ |
| 1513 | case 'I': /* Alt-[-I = Page Up - FreeBSD Console */ |
| 1514 | goto do_pageupkey; |
| 1515 | break; |
| 1516 | case '6': /* Alt-[-6 = Page Down */ |
| 1517 | wgetch(edit); |
| 1518 | goto do_pagedownkey; |
| 1519 | break; |
| 1520 | case 'U': /* Alt-[-U = Page Down in Hurd Console */ |
| 1521 | case 'G': /* Alt-[-G = Page Down - FreeBSD Console */ |
| 1522 | goto do_pagedownkey; |
| 1523 | break; |
| 1524 | } |
| 1525 | break; |
| 1526 | } |
| 1527 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1528 | case NANO_NEXTPAGE_KEY: |
| 1529 | case NANO_NEXTPAGE_FKEY: |
| 1530 | case KEY_NPAGE: |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1531 | do_pagedownkey: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1532 | if (!no_more) { |
| 1533 | blank_edit(); |
| 1534 | page++; |
| 1535 | } |
| 1536 | break; |
| 1537 | case NANO_PREVPAGE_KEY: |
| 1538 | case NANO_PREVPAGE_FKEY: |
| 1539 | case KEY_PPAGE: |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1540 | do_pageupkey: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1541 | if (page > 1) { |
| 1542 | no_more = 0; |
| 1543 | blank_edit(); |
| 1544 | page--; |
| 1545 | } |
| 1546 | break; |
| 1547 | } |
| 1548 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1549 | /* Calculate where in the text we should be, based on the page */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1550 | for (i = 1; i < page; i++) { |
| 1551 | row = 0; |
| 1552 | j = 0; |
Chris Allegretta | 44e73df | 2000-09-07 03:37:38 +0000 | [diff] [blame] | 1553 | |
| 1554 | while (row < editwinrows - 2 && *ptr != '\0') { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1555 | if (*ptr == '\n' || j == COLS - 5) { |
| 1556 | j = 0; |
| 1557 | row++; |
| 1558 | } |
| 1559 | ptr++; |
| 1560 | j++; |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | i = 0; |
| 1565 | j = 0; |
| 1566 | while (i < editwinrows && *ptr != '\0') { |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1567 | const char *end = ptr; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1568 | while (*end != '\n' && *end != '\0' && j != COLS - 5) { |
| 1569 | end++; |
| 1570 | j++; |
| 1571 | } |
| 1572 | if (j == COLS - 5) { |
| 1573 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1574 | /* Don't print half a word if we've run out of space */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1575 | while (*end != ' ' && *end != '\0') { |
| 1576 | end--; |
| 1577 | j--; |
| 1578 | } |
| 1579 | } |
| 1580 | mvwaddnstr(edit, i, 0, ptr, j); |
| 1581 | j = 0; |
| 1582 | i++; |
| 1583 | if (*end == '\n') |
| 1584 | end++; |
| 1585 | ptr = end; |
| 1586 | } |
| 1587 | if (*ptr == '\0') { |
| 1588 | no_more = 1; |
| 1589 | continue; |
| 1590 | } |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1591 | } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY && |
| 1592 | kbinput != NANO_EXIT_FKEY); |
Chris Allegretta | d1627cf | 2000-12-18 05:03:16 +0000 | [diff] [blame] | 1593 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1594 | currshortcut = oldshortcut; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1595 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1596 | if (no_help_flag) { |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1597 | blank_bottombars(); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1598 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1599 | SET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1600 | window_init(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1601 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1602 | bottombars(currshortcut); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1603 | |
| 1604 | curs_set(1); |
| 1605 | edit_refresh(); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1606 | kp = keypad_on(edit, kp); |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1607 | kp2 = keypad_on(bottomwin, kp2); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1608 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame] | 1609 | /* The help_init() at the beginning allocated help_text, which has |
| 1610 | now been written to screen. */ |
| 1611 | free(help_text); |
| 1612 | help_text = NULL; |
| 1613 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1614 | #elif defined(DISABLE_HELP) |
| 1615 | nano_disabled_msg(); |
| 1616 | #endif |
| 1617 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1618 | return 1; |
| 1619 | } |
| 1620 | |
David Lawrence Ramsey | 9b13ff3 | 2002-12-22 16:30:00 +0000 | [diff] [blame] | 1621 | int keypad_on(WINDOW *win, int newval) |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1622 | { |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1623 | /* This is taken right from aumix. Don't sue me. */ |
| 1624 | #ifdef HAVE_USEKEYPAD |
| 1625 | int old = win->_use_keypad; |
| 1626 | keypad(win, newval); |
| 1627 | return old; |
| 1628 | #else |
| 1629 | keypad(win, newval); |
| 1630 | return 1; |
| 1631 | #endif /* HAVE_USEKEYPAD */ |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1632 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1633 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1634 | /* Highlight the current word being replaced or spell checked. */ |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1635 | void do_replace_highlight(int highlight_flag, const char *word) |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1636 | { |
| 1637 | char *highlight_word = NULL; |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1638 | int x, y, word_len; |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1639 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1640 | highlight_word = |
| 1641 | mallocstrcpy(highlight_word, ¤t->data[current_x]); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1642 | |
| 1643 | #ifdef HAVE_REGEX_H |
| 1644 | if (ISSET(USE_REGEXP)) |
| 1645 | /* if we're using regexps, the highlight is the length of the |
| 1646 | search result, not the length of the regexp string */ |
| 1647 | word_len = regmatches[0].rm_eo - regmatches[0].rm_so; |
| 1648 | else |
| 1649 | #endif |
| 1650 | word_len = strlen(word); |
| 1651 | |
| 1652 | highlight_word[word_len] = '\0'; |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1653 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1654 | /* adjust output when word extends beyond screen */ |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1655 | |
| 1656 | x = xplustabs(); |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1657 | y = get_page_start(x) + COLS; |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1658 | |
Chris Allegretta | 6df90f5 | 2002-07-19 01:08:59 +0000 | [diff] [blame] | 1659 | if ((COLS - (y - x) + word_len) > COLS) { |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1660 | highlight_word[y - x - 1] = '$'; |
| 1661 | highlight_word[y - x] = '\0'; |
| 1662 | } |
| 1663 | |
| 1664 | /* OK display the output */ |
| 1665 | |
| 1666 | reset_cursor(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1667 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1668 | if (highlight_flag) |
| 1669 | wattron(edit, A_REVERSE); |
| 1670 | |
| 1671 | waddstr(edit, highlight_word); |
| 1672 | |
| 1673 | if (highlight_flag) |
| 1674 | wattroff(edit, A_REVERSE); |
| 1675 | |
| 1676 | free(highlight_word); |
| 1677 | } |
| 1678 | |
David Lawrence Ramsey | ad40fdb | 2002-09-06 20:35:28 +0000 | [diff] [blame] | 1679 | /* Fix editbot, based on the assumption that edittop is correct. */ |
| 1680 | void fix_editbot(void) |
| 1681 | { |
| 1682 | int i; |
| 1683 | |
| 1684 | editbot = edittop; |
| 1685 | for (i = 0; i < editwinrows && editbot->next != NULL; i++) |
| 1686 | editbot = editbot->next; |
| 1687 | } |
| 1688 | |
| 1689 | #ifdef DEBUG |
| 1690 | /* Dump the current file structure to stderr */ |
| 1691 | void dump_buffer(const filestruct *inptr) { |
| 1692 | if (inptr == fileage) |
| 1693 | fprintf(stderr, _("Dumping file buffer to stderr...\n")); |
| 1694 | else if (inptr == cutbuffer) |
| 1695 | fprintf(stderr, _("Dumping cutbuffer to stderr...\n")); |
| 1696 | else |
| 1697 | fprintf(stderr, _("Dumping a buffer to stderr...\n")); |
| 1698 | |
| 1699 | while (inptr != NULL) { |
| 1700 | fprintf(stderr, "(%d) %s\n", inptr->lineno, inptr->data); |
| 1701 | inptr = inptr->next; |
| 1702 | } |
| 1703 | } |
| 1704 | #endif /* DEBUG */ |
| 1705 | |
| 1706 | #ifdef DEBUG |
| 1707 | void dump_buffer_reverse(void) { |
| 1708 | const filestruct *fileptr = filebot; |
| 1709 | |
| 1710 | while (fileptr != NULL) { |
| 1711 | fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data); |
| 1712 | fileptr = fileptr->prev; |
| 1713 | } |
| 1714 | } |
| 1715 | #endif /* DEBUG */ |
| 1716 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1717 | #ifdef NANO_EXTRA |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 1718 | #define CREDIT_LEN 53 |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1719 | #define XLCREDIT_LEN 8 |
| 1720 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1721 | void do_credits(void) |
| 1722 | { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1723 | int i, j = 0, k, place = 0, start_x; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1724 | |
David Lawrence Ramsey | e21adfa | 2002-09-13 18:14:04 +0000 | [diff] [blame] | 1725 | const char *what; |
| 1726 | const char *xlcredits[XLCREDIT_LEN]; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1727 | |
David Lawrence Ramsey | e21adfa | 2002-09-13 18:14:04 +0000 | [diff] [blame] | 1728 | const char *credits[CREDIT_LEN] = { |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1729 | "0", /* "The nano text editor" */ |
| 1730 | "1", /* "version" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1731 | VERSION, |
| 1732 | "", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1733 | "2", /* "Brought to you by:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1734 | "Chris Allegretta", |
| 1735 | "Jordi Mallach", |
| 1736 | "Adam Rogoyski", |
| 1737 | "Rob Siemborski", |
| 1738 | "Rocco Corsi", |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1739 | "David Lawrence Ramsey", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 1740 | "David Benbennick", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1741 | "Ken Tyler", |
| 1742 | "Sven Guckes", |
| 1743 | "Florian König", |
| 1744 | "Pauli Virtanen", |
| 1745 | "Daniele Medri", |
| 1746 | "Clement Laforet", |
| 1747 | "Tedi Heriyanto", |
| 1748 | "Bill Soudan", |
| 1749 | "Christian Weisgerber", |
| 1750 | "Erik Andersen", |
| 1751 | "Big Gaute", |
| 1752 | "Joshua Jensen", |
| 1753 | "Ryan Krebs", |
| 1754 | "Albert Chin", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1755 | "", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1756 | "3", /* "Special thanks to:" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1757 | "Plattsburgh State University", |
| 1758 | "Benet Laboratories", |
| 1759 | "Amy Allegretta", |
| 1760 | "Linda Young", |
| 1761 | "Jeremy Robichaud", |
| 1762 | "Richard Kolb II", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1763 | "4", /* "The Free Software Foundation" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1764 | "Linus Torvalds", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1765 | "5", /* "For ncurses:" */ |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 1766 | "Thomas Dickey", |
| 1767 | "Pavel Curtis", |
| 1768 | "Zeyd Ben-Halim", |
| 1769 | "Eric S. Raymond", |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1770 | "6", /* "and anyone else we forgot..." */ |
| 1771 | "7", /* "Thank you for using nano!\n" */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1772 | "", "", "", "", |
| 1773 | "(c) 1999-2002 Chris Allegretta", |
| 1774 | "", "", "", "", |
David Lawrence Ramsey | 0084eaa | 2002-11-04 16:05:42 +0000 | [diff] [blame] | 1775 | "http://www.nano-editor.org/" |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1776 | }; |
| 1777 | |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1778 | xlcredits[0] = _("The nano text editor"); |
| 1779 | xlcredits[1] = _("version "); |
| 1780 | xlcredits[2] = _("Brought to you by:"); |
| 1781 | xlcredits[3] = _("Special thanks to:"); |
| 1782 | xlcredits[4] = _("The Free Software Foundation"); |
| 1783 | xlcredits[5] = _("For ncurses:"); |
| 1784 | xlcredits[6] = _("and anyone else we forgot..."); |
| 1785 | xlcredits[7] = _("Thank you for using nano!\n"); |
| 1786 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1787 | curs_set(0); |
| 1788 | nodelay(edit, TRUE); |
| 1789 | blank_bottombars(); |
| 1790 | mvwaddstr(topwin, 0, 0, hblank); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1791 | blank_edit(); |
| 1792 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1793 | wrefresh(bottomwin); |
| 1794 | wrefresh(topwin); |
| 1795 | |
| 1796 | while (wgetch(edit) == ERR) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1797 | for (k = 0; k <= 1; k++) { |
| 1798 | blank_edit(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1799 | for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); |
| 1800 | i--) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1801 | mvwaddstr(edit, i * 2 - k, 0, hblank); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1802 | |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1803 | if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1804 | what = credits[place - (editwinrows / 2 - 1 - i)]; |
Chris Allegretta | c4e3d9e | 2002-07-21 15:44:13 +0000 | [diff] [blame] | 1805 | |
| 1806 | /* God I've missed hacking. If what is exactly |
| 1807 | 1 char long, it's a sentinel for a translated |
| 1808 | string, so use that instead. This means no |
| 1809 | thanking people with 1 character long names ;-) */ |
| 1810 | if (strlen(what) == 1) |
| 1811 | what = xlcredits[atoi(what)]; |
| 1812 | } else |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1813 | what = ""; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1814 | |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 1815 | start_x = COLS / 2 - strlen(what) / 2 - 1; |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1816 | mvwaddstr(edit, i * 2 - k, start_x, what); |
| 1817 | } |
| 1818 | usleep(700000); |
| 1819 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1820 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1821 | if (j < editwinrows / 2 - 1) |
| 1822 | j++; |
| 1823 | |
| 1824 | place++; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1825 | |
| 1826 | if (place >= CREDIT_LEN + editwinrows / 2) |
| 1827 | break; |
| 1828 | } |
| 1829 | |
| 1830 | nodelay(edit, FALSE); |
| 1831 | curs_set(1); |
| 1832 | display_main_list(); |
| 1833 | total_refresh(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1834 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1835 | #endif |