blob: 55a2a21807d3bf3565644ba4a86dc3cd23b2b3d3 [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 Allegretta6b58acd2001-04-12 03:01:53 +0000311#ifndef NANO_SMALL
312#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 */
1047
1048 /* Yes, no and all are strings of any length. Each string consists of
1049 all characters accepted as a valid character for that value.
1050 The first value will be the one displayed in the shortcuts. */
1051 yesstr = _("Yy");
1052 nostr = _("Nn");
1053 allstr = _("Aa");
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001054
1055 /* Write the bottom of the screen */
1056 clear_bottomwin();
1057 wattron(bottomwin, A_REVERSE);
1058 blank_statusbar_refresh();
1059 wattroff(bottomwin, A_REVERSE);
1060
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001061 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001062 if (!ISSET(NO_HELP)) {
1063 wmove(bottomwin, 1, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001064
1065 snprintf(shortstr, 3, " %c", yesstr[0]);
1066 onekey(shortstr, _("Yes"));
1067
1068 if (all) {
1069 snprintf(shortstr, 3, " %c", allstr[0]);
1070 onekey(shortstr, _("All"));
1071 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001072 wmove(bottomwin, 2, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001073
1074 snprintf(shortstr, 3, " %c", nostr[0]);
1075 onekey(shortstr, _("No"));
1076
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001077 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001078 }
1079 va_start(ap, msg);
1080 vsnprintf(foo, 132, msg, ap);
1081 va_end(ap);
1082 wattron(bottomwin, A_REVERSE);
1083 mvwaddstr(bottomwin, 0, 0, foo);
1084 wattroff(bottomwin, A_REVERSE);
1085 wrefresh(bottomwin);
1086
1087 if (leavecursor == 1)
1088 reset_cursor();
1089
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001090 while (ok == -1) {
1091 kbinput = wgetch(edit);
1092
1093 switch (kbinput) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001094 case NANO_CONTROL_C:
1095 ok = -2;
1096 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001097 default:
1098
1099 /* Look for the kbinput in the yes, no and (optinally) all str */
1100 for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++)
1101 ;
1102 if (yesstr[i] != 0) {
Chris Allegrettaea620fe2001-02-18 05:39:41 +00001103 ok = 1;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001104 break;
1105 }
1106
1107 for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++)
1108 ;
1109 if (nostr[i] != 0) {
1110 ok = 0;
1111 break;
1112 }
1113
1114 if (all) {
1115 for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++)
1116 ;
1117 if (allstr[i] != 0) {
1118 ok = 2;
1119 break;
1120 }
1121 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001122 }
1123 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001124
1125 /* Then blank the screen */
1126 blank_statusbar_refresh();
1127
1128 if (ok == -2)
1129 return -1;
1130 else
1131 return ok;
1132}
1133
1134void statusbar(char *msg, ...)
1135{
1136 va_list ap;
1137 char foo[133];
1138 int start_x = 0;
1139
1140 va_start(ap, msg);
1141 vsnprintf(foo, 132, msg, ap);
1142 va_end(ap);
1143
Chris Allegretta17dcb722001-01-20 21:40:07 +00001144 start_x = COLS / 2 - strlen(foo) / 2 - 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001145
1146 /* Blank out line */
1147 blank_statusbar();
1148
1149 wmove(bottomwin, 0, start_x);
1150
1151 wattron(bottomwin, A_REVERSE);
1152
1153 waddstr(bottomwin, "[ ");
1154 waddstr(bottomwin, foo);
1155 waddstr(bottomwin, " ]");
1156 wattroff(bottomwin, A_REVERSE);
1157 wrefresh(bottomwin);
1158
1159 if (ISSET(CONSTUPDATE))
1160 statblank = 1;
1161 else
1162 statblank = 25;
1163}
1164
1165void display_main_list(void)
1166{
1167 bottombars(main_list, MAIN_VISIBLE);
1168}
1169
1170int total_refresh(void)
1171{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001172 clearok(edit, TRUE);
1173 clearok(topwin, TRUE);
1174 clearok(bottomwin, TRUE);
1175 wnoutrefresh(edit);
1176 wnoutrefresh(topwin);
1177 wnoutrefresh(bottomwin);
1178 doupdate();
1179 clearok(edit, FALSE);
1180 clearok(topwin, FALSE);
1181 clearok(bottomwin, FALSE);
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001182 edit_refresh();
Chris Allegrettaf4b96012001-01-03 07:11:47 +00001183 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001184 return 1;
1185}
1186
1187void previous_line(void)
1188{
1189 if (current_y > 0)
1190 current_y--;
1191}
1192
1193int do_cursorpos(void)
1194{
1195 filestruct *fileptr;
Chris Allegretta66795ec2000-12-27 04:47:28 +00001196 float linepct = 0.0, bytepct = 0.0;
1197 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001198
1199 if (current == NULL || fileage == NULL)
1200 return 0;
1201
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001202 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1203 fileptr = fileptr->next)
Chris Allegretta66795ec2000-12-27 04:47:28 +00001204 i += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001205
1206 if (fileptr == NULL)
1207 return -1;
1208
Chris Allegretta66795ec2000-12-27 04:47:28 +00001209 i += current_x;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001210
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001211 if (totlines > 0)
1212 linepct = 100 * current->lineno / totlines;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001213
1214 if (totsize > 0)
1215 bytepct = 100 * i / totsize;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001216
1217#ifdef DEBUG
1218 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1219 linepct, bytepct);
1220#endif
1221
1222 statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"),
1223 current->lineno, totlines, linepct, i, totsize, bytepct);
1224 reset_cursor();
1225 return 1;
1226}
1227
1228/* Our broken, non-shortcut list compliant help function.
1229 But hey, it's better than nothing, and it's dynamic! */
1230int do_help(void)
1231{
Rocco Corsiaf5c3022001-01-12 07:51:05 +00001232#ifndef DISABLE_HELP
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001233 char *ptr = help_text, *end;
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001234 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001235 int no_help_flag = 0;
1236
1237 blank_edit();
1238 curs_set(0);
1239 blank_statusbar();
1240
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001241 currshortcut = help_list;
1242 currslen = HELP_LIST_LEN;
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001243 kp = keypad_on(edit, 1);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001244 kp2 = keypad_on(bottomwin, 1);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001245
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001246 if (ISSET(NO_HELP)) {
1247
Chris Allegretta70444892001-01-07 23:02:02 +00001248 /* Well if we're going to do this, we should at least
1249 do it the right way */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001250 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001251 UNSET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001252 window_init();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001253 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta70444892001-01-07 23:02:02 +00001254
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001255 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001256 bottombars(help_list, HELP_LIST_LEN);
1257
1258 do {
1259 ptr = help_text;
1260 switch (kbinput) {
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001261#ifndef NANO_SMALL
1262#ifdef NCURSES_MOUSE_VERSION
1263 case KEY_MOUSE:
1264 do_mouse();
1265 break;
1266#endif
1267#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001268 case NANO_NEXTPAGE_KEY:
1269 case NANO_NEXTPAGE_FKEY:
1270 case KEY_NPAGE:
1271 if (!no_more) {
1272 blank_edit();
1273 page++;
1274 }
1275 break;
1276 case NANO_PREVPAGE_KEY:
1277 case NANO_PREVPAGE_FKEY:
1278 case KEY_PPAGE:
1279 if (page > 1) {
1280 no_more = 0;
1281 blank_edit();
1282 page--;
1283 }
1284 break;
1285 }
1286
1287 /* Calculate where in the text we should be based on the page */
1288 for (i = 1; i < page; i++) {
1289 row = 0;
1290 j = 0;
Chris Allegretta44e73df2000-09-07 03:37:38 +00001291
1292 while (row < editwinrows - 2 && *ptr != '\0') {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001293 if (*ptr == '\n' || j == COLS - 5) {
1294 j = 0;
1295 row++;
1296 }
1297 ptr++;
1298 j++;
1299 }
1300 }
1301
Chris Allegretta44e73df2000-09-07 03:37:38 +00001302 if (i > 1) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001303
Chris Allegretta44e73df2000-09-07 03:37:38 +00001304 }
1305
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001306 i = 0;
1307 j = 0;
1308 while (i < editwinrows && *ptr != '\0') {
1309 end = ptr;
1310 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1311 end++;
1312 j++;
1313 }
1314 if (j == COLS - 5) {
1315
1316 /* Don't print half a word if we've run of of space */
1317 while (*end != ' ' && *end != '\0') {
1318 end--;
1319 j--;
1320 }
1321 }
1322 mvwaddnstr(edit, i, 0, ptr, j);
1323 j = 0;
1324 i++;
1325 if (*end == '\n')
1326 end++;
1327 ptr = end;
1328 }
1329 if (*ptr == '\0') {
1330 no_more = 1;
1331 continue;
1332 }
Chris Allegrettad1627cf2000-12-18 05:03:16 +00001333 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
1334 kbinput != NANO_EXIT_FKEY);
1335
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001336 if (no_help_flag) {
Chris Allegretta70444892001-01-07 23:02:02 +00001337 blank_bottombars();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001338 wrefresh(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001339 SET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001340 window_init();
1341 }
1342 display_main_list();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001343
1344 curs_set(1);
1345 edit_refresh();
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001346 kp = keypad_on(edit, kp);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001347 kp2 = keypad_on(bottomwin, kp2);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001348
Chris Allegretta3bc8c722000-12-10 17:03:25 +00001349#elif defined(DISABLE_HELP)
1350 nano_disabled_msg();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001351#endif
1352
1353 return 1;
1354}
1355
1356/* Dump the current file structure to stderr */
1357void dump_buffer(filestruct * inptr)
1358{
1359#ifdef DEBUG
1360 filestruct *fileptr;
1361
1362 if (inptr == fileage)
1363 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1364 else if (inptr == cutbuffer)
1365 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1366 else
1367 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1368
1369 fileptr = inptr;
1370 while (fileptr != NULL) {
1371 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1372 fflush(stderr);
1373 fileptr = fileptr->next;
1374 }
1375#endif /* DEBUG */
1376}
1377
1378void dump_buffer_reverse(filestruct * inptr)
1379{
1380#ifdef DEBUG
1381 filestruct *fileptr;
1382
1383 fileptr = filebot;
1384 while (fileptr != NULL) {
1385 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1386 fflush(stderr);
1387 fileptr = fileptr->prev;
1388 }
1389#endif /* DEBUG */
1390}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001391
1392/* Fix editbot based on the assumption that edittop is correct */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001393void fix_editbot(void)
1394{
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001395 int i;
1396 editbot = edittop;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001397 for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1398 && (editbot != filebot); i++, editbot = editbot->next);
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001399}
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001400
Chris Allegrettafb62f732000-12-05 11:36:41 +00001401/* highlight the current word being replaced or spell checked */
1402void do_replace_highlight(int highlight_flag, char *word)
1403{
1404 char *highlight_word = NULL;
1405 int x, y;
1406
1407 highlight_word = mallocstrcpy(highlight_word, &current->data[current_x]);
1408 highlight_word[strlen(word)] = '\0';
1409
1410 /* adjust output when word extends beyond screen*/
1411
1412 x = xplustabs();
1413 y = get_page_end_virtual(get_page_from_virtual(x)) + 1;
1414
1415 if ((COLS - (y - x) + strlen(word)) > COLS) {
1416 highlight_word[y - x - 1] = '$';
1417 highlight_word[y - x] = '\0';
1418 }
1419
1420 /* OK display the output */
1421
1422 reset_cursor();
1423
1424 if (highlight_flag)
1425 wattron(edit, A_REVERSE);
1426
1427 waddstr(edit, highlight_word);
1428
1429 if (highlight_flag)
1430 wattroff(edit, A_REVERSE);
1431
1432 free(highlight_word);
1433}
1434
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001435#ifdef NANO_EXTRA
Chris Allegretta2bfbda02001-03-23 03:50:44 +00001436#define CREDIT_LEN 47
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001437void do_credits(void)
1438{
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001439 int i, j = 0, k, place = 0, start_x;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001440 char *what;
1441
1442 char *nanotext = _("The nano text editor");
1443 char *version = _("version ");
1444 char *brought = _("Brought to you by:");
1445 char *specialthx = _("Special thanks to:");
1446 char *fsf = _("The Free Software Foundation");
1447 char *ncurses = _("Pavel Curtis, Zeyd Ben-Halim and Eric S. Raymond for ncurses");
1448 char *anyonelse = _("and anyone else we forgot...");
1449 char *thankyou = _("Thank you for using nano!\n");
1450
1451 char *credits[CREDIT_LEN] = {nanotext,
1452 version,
1453 VERSION,
1454 "",
1455 brought,
1456 "Chris Allegretta",
1457 "Jordi Mallach",
1458 "Adam Rogoyski",
1459 "Rob Siemborski",
1460 "Rocco Corsi",
1461 "Ken Tyler",
1462 "Sven Guckes",
1463 "Florian König",
1464 "Pauli Virtanen",
1465 "Daniele Medri",
1466 "Clement Laforet",
1467 "Tedi Heriyanto",
Chris Allegrettaa131c7c2000-11-25 19:59:41 +00001468 "Bill Soudan",
Chris Allegretta7cd9f742000-11-25 20:17:28 +00001469 "Christian Weisgerber",
Chris Allegretta827b15f2001-01-03 02:09:04 +00001470 "Erik Andersen",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001471 "Big Gaute",
1472 "Joshua Jensen",
Chris Allegretta0d471de2001-03-15 14:40:42 +00001473 "Ryan Krebs",
Chris Allegretta7ab3e8f2001-03-22 23:12:22 +00001474 "Albert Chin",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001475 "",
1476 specialthx,
1477 "Plattsburgh State University",
1478 "Benet Laboratories",
1479 "Amy Allegretta",
1480 "Linda Young",
1481 "Jeremy Robichaud",
1482 "Richard Kolb II",
1483 fsf,
1484 "Linus Torvalds",
1485 ncurses,
1486 anyonelse,
1487 thankyou,
1488 "", "", "", "",
1489 "(c) 2000 Chris Allegretta",
1490 "", "", "", "",
1491 "www.nano-editor.org"
1492 };
1493
1494 curs_set(0);
1495 nodelay(edit, TRUE);
1496 blank_bottombars();
1497 mvwaddstr(topwin, 0, 0, hblank);
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001498 blank_edit();
1499 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001500 wrefresh(bottomwin);
1501 wrefresh(topwin);
1502
1503 while (wgetch(edit) == ERR) {
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001504 for (k = 0; k <= 1; k++) {
1505 blank_edit();
1506 for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); i--) {
1507 mvwaddstr(edit, i * 2 - k, 0, hblank);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001508
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001509 if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
1510 what = credits[place - (editwinrows / 2 - 1 - i)];
1511 else
1512 what = "";
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001513
Chris Allegretta17dcb722001-01-20 21:40:07 +00001514 start_x = COLS / 2 - strlen(what) / 2 - 1;
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001515 mvwaddstr(edit, i * 2 - k, start_x, what);
1516 }
1517 usleep(700000);
1518 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001519 }
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001520 if (j < editwinrows / 2 - 1)
1521 j++;
1522
1523 place++;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001524
1525 if (place >= CREDIT_LEN + editwinrows / 2)
1526 break;
1527 }
1528
1529 nodelay(edit, FALSE);
1530 curs_set(1);
1531 display_main_list();
1532 total_refresh();
1533 }
1534#endif
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001535
Chris Allegrettae3167732001-03-18 16:59:34 +00001536int keypad_on(WINDOW * win, int newval)
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001537{
1538
1539/* This is taken right from aumix. Don't sue me */
1540#ifdef HAVE_USEKEYPAD
1541 int old;
1542
1543 old = win->_use_keypad;
Chris Allegrettae3167732001-03-18 16:59:34 +00001544 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001545 return old;
1546#else
Chris Allegrettae3167732001-03-18 16:59:34 +00001547 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001548 return 1;
1549#endif /* HAVE_USEKEYPAD */
1550
1551}
1552
1553
1554