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 | |
| 22 | #include <stdarg.h> |
| 23 | #include <string.h> |
Chris Allegretta | dba37ae | 2000-07-07 05:13:09 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 25 | #include <unistd.h> |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 26 | #include <ctype.h> |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 27 | #include <assert.h> |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 28 | #include "config.h" |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 29 | #include "proto.h" |
| 30 | #include "nano.h" |
| 31 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 32 | #ifdef ENABLE_NLS |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 33 | #include <libintl.h> |
| 34 | #define _(string) gettext(string) |
| 35 | #else |
| 36 | #define _(string) (string) |
| 37 | #endif |
| 38 | |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 39 | |
| 40 | /* winio.c statics */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 41 | static int statblank = 0; /* Number of keystrokes left after |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 42 | we call statusbar(), before we |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 43 | actually blank the statusbar */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 44 | |
| 45 | /* Local Function Prototypes for only winio.c */ |
| 46 | inline int get_page_from_virtual(int virtual); |
| 47 | inline int get_page_start_virtual(int page); |
| 48 | inline int get_page_end_virtual(int page); |
| 49 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 50 | /* Window I/O */ |
| 51 | |
| 52 | int do_first_line(void) |
| 53 | { |
| 54 | current = fileage; |
| 55 | placewewant = 0; |
| 56 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 57 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 58 | return 1; |
| 59 | } |
| 60 | |
| 61 | int do_last_line(void) |
| 62 | { |
| 63 | current = filebot; |
| 64 | placewewant = 0; |
| 65 | current_x = 0; |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 66 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 67 | return 1; |
| 68 | } |
| 69 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 70 | /* Like xplustabs, but for a specific index of a specific filestruct */ |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 71 | int xpt(const filestruct *fileptr, int index) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 72 | { |
| 73 | int i, tabs = 0; |
| 74 | |
| 75 | if (fileptr == NULL || fileptr->data == NULL) |
| 76 | return 0; |
| 77 | |
| 78 | for (i = 0; i < index && fileptr->data[i] != 0; i++) { |
| 79 | tabs++; |
| 80 | |
| 81 | if (fileptr->data[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 82 | if (tabs % tabsize == 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 83 | else |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 84 | tabs += tabsize - (tabs % tabsize); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 85 | } else if (fileptr->data[i] & 0x80) |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 86 | /* Make 8 bit chars only 1 column! */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 87 | ; |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 88 | else if (iscntrl((int) fileptr->data[i])) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 89 | tabs++; |
| 90 | } |
| 91 | |
| 92 | return tabs; |
| 93 | } |
| 94 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 95 | /* Return the actual place on the screen of current->data[current_x], which |
| 96 | should always be > current_x */ |
| 97 | int xplustabs(void) |
| 98 | { |
| 99 | return xpt(current, current_x); |
| 100 | } |
| 101 | |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 102 | /* Return what current_x should be, given xplustabs() for the line, |
| 103 | * given a start position in the filestruct's data */ |
| 104 | int actual_x_from_start(filestruct * fileptr, int xplus, int start) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 105 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 106 | int i, tot = 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 107 | |
| 108 | if (fileptr == NULL || fileptr->data == NULL) |
| 109 | return 0; |
| 110 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 111 | for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 112 | if (fileptr->data[i] == NANO_CONTROL_I) { |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 113 | if (tot % tabsize != 0) |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 114 | tot += tabsize - (tot % tabsize); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 115 | } else if (fileptr->data[i] & 0x80) |
| 116 | tot++; /* Make 8 bit chars only 1 column (again) */ |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 117 | else if (iscntrl((int) fileptr->data[i])) { |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 118 | i++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 119 | tot += 2; |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 120 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 121 | |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 122 | if (i > strlen(fileptr->data)) |
| 123 | i = strlen(fileptr->data); |
| 124 | |
| 125 | /* see if we're in the x-plus-tabs column of xplus; if not, look |
| 126 | for the closest column to it */ |
| 127 | if (xpt(fileptr, i) < xplus) { |
| 128 | while (xpt(fileptr, i) < xplus && i < strlen(fileptr->data)) |
| 129 | i++; |
| 130 | } |
| 131 | else if (xpt(fileptr, i) > xplus) { |
| 132 | while (xpt(fileptr, i) > xplus && i > start) |
| 133 | i--; |
| 134 | } |
| 135 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 136 | #ifdef DEBUG |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 137 | fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"), |
| 138 | xplus, i); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 139 | #endif |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 140 | |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 141 | return i - start; |
| 142 | } |
| 143 | |
| 144 | /* Opposite of xplustabs */ |
Chris Allegretta | 6efda54 | 2001-04-28 18:03:52 +0000 | [diff] [blame] | 145 | int actual_x(filestruct * fileptr, int xplus) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 146 | { |
| 147 | return actual_x_from_start(fileptr, xplus, 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* a strlen with tabs factored in, similar to xplustabs() */ |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 151 | int strnlenpt(char *buf, int size) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 152 | { |
| 153 | int i, tabs = 0; |
| 154 | |
| 155 | if (buf == NULL) |
| 156 | return 0; |
| 157 | |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 158 | for (i = 0; i < size; i++) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 159 | tabs++; |
| 160 | |
| 161 | if (buf[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 162 | if (tabs % tabsize == 0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 163 | else |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 164 | tabs += tabsize - (tabs % tabsize); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 165 | } else if (buf[i] & 0x80) |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 166 | /* Make 8 bit chars only 1 column! */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 167 | ; |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 168 | else if (iscntrl((int) buf[i])) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 169 | tabs++; |
| 170 | } |
| 171 | |
| 172 | return tabs; |
| 173 | } |
| 174 | |
Chris Allegretta | d4fa0d3 | 2002-03-05 19:55:55 +0000 | [diff] [blame] | 175 | int strlenpt(char *buf) |
| 176 | { |
| 177 | return strnlenpt(buf, strlen(buf)); |
| 178 | } |
| 179 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 180 | /* resets current_y, based on the position of current, and puts the cursor at |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 181 | (current_y, current_x) */ |
| 182 | void reset_cursor(void) |
| 183 | { |
| 184 | filestruct *ptr = edittop; |
| 185 | int x; |
| 186 | |
| 187 | current_y = 0; |
| 188 | |
| 189 | while (ptr != current && ptr != editbot && ptr->next != NULL) { |
| 190 | ptr = ptr->next; |
| 191 | current_y++; |
| 192 | } |
| 193 | |
| 194 | x = xplustabs(); |
| 195 | if (x <= COLS - 2) |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 196 | wmove(edit, current_y, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 197 | else |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 198 | wmove(edit, current_y, x - |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 199 | get_page_start_virtual(get_page_from_virtual(x))); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 200 | |
| 201 | } |
| 202 | |
| 203 | void blank_bottombars(void) |
| 204 | { |
| 205 | int i = no_help()? 3 : 1; |
| 206 | |
| 207 | for (; i <= 2; i++) |
| 208 | mvwaddstr(bottomwin, i, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void blank_edit(void) |
| 212 | { |
| 213 | int i; |
| 214 | for (i = 0; i <= editwinrows - 1; i++) |
| 215 | mvwaddstr(edit, i, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | |
| 219 | void blank_statusbar(void) |
| 220 | { |
| 221 | mvwaddstr(bottomwin, 0, 0, hblank); |
| 222 | } |
| 223 | |
| 224 | void blank_statusbar_refresh(void) |
| 225 | { |
| 226 | blank_statusbar(); |
| 227 | wrefresh(bottomwin); |
| 228 | } |
| 229 | |
| 230 | void check_statblank(void) |
| 231 | { |
| 232 | |
| 233 | if (statblank > 1) |
| 234 | statblank--; |
| 235 | else if (statblank == 1 && !ISSET(CONSTUPDATE)) { |
| 236 | statblank--; |
| 237 | blank_statusbar_refresh(); |
| 238 | } |
| 239 | } |
| 240 | |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 241 | /* Repaint the statusbar when getting a character in nanogetstr */ |
| 242 | void nanoget_repaint(char *buf, char *inputbuf, int x) |
| 243 | { |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 244 | int len = strlen(buf); |
| 245 | int wid = COLS - len; |
| 246 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 247 | #ifdef ENABLE_COLOR |
| 248 | color_on(bottomwin, COLOR_STATUSBAR); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 249 | #else |
| 250 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 251 | #endif |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 252 | blank_statusbar(); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 253 | |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 254 | if (x <= COLS - 1) { |
| 255 | /* Black magic */ |
| 256 | buf[len - 1] = ' '; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 257 | |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 258 | mvwaddstr(bottomwin, 0, 0, buf); |
| 259 | waddnstr(bottomwin, inputbuf, wid); |
| 260 | wmove(bottomwin, 0, (x % COLS)); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 261 | } else { |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 262 | /* Black magic */ |
| 263 | buf[len - 1] = '$'; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 264 | |
Chris Allegretta | 0d1e8d6 | 2000-11-02 15:30:24 +0000 | [diff] [blame] | 265 | mvwaddstr(bottomwin, 0, 0, buf); |
| 266 | waddnstr(bottomwin, &inputbuf[wid * ((x - len) / (wid))], wid); |
| 267 | wmove(bottomwin, 0, ((x - len) % wid) + len); |
| 268 | } |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 269 | |
| 270 | #ifdef ENABLE_COLOR |
| 271 | color_off(bottomwin, COLOR_STATUSBAR); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 272 | #else |
| 273 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 274 | #endif |
Chris Allegretta | a0e957b | 2000-10-24 22:25:36 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 277 | /* Get the input from the kb; this should only be called from statusq */ |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 278 | int nanogetstr(int allowtabs, char *buf, char *def, shortcut *s, |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 279 | int start_x, int list) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 280 | { |
Chris Allegretta | 9caa193 | 2002-02-15 20:08:05 +0000 | [diff] [blame] | 281 | int kbinput = 0, x = 0, xend, slen; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 282 | int x_left = 0, inputlen, tabbed = 0; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 283 | char *inputbuf; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 284 | shortcut *t; |
Rocco Corsi | 06aca1c | 2001-01-11 05:30:31 +0000 | [diff] [blame] | 285 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 286 | int shift = 0; |
| 287 | #endif |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 288 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 289 | slen = length_of_list(s); |
Chris Allegretta | 88b0915 | 2001-05-17 11:35:43 +0000 | [diff] [blame] | 290 | inputbuf = charalloc(strlen(def) + 1); |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 291 | inputbuf[0] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 292 | |
| 293 | x_left = strlen(buf); |
| 294 | x = strlen(def) + x_left; |
| 295 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 296 | #if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE) |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 297 | currshortcut = s; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 298 | #endif |
| 299 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 300 | /* Get the input! */ |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 301 | if (strlen(def) > 0) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 302 | strcpy(inputbuf, def); |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 303 | |
| 304 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 305 | |
Chris Allegretta | 022b96f | 2000-11-14 17:47:58 +0000 | [diff] [blame] | 306 | /* Make sure any editor screen updates are displayed before getting input */ |
| 307 | wrefresh(edit); |
| 308 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 309 | while ((kbinput = wgetch(bottomwin)) != 13) { |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 310 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 311 | #ifdef DEBUG |
| 312 | fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput); |
| 313 | #endif |
| 314 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 315 | if (kbinput == t->val && kbinput < 32) { |
Chris Allegretta | 5bf51d3 | 2000-11-16 06:01:10 +0000 | [diff] [blame] | 316 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 317 | #ifndef DISABLE_HELP |
| 318 | /* Have to do this here, it would be too late to do it in statusq */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 319 | if (kbinput == NANO_HELP_KEY || kbinput == NANO_HELP_FKEY) { |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 320 | do_help(); |
| 321 | break; |
| 322 | } |
| 323 | #endif |
| 324 | |
Chris Allegretta | 5bf51d3 | 2000-11-16 06:01:10 +0000 | [diff] [blame] | 325 | /* We shouldn't discard the answer it gave, just because |
| 326 | we hit a keystroke, GEEZ! */ |
| 327 | answer = mallocstrcpy(answer, inputbuf); |
Chris Allegretta | 92d2bab | 2000-11-02 14:53:46 +0000 | [diff] [blame] | 328 | free(inputbuf); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 329 | return t->val; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | xend = strlen(buf) + strlen(inputbuf); |
| 333 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 334 | if (kbinput != '\t') |
| 335 | tabbed = 0; |
| 336 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 337 | switch (kbinput) { |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 338 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 339 | /* Stuff we want to equate with <enter>, ASCII 13 */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 340 | case 343: |
Chris Allegretta | f9b6c9b | 2000-10-18 19:35:59 +0000 | [diff] [blame] | 341 | ungetch(13); /* Enter on iris-ansi $TERM, sometimes */ |
| 342 | break; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 343 | /* Stuff we want to ignore */ |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 344 | #ifdef PDCURSES |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 345 | case 541: |
| 346 | case 542: |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 347 | case 543: /* Right ctrl again */ |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 348 | case 544: |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 349 | case 545: /* Right alt again */ |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 350 | break; |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 351 | #endif |
Chris Allegretta | 84de552 | 2001-04-12 14:51:48 +0000 | [diff] [blame] | 352 | #ifndef DISABLE_MOUSE |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 353 | #ifdef NCURSES_MOUSE_VERSION |
| 354 | case KEY_MOUSE: |
| 355 | do_mouse(); |
| 356 | break; |
| 357 | #endif |
| 358 | #endif |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 359 | case NANO_HOME_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 360 | case KEY_HOME: |
| 361 | x = x_left; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 362 | break; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 363 | case NANO_END_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 364 | case KEY_END: |
| 365 | x = x_left + strlen(inputbuf); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 366 | break; |
| 367 | case KEY_RIGHT: |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 368 | case NANO_FORWARD_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 369 | |
| 370 | if (x < xend) |
| 371 | x++; |
| 372 | wmove(bottomwin, 0, x); |
| 373 | break; |
| 374 | case NANO_CONTROL_D: |
| 375 | if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) { |
| 376 | memmove(inputbuf + (x - x_left), |
| 377 | inputbuf + (x - x_left) + 1, |
| 378 | strlen(inputbuf) - (x - x_left) - 1); |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 379 | inputbuf[strlen(inputbuf) - 1] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 380 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 381 | break; |
| 382 | case NANO_CONTROL_K: |
| 383 | case NANO_CONTROL_U: |
| 384 | *inputbuf = 0; |
| 385 | x = x_left; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 386 | break; |
| 387 | case KEY_BACKSPACE: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 388 | case 127: |
| 389 | case NANO_CONTROL_H: |
| 390 | if (strlen(inputbuf) > 0) { |
| 391 | if (x == (x_left + strlen(inputbuf))) |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 392 | inputbuf[strlen(inputbuf) - 1] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 393 | else if (x - x_left) { |
| 394 | memmove(inputbuf + (x - x_left) - 1, |
| 395 | inputbuf + (x - x_left), |
| 396 | strlen(inputbuf) - (x - x_left)); |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 397 | inputbuf[strlen(inputbuf) - 1] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 398 | } |
| 399 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 400 | if (x > strlen(buf)) |
| 401 | x--; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 402 | break; |
Rocco Corsi | 06aca1c | 2001-01-11 05:30:31 +0000 | [diff] [blame] | 403 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 404 | case NANO_CONTROL_I: |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 405 | if (allowtabs) { |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 406 | shift = 0; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 407 | inputbuf = input_tab(inputbuf, (x - x_left), |
| 408 | &tabbed, &shift, &list); |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 409 | x += shift; |
Chris Allegretta | e434b45 | 2001-01-27 19:25:00 +0000 | [diff] [blame] | 410 | if (x - x_left > strlen(inputbuf)) |
| 411 | x = strlen(inputbuf) + x_left; |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 412 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 413 | break; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 414 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 415 | case KEY_LEFT: |
Chris Allegretta | 35dac58 | 2001-03-21 15:07:20 +0000 | [diff] [blame] | 416 | case NANO_BACK_KEY: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 417 | if (x > strlen(buf)) |
| 418 | x--; |
| 419 | wmove(bottomwin, 0, x); |
| 420 | break; |
| 421 | case KEY_UP: |
| 422 | case KEY_DOWN: |
| 423 | break; |
| 424 | |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 425 | case KEY_DC: |
| 426 | goto do_deletekey; |
| 427 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 428 | case 27: |
| 429 | switch (kbinput = wgetch(edit)) { |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 430 | case 'O': |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 431 | switch (kbinput = wgetch(edit)) { |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 432 | case 'F': |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 433 | x = x_left + strlen(inputbuf); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 434 | break; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 435 | case 'H': |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 436 | x = x_left; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 437 | break; |
| 438 | } |
| 439 | break; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 440 | case '[': |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 441 | switch (kbinput = wgetch(edit)) { |
| 442 | case 'C': |
| 443 | if (x < xend) |
| 444 | x++; |
| 445 | wmove(bottomwin, 0, x); |
| 446 | break; |
| 447 | case 'D': |
| 448 | if (x > strlen(buf)) |
| 449 | x--; |
| 450 | wmove(bottomwin, 0, x); |
| 451 | break; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 452 | case '1': |
| 453 | case '7': |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 454 | x = x_left; |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 455 | goto skip_tilde; |
| 456 | case '3': |
| 457 | do_deletekey: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 458 | if (strlen(inputbuf) > 0 |
| 459 | && (x - x_left) != strlen(inputbuf)) { |
| 460 | memmove(inputbuf + (x - x_left), |
| 461 | inputbuf + (x - x_left) + 1, |
| 462 | strlen(inputbuf) - (x - x_left) - 1); |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 463 | inputbuf[strlen(inputbuf) - 1] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 464 | } |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 465 | goto skip_tilde; |
| 466 | case '4': |
| 467 | case '8': |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 468 | x = x_left + strlen(inputbuf); |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 469 | goto skip_tilde; |
| 470 | skip_tilde: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 471 | nodelay(edit, TRUE); |
| 472 | kbinput = wgetch(edit); |
Chris Allegretta | ce78c1e | 2001-09-23 01:18:03 +0000 | [diff] [blame] | 473 | if (kbinput == '~' || kbinput == ERR) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 474 | kbinput = -1; |
| 475 | nodelay(edit, FALSE); |
| 476 | break; |
| 477 | } |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 478 | default: |
| 479 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 480 | for (t = s; t != NULL; t = t->next) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 481 | #ifdef DEBUG |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 482 | fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, |
| 483 | kbinput); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 484 | #endif |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 485 | if (kbinput == t->val || kbinput == t->val - 32) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 486 | |
| 487 | /* We hit an Alt key. Do like above. We don't |
| 488 | just ungetch the letter and let it get caught |
| 489 | above cause that screws the keypad... */ |
| 490 | answer = mallocstrcpy(answer, inputbuf); |
| 491 | free(inputbuf); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 492 | return t->val; |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 496 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 497 | break; |
| 498 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 499 | default: |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 500 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 501 | if (kbinput < 32) |
| 502 | break; |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 503 | |
| 504 | inputlen = strlen(inputbuf); |
| 505 | inputbuf = nrealloc(inputbuf, inputlen + 2); |
| 506 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 507 | memmove(&inputbuf[x - x_left + 1], |
| 508 | &inputbuf[x - x_left], inputlen - (x - x_left) + 1); |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 509 | inputbuf[x - x_left] = kbinput; |
| 510 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 511 | x++; |
| 512 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 513 | #ifdef DEBUG |
| 514 | fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput); |
| 515 | #endif |
| 516 | } |
Chris Allegretta | 386e051 | 2001-10-02 02:57:26 +0000 | [diff] [blame] | 517 | nanoget_repaint(buf, inputbuf, x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 518 | wrefresh(bottomwin); |
| 519 | } |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 520 | #ifndef DISABLE_TABCOMP |
| 521 | /* if we've done tab completion, there might be a list of filename |
| 522 | matches on the edit window at this point; make sure they're |
| 523 | cleared off */ |
| 524 | if (list) |
| 525 | edit_refresh(); |
| 526 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 527 | |
Chris Allegretta | 31925e4 | 2000-11-02 04:40:39 +0000 | [diff] [blame] | 528 | answer = mallocstrcpy(answer, inputbuf); |
Chris Allegretta | 92d2bab | 2000-11-02 14:53:46 +0000 | [diff] [blame] | 529 | free(inputbuf); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 530 | |
Chris Allegretta | c1049ac | 2001-08-17 00:03:46 +0000 | [diff] [blame] | 531 | /* In pico mode, just check for a blank answer here */ |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 532 | if (ISSET(PICO_MODE) && answer[0] == '\0') |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 533 | return -2; |
| 534 | else |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | void horizbar(WINDOW * win, int y) |
| 539 | { |
| 540 | wattron(win, A_REVERSE); |
| 541 | mvwaddstr(win, 0, 0, hblank); |
| 542 | wattroff(win, A_REVERSE); |
| 543 | } |
| 544 | |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 545 | void titlebar(char *path) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 546 | { |
| 547 | int namelen, space; |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 548 | char *what = path; |
| 549 | |
| 550 | if (path == NULL) |
| 551 | what = filename; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 552 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 553 | #ifdef ENABLE_COLOR |
| 554 | color_on(topwin, COLOR_TITLEBAR); |
| 555 | mvwaddstr(topwin, 0, 0, hblank); |
| 556 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 557 | horizbar(topwin, 0); |
| 558 | wattron(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 559 | #endif |
| 560 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 561 | mvwaddnstr(topwin, 0, 2, VERMSG, COLS - 3); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 562 | |
| 563 | space = COLS - strlen(VERMSG) - strlen(VERSION) - 21; |
| 564 | |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 565 | namelen = strlen(what); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 566 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 567 | if (space > 0) { |
| 568 | if (what[0] == '\0') |
| 569 | mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer")); |
| 570 | else { |
| 571 | if (namelen > space) { |
| 572 | if (path == NULL) |
| 573 | waddstr(topwin, _(" File: ...")); |
| 574 | else |
| 575 | waddstr(topwin, _(" DIR: ...")); |
| 576 | waddstr(topwin, &what[namelen - space]); |
| 577 | } else { |
| 578 | if (path == NULL) |
| 579 | mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), |
| 580 | _("File: ")); |
| 581 | else |
| 582 | mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), |
| 583 | _(" DIR: ")); |
| 584 | waddstr(topwin, what); |
| 585 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 586 | } |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 587 | } /* If we don't have space, we shouldn't bother */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 588 | if (ISSET(MODIFIED)) |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 589 | mvwaddstr(topwin, 0, COLS - 11, _(" Modified ")); |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 590 | else if (ISSET(VIEW_MODE)) |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 591 | mvwaddstr(topwin, 0, COLS - 11, _(" View ")); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 592 | |
| 593 | #ifdef ENABLE_COLOR |
| 594 | color_off(topwin, COLOR_TITLEBAR); |
| 595 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 596 | wattroff(topwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 597 | #endif |
| 598 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 599 | wrefresh(topwin); |
| 600 | reset_cursor(); |
| 601 | } |
| 602 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 603 | /* Write a shortcut key to the help area at the bottom of the window. |
| 604 | * keystroke is e.g. "^G" and desc is e.g. "Get Help". |
| 605 | * We are careful to write exactly len characters, even if len is |
| 606 | * very small and keystroke and desc are long. */ |
| 607 | static void onekey(const char *keystroke, const char *desc, int len) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 608 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 609 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 610 | waddnstr(bottomwin, keystroke, len); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 611 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 612 | len -= strlen(keystroke); |
| 613 | if (len > 0) { |
| 614 | waddch(bottomwin, ' '); |
| 615 | len--; |
| 616 | waddnstr(bottomwin, desc, len); |
| 617 | len -= strlen(desc); |
| 618 | for (; len > 0; len--) |
| 619 | waddch(bottomwin, ' '); |
| 620 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | void clear_bottomwin(void) |
| 624 | { |
| 625 | if (ISSET(NO_HELP)) |
| 626 | return; |
| 627 | |
| 628 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 629 | mvwaddstr(bottomwin, 2, 0, hblank); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 632 | void bottombars(const shortcut *s) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 633 | { |
Chris Allegretta | bc72e36 | 2002-02-16 20:03:44 +0000 | [diff] [blame] | 634 | int i, j, numcols; |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 635 | char keystr[4]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 636 | int slen; |
| 637 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 638 | if (ISSET(NO_HELP)) |
| 639 | return; |
| 640 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 641 | if (s == main_list) { |
| 642 | slen = MAIN_VISIBLE; |
| 643 | assert(MAIN_VISIBLE <= length_of_list(s)); |
| 644 | } else |
| 645 | slen = length_of_list(s); |
| 646 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 647 | #ifdef ENABLE_COLOR |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 648 | color_on(bottomwin, COLOR_BOTTOMBARS); |
Chris Allegretta | 66577ac | 2002-01-05 02:03:29 +0000 | [diff] [blame] | 649 | if (!colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].set || |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 650 | colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].fg != COLOR_BLACK) |
| 651 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 652 | #endif |
| 653 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 654 | /* There will be this many columns of shortcuts */ |
| 655 | numcols = (slen + (slen % 2)) / 2; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 656 | |
| 657 | clear_bottomwin(); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 658 | |
Chris Allegretta | bc72e36 | 2002-02-16 20:03:44 +0000 | [diff] [blame] | 659 | for (i = 0; i < numcols; i++) { |
| 660 | for (j = 0; j <= 1; j++) { |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 661 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 662 | wmove(bottomwin, 1 + j, i * (COLS / numcols)); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 663 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 664 | #ifndef NANO_SMALL |
| 665 | if (s->val == NANO_CONTROL_SPACE) |
| 666 | strcpy(keystr, "^ "); |
Chris Allegretta | bc72e36 | 2002-02-16 20:03:44 +0000 | [diff] [blame] | 667 | else |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 668 | #endif /* !NANO_SMALL */ |
| 669 | if (s->val > 0) { |
| 670 | if (s->val < 64) |
| 671 | sprintf(keystr, "^%c", s->val + 64); |
| 672 | else |
| 673 | sprintf(keystr, "M-%c", s->val - 32); |
| 674 | } else if (s->altval > 0) |
| 675 | sprintf(keystr, "M-%c", s->altval); |
Chris Allegretta | 658399a | 2001-06-14 02:54:22 +0000 | [diff] [blame] | 676 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 677 | onekey(keystr, s->desc, COLS / numcols); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 678 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 679 | s = s->next; |
| 680 | if (s == NULL) |
| 681 | goto break_completely_out; |
| 682 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 683 | } |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 684 | break_completely_out: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 685 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 686 | #ifdef ENABLE_COLOR |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 687 | color_off(bottomwin, COLOR_BOTTOMBARS); |
| 688 | #endif |
| 689 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 690 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /* If modified is not already set, set it and update titlebar */ |
| 694 | void set_modified(void) |
| 695 | { |
| 696 | if (!ISSET(MODIFIED)) { |
| 697 | SET(MODIFIED); |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 698 | titlebar(NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 699 | wrefresh(topwin); |
| 700 | } |
| 701 | } |
| 702 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 703 | /* And so start the display update routines */ |
| 704 | /* Given a column, this returns the "page" it is on */ |
| 705 | /* "page" in the case of the display columns, means which set of 80 */ |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 706 | /* characters is viewable (e.g.: page 1 shows from 1 to COLS) */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 707 | inline int get_page_from_virtual(int virtual) |
| 708 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 709 | int page = 2; |
| 710 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 711 | if (virtual <= COLS - 2) |
| 712 | return 1; |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 713 | virtual -= (COLS - 2); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 714 | |
| 715 | while (virtual > COLS - 2 - 7) { |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 716 | virtual -= (COLS - 2 - 7); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 717 | page++; |
| 718 | } |
| 719 | |
| 720 | return page; |
| 721 | } |
| 722 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 723 | /* The inverse of the above function */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 724 | inline int get_page_start_virtual(int page) |
| 725 | { |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 726 | int virtual; |
| 727 | virtual = --page * (COLS - 7); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 728 | if (page) |
| 729 | virtual -= 2 * page - 1; |
Robert Siemborski | e8c6fd0 | 2000-06-07 04:40:09 +0000 | [diff] [blame] | 730 | return virtual; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 733 | inline int get_page_end_virtual(int page) |
| 734 | { |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 735 | return get_page_start_virtual(page) + COLS - 1; |
| 736 | } |
| 737 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 738 | #ifndef NANO_SMALL |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 739 | /* This takes care of the case where there is a mark that covers only */ |
| 740 | /* the current line. */ |
| 741 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 742 | /* It expects a line with no tab characters (i.e.: the type that edit_add */ |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 743 | /* deals with */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 744 | void add_marked_sameline(int begin, int end, filestruct * fileptr, int y, |
| 745 | int virt_cur_x, int this_page) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 746 | { |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 747 | /* |
| 748 | * The general idea is to break the line up into 3 sections: before |
| 749 | * the mark, the mark, and after the mark. We then paint each in |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 750 | * turn (for those that are currently visible, of course) |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 751 | * |
| 752 | * 3 start points: 0 -> begin, begin->end, end->strlen(data) |
| 753 | * in data : pre sel post |
| 754 | */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 755 | int this_page_start = get_page_start_virtual(this_page), |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 756 | this_page_end = get_page_end_virtual(this_page); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 757 | |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 758 | /* likewise, 3 data lengths */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 759 | int pre_data_len = begin, sel_data_len = end - begin, post_data_len = 0; /* Determined from the other two */ |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 760 | |
| 761 | /* now fix the start locations & lengths according to the cursor's |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 762 | * position (i.e.: our page) */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 763 | if (pre_data_len < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 764 | pre_data_len = 0; |
| 765 | else |
| 766 | pre_data_len -= this_page_start; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 767 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 768 | if (begin < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 769 | begin = this_page_start; |
| 770 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 771 | if (end < this_page_start) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 772 | end = this_page_start; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 773 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 774 | if (begin > this_page_end) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 775 | begin = this_page_end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 776 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 777 | if (end > this_page_end) |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 778 | end = this_page_end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 779 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 780 | /* Now calculate the lengths */ |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 781 | sel_data_len = end - begin; |
| 782 | post_data_len = this_page_end - end; |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 783 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 784 | #ifdef ENABLE_COLOR |
| 785 | color_on(edit, COLOR_MARKER); |
| 786 | #else |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 787 | wattron(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 788 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 789 | |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 790 | mvwaddnstr(edit, y, begin - this_page_start, |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 791 | &fileptr->data[begin], sel_data_len); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 792 | |
| 793 | #ifdef ENABLE_COLOR |
| 794 | color_off(edit, COLOR_MARKER); |
| 795 | #else |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 796 | wattroff(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 797 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 798 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 799 | } |
| 800 | #endif |
| 801 | |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 802 | /* edit_add takes care of the job of actually painting a line into the |
| 803 | * edit window. |
| 804 | * |
| 805 | * Called only from update_line. Expects a converted-to-not-have-tabs |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 806 | * line */ |
| 807 | void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x, |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 808 | int virt_mark_beginx, int this_page) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 809 | { |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 810 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 811 | #ifdef ENABLE_COLOR |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 812 | colortype *tmpcolor = NULL; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 813 | int k, paintlen; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 814 | filestruct *e, *s; |
| 815 | regoff_t ematch, smatch; |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 816 | #endif |
| 817 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 818 | /* 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] | 819 | just the text that needs it */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 820 | mvwaddnstr(edit, yval, 0, &fileptr->data[start], |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 821 | get_page_end_virtual(this_page) - start + 1); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 822 | |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 823 | #ifdef ENABLE_COLOR |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 824 | if (colorstrings != NULL) |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 825 | for (tmpcolor = colorstrings; tmpcolor != NULL; |
| 826 | tmpcolor = tmpcolor->next) { |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 827 | |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 828 | if (tmpcolor->end == NULL) { |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 829 | |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 830 | /* First, highlight all single-line regexes */ |
| 831 | k = start; |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 832 | regcomp(&color_regexp, tmpcolor->start, 0); |
| 833 | while (!regexec(&color_regexp, &fileptr->data[k], 1, |
| 834 | colormatches, 0)) { |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 835 | |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 836 | if (colormatches[0].rm_eo - colormatches[0].rm_so < 1) { |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 837 | statusbar(_("Refusing 0 length regex match")); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 838 | break; |
| 839 | } |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 840 | #ifdef DEBUG |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 841 | fprintf(stderr, _("Match! (%d chars) \"%s\"\n"), |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 842 | colormatches[0].rm_eo - colormatches[0].rm_so, |
| 843 | &fileptr->data[k + colormatches[0].rm_so]); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 844 | #endif |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 845 | if (colormatches[0].rm_so < COLS - 1) { |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 846 | if (tmpcolor->bright) |
| 847 | wattron(edit, A_BOLD); |
| 848 | wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); |
| 849 | |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 850 | if (colormatches[0].rm_eo + k <= COLS) { |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 851 | paintlen = |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 852 | colormatches[0].rm_eo - colormatches[0].rm_so; |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 853 | #ifdef DEBUG |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 854 | fprintf(stderr, _("paintlen (%d) = eo (%d) - so (%d)\n"), |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 855 | paintlen, colormatches[0].rm_eo, colormatches[0].rm_so); |
| 856 | #endif |
| 857 | |
| 858 | } |
| 859 | else { |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 860 | paintlen = COLS - k - colormatches[0].rm_so - 1; |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 861 | #ifdef DEBUG |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 862 | fprintf(stderr, _("paintlen (%d) = COLS (%d) - k (%d), - rm.so (%d) - 1\n"), |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 863 | paintlen, COLS, k, colormatches[0].rm_so); |
| 864 | #endif |
| 865 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 866 | |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 867 | mvwaddnstr(edit, yval, colormatches[0].rm_so + k, |
| 868 | &fileptr->data[k + colormatches[0].rm_so], |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 869 | paintlen); |
| 870 | |
| 871 | } |
| 872 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 873 | if (tmpcolor->bright) |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 874 | wattroff(edit, A_BOLD); |
| 875 | wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 876 | |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 877 | k += colormatches[0].rm_eo; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 878 | |
| 879 | } |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 880 | regfree(&color_regexp); |
| 881 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 882 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 883 | /* Now, if there's an 'end' somewhere below, and a 'start' |
| 884 | somewhere above, things get really fun. We have to look |
| 885 | down for an end, make sure there's not a start before |
| 886 | the end after us, and then look up for a start, |
| 887 | and see if there's an end after the start, before us :) */ |
| 888 | else { |
| 889 | |
| 890 | s = fileptr; |
| 891 | while (s != NULL) { |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 892 | regcomp(&color_regexp, tmpcolor->start, 0); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 893 | if (!regexec |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 894 | (&color_regexp, s->data, 1, colormatches, 0)) { |
| 895 | regfree(&color_regexp); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 896 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 897 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 898 | s = s->prev; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 899 | regfree(&color_regexp); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | if (s != NULL) { |
| 903 | /* We found a start, mark it */ |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 904 | smatch = colormatches[0].rm_so; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 905 | |
| 906 | e = s; |
| 907 | while (e != NULL && e != fileptr) { |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 908 | regcomp(&color_regexp, tmpcolor->end, 0); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 909 | if (!regexec |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 910 | (&color_regexp, e->data, 1, colormatches, 0)) { |
| 911 | regfree(&color_regexp); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 912 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 913 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 914 | e = e->next; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 915 | regfree(&color_regexp); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | if (e != fileptr) |
| 919 | continue; /* There's an end before us */ |
| 920 | else { /* Keep looking for an end */ |
| 921 | while (e != NULL) { |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 922 | regcomp(&color_regexp, tmpcolor->end, 0); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 923 | if (!regexec |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 924 | (&color_regexp, e->data, 1, colormatches, |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 925 | 0)) { |
| 926 | regfree(&color_regexp); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 927 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 928 | } |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 929 | e = e->next; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 930 | regfree(&color_regexp); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | if (e == NULL) |
| 934 | continue; /* There's no start before the end :) */ |
| 935 | else { /* Okay, we found an end, mark it! */ |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 936 | ematch = colormatches[0].rm_eo; |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 937 | |
| 938 | while (e != NULL) { |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 939 | regcomp(&color_regexp, tmpcolor->end, 0); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 940 | if (!regexec |
Chris Allegretta | 3533a34 | 2002-03-24 23:19:32 +0000 | [diff] [blame] | 941 | (&color_regexp, e->data, 1, |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 942 | colormatches, 0)) { |
| 943 | regfree(&color_regexp); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 944 | break; |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 945 | } e = e->next; |
| 946 | regfree(&color_regexp); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | if (e == NULL) |
| 950 | continue; /* No end, oh well :) */ |
| 951 | |
| 952 | /* Didn't find another end, we must be in the |
| 953 | middle of a highlighted bit */ |
| 954 | |
| 955 | if (tmpcolor->bright) |
| 956 | wattron(edit, A_BOLD); |
| 957 | |
| 958 | wattron(edit, COLOR_PAIR(tmpcolor->pairnum)); |
| 959 | |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 960 | if (s == fileptr && e == fileptr && ematch < COLS) { |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 961 | mvwaddnstr(edit, yval, start + smatch, |
| 962 | &fileptr->data[start + smatch], |
| 963 | ematch - smatch); |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 964 | #ifdef DEBUG |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 965 | fprintf(stderr, _("start = %d, smatch = %d, ematch = %d\n"), start, |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 966 | smatch, ematch); |
| 967 | #endif |
| 968 | |
| 969 | } else if (s == fileptr) |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 970 | mvwaddnstr(edit, yval, start + smatch, |
| 971 | &fileptr->data[start + smatch], |
| 972 | COLS - smatch); |
| 973 | else if (e == fileptr) |
| 974 | mvwaddnstr(edit, yval, start, |
| 975 | &fileptr->data[start], |
Chris Allegretta | 7c27be4 | 2002-05-05 23:03:54 +0000 | [diff] [blame] | 976 | COLS - start); |
Chris Allegretta | 6c1e661 | 2002-01-19 16:52:34 +0000 | [diff] [blame] | 977 | else |
| 978 | mvwaddnstr(edit, yval, start, |
| 979 | &fileptr->data[start], |
| 980 | COLS); |
| 981 | |
| 982 | if (tmpcolor->bright) |
| 983 | wattroff(edit, A_BOLD); |
| 984 | |
| 985 | wattroff(edit, COLOR_PAIR(tmpcolor->pairnum)); |
| 986 | |
| 987 | } |
| 988 | |
| 989 | } |
| 990 | |
| 991 | /* Else go to the next string, yahoo! =) */ |
| 992 | } |
| 993 | |
| 994 | } |
| 995 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 996 | } |
Chris Allegretta | 3674c1d | 2002-05-12 20:43:49 +0000 | [diff] [blame] | 997 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 998 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 7dd7768 | 2001-12-08 19:52:28 +0000 | [diff] [blame] | 999 | #ifndef NANO_SMALL |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1000 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1001 | /* There are quite a few cases that could take place; we'll deal |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 1002 | * with them each in turn */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1003 | if (ISSET(MARK_ISSET) && |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1004 | !((fileptr->lineno > mark_beginbuf->lineno |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1005 | && fileptr->lineno > current->lineno) |
| 1006 | || (fileptr->lineno < mark_beginbuf->lineno |
| 1007 | && fileptr->lineno < current->lineno))) { |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1008 | /* If we get here we are on a line that is at least |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1009 | * partially selected. The lineno checks above determined |
| 1010 | * that */ |
| 1011 | if (fileptr != mark_beginbuf && fileptr != current) { |
| 1012 | /* We are on a completely marked line, paint it all |
| 1013 | * inverse */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1014 | #ifdef ENABLE_COLOR |
| 1015 | color_on(edit, COLOR_MARKER); |
| 1016 | #else |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1017 | wattron(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1018 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1019 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1020 | mvwaddnstr(edit, yval, 0, fileptr->data, COLS); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1021 | |
| 1022 | #ifdef ENABLE_COLOR |
| 1023 | color_off(edit, COLOR_MARKER); |
| 1024 | #else |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1025 | wattroff(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1026 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1027 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1028 | } else if (fileptr == mark_beginbuf && fileptr == current) { |
| 1029 | /* Special case, we're still on the same line we started |
| 1030 | * marking -- so we call our helper function */ |
| 1031 | if (virt_cur_x < virt_mark_beginx) { |
| 1032 | /* To the right of us is marked */ |
| 1033 | add_marked_sameline(virt_cur_x, virt_mark_beginx, |
| 1034 | fileptr, yval, virt_cur_x, this_page); |
| 1035 | } else { |
| 1036 | /* To the left of us is marked */ |
| 1037 | add_marked_sameline(virt_mark_beginx, virt_cur_x, |
| 1038 | fileptr, yval, virt_cur_x, this_page); |
| 1039 | } |
| 1040 | } else if (fileptr == mark_beginbuf) { |
| 1041 | /* |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1042 | * We're updating the line that was first marked, |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1043 | * but we're not currently on it. So we want to |
Robert Siemborski | a0238ed | 2001-03-31 21:46:43 +0000 | [diff] [blame] | 1044 | * figure out which half to invert based on our |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1045 | * relative line numbers. |
| 1046 | * |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1047 | * I.e. if we're above the "beginbuf" line, we want to |
| 1048 | * mark the left side. Otherwise, we're below, so we |
| 1049 | * mark the right. |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1050 | */ |
| 1051 | int target; |
| 1052 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1053 | if (mark_beginbuf->lineno > current->lineno) { |
| 1054 | #ifdef ENABLE_COLOR |
| 1055 | color_on(edit, COLOR_MARKER); |
| 1056 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1057 | wattron(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1058 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1059 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1060 | target = |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1061 | (virt_mark_beginx < |
| 1062 | COLS - 1) ? virt_mark_beginx : COLS - 1; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1063 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1064 | mvwaddnstr(edit, yval, 0, fileptr->data, target); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1065 | |
| 1066 | #ifdef ENABLE_COLOR |
| 1067 | color_off(edit, COLOR_MARKER); |
| 1068 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1069 | wattroff(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1070 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1071 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1072 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1073 | } |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1074 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1075 | if (mark_beginbuf->lineno < current->lineno) { |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1076 | #ifdef ENABLE_COLOR |
| 1077 | color_on(edit, COLOR_MARKER); |
| 1078 | #else |
| 1079 | wattron(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1080 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1081 | |
| 1082 | target = (COLS - 1) - virt_mark_beginx; |
| 1083 | |
| 1084 | if (target < 0) |
| 1085 | target = 0; |
| 1086 | |
| 1087 | mvwaddnstr(edit, yval, virt_mark_beginx, |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1088 | &fileptr->data[virt_mark_beginx], target); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1089 | |
| 1090 | #ifdef ENABLE_COLOR |
| 1091 | color_off(edit, COLOR_MARKER); |
| 1092 | #else |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1093 | wattroff(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1094 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1095 | |
| 1096 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1097 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1098 | } else if (fileptr == current) { |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1099 | /* We're on the cursor's line, but it's not the first |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1100 | * one we marked. Similar to the previous logic. */ |
| 1101 | int this_page_start = get_page_start_virtual(this_page), |
| 1102 | this_page_end = get_page_end_virtual(this_page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1103 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1104 | if (mark_beginbuf->lineno < current->lineno) { |
| 1105 | |
| 1106 | #ifdef ENABLE_COLOR |
| 1107 | color_on(edit, COLOR_MARKER); |
| 1108 | #else |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1109 | wattron(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1110 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1111 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1112 | if (virt_cur_x > COLS - 2) { |
| 1113 | mvwaddnstr(edit, yval, 0, |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1114 | &fileptr->data[this_page_start], |
| 1115 | virt_cur_x - this_page_start); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1116 | } else |
| 1117 | mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x); |
| 1118 | |
| 1119 | #ifdef ENABLE_COLOR |
| 1120 | color_off(edit, COLOR_MARKER); |
| 1121 | #else |
| 1122 | wattroff(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1123 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1124 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1125 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1126 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1127 | if (mark_beginbuf->lineno > current->lineno) { |
| 1128 | |
| 1129 | #ifdef ENABLE_COLOR |
| 1130 | color_on(edit, COLOR_MARKER); |
| 1131 | #else |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1132 | wattron(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1133 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1134 | |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1135 | if (virt_cur_x > COLS - 2) |
| 1136 | mvwaddnstr(edit, yval, virt_cur_x - this_page_start, |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1137 | &fileptr->data[virt_cur_x], |
| 1138 | this_page_end - virt_cur_x); |
Chris Allegretta | 2fa11b8 | 2001-12-02 04:55:44 +0000 | [diff] [blame] | 1139 | else |
| 1140 | mvwaddnstr(edit, yval, virt_cur_x, |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1141 | &fileptr->data[virt_cur_x], |
| 1142 | COLS - virt_cur_x); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1143 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1144 | #ifdef ENABLE_COLOR |
| 1145 | color_off(edit, COLOR_MARKER); |
| 1146 | #else |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1147 | wattroff(edit, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1148 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1149 | |
| 1150 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1151 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 1152 | } |
Chris Allegretta | 08893e0 | 2001-11-29 02:42:27 +0000 | [diff] [blame] | 1153 | #endif |
| 1154 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /* |
Robert Siemborski | 9d58455 | 2000-07-08 00:41:29 +0000 | [diff] [blame] | 1158 | * Just update one line in the edit buffer. Basically a wrapper for |
| 1159 | * edit_add |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1160 | * |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1161 | * index gives us a place in the string to update starting from. |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1162 | * Likely args are current_x or 0. |
| 1163 | */ |
| 1164 | void update_line(filestruct * fileptr, int index) |
| 1165 | { |
| 1166 | filestruct *filetmp; |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1167 | int line = 0, col = 0; |
| 1168 | int virt_cur_x = current_x, virt_mark_beginx = mark_beginx; |
| 1169 | char *realdata, *tmp; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1170 | int i, pos, len, page; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1171 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1172 | if (!fileptr) |
| 1173 | return; |
Robert Siemborski | 53154a7 | 2000-06-18 00:11:03 +0000 | [diff] [blame] | 1174 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1175 | /* First, blank out the line (at a minimum) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1176 | for (filetmp = edittop; filetmp != fileptr && filetmp != editbot; |
| 1177 | filetmp = filetmp->next) |
| 1178 | line++; |
| 1179 | |
| 1180 | mvwaddstr(edit, line, 0, hblank); |
| 1181 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1182 | /* Next, convert all the tabs to spaces, so everything else is easy */ |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1183 | index = xpt(fileptr, index); |
| 1184 | |
| 1185 | realdata = fileptr->data; |
| 1186 | len = strlen(realdata); |
Chris Allegretta | 88b0915 | 2001-05-17 11:35:43 +0000 | [diff] [blame] | 1187 | fileptr->data = charalloc(xpt(fileptr, len) + 1); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1188 | |
| 1189 | pos = 0; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1190 | for (i = 0; i < len; i++) { |
| 1191 | if (realdata[i] == '\t') { |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1192 | do { |
| 1193 | fileptr->data[pos++] = ' '; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1194 | if (i < current_x) |
| 1195 | virt_cur_x++; |
| 1196 | if (i < mark_beginx) |
| 1197 | virt_mark_beginx++; |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 1198 | } while (pos % tabsize); |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1199 | /* must decrement once to account for tab-is-one-character */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1200 | if (i < current_x) |
| 1201 | virt_cur_x--; |
| 1202 | if (i < mark_beginx) |
| 1203 | virt_mark_beginx--; |
Chris Allegretta | 2598c66 | 2002-03-28 01:59:34 +0000 | [diff] [blame] | 1204 | } else if (realdata[i] == 127) { |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1205 | /* Treat control characters as ^symbol (ASCII 1 - 31 omitting |
| 1206 | 10, 127) */ |
Chris Allegretta | 2598c66 | 2002-03-28 01:59:34 +0000 | [diff] [blame] | 1207 | fileptr->data[pos++] = '^'; |
| 1208 | fileptr->data[pos++] = '?'; |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1209 | if (i < current_x) |
| 1210 | virt_cur_x++; |
| 1211 | if (i < mark_beginx) |
| 1212 | virt_mark_beginx++; |
| 1213 | } else if (realdata[i] >= 1 && realdata[i] <= 31 && realdata[i] != 10) { |
Chris Allegretta | 6306a11 | 2000-09-02 07:55:41 +0000 | [diff] [blame] | 1214 | fileptr->data[pos++] = '^'; |
| 1215 | fileptr->data[pos++] = realdata[i] + 64; |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1216 | if (i < current_x) |
| 1217 | virt_cur_x++; |
| 1218 | if (i < mark_beginx) |
| 1219 | virt_mark_beginx++; |
| 1220 | } else if (realdata[i] == 10) { |
| 1221 | /* Treat newlines (ASCII 10's) embedded in a line as encoded |
| 1222 | nulls (ASCII 0's); the line in question should be run |
| 1223 | through unsunder() before reaching here */ |
| 1224 | fileptr->data[pos++] = '^'; |
| 1225 | fileptr->data[pos++] = '@'; |
| 1226 | if (i < current_x) |
| 1227 | virt_cur_x++; |
| 1228 | if (i < mark_beginx) |
| 1229 | virt_mark_beginx++; |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1230 | } else { |
| 1231 | fileptr->data[pos++] = realdata[i]; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | fileptr->data[pos] = '\0'; |
| 1236 | |
Chris Allegretta | 4dc03d5 | 2002-05-11 03:04:44 +0000 | [diff] [blame] | 1237 | /* Now, paint the line */ |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1238 | if (current == fileptr && index > COLS - 2) { |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 1239 | /* This handles when the current line is beyond COLS */ |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1240 | /* It requires figuring out what page we're on */ |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 1241 | page = get_page_from_virtual(index); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1242 | col = get_page_start_virtual(page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1243 | |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 1244 | edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1245 | mvwaddch(edit, line, 0, '$'); |
| 1246 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1247 | if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1248 | mvwaddch(edit, line, COLS - 1, '$'); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1249 | } else { |
Robert Siemborski | a9addc7 | 2000-06-17 06:06:35 +0000 | [diff] [blame] | 1250 | /* It's not the current line means that it's at x=0 and page=1 */ |
| 1251 | /* If it is the current line, then we're in the same boat */ |
| 1252 | edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1253 | |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1254 | if (strlenpt(&filetmp->data[col]) > COLS) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1255 | mvwaddch(edit, line, COLS - 1, '$'); |
Robert Siemborski | d8510b2 | 2000-06-06 23:04:06 +0000 | [diff] [blame] | 1256 | } |
Robert Siemborski | 5387591 | 2000-06-16 04:25:30 +0000 | [diff] [blame] | 1257 | |
| 1258 | /* Clean up our mess */ |
| 1259 | tmp = fileptr->data; |
| 1260 | fileptr->data = realdata; |
| 1261 | free(tmp); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | void center_cursor(void) |
| 1265 | { |
| 1266 | current_y = editwinrows / 2; |
| 1267 | wmove(edit, current_y, current_x); |
| 1268 | } |
| 1269 | |
| 1270 | /* Refresh the screen without changing the position of lines */ |
| 1271 | void edit_refresh(void) |
| 1272 | { |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 1273 | static int noloop = 0; |
Chris Allegretta | 3d0739c | 2002-01-07 14:41:32 +0000 | [diff] [blame] | 1274 | int nlines = 0, i = 0, currentcheck = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1275 | filestruct *temp, *hold = current; |
| 1276 | |
| 1277 | if (current == NULL) |
| 1278 | return; |
| 1279 | |
| 1280 | temp = edittop; |
| 1281 | |
Chris Allegretta | 3d0739c | 2002-01-07 14:41:32 +0000 | [diff] [blame] | 1282 | while (nlines <= editwinrows - 1 && nlines <= totlines && temp != NULL) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1283 | hold = temp; |
| 1284 | update_line(temp, current_x); |
Chris Allegretta | 95b0b52 | 2000-07-28 02:58:06 +0000 | [diff] [blame] | 1285 | if (temp == current) |
| 1286 | currentcheck = 1; |
| 1287 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1288 | temp = temp->next; |
Chris Allegretta | 3d0739c | 2002-01-07 14:41:32 +0000 | [diff] [blame] | 1289 | nlines++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1290 | } |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 1291 | /* If noloop == 1, then we already did an edit_update without finishing |
| 1292 | this function. So we don't run edit_update again */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1293 | if (!currentcheck && !noloop) { /* Then current has run off the screen... */ |
Chris Allegretta | da721be | 2000-07-31 01:26:42 +0000 | [diff] [blame] | 1294 | edit_update(current, CENTER); |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 1295 | noloop = 1; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1296 | } else if (noloop) |
Chris Allegretta | ed02216 | 2000-08-03 16:54:11 +0000 | [diff] [blame] | 1297 | noloop = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1298 | |
Chris Allegretta | 3d0739c | 2002-01-07 14:41:32 +0000 | [diff] [blame] | 1299 | if (nlines <= editwinrows - 1) |
| 1300 | while (nlines <= editwinrows - 1) { |
| 1301 | mvwaddstr(edit, nlines, i, hblank); |
| 1302 | nlines++; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1303 | } |
| 1304 | if (temp == NULL) |
| 1305 | editbot = hold; |
| 1306 | else |
| 1307 | editbot = temp; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1308 | |
| 1309 | /* What the hell are we expecting to update the screen if this isn't |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1310 | here? luck?? */ |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1311 | wrefresh(edit); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | /* |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1315 | * Same as above, but touch the window first, so everything is redrawn. |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 1316 | */ |
| 1317 | void edit_refresh_clearok(void) |
| 1318 | { |
| 1319 | clearok(edit, TRUE); |
| 1320 | edit_refresh(); |
| 1321 | clearok(edit, FALSE); |
| 1322 | } |
| 1323 | |
| 1324 | /* |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1325 | * 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] | 1326 | * file struct =) |
| 1327 | */ |
Chris Allegretta | 2d7893d | 2001-07-11 02:08:33 +0000 | [diff] [blame] | 1328 | void edit_update(filestruct * fileptr, int topmidbotnone) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1329 | { |
Robert Siemborski | 29e9a76 | 2000-07-05 03:16:04 +0000 | [diff] [blame] | 1330 | int i = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1331 | filestruct *temp; |
| 1332 | |
| 1333 | if (fileptr == NULL) |
| 1334 | return; |
| 1335 | |
| 1336 | temp = fileptr; |
Chris Allegretta | 2d7893d | 2001-07-11 02:08:33 +0000 | [diff] [blame] | 1337 | if (topmidbotnone == TOP); |
| 1338 | else if (topmidbotnone == NONE) |
| 1339 | for (i = 0; i <= current_y - 1 && temp->prev != NULL; i++) |
| 1340 | temp = temp->prev; |
| 1341 | else if (topmidbotnone == BOTTOM) |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 1342 | for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++) |
| 1343 | temp = temp->prev; |
| 1344 | else |
| 1345 | for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++) |
| 1346 | temp = temp->prev; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1347 | |
Robert Siemborski | 29e9a76 | 2000-07-05 03:16:04 +0000 | [diff] [blame] | 1348 | edittop = temp; |
| 1349 | fix_editbot(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1350 | |
| 1351 | edit_refresh(); |
| 1352 | } |
| 1353 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1354 | /* This function updates current, based on where current_y is; reset_cursor |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1355 | does the opposite */ |
| 1356 | void update_cursor(void) |
| 1357 | { |
| 1358 | int i = 0; |
| 1359 | |
| 1360 | #ifdef DEBUG |
| 1361 | fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y, |
| 1362 | current_x); |
| 1363 | #endif |
| 1364 | |
| 1365 | current = edittop; |
| 1366 | while (i <= current_y - 1 && current->next != NULL) { |
| 1367 | current = current->next; |
| 1368 | i++; |
| 1369 | } |
| 1370 | |
| 1371 | #ifdef DEBUG |
| 1372 | fprintf(stderr, _("current->data = \"%s\"\n"), current->data); |
| 1373 | #endif |
| 1374 | |
| 1375 | } |
| 1376 | |
| 1377 | /* |
| 1378 | * Ask a question on the statusbar. Answer will be stored in answer |
| 1379 | * 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] | 1380 | * otherwise, the valid shortcut key caught. Def is any editable text we |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1381 | * want to put up by default. |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 1382 | * |
| 1383 | * New arg tabs tells whether or not to allow tab completion. |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1384 | */ |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1385 | int statusq(int tabs, shortcut *s, char *def, char *msg, ...) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1386 | { |
| 1387 | va_list ap; |
| 1388 | char foo[133]; |
Chris Allegretta | 9caa193 | 2002-02-15 20:08:05 +0000 | [diff] [blame] | 1389 | int ret; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1390 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1391 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | a16e4e9 | 2002-01-05 18:59:54 +0000 | [diff] [blame] | 1392 | int list = 0; |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1393 | #endif |
| 1394 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1395 | bottombars(s); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1396 | |
| 1397 | va_start(ap, msg); |
| 1398 | vsnprintf(foo, 132, msg, ap); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1399 | va_end(ap); |
Chris Allegretta | a4d2162 | 2000-07-08 23:57:03 +0000 | [diff] [blame] | 1400 | strncat(foo, ": ", 132); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1401 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1402 | #ifdef ENABLE_COLOR |
| 1403 | color_on(bottomwin, COLOR_STATUSBAR); |
| 1404 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1405 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1406 | #endif |
| 1407 | |
| 1408 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1409 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1410 | ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), list); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1411 | #else |
| 1412 | /* if we've disabled tab completion, the value of list won't be |
| 1413 | used at all, so it's safe to use 0 (NULL) as a placeholder */ |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1414 | ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), 0); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1415 | #endif |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1416 | |
| 1417 | #ifdef ENABLE_COLOR |
| 1418 | color_off(bottomwin, COLOR_STATUSBAR); |
| 1419 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1420 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1421 | #endif |
| 1422 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1423 | |
| 1424 | switch (ret) { |
| 1425 | |
| 1426 | case NANO_FIRSTLINE_KEY: |
| 1427 | do_first_line(); |
| 1428 | break; |
| 1429 | case NANO_LASTLINE_KEY: |
| 1430 | do_last_line(); |
| 1431 | break; |
| 1432 | case NANO_CANCEL_KEY: |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1433 | #ifndef DISABLE_TABCOMP |
| 1434 | /* if we've done tab completion, there might be a list of |
| 1435 | filename matches on the edit window at this point; make sure |
| 1436 | they're cleared off */ |
| 1437 | if (list) |
| 1438 | edit_refresh(); |
| 1439 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1440 | return -1; |
| 1441 | default: |
Chris Allegretta | 5b1faac | 2000-11-16 19:55:30 +0000 | [diff] [blame] | 1442 | blank_statusbar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | #ifdef DEBUG |
| 1446 | fprintf(stderr, _("I got \"%s\"\n"), answer); |
| 1447 | #endif |
| 1448 | |
| 1449 | return ret; |
| 1450 | } |
| 1451 | |
| 1452 | /* |
| 1453 | * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for |
| 1454 | * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C) |
| 1455 | */ |
| 1456 | int do_yesno(int all, int leavecursor, char *msg, ...) |
| 1457 | { |
| 1458 | va_list ap; |
| 1459 | char foo[133]; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1460 | int kbinput, ok = -1, i; |
| 1461 | char *yesstr; /* String of yes characters accepted */ |
| 1462 | char *nostr; /* Same for no */ |
| 1463 | char *allstr; /* And all, surprise! */ |
Chris Allegretta | 84de552 | 2001-04-12 14:51:48 +0000 | [diff] [blame] | 1464 | #ifndef DISABLE_MOUSE |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1465 | #ifdef NCURSES_MOUSE_VERSION |
| 1466 | MEVENT mevent; |
| 1467 | #endif |
| 1468 | #endif |
| 1469 | |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1470 | |
| 1471 | /* 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] | 1472 | all characters accepted as a valid character for that value. |
| 1473 | The first value will be the one displayed in the shortcuts. */ |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1474 | yesstr = _("Yy"); |
| 1475 | nostr = _("Nn"); |
| 1476 | allstr = _("Aa"); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1477 | |
| 1478 | /* Write the bottom of the screen */ |
| 1479 | clear_bottomwin(); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1480 | |
| 1481 | #ifdef ENABLE_COLOR |
| 1482 | color_on(bottomwin, COLOR_BOTTOMBARS); |
| 1483 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1484 | |
Jordi Mallach | 0b0fc49 | 2000-06-23 01:00:13 +0000 | [diff] [blame] | 1485 | /* Remove gettext call for keybindings until we clear the thing up */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1486 | if (!ISSET(NO_HELP)) { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1487 | char shortstr[3]; /* Temp string for Y, N, A */ |
| 1488 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1489 | wmove(bottomwin, 1, 0); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1490 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1491 | sprintf(shortstr, " %c", yesstr[0]); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1492 | onekey(shortstr, _("Yes"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1493 | |
| 1494 | if (all) { |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1495 | shortstr[1] = allstr[0]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1496 | onekey(shortstr, _("All"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1497 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1498 | wmove(bottomwin, 2, 0); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1499 | |
Chris Allegretta | 6232d66 | 2002-05-12 19:52:15 +0000 | [diff] [blame] | 1500 | shortstr[1] = nostr[0]; |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1501 | onekey(shortstr, _("No"), 16); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1502 | |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1503 | onekey("^C", _("Cancel"), 16); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1504 | } |
| 1505 | va_start(ap, msg); |
| 1506 | vsnprintf(foo, 132, msg, ap); |
| 1507 | va_end(ap); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1508 | |
| 1509 | #ifdef ENABLE_COLOR |
| 1510 | color_off(bottomwin, COLOR_BOTTOMBARS); |
| 1511 | color_on(bottomwin, COLOR_STATUSBAR); |
| 1512 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1513 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1514 | #endif /* ENABLE_COLOR */ |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1515 | |
| 1516 | blank_statusbar(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1517 | mvwaddstr(bottomwin, 0, 0, foo); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1518 | |
| 1519 | #ifdef ENABLE_COLOR |
| 1520 | color_off(bottomwin, COLOR_STATUSBAR); |
| 1521 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1522 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1523 | #endif |
| 1524 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1525 | wrefresh(bottomwin); |
| 1526 | |
| 1527 | if (leavecursor == 1) |
| 1528 | reset_cursor(); |
| 1529 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1530 | while (ok == -1) { |
| 1531 | kbinput = wgetch(edit); |
| 1532 | |
| 1533 | switch (kbinput) { |
Chris Allegretta | 84de552 | 2001-04-12 14:51:48 +0000 | [diff] [blame] | 1534 | #ifndef DISABLE_MOUSE |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1535 | #ifdef NCURSES_MOUSE_VERSION |
| 1536 | case KEY_MOUSE: |
| 1537 | |
| 1538 | /* Look ma! We get to duplicate lots of code from do_mouse!! */ |
| 1539 | if (getmouse(&mevent) == ERR) |
| 1540 | break; |
| 1541 | if (!wenclose(bottomwin, mevent.y, mevent.x) || ISSET(NO_HELP)) |
| 1542 | break; |
| 1543 | mevent.y -= editwinrows + 3; |
| 1544 | if (mevent.y < 0) |
| 1545 | break; |
| 1546 | else { |
| 1547 | |
| 1548 | /* Rather than a bunch of if statements, set up a matrix |
| 1549 | of possible return keystrokes based on the x and y values */ |
| 1550 | if (all) { |
| 1551 | char yesnosquare[2][2] = { |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1552 | {yesstr[0], allstr[0]}, |
| 1553 | {nostr[0], NANO_CONTROL_C} |
| 1554 | }; |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1555 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1556 | ungetch(yesnosquare[mevent.y][mevent.x / (COLS / 6)]); |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1557 | } else { |
| 1558 | char yesnosquare[2][2] = { |
| 1559 | {yesstr[0], '\0'}, |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1560 | {nostr[0], NANO_CONTROL_C} |
| 1561 | }; |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1562 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1563 | ungetch(yesnosquare[mevent.y][mevent.x / (COLS / 6)]); |
Chris Allegretta | 235ab19 | 2001-04-12 13:24:40 +0000 | [diff] [blame] | 1564 | } |
| 1565 | } |
| 1566 | break; |
| 1567 | #endif |
| 1568 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1569 | case NANO_CONTROL_C: |
| 1570 | ok = -2; |
| 1571 | break; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1572 | default: |
| 1573 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1574 | /* Look for the kbinput in the yes, no and (optimally) all str */ |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1575 | for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1576 | if (yesstr[i] != 0) { |
Chris Allegretta | ea620fe | 2001-02-18 05:39:41 +0000 | [diff] [blame] | 1577 | ok = 1; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1578 | break; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1581 | for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1582 | if (nostr[i] != 0) { |
| 1583 | ok = 0; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1584 | break; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | if (all) { |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1588 | for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++); |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1589 | if (allstr[i] != 0) { |
| 1590 | ok = 2; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1591 | break; |
Chris Allegretta | 4ce8e3b | 2001-02-16 01:49:31 +0000 | [diff] [blame] | 1592 | } |
| 1593 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1594 | } |
| 1595 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1596 | |
| 1597 | /* Then blank the screen */ |
| 1598 | blank_statusbar_refresh(); |
| 1599 | |
| 1600 | if (ok == -2) |
| 1601 | return -1; |
| 1602 | else |
| 1603 | return ok; |
| 1604 | } |
| 1605 | |
| 1606 | void statusbar(char *msg, ...) |
| 1607 | { |
| 1608 | va_list ap; |
| 1609 | char foo[133]; |
| 1610 | int start_x = 0; |
| 1611 | |
| 1612 | va_start(ap, msg); |
| 1613 | vsnprintf(foo, 132, msg, ap); |
| 1614 | va_end(ap); |
| 1615 | |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 1616 | start_x = COLS / 2 - strlen(foo) / 2 - 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1617 | |
| 1618 | /* Blank out line */ |
| 1619 | blank_statusbar(); |
| 1620 | |
| 1621 | wmove(bottomwin, 0, start_x); |
| 1622 | |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1623 | #ifdef ENABLE_COLOR |
| 1624 | color_on(bottomwin, COLOR_STATUSBAR); |
| 1625 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1626 | wattron(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1627 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1628 | |
| 1629 | waddstr(bottomwin, "[ "); |
| 1630 | waddstr(bottomwin, foo); |
| 1631 | waddstr(bottomwin, " ]"); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1632 | |
| 1633 | #ifdef ENABLE_COLOR |
| 1634 | color_off(bottomwin, COLOR_STATUSBAR); |
| 1635 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1636 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | 8ce2413 | 2001-04-30 11:28:46 +0000 | [diff] [blame] | 1637 | #endif |
| 1638 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1639 | wrefresh(bottomwin); |
| 1640 | |
| 1641 | if (ISSET(CONSTUPDATE)) |
| 1642 | statblank = 1; |
| 1643 | else |
| 1644 | statblank = 25; |
| 1645 | } |
| 1646 | |
| 1647 | void display_main_list(void) |
| 1648 | { |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1649 | bottombars(main_list); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | int total_refresh(void) |
| 1653 | { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1654 | clearok(edit, TRUE); |
| 1655 | clearok(topwin, TRUE); |
| 1656 | clearok(bottomwin, TRUE); |
| 1657 | wnoutrefresh(edit); |
| 1658 | wnoutrefresh(topwin); |
| 1659 | wnoutrefresh(bottomwin); |
| 1660 | doupdate(); |
| 1661 | clearok(edit, FALSE); |
| 1662 | clearok(topwin, FALSE); |
| 1663 | clearok(bottomwin, FALSE); |
Chris Allegretta | f1d33d3 | 2000-08-19 03:53:39 +0000 | [diff] [blame] | 1664 | edit_refresh(); |
Chris Allegretta | f4b9601 | 2001-01-03 07:11:47 +0000 | [diff] [blame] | 1665 | titlebar(NULL); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1666 | return 1; |
| 1667 | } |
| 1668 | |
| 1669 | void previous_line(void) |
| 1670 | { |
| 1671 | if (current_y > 0) |
| 1672 | current_y--; |
| 1673 | } |
| 1674 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1675 | int do_cursorpos(int constant) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1676 | { |
| 1677 | filestruct *fileptr; |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1678 | float linepct = 0.0, bytepct = 0.0, colpct = 0.0; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1679 | long i = 0, j = 0; |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1680 | static long old_i = -1, old_totsize = -1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1681 | |
| 1682 | if (current == NULL || fileage == NULL) |
| 1683 | return 0; |
| 1684 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1685 | if (old_i == -1) |
| 1686 | old_i = i; |
| 1687 | |
| 1688 | if (old_totsize == -1) |
| 1689 | old_totsize = totsize; |
| 1690 | |
Chris Allegretta | f3a07b2 | 2002-03-29 15:15:38 +0000 | [diff] [blame] | 1691 | colpct = 100 * (xplustabs() + 1) / (xpt(current, strlen(current->data)) + 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1692 | |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1693 | for (fileptr = fileage; fileptr != current && fileptr != NULL; |
| 1694 | fileptr = fileptr->next) |
| 1695 | i += strlen(fileptr->data) + 1; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1696 | |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1697 | if (fileptr == NULL) |
| 1698 | return -1; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1699 | |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1700 | i += current_x; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1701 | |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1702 | j = totsize; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1703 | |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1704 | if (totsize > 0) |
| 1705 | bytepct = 100 * i / totsize; |
Chris Allegretta | 14b3ca9 | 2002-01-25 21:59:02 +0000 | [diff] [blame] | 1706 | |
| 1707 | if (totlines > 0) |
| 1708 | linepct = 100 * current->lineno / totlines; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1709 | |
| 1710 | #ifdef DEBUG |
| 1711 | fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"), |
| 1712 | linepct, bytepct); |
| 1713 | #endif |
| 1714 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1715 | /* if constant is zero, display the position on the statusbar |
| 1716 | unconditionally; otherwise, only display the position when the |
| 1717 | character values have changed */ |
| 1718 | if (!constant || (old_i != i || old_totsize != totsize)) { |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1719 | statusbar(_ |
Chris Allegretta | f27c697 | 2002-02-12 01:57:24 +0000 | [diff] [blame] | 1720 | ("line %d/%d (%.0f%%), col %ld/%ld (%.0f%%), char %ld/%ld (%.0f%%)"), |
Chris Allegretta | f3a07b2 | 2002-03-29 15:15:38 +0000 | [diff] [blame] | 1721 | current->lineno, totlines, linepct, xplustabs() + 1, |
| 1722 | xpt(current, strlen(current->data)) + 1, colpct, i, j, bytepct); |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | old_i = i; |
| 1726 | old_totsize = totsize; |
| 1727 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1728 | reset_cursor(); |
| 1729 | return 1; |
| 1730 | } |
| 1731 | |
Chris Allegretta | 2084acc | 2001-11-29 03:43:08 +0000 | [diff] [blame] | 1732 | int do_cursorpos_void(void) |
| 1733 | { |
| 1734 | return do_cursorpos(0); |
| 1735 | } |
| 1736 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 1737 | /* Our shortcut-list-compliant help function, which is |
| 1738 | * better than nothing, and dynamic! */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1739 | int do_help(void) |
| 1740 | { |
Rocco Corsi | af5c302 | 2001-01-12 07:51:05 +0000 | [diff] [blame] | 1741 | #ifndef DISABLE_HELP |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1742 | 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] | 1743 | int no_help_flag = 0; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1744 | shortcut *oldshortcut; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1745 | |
| 1746 | blank_edit(); |
| 1747 | curs_set(0); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1748 | wattroff(bottomwin, A_REVERSE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1749 | blank_statusbar(); |
| 1750 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 1751 | /* set help_text as the string to display */ |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1752 | help_init(); |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 1753 | assert(help_text != NULL); |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1754 | |
| 1755 | oldshortcut = currshortcut; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1756 | |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1757 | currshortcut = help_list; |
Chris Allegretta | 6fe6149 | 2001-05-21 12:56:25 +0000 | [diff] [blame] | 1758 | |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1759 | kp = keypad_on(edit, 1); |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1760 | kp2 = keypad_on(bottomwin, 1); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1761 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1762 | if (ISSET(NO_HELP)) { |
| 1763 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1764 | /* Well, if we're going to do this, we should at least |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1765 | do it the right way */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1766 | no_help_flag = 1; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1767 | UNSET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1768 | window_init(); |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1769 | bottombars(help_list); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1770 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1771 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1772 | bottombars(help_list); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1773 | |
| 1774 | do { |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 1775 | const char *ptr = help_text; |
| 1776 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1777 | switch (kbinput) { |
Chris Allegretta | 84de552 | 2001-04-12 14:51:48 +0000 | [diff] [blame] | 1778 | #ifndef DISABLE_MOUSE |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1779 | #ifdef NCURSES_MOUSE_VERSION |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1780 | case KEY_MOUSE: |
| 1781 | do_mouse(); |
| 1782 | break; |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1783 | #endif |
| 1784 | #endif |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1785 | case 27: |
| 1786 | kbinput = wgetch(edit); |
| 1787 | switch(kbinput) { |
| 1788 | case '[': |
| 1789 | kbinput = wgetch(edit); |
| 1790 | switch(kbinput) { |
| 1791 | case '5': /* Alt-[-5 = Page Up */ |
| 1792 | wgetch(edit); |
| 1793 | goto do_pageupkey; |
| 1794 | break; |
| 1795 | case 'V': /* Alt-[-V = Page Up in Hurd Console */ |
| 1796 | case 'I': /* Alt-[-I = Page Up - FreeBSD Console */ |
| 1797 | goto do_pageupkey; |
| 1798 | break; |
| 1799 | case '6': /* Alt-[-6 = Page Down */ |
| 1800 | wgetch(edit); |
| 1801 | goto do_pagedownkey; |
| 1802 | break; |
| 1803 | case 'U': /* Alt-[-U = Page Down in Hurd Console */ |
| 1804 | case 'G': /* Alt-[-G = Page Down - FreeBSD Console */ |
| 1805 | goto do_pagedownkey; |
| 1806 | break; |
| 1807 | } |
| 1808 | break; |
| 1809 | } |
| 1810 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1811 | case NANO_NEXTPAGE_KEY: |
| 1812 | case NANO_NEXTPAGE_FKEY: |
| 1813 | case KEY_NPAGE: |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1814 | do_pagedownkey: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1815 | if (!no_more) { |
| 1816 | blank_edit(); |
| 1817 | page++; |
| 1818 | } |
| 1819 | break; |
| 1820 | case NANO_PREVPAGE_KEY: |
| 1821 | case NANO_PREVPAGE_FKEY: |
| 1822 | case KEY_PPAGE: |
David Lawrence Ramsey | f21cd10 | 2002-06-13 00:40:19 +0000 | [diff] [blame] | 1823 | do_pageupkey: |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1824 | if (page > 1) { |
| 1825 | no_more = 0; |
| 1826 | blank_edit(); |
| 1827 | page--; |
| 1828 | } |
| 1829 | break; |
| 1830 | } |
| 1831 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1832 | /* Calculate where in the text we should be, based on the page */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1833 | for (i = 1; i < page; i++) { |
| 1834 | row = 0; |
| 1835 | j = 0; |
Chris Allegretta | 44e73df | 2000-09-07 03:37:38 +0000 | [diff] [blame] | 1836 | |
| 1837 | while (row < editwinrows - 2 && *ptr != '\0') { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1838 | if (*ptr == '\n' || j == COLS - 5) { |
| 1839 | j = 0; |
| 1840 | row++; |
| 1841 | } |
| 1842 | ptr++; |
| 1843 | j++; |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | i = 0; |
| 1848 | j = 0; |
| 1849 | while (i < editwinrows && *ptr != '\0') { |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 1850 | const char *end = ptr; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1851 | while (*end != '\n' && *end != '\0' && j != COLS - 5) { |
| 1852 | end++; |
| 1853 | j++; |
| 1854 | } |
| 1855 | if (j == COLS - 5) { |
| 1856 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1857 | /* 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] | 1858 | while (*end != ' ' && *end != '\0') { |
| 1859 | end--; |
| 1860 | j--; |
| 1861 | } |
| 1862 | } |
| 1863 | mvwaddnstr(edit, i, 0, ptr, j); |
| 1864 | j = 0; |
| 1865 | i++; |
| 1866 | if (*end == '\n') |
| 1867 | end++; |
| 1868 | ptr = end; |
| 1869 | } |
| 1870 | if (*ptr == '\0') { |
| 1871 | no_more = 1; |
| 1872 | continue; |
| 1873 | } |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1874 | } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY && |
| 1875 | kbinput != NANO_EXIT_FKEY); |
Chris Allegretta | d1627cf | 2000-12-18 05:03:16 +0000 | [diff] [blame] | 1876 | |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1877 | currshortcut = oldshortcut; |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1878 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1879 | if (no_help_flag) { |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1880 | blank_bottombars(); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1881 | wrefresh(bottomwin); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1882 | SET(NO_HELP); |
Chris Allegretta | 7044489 | 2001-01-07 23:02:02 +0000 | [diff] [blame] | 1883 | window_init(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1884 | } else |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 1885 | bottombars(currshortcut); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1886 | |
| 1887 | curs_set(1); |
| 1888 | edit_refresh(); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1889 | kp = keypad_on(edit, kp); |
Chris Allegretta | 6b58acd | 2001-04-12 03:01:53 +0000 | [diff] [blame] | 1890 | kp2 = keypad_on(bottomwin, kp2); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 1891 | |
Chris Allegretta | 3bc8c72 | 2000-12-10 17:03:25 +0000 | [diff] [blame] | 1892 | #elif defined(DISABLE_HELP) |
| 1893 | nano_disabled_msg(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1894 | #endif |
| 1895 | |
David Lawrence Ramsey | c596755 | 2002-06-21 03:20:06 +0000 | [diff] [blame^] | 1896 | /* The help_init() at the beginning allocated help_text, which has |
| 1897 | now been written to screen. */ |
| 1898 | free(help_text); |
| 1899 | help_text = NULL; |
| 1900 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1901 | return 1; |
| 1902 | } |
| 1903 | |
| 1904 | /* Dump the current file structure to stderr */ |
| 1905 | void dump_buffer(filestruct * inptr) |
| 1906 | { |
| 1907 | #ifdef DEBUG |
| 1908 | filestruct *fileptr; |
| 1909 | |
| 1910 | if (inptr == fileage) |
| 1911 | fprintf(stderr, _("Dumping file buffer to stderr...\n")); |
| 1912 | else if (inptr == cutbuffer) |
| 1913 | fprintf(stderr, _("Dumping cutbuffer to stderr...\n")); |
| 1914 | else |
| 1915 | fprintf(stderr, _("Dumping a buffer to stderr...\n")); |
| 1916 | |
| 1917 | fileptr = inptr; |
| 1918 | while (fileptr != NULL) { |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1919 | fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1920 | fflush(stderr); |
| 1921 | fileptr = fileptr->next; |
| 1922 | } |
| 1923 | #endif /* DEBUG */ |
| 1924 | } |
| 1925 | |
| 1926 | void dump_buffer_reverse(filestruct * inptr) |
| 1927 | { |
| 1928 | #ifdef DEBUG |
| 1929 | filestruct *fileptr; |
| 1930 | |
| 1931 | fileptr = filebot; |
| 1932 | while (fileptr != NULL) { |
Chris Allegretta | b3655b4 | 2001-10-22 03:15:31 +0000 | [diff] [blame] | 1933 | fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1934 | fflush(stderr); |
| 1935 | fileptr = fileptr->prev; |
| 1936 | } |
| 1937 | #endif /* DEBUG */ |
| 1938 | } |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1939 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1940 | /* Fix editbot, based on the assumption that edittop is correct */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1941 | void fix_editbot(void) |
| 1942 | { |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1943 | int i; |
| 1944 | editbot = edittop; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1945 | for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL) |
| 1946 | && (editbot != filebot); i++, editbot = editbot->next); |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1947 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1948 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1949 | /* highlight the current word being replaced or spell checked */ |
| 1950 | void do_replace_highlight(int highlight_flag, char *word) |
| 1951 | { |
| 1952 | char *highlight_word = NULL; |
| 1953 | int x, y; |
| 1954 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1955 | highlight_word = |
| 1956 | mallocstrcpy(highlight_word, ¤t->data[current_x]); |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1957 | highlight_word[strlen(word)] = '\0'; |
| 1958 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 1959 | /* adjust output when word extends beyond screen */ |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1960 | |
| 1961 | x = xplustabs(); |
| 1962 | y = get_page_end_virtual(get_page_from_virtual(x)) + 1; |
| 1963 | |
| 1964 | if ((COLS - (y - x) + strlen(word)) > COLS) { |
| 1965 | highlight_word[y - x - 1] = '$'; |
| 1966 | highlight_word[y - x] = '\0'; |
| 1967 | } |
| 1968 | |
| 1969 | /* OK display the output */ |
| 1970 | |
| 1971 | reset_cursor(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 1972 | |
Chris Allegretta | fb62f73 | 2000-12-05 11:36:41 +0000 | [diff] [blame] | 1973 | if (highlight_flag) |
| 1974 | wattron(edit, A_REVERSE); |
| 1975 | |
| 1976 | waddstr(edit, highlight_word); |
| 1977 | |
| 1978 | if (highlight_flag) |
| 1979 | wattroff(edit, A_REVERSE); |
| 1980 | |
| 1981 | free(highlight_word); |
| 1982 | } |
| 1983 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1984 | #ifdef NANO_EXTRA |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 1985 | #define CREDIT_LEN 52 |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1986 | void do_credits(void) |
| 1987 | { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 1988 | int i, j = 0, k, place = 0, start_x; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1989 | char *what; |
| 1990 | |
| 1991 | char *nanotext = _("The nano text editor"); |
| 1992 | char *version = _("version "); |
| 1993 | char *brought = _("Brought to you by:"); |
| 1994 | char *specialthx = _("Special thanks to:"); |
| 1995 | char *fsf = _("The Free Software Foundation"); |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 1996 | char *ncurses = _("For ncurses:"); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 1997 | char *anyonelse = _("and anyone else we forgot..."); |
| 1998 | char *thankyou = _("Thank you for using nano!\n"); |
| 1999 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2000 | char *credits[CREDIT_LEN] = { nanotext, |
| 2001 | version, |
| 2002 | VERSION, |
| 2003 | "", |
| 2004 | brought, |
| 2005 | "Chris Allegretta", |
| 2006 | "Jordi Mallach", |
| 2007 | "Adam Rogoyski", |
| 2008 | "Rob Siemborski", |
| 2009 | "Rocco Corsi", |
Chris Allegretta | a8c2257 | 2002-02-15 19:17:02 +0000 | [diff] [blame] | 2010 | "David Lawrence Ramsey", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2011 | "Ken Tyler", |
| 2012 | "Sven Guckes", |
| 2013 | "Florian König", |
| 2014 | "Pauli Virtanen", |
| 2015 | "Daniele Medri", |
| 2016 | "Clement Laforet", |
| 2017 | "Tedi Heriyanto", |
| 2018 | "Bill Soudan", |
| 2019 | "Christian Weisgerber", |
| 2020 | "Erik Andersen", |
| 2021 | "Big Gaute", |
| 2022 | "Joshua Jensen", |
| 2023 | "Ryan Krebs", |
| 2024 | "Albert Chin", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2025 | "", |
| 2026 | specialthx, |
| 2027 | "Plattsburgh State University", |
| 2028 | "Benet Laboratories", |
| 2029 | "Amy Allegretta", |
| 2030 | "Linda Young", |
| 2031 | "Jeremy Robichaud", |
| 2032 | "Richard Kolb II", |
| 2033 | fsf, |
| 2034 | "Linus Torvalds", |
| 2035 | ncurses, |
Chris Allegretta | dce44ab | 2002-03-16 01:03:41 +0000 | [diff] [blame] | 2036 | "Thomas Dickey", |
| 2037 | "Pavel Curtis", |
| 2038 | "Zeyd Ben-Halim", |
| 2039 | "Eric S. Raymond", |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2040 | anyonelse, |
| 2041 | thankyou, |
| 2042 | "", "", "", "", |
| 2043 | "(c) 1999-2002 Chris Allegretta", |
| 2044 | "", "", "", "", |
| 2045 | "www.nano-editor.org" |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2046 | }; |
| 2047 | |
| 2048 | curs_set(0); |
| 2049 | nodelay(edit, TRUE); |
| 2050 | blank_bottombars(); |
| 2051 | mvwaddstr(topwin, 0, 0, hblank); |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2052 | blank_edit(); |
| 2053 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2054 | wrefresh(bottomwin); |
| 2055 | wrefresh(topwin); |
| 2056 | |
| 2057 | while (wgetch(edit) == ERR) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2058 | for (k = 0; k <= 1; k++) { |
| 2059 | blank_edit(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2060 | for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); |
| 2061 | i--) { |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2062 | mvwaddstr(edit, i * 2 - k, 0, hblank); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2063 | |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2064 | if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN) |
| 2065 | what = credits[place - (editwinrows / 2 - 1 - i)]; |
| 2066 | else |
| 2067 | what = ""; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2068 | |
Chris Allegretta | 17dcb72 | 2001-01-20 21:40:07 +0000 | [diff] [blame] | 2069 | start_x = COLS / 2 - strlen(what) / 2 - 1; |
Chris Allegretta | 8b4ca4a | 2000-11-25 18:21:37 +0000 | [diff] [blame] | 2070 | mvwaddstr(edit, i * 2 - k, start_x, what); |
| 2071 | } |
| 2072 | usleep(700000); |
| 2073 | wrefresh(edit); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2074 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2075 | if (j < editwinrows / 2 - 1) |
| 2076 | j++; |
| 2077 | |
| 2078 | place++; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2079 | |
| 2080 | if (place >= CREDIT_LEN + editwinrows / 2) |
| 2081 | break; |
| 2082 | } |
| 2083 | |
| 2084 | nodelay(edit, FALSE); |
| 2085 | curs_set(1); |
| 2086 | display_main_list(); |
| 2087 | total_refresh(); |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2088 | } |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 2089 | #endif |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 2090 | |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2091 | int keypad_on(WINDOW * win, int newval) |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 2092 | { |
| 2093 | |
Chris Allegretta | 88520c9 | 2001-05-05 17:45:54 +0000 | [diff] [blame] | 2094 | /* This is taken right from aumix. Don't sue me. */ |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 2095 | #ifdef HAVE_USEKEYPAD |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2096 | int old; |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 2097 | |
| 2098 | old = win->_use_keypad; |
Chris Allegretta | e316773 | 2001-03-18 16:59:34 +0000 | [diff] [blame] | 2099 | keypad(win, newval); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 2100 | return old; |
| 2101 | #else |
Chris Allegretta | e316773 | 2001-03-18 16:59:34 +0000 | [diff] [blame] | 2102 | keypad(win, newval); |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 2103 | return 1; |
Chris Allegretta | 598106e | 2002-01-19 01:59:37 +0000 | [diff] [blame] | 2104 | #endif /* HAVE_USEKEYPAD */ |
Chris Allegretta | c08f50d | 2001-01-06 18:12:43 +0000 | [diff] [blame] | 2105 | |
| 2106 | } |