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