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