blob: 6405adcc5936995da7e25515c7e071abe18a434d [file] [log] [blame]
Chris Allegretta11b00112000-08-06 21:13:45 +00001/* $Id$ */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00002/**************************************************************************
3 * winio.c *
4 * *
5 * Copyright (C) 1999 Chris Allegretta *
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 *
8 * the Free Software Foundation; either version 1, or (at your option) *
9 * any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
19 * *
20 **************************************************************************/
21
22#include <stdarg.h>
23#include <string.h>
Chris Allegrettadba37ae2000-07-07 05:13:09 +000024#include <stdlib.h>
Chris Allegretta8a0de3b2000-11-24 20:45:14 +000025#include <unistd.h>
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000026#include "config.h"
27#include "proto.h"
28#include "nano.h"
29
30#ifndef NANO_SMALL
31#include <libintl.h>
32#define _(string) gettext(string)
33#else
34#define _(string) (string)
35#endif
36
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +000037
38/* winio.c statics */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000039static int statblank = 0; /* Number of keystrokes left after
40 we call statubar() before we
41 actually blank the statusbar */
Robert Siemborskid8510b22000-06-06 23:04:06 +000042
43/* Local Function Prototypes for only winio.c */
44inline int get_page_from_virtual(int virtual);
45inline int get_page_start_virtual(int page);
46inline int get_page_end_virtual(int page);
47
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000048/* Window I/O */
49
50int do_first_line(void)
51{
52 current = fileage;
53 placewewant = 0;
54 current_x = 0;
Chris Allegretta234a34d2000-07-29 04:33:38 +000055 edit_update(current, CENTER);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000056 return 1;
57}
58
59int do_last_line(void)
60{
61 current = filebot;
62 placewewant = 0;
63 current_x = 0;
Chris Allegretta234a34d2000-07-29 04:33:38 +000064 edit_update(current, CENTER);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000065 return 1;
66}
67
68/* Like xplustabs, but for a specifc index of a speficific filestruct */
69int xpt(filestruct * fileptr, int index)
70{
71 int i, tabs = 0;
72
73 if (fileptr == NULL || fileptr->data == NULL)
74 return 0;
75
76 for (i = 0; i < index && fileptr->data[i] != 0; i++) {
77 tabs++;
78
79 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta6d690a32000-08-03 22:51:21 +000080 if (tabs % tabsize == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000081 else
Chris Allegretta6d690a32000-08-03 22:51:21 +000082 tabs += tabsize - (tabs % tabsize);
Chris Allegretta4da1fc62000-06-21 03:00:43 +000083 } else if (fileptr->data[i] & 0x80)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000084 /* Make 8 bit chars only 1 collumn! */
85 ;
86 else if (fileptr->data[i] < 32)
87 tabs++;
88 }
89
90 return tabs;
91}
92
93
94/* Return the actual place on the screen of current->data[current_x], which
95 should always be > current_x */
96int xplustabs(void)
97{
98 return xpt(current, current_x);
99}
100
101
Robert Siemborskid8510b22000-06-06 23:04:06 +0000102/* Return what current_x should be, given xplustabs() for the line,
103 * given a start position in the filestruct's data */
104int actual_x_from_start(filestruct * fileptr, int xplus, int start)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000105{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000106 int i, tot = 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000107
108 if (fileptr == NULL || fileptr->data == NULL)
109 return 0;
110
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000111 for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000112 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta6d690a32000-08-03 22:51:21 +0000113 if (tot % tabsize == 0)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000114 tot++;
115 else
Chris Allegretta6d690a32000-08-03 22:51:21 +0000116 tot += tabsize - (tot % tabsize);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000117 } else if (fileptr->data[i] & 0x80)
118 tot++; /* Make 8 bit chars only 1 column (again) */
119 else if (fileptr->data[i] < 32)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000120 tot += 2;
121
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000122#ifdef DEBUG
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000123 fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"),
124 xplus, i);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000125#endif
Robert Siemborskid8510b22000-06-06 23:04:06 +0000126 return i - start;
127}
128
129/* Opposite of xplustabs */
130inline int actual_x(filestruct * fileptr, int xplus)
131{
132 return actual_x_from_start(fileptr, xplus, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000133}
134
135/* a strlen with tabs factored in, similar to xplustabs() */
136int strlenpt(char *buf)
137{
138 int i, tabs = 0;
139
140 if (buf == NULL)
141 return 0;
142
143 for (i = 0; buf[i] != 0; i++) {
144 tabs++;
145
146 if (buf[i] == NANO_CONTROL_I) {
Chris Allegretta6d690a32000-08-03 22:51:21 +0000147 if (tabs % tabsize == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000148 else
Chris Allegretta6d690a32000-08-03 22:51:21 +0000149 tabs += tabsize - (tabs % tabsize);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000150 } else if (buf[i] & 0x80)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000151 /* Make 8 bit chars only 1 collumn! */
152 ;
153 else if (buf[i] < 32)
154 tabs++;
155 }
156
157 return tabs;
158}
159
160
161/* resets current_y based on the position of current and puts the cursor at
162 (current_y, current_x) */
163void reset_cursor(void)
164{
165 filestruct *ptr = edittop;
166 int x;
167
168 current_y = 0;
169
170 while (ptr != current && ptr != editbot && ptr->next != NULL) {
171 ptr = ptr->next;
172 current_y++;
173 }
174
175 x = xplustabs();
176 if (x <= COLS - 2)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000177 wmove(edit, current_y, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000178 else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000179 wmove(edit, current_y, x -
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000180 get_page_start_virtual(get_page_from_virtual(x)));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000181
182}
183
184void blank_bottombars(void)
185{
186 int i = no_help()? 3 : 1;
187
188 for (; i <= 2; i++)
189 mvwaddstr(bottomwin, i, 0, hblank);
190
191}
192
193void blank_edit(void)
194{
195 int i;
196 for (i = 0; i <= editwinrows - 1; i++)
197 mvwaddstr(edit, i, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000198}
199
200
201void blank_statusbar(void)
202{
203 mvwaddstr(bottomwin, 0, 0, hblank);
204}
205
206void blank_statusbar_refresh(void)
207{
208 blank_statusbar();
209 wrefresh(bottomwin);
210}
211
212void check_statblank(void)
213{
214
215 if (statblank > 1)
216 statblank--;
217 else if (statblank == 1 && !ISSET(CONSTUPDATE)) {
218 statblank--;
219 blank_statusbar_refresh();
220 }
221}
222
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000223/* Repaint the statusbar when getting a character in nanogetstr */
224void nanoget_repaint(char *buf, char *inputbuf, int x)
225{
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000226 int len = strlen(buf);
227 int wid = COLS - len;
228
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000229 blank_statusbar();
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000230 if (x <= COLS - 1) {
231 /* Black magic */
232 buf[len - 1] = ' ';
Chris Allegretta31925e42000-11-02 04:40:39 +0000233
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000234 mvwaddstr(bottomwin, 0, 0, buf);
235 waddnstr(bottomwin, inputbuf, wid);
236 wmove(bottomwin, 0, (x % COLS));
237 }
238 else {
239 /* Black magic */
240 buf[len - 1] = '$';
Chris Allegretta31925e42000-11-02 04:40:39 +0000241
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000242 mvwaddstr(bottomwin, 0, 0, buf);
243 waddnstr(bottomwin, &inputbuf[wid * ((x - len) / (wid))], wid);
244 wmove(bottomwin, 0, ((x - len) % wid) + len);
245 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000246}
247
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000248/* Get the input from the kb, this should only be called from statusq */
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000249int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
250 int start_x)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000251{
252 int kbinput = 0, j = 0, x = 0, xend;
Chris Allegrettabe77c612000-11-24 14:00:16 +0000253 int x_left = 0, inputlen, tabbed = 0;
Chris Allegretta31925e42000-11-02 04:40:39 +0000254 char *inputbuf;
Rocco Corsi06aca1c2001-01-11 05:30:31 +0000255#ifndef DISABLE_TABCOMP
Chris Allegrettabe77c612000-11-24 14:00:16 +0000256 int shift = 0;
257#endif
Chris Allegretta31925e42000-11-02 04:40:39 +0000258
259 inputbuf = nmalloc(strlen(def) + 1);
260 inputbuf[0] = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000261
262 x_left = strlen(buf);
263 x = strlen(def) + x_left;
264
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000265 currshortcut = s;
266 currslen = slen;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000267 /* Get the input! */
Chris Allegretta31925e42000-11-02 04:40:39 +0000268 if (strlen(def) > 0)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000269 strcpy(inputbuf, def);
Chris Allegretta31925e42000-11-02 04:40:39 +0000270
271 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000272
Chris Allegretta022b96f2000-11-14 17:47:58 +0000273 /* Make sure any editor screen updates are displayed before getting input */
274 wrefresh(edit);
275
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000276 while ((kbinput = wgetch(bottomwin)) != 13) {
277 for (j = 0; j <= slen - 1; j++) {
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000278#ifdef DEBUG
279 fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
280#endif
281
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000282 if (kbinput == s[j].val) {
Chris Allegretta5bf51d32000-11-16 06:01:10 +0000283
284 /* We shouldn't discard the answer it gave, just because
285 we hit a keystroke, GEEZ! */
286 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000287 free(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000288 return s[j].val;
289 }
290 }
291 xend = strlen(buf) + strlen(inputbuf);
292
Chris Allegretta04d848e2000-11-05 17:54:41 +0000293 if (kbinput != '\t')
294 tabbed = 0;
295
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000296 switch (kbinput) {
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000297
298 /* Stuff we want to equate with <enter>, ASCII 13 */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000299 case 343:
Chris Allegrettaf9b6c9b2000-10-18 19:35:59 +0000300 ungetch(13); /* Enter on iris-ansi $TERM, sometimes */
301 break;
Chris Allegretta75155df2000-11-28 23:04:24 +0000302 /* Stuff we want to ignore */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000303#ifdef PDCURSES
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000304 case 541:
305 case 542:
Chris Allegretta72623582000-11-29 23:43:28 +0000306 case 543: /* Right ctrl again */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000307 case 544:
Chris Allegretta72623582000-11-29 23:43:28 +0000308 case 545: /* Right alt again */
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000309 break;
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000310#endif
Chris Allegretta84de5522001-04-12 14:51:48 +0000311#ifndef DISABLE_MOUSE
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000312#ifdef NCURSES_MOUSE_VERSION
313 case KEY_MOUSE:
314 do_mouse();
315 break;
316#endif
317#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000318 case KEY_HOME:
319 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000320 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000321 break;
322 case KEY_END:
323 x = x_left + strlen(inputbuf);
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000324 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000325 break;
326 case KEY_RIGHT:
Chris Allegretta35dac582001-03-21 15:07:20 +0000327 case NANO_FORWARD_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000328
329 if (x < xend)
330 x++;
331 wmove(bottomwin, 0, x);
332 break;
333 case NANO_CONTROL_D:
334 if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
335 memmove(inputbuf + (x - x_left),
336 inputbuf + (x - x_left) + 1,
337 strlen(inputbuf) - (x - x_left) - 1);
338 inputbuf[strlen(inputbuf) - 1] = 0;
339 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000340 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000341 break;
342 case NANO_CONTROL_K:
343 case NANO_CONTROL_U:
344 *inputbuf = 0;
345 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000346 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000347 break;
348 case KEY_BACKSPACE:
349 case KEY_DC:
350 case 127:
351 case NANO_CONTROL_H:
352 if (strlen(inputbuf) > 0) {
353 if (x == (x_left + strlen(inputbuf)))
354 inputbuf[strlen(inputbuf) - 1] = 0;
355 else if (x - x_left) {
356 memmove(inputbuf + (x - x_left) - 1,
357 inputbuf + (x - x_left),
358 strlen(inputbuf) - (x - x_left));
359 inputbuf[strlen(inputbuf) - 1] = 0;
360 }
361 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000362 if (x > strlen(buf))
363 x--;
Chris Allegretta31925e42000-11-02 04:40:39 +0000364 nanoget_repaint(buf, inputbuf, x);
Chris Allegretta04d848e2000-11-05 17:54:41 +0000365 break;
Rocco Corsi06aca1c2001-01-11 05:30:31 +0000366#ifndef DISABLE_TABCOMP
Chris Allegretta04d848e2000-11-05 17:54:41 +0000367 case NANO_CONTROL_I:
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000368 if (allowtabs) {
Chris Allegretta442f2c52000-11-14 17:46:06 +0000369 shift = 0;
370 inputbuf = input_tab(inputbuf, (x - x_left),
Chris Allegrettab5b89ae2000-11-14 18:25:26 +0000371 &tabbed, &shift);
Chris Allegretta442f2c52000-11-14 17:46:06 +0000372 x += shift;
Chris Allegrettae434b452001-01-27 19:25:00 +0000373 if (x - x_left > strlen(inputbuf))
374 x = strlen(inputbuf) + x_left;
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000375 nanoget_repaint(buf, inputbuf, x);
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000376 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000377 break;
Chris Allegrettabe77c612000-11-24 14:00:16 +0000378#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000379 case KEY_LEFT:
Chris Allegretta35dac582001-03-21 15:07:20 +0000380 case NANO_BACK_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000381 if (x > strlen(buf))
382 x--;
383 wmove(bottomwin, 0, x);
384 break;
385 case KEY_UP:
386 case KEY_DOWN:
387 break;
388
389 case 27:
390 switch (kbinput = wgetch(edit)) {
391 case 79:
392 switch (kbinput = wgetch(edit)) {
393 case 70:
394 x = x_left + strlen(inputbuf);
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000395 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000396 break;
397 case 72:
398 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000399 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000400 break;
401 }
402 break;
403 case 91:
404 switch (kbinput = wgetch(edit)) {
405 case 'C':
406 if (x < xend)
407 x++;
408 wmove(bottomwin, 0, x);
409 break;
410 case 'D':
411 if (x > strlen(buf))
412 x--;
413 wmove(bottomwin, 0, x);
414 break;
415 case 49:
416 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000417 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000418 goto skip_126;
419 case 51:
420 if (strlen(inputbuf) > 0
421 && (x - x_left) != strlen(inputbuf)) {
422 memmove(inputbuf + (x - x_left),
423 inputbuf + (x - x_left) + 1,
424 strlen(inputbuf) - (x - x_left) - 1);
425 inputbuf[strlen(inputbuf) - 1] = 0;
426 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000427 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000428 goto skip_126;
429 case 52:
430 x = x_left + strlen(inputbuf);
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000431 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000432 goto skip_126;
433 skip_126:
434 nodelay(edit, TRUE);
435 kbinput = wgetch(edit);
436 if (kbinput == 126 || kbinput == ERR)
437 kbinput = -1;
438 nodelay(edit, FALSE);
439 break;
440 }
441 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000442 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000443 break;
444
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000445 default:
446 if (kbinput < 32)
447 break;
Chris Allegretta31925e42000-11-02 04:40:39 +0000448
449 inputlen = strlen(inputbuf);
450 inputbuf = nrealloc(inputbuf, inputlen + 2);
451
452 memmove(&inputbuf[x - x_left + 1],
453 &inputbuf[x - x_left],
454 inputlen - (x - x_left) + 1);
455 inputbuf[x - x_left] = kbinput;
456
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000457 x++;
458
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000459 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000460#ifdef DEBUG
461 fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
462#endif
463 }
464 wrefresh(bottomwin);
465 }
466
Chris Allegretta31925e42000-11-02 04:40:39 +0000467 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000468 free(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000469
Chris Allegretta105da332000-10-31 05:10:10 +0000470 /* Now that the text is editable instead of bracketed, we have to
471 check for answer == def, instead of answer == "" */
Chris Allegrettabf9a8cc2000-11-17 01:37:39 +0000472 if (((ISSET(PICO_MODE)) && !strcmp(answer, "")) ||
473 ((!ISSET(PICO_MODE)) && !strcmp(answer, def)))
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000474 return -2;
475 else
476 return 0;
477}
478
479void horizbar(WINDOW * win, int y)
480{
481 wattron(win, A_REVERSE);
482 mvwaddstr(win, 0, 0, hblank);
483 wattroff(win, A_REVERSE);
484}
485
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000486void titlebar(char *path)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000487{
488 int namelen, space;
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000489 char *what = path;
490
491 if (path == NULL)
492 what = filename;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000493
494 horizbar(topwin, 0);
495 wattron(topwin, A_REVERSE);
496 mvwaddstr(topwin, 0, 3, VERMSG);
497
498 space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
499
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000500 namelen = strlen(what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000501
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000502 if (!strcmp(what, ""))
Chris Allegretta17dcb722001-01-20 21:40:07 +0000503 mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000504 else {
505 if (namelen > space) {
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000506 if (path == NULL)
507 waddstr(topwin, _(" File: ..."));
508 else
509 waddstr(topwin, _(" DIR: ..."));
510 waddstr(topwin, &what[namelen - space]);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000511 } else {
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000512 if (path == NULL)
Chris Allegretta17dcb722001-01-20 21:40:07 +0000513 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), "File: ");
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000514 else
Chris Allegretta17dcb722001-01-20 21:40:07 +0000515 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), " DIR: ");
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000516 waddstr(topwin, what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000517 }
518 }
519 if (ISSET(MODIFIED))
520 mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
521 wattroff(topwin, A_REVERSE);
522 wrefresh(topwin);
523 reset_cursor();
524}
525
526void onekey(char *keystroke, char *desc)
527{
528 char description[80];
529
Chris Allegrettae7034c62000-09-15 03:31:09 +0000530 snprintf(description, 12, " %-10s", desc);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000531 wattron(bottomwin, A_REVERSE);
532 waddstr(bottomwin, keystroke);
533 wattroff(bottomwin, A_REVERSE);
534 waddstr(bottomwin, description);
535}
536
537void clear_bottomwin(void)
538{
539 if (ISSET(NO_HELP))
540 return;
541
542 mvwaddstr(bottomwin, 1, 0, hblank);
543 mvwaddstr(bottomwin, 2, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000544}
545
546void bottombars(shortcut s[], int slen)
547{
548 int i, j, k;
549 char keystr[10];
550
551 if (ISSET(NO_HELP))
552 return;
553
554 /* Determine how many extra spaces are needed to fill the bottom of the screen */
555 k = COLS / 6 - 13;
556
557 clear_bottomwin();
558 wmove(bottomwin, 1, 0);
559 for (i = 0; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000560 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000561 onekey(keystr, s[i].desc);
562
563 for (j = 0; j < k; j++)
564 waddch(bottomwin, ' ');
565 }
566
567 wmove(bottomwin, 2, 0);
568 for (i = 1; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000569 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000570 onekey(keystr, s[i].desc);
571
572 for (j = 0; j < k; j++)
573 waddch(bottomwin, ' ');
574 }
575
576 wrefresh(bottomwin);
577
578}
579
580/* If modified is not already set, set it and update titlebar */
581void set_modified(void)
582{
583 if (!ISSET(MODIFIED)) {
584 SET(MODIFIED);
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000585 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000586 wrefresh(topwin);
587 }
588}
589
Robert Siemborski9d584552000-07-08 00:41:29 +0000590/* And so start the display update routines */
591/* Given a column, this returns the "page" it is on */
592/* "page" in the case of the display columns, means which set of 80 */
593/* characters is viewable (ie: page 1 shows from 1 to COLS) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000594inline int get_page_from_virtual(int virtual)
595{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000596 int page = 2;
597
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000598 if (virtual <= COLS - 2)
599 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000600 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000601
602 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000603 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000604 page++;
605 }
606
607 return page;
608}
609
Robert Siemborski9d584552000-07-08 00:41:29 +0000610/* The inverse of the above function */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000611inline int get_page_start_virtual(int page)
612{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000613 int virtual;
614 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000615 if (page)
616 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000617 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000618}
619
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000620inline int get_page_end_virtual(int page)
621{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000622 return get_page_start_virtual(page) + COLS - 1;
623}
624
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000625#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000626/* This takes care of the case where there is a mark that covers only */
627/* the current line. */
628
Chris Allegrettab275aac2000-07-08 01:22:33 +0000629/* It expects a line with no tab characers (ie: the type that edit_add */
Robert Siemborski9d584552000-07-08 00:41:29 +0000630/* deals with */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000631void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
632 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000633{
Robert Siemborski9d584552000-07-08 00:41:29 +0000634 /*
635 * The general idea is to break the line up into 3 sections: before
636 * the mark, the mark, and after the mark. We then paint each in
637 * turn (for those that are currently visible, of course
638 *
639 * 3 start points: 0 -> begin, begin->end, end->strlen(data)
640 * in data : pre sel post
641 */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000642 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000643 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000644
Robert Siemborskid8510b22000-06-06 23:04:06 +0000645 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000646 int pre_data_len = begin, sel_data_len = end - begin, post_data_len = 0; /* Determined from the other two */
Robert Siemborskid8510b22000-06-06 23:04:06 +0000647
648 /* now fix the start locations & lengths according to the cursor's
649 * position (ie: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000650 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000651 pre_data_len = 0;
652 else
653 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000654
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000655 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000656 begin = this_page_start;
657
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000658 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000659 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000660
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000661 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000662 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000663
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000664 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000665 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000666
Robert Siemborski9d584552000-07-08 00:41:29 +0000667 /* Now calculate the lengths */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000668 sel_data_len = end - begin;
669 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000670
Robert Siemborski9d584552000-07-08 00:41:29 +0000671 /* Paint this line! */
Robert Siemborski53875912000-06-16 04:25:30 +0000672 mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000673 wattron(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000674 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000675 &fileptr->data[begin], sel_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000676 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000677 mvwaddnstr(edit, y, end - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000678 &fileptr->data[end], post_data_len);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000679}
680#endif
681
Robert Siemborski9d584552000-07-08 00:41:29 +0000682/* edit_add takes care of the job of actually painting a line into the
683 * edit window.
684 *
685 * Called only from update_line. Expects a converted-to-not-have-tabs
Robert Siemborski53875912000-06-16 04:25:30 +0000686 * line */
687void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000688 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000689{
690#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000691 /* There are quite a few cases that could take place, we'll deal
692 * with them each in turn */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000693 if (ISSET(MARK_ISSET)
Robert Siemborski9d584552000-07-08 00:41:29 +0000694 && !((fileptr->lineno > mark_beginbuf->lineno
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000695 && fileptr->lineno > current->lineno)
696 || (fileptr->lineno < mark_beginbuf->lineno
697 && fileptr->lineno < current->lineno))) {
698 /* If we get here we are on a line that is atleast
699 * partially selected. The lineno checks above determined
700 * that */
701 if (fileptr != mark_beginbuf && fileptr != current) {
702 /* We are on a completely marked line, paint it all
703 * inverse */
704 wattron(edit, A_REVERSE);
705 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
706 wattroff(edit, A_REVERSE);
707 } else if (fileptr == mark_beginbuf && fileptr == current) {
708 /* Special case, we're still on the same line we started
709 * marking -- so we call our helper function */
710 if (virt_cur_x < virt_mark_beginx) {
711 /* To the right of us is marked */
712 add_marked_sameline(virt_cur_x, virt_mark_beginx,
713 fileptr, yval, virt_cur_x, this_page);
714 } else {
715 /* To the left of us is marked */
716 add_marked_sameline(virt_mark_beginx, virt_cur_x,
717 fileptr, yval, virt_cur_x, this_page);
718 }
719 } else if (fileptr == mark_beginbuf) {
720 /*
721 * we're updating the line that was first marked
722 * but we're not currently on it. So we want to
Robert Siemborskia0238ed2001-03-31 21:46:43 +0000723 * figure out which half to invert based on our
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000724 * relative line numbers.
725 *
726 * i.e. If we're above the "beginbuf" line, we want to
727 * mark the left side. Otherwise we're below, so we
728 * mark the right
729 */
730 int target;
731
732 if (mark_beginbuf->lineno > current->lineno)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000733 wattron(edit, A_REVERSE);
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000734
735 target =
736 (virt_mark_beginx <
737 COLS - 1) ? virt_mark_beginx : COLS - 1;
738
739 mvwaddnstr(edit, yval, 0, fileptr->data, target);
740
741 if (mark_beginbuf->lineno < current->lineno)
742 wattron(edit, A_REVERSE);
743 else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000744 wattroff(edit, A_REVERSE);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000745
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000746 target = (COLS - 1) - virt_mark_beginx;
747 if (target < 0)
748 target = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000749
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000750 mvwaddnstr(edit, yval, virt_mark_beginx,
751 &fileptr->data[virt_mark_beginx], target);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000752
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000753 if (mark_beginbuf->lineno < current->lineno)
754 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000755
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000756 } else if (fileptr == current) {
Robert Siemborskia0238ed2001-03-31 21:46:43 +0000757 /* we're on the cursor's line, but it's not the first
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000758 * one we marked. Similar to the previous logic. */
759 int this_page_start = get_page_start_virtual(this_page),
760 this_page_end = get_page_end_virtual(this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000761
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000762 if (mark_beginbuf->lineno < current->lineno)
763 wattron(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000764
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000765 if (virt_cur_x > COLS - 2) {
766 mvwaddnstr(edit, yval, 0,
767 &fileptr->data[this_page_start],
768 virt_cur_x - this_page_start);
769 } else {
770 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
771 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000772
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000773 if (mark_beginbuf->lineno > current->lineno)
774 wattron(edit, A_REVERSE);
775 else
776 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000777
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000778 if (virt_cur_x > COLS - 2)
779 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
780 &fileptr->data[virt_cur_x],
781 this_page_end - virt_cur_x);
782 else
783 mvwaddnstr(edit, yval, virt_cur_x,
784 &fileptr->data[virt_cur_x], COLS - virt_cur_x);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000785
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000786 if (mark_beginbuf->lineno > current->lineno)
787 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000788 }
789
790 } else
791#endif
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000792 /* Just paint the string (no mark on this line) */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000793 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
Chris Allegretta908805a2000-12-04 04:42:56 +0000794 get_page_end_virtual(this_page) - start + 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000795}
796
797/*
Robert Siemborski9d584552000-07-08 00:41:29 +0000798 * Just update one line in the edit buffer. Basically a wrapper for
799 * edit_add
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000800 *
801 * index gives is a place in the string to update starting from.
802 * Likely args are current_x or 0.
803 */
804void update_line(filestruct * fileptr, int index)
805{
806 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +0000807 int line = 0, col = 0;
808 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
809 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000810 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000811
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000812 if (!fileptr)
813 return;
Robert Siemborski53154a72000-06-18 00:11:03 +0000814
Robert Siemborski53875912000-06-16 04:25:30 +0000815 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000816 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
817 filetmp = filetmp->next)
818 line++;
819
820 mvwaddstr(edit, line, 0, hblank);
821
Robert Siemborski53875912000-06-16 04:25:30 +0000822 /* Next, convert all the tabs to spaces so everything else is easy */
823 index = xpt(fileptr, index);
824
825 realdata = fileptr->data;
826 len = strlen(realdata);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000827 fileptr->data = nmalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +0000828
829 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000830 for (i = 0; i < len; i++) {
831 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +0000832 do {
833 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000834 if (i < current_x)
835 virt_cur_x++;
836 if (i < mark_beginx)
837 virt_mark_beginx++;
Chris Allegretta6d690a32000-08-03 22:51:21 +0000838 } while (pos % tabsize);
Robert Siemborski53875912000-06-16 04:25:30 +0000839 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000840 if (i < current_x)
841 virt_cur_x--;
842 if (i < mark_beginx)
843 virt_mark_beginx--;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000844 } else if (realdata[i] >= 1 && realdata[i] <= 26) {
845 /* Treat control characters as ^letter */
Chris Allegretta6306a112000-09-02 07:55:41 +0000846 fileptr->data[pos++] = '^';
847 fileptr->data[pos++] = realdata[i] + 64;
Robert Siemborski53875912000-06-16 04:25:30 +0000848 } else {
849 fileptr->data[pos++] = realdata[i];
850 }
851 }
852
853 fileptr->data[pos] = '\0';
854
855 /* Now, Paint the line */
856 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000857 /* This handles when the current line is beyond COLS */
858 /* It requires figureing out what page we're at */
859 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000860 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000861
Robert Siemborskia9addc72000-06-17 06:06:35 +0000862 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000863 mvwaddch(edit, line, 0, '$');
864
Chris Allegrettafb62f732000-12-05 11:36:41 +0000865 if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000866 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000867 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000868 /* It's not the current line means that it's at x=0 and page=1 */
869 /* If it is the current line, then we're in the same boat */
870 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000871
Robert Siemborski53875912000-06-16 04:25:30 +0000872 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000873 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000874 }
Robert Siemborski53875912000-06-16 04:25:30 +0000875
876 /* Clean up our mess */
877 tmp = fileptr->data;
878 fileptr->data = realdata;
879 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000880}
881
882void center_cursor(void)
883{
884 current_y = editwinrows / 2;
885 wmove(edit, current_y, current_x);
886}
887
888/* Refresh the screen without changing the position of lines */
889void edit_refresh(void)
890{
Chris Allegrettaed022162000-08-03 16:54:11 +0000891 static int noloop = 0;
Chris Allegretta95b0b522000-07-28 02:58:06 +0000892 int lines = 0, i = 0, currentcheck = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000893 filestruct *temp, *hold = current;
894
895 if (current == NULL)
896 return;
897
898 temp = edittop;
899
900 while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) {
901 hold = temp;
902 update_line(temp, current_x);
Chris Allegretta95b0b522000-07-28 02:58:06 +0000903 if (temp == current)
904 currentcheck = 1;
905
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000906 temp = temp->next;
907 lines++;
908 }
Chris Allegrettaed022162000-08-03 16:54:11 +0000909 /* If noloop == 1, then we already did an edit_update without finishing
910 this function. So we don't run edit_update again */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000911 if (!currentcheck && !noloop) { /* Then current has run off the screen... */
Chris Allegrettada721be2000-07-31 01:26:42 +0000912 edit_update(current, CENTER);
Chris Allegrettaed022162000-08-03 16:54:11 +0000913 noloop = 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000914 } else if (noloop)
Chris Allegrettaed022162000-08-03 16:54:11 +0000915 noloop = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000916
917 if (lines <= editwinrows - 1)
918 while (lines <= editwinrows - 1) {
919 mvwaddstr(edit, lines, i, hblank);
920 lines++;
921 }
922 if (temp == NULL)
923 editbot = hold;
924 else
925 editbot = temp;
926}
927
928/*
Chris Allegrettaf1d33d32000-08-19 03:53:39 +0000929 * Same as above, but touch the window first so everything is redrawn.
930 */
931void edit_refresh_clearok(void)
932{
933 clearok(edit, TRUE);
934 edit_refresh();
935 clearok(edit, FALSE);
936}
937
938/*
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000939 * Nice generic routine to update the edit buffer given a pointer to the
940 * file struct =)
941 */
Chris Allegretta234a34d2000-07-29 04:33:38 +0000942void edit_update(filestruct * fileptr, int topmidbot)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000943{
Robert Siemborski29e9a762000-07-05 03:16:04 +0000944 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000945 filestruct *temp;
946
947 if (fileptr == NULL)
948 return;
949
950 temp = fileptr;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000951 if (topmidbot == 2);
Chris Allegretta234a34d2000-07-29 04:33:38 +0000952 else if (topmidbot == 0)
953 for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++)
954 temp = temp->prev;
955 else
956 for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++)
957 temp = temp->prev;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000958
Robert Siemborski29e9a762000-07-05 03:16:04 +0000959 edittop = temp;
960 fix_editbot();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000961
962 edit_refresh();
963}
964
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000965/* This function updates current based on where current_y is, reset_cursor
966 does the opposite */
967void update_cursor(void)
968{
969 int i = 0;
970
971#ifdef DEBUG
972 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
973 current_x);
974#endif
975
976 current = edittop;
977 while (i <= current_y - 1 && current->next != NULL) {
978 current = current->next;
979 i++;
980 }
981
982#ifdef DEBUG
983 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
984#endif
985
986}
987
988/*
989 * Ask a question on the statusbar. Answer will be stored in answer
990 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
991 * otherwise, the valid shortcut key caught, Def is any editable text we
992 * want to put up by default.
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000993 *
994 * New arg tabs tells whether or not to allow tab completion.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000995 */
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000996int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000997{
998 va_list ap;
999 char foo[133];
1000 int ret;
1001
1002 bottombars(s, slen);
1003
1004 va_start(ap, msg);
1005 vsnprintf(foo, 132, msg, ap);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001006 va_end(ap);
Chris Allegrettaa4d21622000-07-08 23:57:03 +00001007 strncat(foo, ": ", 132);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001008
1009 wattron(bottomwin, A_REVERSE);
Chris Allegretta7da4e9f2000-11-06 02:57:22 +00001010 ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001011 wattroff(bottomwin, A_REVERSE);
1012
1013 switch (ret) {
1014
1015 case NANO_FIRSTLINE_KEY:
1016 do_first_line();
1017 break;
1018 case NANO_LASTLINE_KEY:
1019 do_last_line();
1020 break;
1021 case NANO_CANCEL_KEY:
1022 return -1;
1023 default:
Chris Allegretta5b1faac2000-11-16 19:55:30 +00001024 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001025 }
1026
1027#ifdef DEBUG
1028 fprintf(stderr, _("I got \"%s\"\n"), answer);
1029#endif
1030
1031 return ret;
1032}
1033
1034/*
1035 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
1036 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
1037 */
1038int do_yesno(int all, int leavecursor, char *msg, ...)
1039{
1040 va_list ap;
1041 char foo[133];
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001042 int kbinput, ok = -1, i;
1043 char *yesstr; /* String of yes characters accepted */
1044 char *nostr; /* Same for no */
1045 char *allstr; /* And all, surprise! */
1046 char shortstr[5]; /* Temp string for above */
Chris Allegretta84de5522001-04-12 14:51:48 +00001047#ifndef DISABLE_MOUSE
Chris Allegretta235ab192001-04-12 13:24:40 +00001048#ifdef NCURSES_MOUSE_VERSION
1049 MEVENT mevent;
1050#endif
1051#endif
1052
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001053
1054 /* Yes, no and all are strings of any length. Each string consists of
1055 all characters accepted as a valid character for that value.
1056 The first value will be the one displayed in the shortcuts. */
1057 yesstr = _("Yy");
1058 nostr = _("Nn");
1059 allstr = _("Aa");
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001060
1061 /* Write the bottom of the screen */
1062 clear_bottomwin();
1063 wattron(bottomwin, A_REVERSE);
1064 blank_statusbar_refresh();
1065 wattroff(bottomwin, A_REVERSE);
1066
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001067 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001068 if (!ISSET(NO_HELP)) {
1069 wmove(bottomwin, 1, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001070
1071 snprintf(shortstr, 3, " %c", yesstr[0]);
1072 onekey(shortstr, _("Yes"));
1073
1074 if (all) {
1075 snprintf(shortstr, 3, " %c", allstr[0]);
1076 onekey(shortstr, _("All"));
1077 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001078 wmove(bottomwin, 2, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001079
1080 snprintf(shortstr, 3, " %c", nostr[0]);
1081 onekey(shortstr, _("No"));
1082
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001083 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001084 }
1085 va_start(ap, msg);
1086 vsnprintf(foo, 132, msg, ap);
1087 va_end(ap);
1088 wattron(bottomwin, A_REVERSE);
1089 mvwaddstr(bottomwin, 0, 0, foo);
1090 wattroff(bottomwin, A_REVERSE);
1091 wrefresh(bottomwin);
1092
1093 if (leavecursor == 1)
1094 reset_cursor();
1095
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001096 while (ok == -1) {
1097 kbinput = wgetch(edit);
1098
1099 switch (kbinput) {
Chris Allegretta84de5522001-04-12 14:51:48 +00001100#ifndef DISABLE_MOUSE
Chris Allegretta235ab192001-04-12 13:24:40 +00001101#ifdef NCURSES_MOUSE_VERSION
1102 case KEY_MOUSE:
1103
1104 /* Look ma! We get to duplicate lots of code from do_mouse!! */
1105 if (getmouse(&mevent) == ERR)
1106 break;
1107 if (!wenclose(bottomwin, mevent.y, mevent.x) || ISSET(NO_HELP))
1108 break;
1109 mevent.y -= editwinrows + 3;
1110 if (mevent.y < 0)
1111 break;
1112 else {
1113
1114 /* Rather than a bunch of if statements, set up a matrix
1115 of possible return keystrokes based on the x and y values */
1116 if (all) {
1117 char yesnosquare[2][2] = {
1118 {yesstr[0], allstr[0]},
1119 {nostr[0], NANO_CONTROL_C }};
1120
1121 ungetch(yesnosquare[mevent.y][mevent.x/(COLS/6)]);
1122 } else {
1123 char yesnosquare[2][2] = {
1124 {yesstr[0], '\0'},
1125 {nostr[0], NANO_CONTROL_C }};
1126
1127 ungetch(yesnosquare[mevent.y][mevent.x/(COLS/6)]);
1128 }
1129 }
1130 break;
1131#endif
1132#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001133 case NANO_CONTROL_C:
1134 ok = -2;
1135 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001136 default:
1137
1138 /* Look for the kbinput in the yes, no and (optinally) all str */
1139 for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++)
1140 ;
1141 if (yesstr[i] != 0) {
Chris Allegrettaea620fe2001-02-18 05:39:41 +00001142 ok = 1;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001143 break;
1144 }
1145
1146 for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++)
1147 ;
1148 if (nostr[i] != 0) {
1149 ok = 0;
1150 break;
1151 }
1152
1153 if (all) {
1154 for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++)
1155 ;
1156 if (allstr[i] != 0) {
1157 ok = 2;
1158 break;
1159 }
1160 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001161 }
1162 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001163
1164 /* Then blank the screen */
1165 blank_statusbar_refresh();
1166
1167 if (ok == -2)
1168 return -1;
1169 else
1170 return ok;
1171}
1172
1173void statusbar(char *msg, ...)
1174{
1175 va_list ap;
1176 char foo[133];
1177 int start_x = 0;
1178
1179 va_start(ap, msg);
1180 vsnprintf(foo, 132, msg, ap);
1181 va_end(ap);
1182
Chris Allegretta17dcb722001-01-20 21:40:07 +00001183 start_x = COLS / 2 - strlen(foo) / 2 - 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001184
1185 /* Blank out line */
1186 blank_statusbar();
1187
1188 wmove(bottomwin, 0, start_x);
1189
1190 wattron(bottomwin, A_REVERSE);
1191
1192 waddstr(bottomwin, "[ ");
1193 waddstr(bottomwin, foo);
1194 waddstr(bottomwin, " ]");
1195 wattroff(bottomwin, A_REVERSE);
1196 wrefresh(bottomwin);
1197
1198 if (ISSET(CONSTUPDATE))
1199 statblank = 1;
1200 else
1201 statblank = 25;
1202}
1203
1204void display_main_list(void)
1205{
1206 bottombars(main_list, MAIN_VISIBLE);
1207}
1208
1209int total_refresh(void)
1210{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001211 clearok(edit, TRUE);
1212 clearok(topwin, TRUE);
1213 clearok(bottomwin, TRUE);
1214 wnoutrefresh(edit);
1215 wnoutrefresh(topwin);
1216 wnoutrefresh(bottomwin);
1217 doupdate();
1218 clearok(edit, FALSE);
1219 clearok(topwin, FALSE);
1220 clearok(bottomwin, FALSE);
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001221 edit_refresh();
Chris Allegrettaf4b96012001-01-03 07:11:47 +00001222 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001223 return 1;
1224}
1225
1226void previous_line(void)
1227{
1228 if (current_y > 0)
1229 current_y--;
1230}
1231
1232int do_cursorpos(void)
1233{
1234 filestruct *fileptr;
Chris Allegretta66795ec2000-12-27 04:47:28 +00001235 float linepct = 0.0, bytepct = 0.0;
1236 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001237
1238 if (current == NULL || fileage == NULL)
1239 return 0;
1240
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001241 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1242 fileptr = fileptr->next)
Chris Allegretta66795ec2000-12-27 04:47:28 +00001243 i += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001244
1245 if (fileptr == NULL)
1246 return -1;
1247
Chris Allegretta66795ec2000-12-27 04:47:28 +00001248 i += current_x;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001249
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001250 if (totlines > 0)
1251 linepct = 100 * current->lineno / totlines;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001252
1253 if (totsize > 0)
1254 bytepct = 100 * i / totsize;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001255
1256#ifdef DEBUG
1257 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1258 linepct, bytepct);
1259#endif
1260
1261 statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"),
1262 current->lineno, totlines, linepct, i, totsize, bytepct);
1263 reset_cursor();
1264 return 1;
1265}
1266
1267/* Our broken, non-shortcut list compliant help function.
1268 But hey, it's better than nothing, and it's dynamic! */
1269int do_help(void)
1270{
Rocco Corsiaf5c3022001-01-12 07:51:05 +00001271#ifndef DISABLE_HELP
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001272 char *ptr = help_text, *end;
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001273 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001274 int no_help_flag = 0;
1275
1276 blank_edit();
1277 curs_set(0);
1278 blank_statusbar();
1279
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001280 currshortcut = help_list;
1281 currslen = HELP_LIST_LEN;
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001282 kp = keypad_on(edit, 1);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001283 kp2 = keypad_on(bottomwin, 1);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001284
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001285 if (ISSET(NO_HELP)) {
1286
Chris Allegretta70444892001-01-07 23:02:02 +00001287 /* Well if we're going to do this, we should at least
1288 do it the right way */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001289 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001290 UNSET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001291 window_init();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001292 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta70444892001-01-07 23:02:02 +00001293
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001294 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001295 bottombars(help_list, HELP_LIST_LEN);
1296
1297 do {
1298 ptr = help_text;
1299 switch (kbinput) {
Chris Allegretta84de5522001-04-12 14:51:48 +00001300#ifndef DISABLE_MOUSE
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001301#ifdef NCURSES_MOUSE_VERSION
1302 case KEY_MOUSE:
1303 do_mouse();
1304 break;
1305#endif
1306#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001307 case NANO_NEXTPAGE_KEY:
1308 case NANO_NEXTPAGE_FKEY:
1309 case KEY_NPAGE:
1310 if (!no_more) {
1311 blank_edit();
1312 page++;
1313 }
1314 break;
1315 case NANO_PREVPAGE_KEY:
1316 case NANO_PREVPAGE_FKEY:
1317 case KEY_PPAGE:
1318 if (page > 1) {
1319 no_more = 0;
1320 blank_edit();
1321 page--;
1322 }
1323 break;
1324 }
1325
1326 /* Calculate where in the text we should be based on the page */
1327 for (i = 1; i < page; i++) {
1328 row = 0;
1329 j = 0;
Chris Allegretta44e73df2000-09-07 03:37:38 +00001330
1331 while (row < editwinrows - 2 && *ptr != '\0') {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001332 if (*ptr == '\n' || j == COLS - 5) {
1333 j = 0;
1334 row++;
1335 }
1336 ptr++;
1337 j++;
1338 }
1339 }
1340
Chris Allegretta44e73df2000-09-07 03:37:38 +00001341 if (i > 1) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001342
Chris Allegretta44e73df2000-09-07 03:37:38 +00001343 }
1344
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001345 i = 0;
1346 j = 0;
1347 while (i < editwinrows && *ptr != '\0') {
1348 end = ptr;
1349 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1350 end++;
1351 j++;
1352 }
1353 if (j == COLS - 5) {
1354
1355 /* Don't print half a word if we've run of of space */
1356 while (*end != ' ' && *end != '\0') {
1357 end--;
1358 j--;
1359 }
1360 }
1361 mvwaddnstr(edit, i, 0, ptr, j);
1362 j = 0;
1363 i++;
1364 if (*end == '\n')
1365 end++;
1366 ptr = end;
1367 }
1368 if (*ptr == '\0') {
1369 no_more = 1;
1370 continue;
1371 }
Chris Allegrettad1627cf2000-12-18 05:03:16 +00001372 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
1373 kbinput != NANO_EXIT_FKEY);
1374
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001375 if (no_help_flag) {
Chris Allegretta70444892001-01-07 23:02:02 +00001376 blank_bottombars();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001377 wrefresh(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001378 SET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001379 window_init();
1380 }
1381 display_main_list();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001382
1383 curs_set(1);
1384 edit_refresh();
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001385 kp = keypad_on(edit, kp);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001386 kp2 = keypad_on(bottomwin, kp2);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001387
Chris Allegretta3bc8c722000-12-10 17:03:25 +00001388#elif defined(DISABLE_HELP)
1389 nano_disabled_msg();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001390#endif
1391
1392 return 1;
1393}
1394
1395/* Dump the current file structure to stderr */
1396void dump_buffer(filestruct * inptr)
1397{
1398#ifdef DEBUG
1399 filestruct *fileptr;
1400
1401 if (inptr == fileage)
1402 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1403 else if (inptr == cutbuffer)
1404 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1405 else
1406 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1407
1408 fileptr = inptr;
1409 while (fileptr != NULL) {
1410 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1411 fflush(stderr);
1412 fileptr = fileptr->next;
1413 }
1414#endif /* DEBUG */
1415}
1416
1417void dump_buffer_reverse(filestruct * inptr)
1418{
1419#ifdef DEBUG
1420 filestruct *fileptr;
1421
1422 fileptr = filebot;
1423 while (fileptr != NULL) {
1424 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1425 fflush(stderr);
1426 fileptr = fileptr->prev;
1427 }
1428#endif /* DEBUG */
1429}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001430
1431/* Fix editbot based on the assumption that edittop is correct */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001432void fix_editbot(void)
1433{
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001434 int i;
1435 editbot = edittop;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001436 for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1437 && (editbot != filebot); i++, editbot = editbot->next);
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001438}
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001439
Chris Allegrettafb62f732000-12-05 11:36:41 +00001440/* highlight the current word being replaced or spell checked */
1441void do_replace_highlight(int highlight_flag, char *word)
1442{
1443 char *highlight_word = NULL;
1444 int x, y;
1445
1446 highlight_word = mallocstrcpy(highlight_word, &current->data[current_x]);
1447 highlight_word[strlen(word)] = '\0';
1448
1449 /* adjust output when word extends beyond screen*/
1450
1451 x = xplustabs();
1452 y = get_page_end_virtual(get_page_from_virtual(x)) + 1;
1453
1454 if ((COLS - (y - x) + strlen(word)) > COLS) {
1455 highlight_word[y - x - 1] = '$';
1456 highlight_word[y - x] = '\0';
1457 }
1458
1459 /* OK display the output */
1460
1461 reset_cursor();
1462
1463 if (highlight_flag)
1464 wattron(edit, A_REVERSE);
1465
1466 waddstr(edit, highlight_word);
1467
1468 if (highlight_flag)
1469 wattroff(edit, A_REVERSE);
1470
1471 free(highlight_word);
1472}
1473
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001474#ifdef NANO_EXTRA
Chris Allegretta2bfbda02001-03-23 03:50:44 +00001475#define CREDIT_LEN 47
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001476void do_credits(void)
1477{
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001478 int i, j = 0, k, place = 0, start_x;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001479 char *what;
1480
1481 char *nanotext = _("The nano text editor");
1482 char *version = _("version ");
1483 char *brought = _("Brought to you by:");
1484 char *specialthx = _("Special thanks to:");
1485 char *fsf = _("The Free Software Foundation");
1486 char *ncurses = _("Pavel Curtis, Zeyd Ben-Halim and Eric S. Raymond for ncurses");
1487 char *anyonelse = _("and anyone else we forgot...");
1488 char *thankyou = _("Thank you for using nano!\n");
1489
1490 char *credits[CREDIT_LEN] = {nanotext,
1491 version,
1492 VERSION,
1493 "",
1494 brought,
1495 "Chris Allegretta",
1496 "Jordi Mallach",
1497 "Adam Rogoyski",
1498 "Rob Siemborski",
1499 "Rocco Corsi",
1500 "Ken Tyler",
1501 "Sven Guckes",
1502 "Florian König",
1503 "Pauli Virtanen",
1504 "Daniele Medri",
1505 "Clement Laforet",
1506 "Tedi Heriyanto",
Chris Allegrettaa131c7c2000-11-25 19:59:41 +00001507 "Bill Soudan",
Chris Allegretta7cd9f742000-11-25 20:17:28 +00001508 "Christian Weisgerber",
Chris Allegretta827b15f2001-01-03 02:09:04 +00001509 "Erik Andersen",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001510 "Big Gaute",
1511 "Joshua Jensen",
Chris Allegretta0d471de2001-03-15 14:40:42 +00001512 "Ryan Krebs",
Chris Allegretta7ab3e8f2001-03-22 23:12:22 +00001513 "Albert Chin",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001514 "",
1515 specialthx,
1516 "Plattsburgh State University",
1517 "Benet Laboratories",
1518 "Amy Allegretta",
1519 "Linda Young",
1520 "Jeremy Robichaud",
1521 "Richard Kolb II",
1522 fsf,
1523 "Linus Torvalds",
1524 ncurses,
1525 anyonelse,
1526 thankyou,
1527 "", "", "", "",
1528 "(c) 2000 Chris Allegretta",
1529 "", "", "", "",
1530 "www.nano-editor.org"
1531 };
1532
1533 curs_set(0);
1534 nodelay(edit, TRUE);
1535 blank_bottombars();
1536 mvwaddstr(topwin, 0, 0, hblank);
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001537 blank_edit();
1538 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001539 wrefresh(bottomwin);
1540 wrefresh(topwin);
1541
1542 while (wgetch(edit) == ERR) {
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001543 for (k = 0; k <= 1; k++) {
1544 blank_edit();
1545 for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); i--) {
1546 mvwaddstr(edit, i * 2 - k, 0, hblank);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001547
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001548 if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
1549 what = credits[place - (editwinrows / 2 - 1 - i)];
1550 else
1551 what = "";
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001552
Chris Allegretta17dcb722001-01-20 21:40:07 +00001553 start_x = COLS / 2 - strlen(what) / 2 - 1;
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001554 mvwaddstr(edit, i * 2 - k, start_x, what);
1555 }
1556 usleep(700000);
1557 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001558 }
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001559 if (j < editwinrows / 2 - 1)
1560 j++;
1561
1562 place++;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001563
1564 if (place >= CREDIT_LEN + editwinrows / 2)
1565 break;
1566 }
1567
1568 nodelay(edit, FALSE);
1569 curs_set(1);
1570 display_main_list();
1571 total_refresh();
1572 }
1573#endif
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001574
Chris Allegrettae3167732001-03-18 16:59:34 +00001575int keypad_on(WINDOW * win, int newval)
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001576{
1577
1578/* This is taken right from aumix. Don't sue me */
1579#ifdef HAVE_USEKEYPAD
1580 int old;
1581
1582 old = win->_use_keypad;
Chris Allegrettae3167732001-03-18 16:59:34 +00001583 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001584 return old;
1585#else
Chris Allegrettae3167732001-03-18 16:59:34 +00001586 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001587 return 1;
1588#endif /* HAVE_USEKEYPAD */
1589
1590}
1591
1592
1593