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