blob: 2ce5d818a240c3f0e85084c35420366ba76f675f [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
265 /* Get the input! */
Chris Allegretta31925e42000-11-02 04:40:39 +0000266 if (strlen(def) > 0)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000267 strcpy(inputbuf, def);
Chris Allegretta31925e42000-11-02 04:40:39 +0000268
269 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000270
Chris Allegretta022b96f2000-11-14 17:47:58 +0000271 /* Make sure any editor screen updates are displayed before getting input */
272 wrefresh(edit);
273
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000274 while ((kbinput = wgetch(bottomwin)) != 13) {
275 for (j = 0; j <= slen - 1; j++) {
276 if (kbinput == s[j].val) {
Chris Allegretta5bf51d32000-11-16 06:01:10 +0000277
278 /* We shouldn't discard the answer it gave, just because
279 we hit a keystroke, GEEZ! */
280 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000281 free(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000282 return s[j].val;
283 }
284 }
285 xend = strlen(buf) + strlen(inputbuf);
286
Chris Allegretta04d848e2000-11-05 17:54:41 +0000287 if (kbinput != '\t')
288 tabbed = 0;
289
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000290 switch (kbinput) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000291 /* Stuff we want to equate with <enter>, ASCII 13 */
292 case 343:
Chris Allegrettaf9b6c9b2000-10-18 19:35:59 +0000293 ungetch(13); /* Enter on iris-ansi $TERM, sometimes */
294 break;
Chris Allegretta75155df2000-11-28 23:04:24 +0000295 /* Stuff we want to ignore */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000296#ifdef PDCURSES
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000297 case 541:
298 case 542:
Chris Allegretta72623582000-11-29 23:43:28 +0000299 case 543: /* Right ctrl again */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000300 case 544:
Chris Allegretta72623582000-11-29 23:43:28 +0000301 case 545: /* Right alt again */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000302#endif
Chris Allegretta75155df2000-11-28 23:04:24 +0000303 break;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000304 case KEY_HOME:
305 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000306 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000307 break;
308 case KEY_END:
309 x = x_left + strlen(inputbuf);
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000310 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000311 break;
312 case KEY_RIGHT:
Chris Allegretta35dac582001-03-21 15:07:20 +0000313 case NANO_FORWARD_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000314
315 if (x < xend)
316 x++;
317 wmove(bottomwin, 0, x);
318 break;
319 case NANO_CONTROL_D:
320 if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
321 memmove(inputbuf + (x - x_left),
322 inputbuf + (x - x_left) + 1,
323 strlen(inputbuf) - (x - x_left) - 1);
324 inputbuf[strlen(inputbuf) - 1] = 0;
325 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000326 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000327 break;
328 case NANO_CONTROL_K:
329 case NANO_CONTROL_U:
330 *inputbuf = 0;
331 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000332 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000333 break;
334 case KEY_BACKSPACE:
335 case KEY_DC:
336 case 127:
337 case NANO_CONTROL_H:
338 if (strlen(inputbuf) > 0) {
339 if (x == (x_left + strlen(inputbuf)))
340 inputbuf[strlen(inputbuf) - 1] = 0;
341 else if (x - x_left) {
342 memmove(inputbuf + (x - x_left) - 1,
343 inputbuf + (x - x_left),
344 strlen(inputbuf) - (x - x_left));
345 inputbuf[strlen(inputbuf) - 1] = 0;
346 }
347 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000348 if (x > strlen(buf))
349 x--;
Chris Allegretta31925e42000-11-02 04:40:39 +0000350 nanoget_repaint(buf, inputbuf, x);
Chris Allegretta04d848e2000-11-05 17:54:41 +0000351 break;
Rocco Corsi06aca1c2001-01-11 05:30:31 +0000352#ifndef DISABLE_TABCOMP
Chris Allegretta04d848e2000-11-05 17:54:41 +0000353 case NANO_CONTROL_I:
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000354 if (allowtabs) {
Chris Allegretta442f2c52000-11-14 17:46:06 +0000355 shift = 0;
356 inputbuf = input_tab(inputbuf, (x - x_left),
Chris Allegrettab5b89ae2000-11-14 18:25:26 +0000357 &tabbed, &shift);
Chris Allegretta442f2c52000-11-14 17:46:06 +0000358 x += shift;
Chris Allegrettae434b452001-01-27 19:25:00 +0000359 if (x - x_left > strlen(inputbuf))
360 x = strlen(inputbuf) + x_left;
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000361 nanoget_repaint(buf, inputbuf, x);
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000362 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000363 break;
Chris Allegrettabe77c612000-11-24 14:00:16 +0000364#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000365 case KEY_LEFT:
Chris Allegretta35dac582001-03-21 15:07:20 +0000366 case NANO_BACK_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000367 if (x > strlen(buf))
368 x--;
369 wmove(bottomwin, 0, x);
370 break;
371 case KEY_UP:
372 case KEY_DOWN:
373 break;
374
375 case 27:
376 switch (kbinput = wgetch(edit)) {
377 case 79:
378 switch (kbinput = wgetch(edit)) {
379 case 70:
380 x = x_left + strlen(inputbuf);
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000381 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000382 break;
383 case 72:
384 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000385 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000386 break;
387 }
388 break;
389 case 91:
390 switch (kbinput = wgetch(edit)) {
391 case 'C':
392 if (x < xend)
393 x++;
394 wmove(bottomwin, 0, x);
395 break;
396 case 'D':
397 if (x > strlen(buf))
398 x--;
399 wmove(bottomwin, 0, x);
400 break;
401 case 49:
402 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000403 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000404 goto skip_126;
405 case 51:
406 if (strlen(inputbuf) > 0
407 && (x - x_left) != strlen(inputbuf)) {
408 memmove(inputbuf + (x - x_left),
409 inputbuf + (x - x_left) + 1,
410 strlen(inputbuf) - (x - x_left) - 1);
411 inputbuf[strlen(inputbuf) - 1] = 0;
412 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000413 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000414 goto skip_126;
415 case 52:
416 x = x_left + strlen(inputbuf);
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 skip_126:
420 nodelay(edit, TRUE);
421 kbinput = wgetch(edit);
422 if (kbinput == 126 || kbinput == ERR)
423 kbinput = -1;
424 nodelay(edit, FALSE);
425 break;
426 }
427 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000428 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000429 break;
430
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000431 default:
432 if (kbinput < 32)
433 break;
Chris Allegretta31925e42000-11-02 04:40:39 +0000434
435 inputlen = strlen(inputbuf);
436 inputbuf = nrealloc(inputbuf, inputlen + 2);
437
438 memmove(&inputbuf[x - x_left + 1],
439 &inputbuf[x - x_left],
440 inputlen - (x - x_left) + 1);
441 inputbuf[x - x_left] = kbinput;
442
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000443 x++;
444
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000445 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000446#ifdef DEBUG
447 fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
448#endif
449 }
450 wrefresh(bottomwin);
451 }
452
Chris Allegretta31925e42000-11-02 04:40:39 +0000453 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000454 free(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000455
Chris Allegretta105da332000-10-31 05:10:10 +0000456 /* Now that the text is editable instead of bracketed, we have to
457 check for answer == def, instead of answer == "" */
Chris Allegrettabf9a8cc2000-11-17 01:37:39 +0000458 if (((ISSET(PICO_MODE)) && !strcmp(answer, "")) ||
459 ((!ISSET(PICO_MODE)) && !strcmp(answer, def)))
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000460 return -2;
461 else
462 return 0;
463}
464
465void horizbar(WINDOW * win, int y)
466{
467 wattron(win, A_REVERSE);
468 mvwaddstr(win, 0, 0, hblank);
469 wattroff(win, A_REVERSE);
470}
471
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000472void titlebar(char *path)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000473{
474 int namelen, space;
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000475 char *what = path;
476
477 if (path == NULL)
478 what = filename;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000479
480 horizbar(topwin, 0);
481 wattron(topwin, A_REVERSE);
482 mvwaddstr(topwin, 0, 3, VERMSG);
483
484 space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
485
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000486 namelen = strlen(what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000487
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000488 if (!strcmp(what, ""))
Chris Allegretta17dcb722001-01-20 21:40:07 +0000489 mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000490 else {
491 if (namelen > space) {
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000492 if (path == NULL)
493 waddstr(topwin, _(" File: ..."));
494 else
495 waddstr(topwin, _(" DIR: ..."));
496 waddstr(topwin, &what[namelen - space]);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000497 } else {
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000498 if (path == NULL)
Chris Allegretta17dcb722001-01-20 21:40:07 +0000499 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), "File: ");
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000500 else
Chris Allegretta17dcb722001-01-20 21:40:07 +0000501 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), " DIR: ");
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000502 waddstr(topwin, what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000503 }
504 }
505 if (ISSET(MODIFIED))
506 mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
507 wattroff(topwin, A_REVERSE);
508 wrefresh(topwin);
509 reset_cursor();
510}
511
512void onekey(char *keystroke, char *desc)
513{
514 char description[80];
515
Chris Allegrettae7034c62000-09-15 03:31:09 +0000516 snprintf(description, 12, " %-10s", desc);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000517 wattron(bottomwin, A_REVERSE);
518 waddstr(bottomwin, keystroke);
519 wattroff(bottomwin, A_REVERSE);
520 waddstr(bottomwin, description);
521}
522
523void clear_bottomwin(void)
524{
525 if (ISSET(NO_HELP))
526 return;
527
528 mvwaddstr(bottomwin, 1, 0, hblank);
529 mvwaddstr(bottomwin, 2, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000530}
531
532void bottombars(shortcut s[], int slen)
533{
534 int i, j, k;
535 char keystr[10];
536
537 if (ISSET(NO_HELP))
538 return;
539
540 /* Determine how many extra spaces are needed to fill the bottom of the screen */
541 k = COLS / 6 - 13;
542
543 clear_bottomwin();
544 wmove(bottomwin, 1, 0);
545 for (i = 0; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000546 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000547 onekey(keystr, s[i].desc);
548
549 for (j = 0; j < k; j++)
550 waddch(bottomwin, ' ');
551 }
552
553 wmove(bottomwin, 2, 0);
554 for (i = 1; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000555 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000556 onekey(keystr, s[i].desc);
557
558 for (j = 0; j < k; j++)
559 waddch(bottomwin, ' ');
560 }
561
562 wrefresh(bottomwin);
563
564}
565
566/* If modified is not already set, set it and update titlebar */
567void set_modified(void)
568{
569 if (!ISSET(MODIFIED)) {
570 SET(MODIFIED);
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000571 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000572 wrefresh(topwin);
573 }
574}
575
Robert Siemborski9d584552000-07-08 00:41:29 +0000576/* And so start the display update routines */
577/* Given a column, this returns the "page" it is on */
578/* "page" in the case of the display columns, means which set of 80 */
579/* characters is viewable (ie: page 1 shows from 1 to COLS) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000580inline int get_page_from_virtual(int virtual)
581{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000582 int page = 2;
583
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000584 if (virtual <= COLS - 2)
585 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000586 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000587
588 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000589 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000590 page++;
591 }
592
593 return page;
594}
595
Robert Siemborski9d584552000-07-08 00:41:29 +0000596/* The inverse of the above function */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000597inline int get_page_start_virtual(int page)
598{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000599 int virtual;
600 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000601 if (page)
602 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000603 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000604}
605
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000606inline int get_page_end_virtual(int page)
607{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000608 return get_page_start_virtual(page) + COLS - 1;
609}
610
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000611#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000612/* This takes care of the case where there is a mark that covers only */
613/* the current line. */
614
Chris Allegrettab275aac2000-07-08 01:22:33 +0000615/* It expects a line with no tab characers (ie: the type that edit_add */
Robert Siemborski9d584552000-07-08 00:41:29 +0000616/* deals with */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000617void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
618 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000619{
Robert Siemborski9d584552000-07-08 00:41:29 +0000620 /*
621 * The general idea is to break the line up into 3 sections: before
622 * the mark, the mark, and after the mark. We then paint each in
623 * turn (for those that are currently visible, of course
624 *
625 * 3 start points: 0 -> begin, begin->end, end->strlen(data)
626 * in data : pre sel post
627 */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000628 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000629 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000630
Robert Siemborskid8510b22000-06-06 23:04:06 +0000631 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000632 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 +0000633
634 /* now fix the start locations & lengths according to the cursor's
635 * position (ie: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000636 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000637 pre_data_len = 0;
638 else
639 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000640
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000641 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000642 begin = this_page_start;
643
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000644 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000645 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000646
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000647 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000648 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000649
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000650 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000651 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000652
Robert Siemborski9d584552000-07-08 00:41:29 +0000653 /* Now calculate the lengths */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000654 sel_data_len = end - begin;
655 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000656
Robert Siemborski9d584552000-07-08 00:41:29 +0000657 /* Paint this line! */
Robert Siemborski53875912000-06-16 04:25:30 +0000658 mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000659 wattron(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000660 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000661 &fileptr->data[begin], sel_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000662 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000663 mvwaddnstr(edit, y, end - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000664 &fileptr->data[end], post_data_len);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000665}
666#endif
667
Robert Siemborski9d584552000-07-08 00:41:29 +0000668/* edit_add takes care of the job of actually painting a line into the
669 * edit window.
670 *
671 * Called only from update_line. Expects a converted-to-not-have-tabs
Robert Siemborski53875912000-06-16 04:25:30 +0000672 * line */
673void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000674 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000675{
676#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000677 /* There are quite a few cases that could take place, we'll deal
678 * with them each in turn */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000679 if (ISSET(MARK_ISSET)
Robert Siemborski9d584552000-07-08 00:41:29 +0000680 && !((fileptr->lineno > mark_beginbuf->lineno
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000681 && fileptr->lineno > current->lineno)
682 || (fileptr->lineno < mark_beginbuf->lineno
683 && fileptr->lineno < current->lineno))) {
684 /* If we get here we are on a line that is atleast
685 * partially selected. The lineno checks above determined
686 * that */
687 if (fileptr != mark_beginbuf && fileptr != current) {
688 /* We are on a completely marked line, paint it all
689 * inverse */
690 wattron(edit, A_REVERSE);
691 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
692 wattroff(edit, A_REVERSE);
693 } else if (fileptr == mark_beginbuf && fileptr == current) {
694 /* Special case, we're still on the same line we started
695 * marking -- so we call our helper function */
696 if (virt_cur_x < virt_mark_beginx) {
697 /* To the right of us is marked */
698 add_marked_sameline(virt_cur_x, virt_mark_beginx,
699 fileptr, yval, virt_cur_x, this_page);
700 } else {
701 /* To the left of us is marked */
702 add_marked_sameline(virt_mark_beginx, virt_cur_x,
703 fileptr, yval, virt_cur_x, this_page);
704 }
705 } else if (fileptr == mark_beginbuf) {
706 /*
707 * we're updating the line that was first marked
708 * but we're not currently on it. So we want to
709 * figur out which half to invert based on our
710 * relative line numbers.
711 *
712 * i.e. If we're above the "beginbuf" line, we want to
713 * mark the left side. Otherwise we're below, so we
714 * mark the right
715 */
716 int target;
717
718 if (mark_beginbuf->lineno > current->lineno)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000719 wattron(edit, A_REVERSE);
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000720
721 target =
722 (virt_mark_beginx <
723 COLS - 1) ? virt_mark_beginx : COLS - 1;
724
725 mvwaddnstr(edit, yval, 0, fileptr->data, target);
726
727 if (mark_beginbuf->lineno < current->lineno)
728 wattron(edit, A_REVERSE);
729 else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000730 wattroff(edit, A_REVERSE);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000731
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000732 target = (COLS - 1) - virt_mark_beginx;
733 if (target < 0)
734 target = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000735
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000736 mvwaddnstr(edit, yval, virt_mark_beginx,
737 &fileptr->data[virt_mark_beginx], target);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000738
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000739 if (mark_beginbuf->lineno < current->lineno)
740 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000741
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000742 } else if (fileptr == current) {
743 /* we're on the cursors line, but it's not the first
744 * one we marked. Similar to the previous logic. */
745 int this_page_start = get_page_start_virtual(this_page),
746 this_page_end = get_page_end_virtual(this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000747
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000748 if (mark_beginbuf->lineno < current->lineno)
749 wattron(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000750
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000751 if (virt_cur_x > COLS - 2) {
752 mvwaddnstr(edit, yval, 0,
753 &fileptr->data[this_page_start],
754 virt_cur_x - this_page_start);
755 } else {
756 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
757 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000758
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000759 if (mark_beginbuf->lineno > current->lineno)
760 wattron(edit, A_REVERSE);
761 else
762 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000763
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000764 if (virt_cur_x > COLS - 2)
765 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
766 &fileptr->data[virt_cur_x],
767 this_page_end - virt_cur_x);
768 else
769 mvwaddnstr(edit, yval, virt_cur_x,
770 &fileptr->data[virt_cur_x], COLS - virt_cur_x);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000771
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000772 if (mark_beginbuf->lineno > current->lineno)
773 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000774 }
775
776 } else
777#endif
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000778 /* Just paint the string (no mark on this line) */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000779 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
Chris Allegretta908805a2000-12-04 04:42:56 +0000780 get_page_end_virtual(this_page) - start + 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000781}
782
783/*
Robert Siemborski9d584552000-07-08 00:41:29 +0000784 * Just update one line in the edit buffer. Basically a wrapper for
785 * edit_add
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000786 *
787 * index gives is a place in the string to update starting from.
788 * Likely args are current_x or 0.
789 */
790void update_line(filestruct * fileptr, int index)
791{
792 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +0000793 int line = 0, col = 0;
794 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
795 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000796 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000797
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000798 if (!fileptr)
799 return;
Robert Siemborski53154a72000-06-18 00:11:03 +0000800
Robert Siemborski53875912000-06-16 04:25:30 +0000801 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000802 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
803 filetmp = filetmp->next)
804 line++;
805
806 mvwaddstr(edit, line, 0, hblank);
807
Robert Siemborski53875912000-06-16 04:25:30 +0000808 /* Next, convert all the tabs to spaces so everything else is easy */
809 index = xpt(fileptr, index);
810
811 realdata = fileptr->data;
812 len = strlen(realdata);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000813 fileptr->data = nmalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +0000814
815 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000816 for (i = 0; i < len; i++) {
817 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +0000818 do {
819 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000820 if (i < current_x)
821 virt_cur_x++;
822 if (i < mark_beginx)
823 virt_mark_beginx++;
Chris Allegretta6d690a32000-08-03 22:51:21 +0000824 } while (pos % tabsize);
Robert Siemborski53875912000-06-16 04:25:30 +0000825 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000826 if (i < current_x)
827 virt_cur_x--;
828 if (i < mark_beginx)
829 virt_mark_beginx--;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000830 } else if (realdata[i] >= 1 && realdata[i] <= 26) {
831 /* Treat control characters as ^letter */
Chris Allegretta6306a112000-09-02 07:55:41 +0000832 fileptr->data[pos++] = '^';
833 fileptr->data[pos++] = realdata[i] + 64;
Robert Siemborski53875912000-06-16 04:25:30 +0000834 } else {
835 fileptr->data[pos++] = realdata[i];
836 }
837 }
838
839 fileptr->data[pos] = '\0';
840
841 /* Now, Paint the line */
842 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000843 /* This handles when the current line is beyond COLS */
844 /* It requires figureing out what page we're at */
845 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000846 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000847
Robert Siemborskia9addc72000-06-17 06:06:35 +0000848 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000849 mvwaddch(edit, line, 0, '$');
850
Chris Allegrettafb62f732000-12-05 11:36:41 +0000851 if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000852 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000853 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000854 /* It's not the current line means that it's at x=0 and page=1 */
855 /* If it is the current line, then we're in the same boat */
856 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000857
Robert Siemborski53875912000-06-16 04:25:30 +0000858 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000859 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000860 }
Robert Siemborski53875912000-06-16 04:25:30 +0000861
862 /* Clean up our mess */
863 tmp = fileptr->data;
864 fileptr->data = realdata;
865 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000866}
867
868void center_cursor(void)
869{
870 current_y = editwinrows / 2;
871 wmove(edit, current_y, current_x);
872}
873
874/* Refresh the screen without changing the position of lines */
875void edit_refresh(void)
876{
Chris Allegrettaed022162000-08-03 16:54:11 +0000877 static int noloop = 0;
Chris Allegretta95b0b522000-07-28 02:58:06 +0000878 int lines = 0, i = 0, currentcheck = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000879 filestruct *temp, *hold = current;
880
881 if (current == NULL)
882 return;
883
884 temp = edittop;
885
886 while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) {
887 hold = temp;
888 update_line(temp, current_x);
Chris Allegretta95b0b522000-07-28 02:58:06 +0000889 if (temp == current)
890 currentcheck = 1;
891
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000892 temp = temp->next;
893 lines++;
894 }
Chris Allegrettaed022162000-08-03 16:54:11 +0000895 /* If noloop == 1, then we already did an edit_update without finishing
896 this function. So we don't run edit_update again */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000897 if (!currentcheck && !noloop) { /* Then current has run off the screen... */
Chris Allegrettada721be2000-07-31 01:26:42 +0000898 edit_update(current, CENTER);
Chris Allegrettaed022162000-08-03 16:54:11 +0000899 noloop = 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000900 } else if (noloop)
Chris Allegrettaed022162000-08-03 16:54:11 +0000901 noloop = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000902
903 if (lines <= editwinrows - 1)
904 while (lines <= editwinrows - 1) {
905 mvwaddstr(edit, lines, i, hblank);
906 lines++;
907 }
908 if (temp == NULL)
909 editbot = hold;
910 else
911 editbot = temp;
912}
913
914/*
Chris Allegrettaf1d33d32000-08-19 03:53:39 +0000915 * Same as above, but touch the window first so everything is redrawn.
916 */
917void edit_refresh_clearok(void)
918{
919 clearok(edit, TRUE);
920 edit_refresh();
921 clearok(edit, FALSE);
922}
923
924/*
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000925 * Nice generic routine to update the edit buffer given a pointer to the
926 * file struct =)
927 */
Chris Allegretta234a34d2000-07-29 04:33:38 +0000928void edit_update(filestruct * fileptr, int topmidbot)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000929{
Robert Siemborski29e9a762000-07-05 03:16:04 +0000930 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000931 filestruct *temp;
932
933 if (fileptr == NULL)
934 return;
935
936 temp = fileptr;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000937 if (topmidbot == 2);
Chris Allegretta234a34d2000-07-29 04:33:38 +0000938 else if (topmidbot == 0)
939 for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++)
940 temp = temp->prev;
941 else
942 for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++)
943 temp = temp->prev;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000944
Robert Siemborski29e9a762000-07-05 03:16:04 +0000945 edittop = temp;
946 fix_editbot();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000947
948 edit_refresh();
949}
950
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000951/* This function updates current based on where current_y is, reset_cursor
952 does the opposite */
953void update_cursor(void)
954{
955 int i = 0;
956
957#ifdef DEBUG
958 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
959 current_x);
960#endif
961
962 current = edittop;
963 while (i <= current_y - 1 && current->next != NULL) {
964 current = current->next;
965 i++;
966 }
967
968#ifdef DEBUG
969 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
970#endif
971
972}
973
974/*
975 * Ask a question on the statusbar. Answer will be stored in answer
976 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
977 * otherwise, the valid shortcut key caught, Def is any editable text we
978 * want to put up by default.
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000979 *
980 * New arg tabs tells whether or not to allow tab completion.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000981 */
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000982int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000983{
984 va_list ap;
985 char foo[133];
986 int ret;
987
988 bottombars(s, slen);
989
990 va_start(ap, msg);
991 vsnprintf(foo, 132, msg, ap);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000992 va_end(ap);
Chris Allegrettaa4d21622000-07-08 23:57:03 +0000993 strncat(foo, ": ", 132);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000994
995 wattron(bottomwin, A_REVERSE);
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000996 ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000997 wattroff(bottomwin, A_REVERSE);
998
999 switch (ret) {
1000
1001 case NANO_FIRSTLINE_KEY:
1002 do_first_line();
1003 break;
1004 case NANO_LASTLINE_KEY:
1005 do_last_line();
1006 break;
1007 case NANO_CANCEL_KEY:
1008 return -1;
1009 default:
Chris Allegretta5b1faac2000-11-16 19:55:30 +00001010 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001011 }
1012
1013#ifdef DEBUG
1014 fprintf(stderr, _("I got \"%s\"\n"), answer);
1015#endif
1016
1017 return ret;
1018}
1019
1020/*
1021 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
1022 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
1023 */
1024int do_yesno(int all, int leavecursor, char *msg, ...)
1025{
1026 va_list ap;
1027 char foo[133];
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001028 int kbinput, ok = -1, i;
1029 char *yesstr; /* String of yes characters accepted */
1030 char *nostr; /* Same for no */
1031 char *allstr; /* And all, surprise! */
1032 char shortstr[5]; /* Temp string for above */
1033
1034 /* Yes, no and all are strings of any length. Each string consists of
1035 all characters accepted as a valid character for that value.
1036 The first value will be the one displayed in the shortcuts. */
1037 yesstr = _("Yy");
1038 nostr = _("Nn");
1039 allstr = _("Aa");
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001040
1041 /* Write the bottom of the screen */
1042 clear_bottomwin();
1043 wattron(bottomwin, A_REVERSE);
1044 blank_statusbar_refresh();
1045 wattroff(bottomwin, A_REVERSE);
1046
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001047 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001048 if (!ISSET(NO_HELP)) {
1049 wmove(bottomwin, 1, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001050
1051 snprintf(shortstr, 3, " %c", yesstr[0]);
1052 onekey(shortstr, _("Yes"));
1053
1054 if (all) {
1055 snprintf(shortstr, 3, " %c", allstr[0]);
1056 onekey(shortstr, _("All"));
1057 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001058 wmove(bottomwin, 2, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001059
1060 snprintf(shortstr, 3, " %c", nostr[0]);
1061 onekey(shortstr, _("No"));
1062
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001063 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001064 }
1065 va_start(ap, msg);
1066 vsnprintf(foo, 132, msg, ap);
1067 va_end(ap);
1068 wattron(bottomwin, A_REVERSE);
1069 mvwaddstr(bottomwin, 0, 0, foo);
1070 wattroff(bottomwin, A_REVERSE);
1071 wrefresh(bottomwin);
1072
1073 if (leavecursor == 1)
1074 reset_cursor();
1075
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001076 while (ok == -1) {
1077 kbinput = wgetch(edit);
1078
1079 switch (kbinput) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001080 case NANO_CONTROL_C:
1081 ok = -2;
1082 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001083 default:
1084
1085 /* Look for the kbinput in the yes, no and (optinally) all str */
1086 for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++)
1087 ;
1088 if (yesstr[i] != 0) {
Chris Allegrettaea620fe2001-02-18 05:39:41 +00001089 ok = 1;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001090 break;
1091 }
1092
1093 for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++)
1094 ;
1095 if (nostr[i] != 0) {
1096 ok = 0;
1097 break;
1098 }
1099
1100 if (all) {
1101 for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++)
1102 ;
1103 if (allstr[i] != 0) {
1104 ok = 2;
1105 break;
1106 }
1107 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001108 }
1109 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001110
1111 /* Then blank the screen */
1112 blank_statusbar_refresh();
1113
1114 if (ok == -2)
1115 return -1;
1116 else
1117 return ok;
1118}
1119
1120void statusbar(char *msg, ...)
1121{
1122 va_list ap;
1123 char foo[133];
1124 int start_x = 0;
1125
1126 va_start(ap, msg);
1127 vsnprintf(foo, 132, msg, ap);
1128 va_end(ap);
1129
Chris Allegretta17dcb722001-01-20 21:40:07 +00001130 start_x = COLS / 2 - strlen(foo) / 2 - 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001131
1132 /* Blank out line */
1133 blank_statusbar();
1134
1135 wmove(bottomwin, 0, start_x);
1136
1137 wattron(bottomwin, A_REVERSE);
1138
1139 waddstr(bottomwin, "[ ");
1140 waddstr(bottomwin, foo);
1141 waddstr(bottomwin, " ]");
1142 wattroff(bottomwin, A_REVERSE);
1143 wrefresh(bottomwin);
1144
1145 if (ISSET(CONSTUPDATE))
1146 statblank = 1;
1147 else
1148 statblank = 25;
1149}
1150
1151void display_main_list(void)
1152{
1153 bottombars(main_list, MAIN_VISIBLE);
1154}
1155
1156int total_refresh(void)
1157{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001158 clearok(edit, TRUE);
1159 clearok(topwin, TRUE);
1160 clearok(bottomwin, TRUE);
1161 wnoutrefresh(edit);
1162 wnoutrefresh(topwin);
1163 wnoutrefresh(bottomwin);
1164 doupdate();
1165 clearok(edit, FALSE);
1166 clearok(topwin, FALSE);
1167 clearok(bottomwin, FALSE);
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001168 edit_refresh();
Chris Allegrettaf4b96012001-01-03 07:11:47 +00001169 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001170 return 1;
1171}
1172
1173void previous_line(void)
1174{
1175 if (current_y > 0)
1176 current_y--;
1177}
1178
1179int do_cursorpos(void)
1180{
1181 filestruct *fileptr;
Chris Allegretta66795ec2000-12-27 04:47:28 +00001182 float linepct = 0.0, bytepct = 0.0;
1183 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001184
1185 if (current == NULL || fileage == NULL)
1186 return 0;
1187
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001188 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1189 fileptr = fileptr->next)
Chris Allegretta66795ec2000-12-27 04:47:28 +00001190 i += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001191
1192 if (fileptr == NULL)
1193 return -1;
1194
Chris Allegretta66795ec2000-12-27 04:47:28 +00001195 i += current_x;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001196
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001197 if (totlines > 0)
1198 linepct = 100 * current->lineno / totlines;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001199
1200 if (totsize > 0)
1201 bytepct = 100 * i / totsize;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001202
1203#ifdef DEBUG
1204 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1205 linepct, bytepct);
1206#endif
1207
1208 statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"),
1209 current->lineno, totlines, linepct, i, totsize, bytepct);
1210 reset_cursor();
1211 return 1;
1212}
1213
1214/* Our broken, non-shortcut list compliant help function.
1215 But hey, it's better than nothing, and it's dynamic! */
1216int do_help(void)
1217{
Rocco Corsiaf5c3022001-01-12 07:51:05 +00001218#ifndef DISABLE_HELP
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001219 char *ptr = help_text, *end;
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001220 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001221 int no_help_flag = 0;
1222
1223 blank_edit();
1224 curs_set(0);
1225 blank_statusbar();
1226
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001227 kp = keypad_on(edit, 1);
1228
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001229 if (ISSET(NO_HELP)) {
1230
Chris Allegretta70444892001-01-07 23:02:02 +00001231 /* Well if we're going to do this, we should at least
1232 do it the right way */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001233 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001234 UNSET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001235 window_init();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001236 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta70444892001-01-07 23:02:02 +00001237
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001238 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001239 bottombars(help_list, HELP_LIST_LEN);
1240
1241 do {
1242 ptr = help_text;
1243 switch (kbinput) {
1244 case NANO_NEXTPAGE_KEY:
1245 case NANO_NEXTPAGE_FKEY:
1246 case KEY_NPAGE:
1247 if (!no_more) {
1248 blank_edit();
1249 page++;
1250 }
1251 break;
1252 case NANO_PREVPAGE_KEY:
1253 case NANO_PREVPAGE_FKEY:
1254 case KEY_PPAGE:
1255 if (page > 1) {
1256 no_more = 0;
1257 blank_edit();
1258 page--;
1259 }
1260 break;
1261 }
1262
1263 /* Calculate where in the text we should be based on the page */
1264 for (i = 1; i < page; i++) {
1265 row = 0;
1266 j = 0;
Chris Allegretta44e73df2000-09-07 03:37:38 +00001267
1268 while (row < editwinrows - 2 && *ptr != '\0') {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001269 if (*ptr == '\n' || j == COLS - 5) {
1270 j = 0;
1271 row++;
1272 }
1273 ptr++;
1274 j++;
1275 }
1276 }
1277
Chris Allegretta44e73df2000-09-07 03:37:38 +00001278 if (i > 1) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001279
Chris Allegretta44e73df2000-09-07 03:37:38 +00001280 }
1281
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001282 i = 0;
1283 j = 0;
1284 while (i < editwinrows && *ptr != '\0') {
1285 end = ptr;
1286 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1287 end++;
1288 j++;
1289 }
1290 if (j == COLS - 5) {
1291
1292 /* Don't print half a word if we've run of of space */
1293 while (*end != ' ' && *end != '\0') {
1294 end--;
1295 j--;
1296 }
1297 }
1298 mvwaddnstr(edit, i, 0, ptr, j);
1299 j = 0;
1300 i++;
1301 if (*end == '\n')
1302 end++;
1303 ptr = end;
1304 }
1305 if (*ptr == '\0') {
1306 no_more = 1;
1307 continue;
1308 }
Chris Allegrettad1627cf2000-12-18 05:03:16 +00001309 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
1310 kbinput != NANO_EXIT_FKEY);
1311
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001312 if (no_help_flag) {
Chris Allegretta70444892001-01-07 23:02:02 +00001313 blank_bottombars();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001314 wrefresh(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001315 SET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001316 window_init();
1317 }
1318 display_main_list();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001319
1320 curs_set(1);
1321 edit_refresh();
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001322 kp = keypad_on(edit, kp);
1323
Chris Allegretta3bc8c722000-12-10 17:03:25 +00001324#elif defined(DISABLE_HELP)
1325 nano_disabled_msg();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001326#endif
1327
1328 return 1;
1329}
1330
1331/* Dump the current file structure to stderr */
1332void dump_buffer(filestruct * inptr)
1333{
1334#ifdef DEBUG
1335 filestruct *fileptr;
1336
1337 if (inptr == fileage)
1338 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1339 else if (inptr == cutbuffer)
1340 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1341 else
1342 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1343
1344 fileptr = inptr;
1345 while (fileptr != NULL) {
1346 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1347 fflush(stderr);
1348 fileptr = fileptr->next;
1349 }
1350#endif /* DEBUG */
1351}
1352
1353void dump_buffer_reverse(filestruct * inptr)
1354{
1355#ifdef DEBUG
1356 filestruct *fileptr;
1357
1358 fileptr = filebot;
1359 while (fileptr != NULL) {
1360 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1361 fflush(stderr);
1362 fileptr = fileptr->prev;
1363 }
1364#endif /* DEBUG */
1365}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001366
1367/* Fix editbot based on the assumption that edittop is correct */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001368void fix_editbot(void)
1369{
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001370 int i;
1371 editbot = edittop;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001372 for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1373 && (editbot != filebot); i++, editbot = editbot->next);
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001374}
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001375
Chris Allegrettafb62f732000-12-05 11:36:41 +00001376/* highlight the current word being replaced or spell checked */
1377void do_replace_highlight(int highlight_flag, char *word)
1378{
1379 char *highlight_word = NULL;
1380 int x, y;
1381
1382 highlight_word = mallocstrcpy(highlight_word, &current->data[current_x]);
1383 highlight_word[strlen(word)] = '\0';
1384
1385 /* adjust output when word extends beyond screen*/
1386
1387 x = xplustabs();
1388 y = get_page_end_virtual(get_page_from_virtual(x)) + 1;
1389
1390 if ((COLS - (y - x) + strlen(word)) > COLS) {
1391 highlight_word[y - x - 1] = '$';
1392 highlight_word[y - x] = '\0';
1393 }
1394
1395 /* OK display the output */
1396
1397 reset_cursor();
1398
1399 if (highlight_flag)
1400 wattron(edit, A_REVERSE);
1401
1402 waddstr(edit, highlight_word);
1403
1404 if (highlight_flag)
1405 wattroff(edit, A_REVERSE);
1406
1407 free(highlight_word);
1408}
1409
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001410#ifdef NANO_EXTRA
Chris Allegretta7cd9f742000-11-25 20:17:28 +00001411#define CREDIT_LEN 45
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001412void do_credits(void)
1413{
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001414 int i, j = 0, k, place = 0, start_x;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001415 char *what;
1416
1417 char *nanotext = _("The nano text editor");
1418 char *version = _("version ");
1419 char *brought = _("Brought to you by:");
1420 char *specialthx = _("Special thanks to:");
1421 char *fsf = _("The Free Software Foundation");
1422 char *ncurses = _("Pavel Curtis, Zeyd Ben-Halim and Eric S. Raymond for ncurses");
1423 char *anyonelse = _("and anyone else we forgot...");
1424 char *thankyou = _("Thank you for using nano!\n");
1425
1426 char *credits[CREDIT_LEN] = {nanotext,
1427 version,
1428 VERSION,
1429 "",
1430 brought,
1431 "Chris Allegretta",
1432 "Jordi Mallach",
1433 "Adam Rogoyski",
1434 "Rob Siemborski",
1435 "Rocco Corsi",
1436 "Ken Tyler",
1437 "Sven Guckes",
1438 "Florian König",
1439 "Pauli Virtanen",
1440 "Daniele Medri",
1441 "Clement Laforet",
1442 "Tedi Heriyanto",
Chris Allegrettaa131c7c2000-11-25 19:59:41 +00001443 "Bill Soudan",
Chris Allegretta7cd9f742000-11-25 20:17:28 +00001444 "Christian Weisgerber",
Chris Allegretta827b15f2001-01-03 02:09:04 +00001445 "Erik Andersen",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001446 "Big Gaute",
1447 "Joshua Jensen",
Chris Allegretta0d471de2001-03-15 14:40:42 +00001448 "Ryan Krebs",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001449 "",
1450 specialthx,
1451 "Plattsburgh State University",
1452 "Benet Laboratories",
1453 "Amy Allegretta",
1454 "Linda Young",
1455 "Jeremy Robichaud",
1456 "Richard Kolb II",
1457 fsf,
1458 "Linus Torvalds",
1459 ncurses,
1460 anyonelse,
1461 thankyou,
1462 "", "", "", "",
1463 "(c) 2000 Chris Allegretta",
1464 "", "", "", "",
1465 "www.nano-editor.org"
1466 };
1467
1468 curs_set(0);
1469 nodelay(edit, TRUE);
1470 blank_bottombars();
1471 mvwaddstr(topwin, 0, 0, hblank);
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001472 blank_edit();
1473 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001474 wrefresh(bottomwin);
1475 wrefresh(topwin);
1476
1477 while (wgetch(edit) == ERR) {
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001478 for (k = 0; k <= 1; k++) {
1479 blank_edit();
1480 for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); i--) {
1481 mvwaddstr(edit, i * 2 - k, 0, hblank);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001482
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001483 if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
1484 what = credits[place - (editwinrows / 2 - 1 - i)];
1485 else
1486 what = "";
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001487
Chris Allegretta17dcb722001-01-20 21:40:07 +00001488 start_x = COLS / 2 - strlen(what) / 2 - 1;
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001489 mvwaddstr(edit, i * 2 - k, start_x, what);
1490 }
1491 usleep(700000);
1492 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001493 }
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001494 if (j < editwinrows / 2 - 1)
1495 j++;
1496
1497 place++;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001498
1499 if (place >= CREDIT_LEN + editwinrows / 2)
1500 break;
1501 }
1502
1503 nodelay(edit, FALSE);
1504 curs_set(1);
1505 display_main_list();
1506 total_refresh();
1507 }
1508#endif
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001509
Chris Allegrettae3167732001-03-18 16:59:34 +00001510int keypad_on(WINDOW * win, int newval)
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001511{
1512
1513/* This is taken right from aumix. Don't sue me */
1514#ifdef HAVE_USEKEYPAD
1515 int old;
1516
1517 old = win->_use_keypad;
Chris Allegrettae3167732001-03-18 16:59:34 +00001518 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001519 return old;
1520#else
Chris Allegrettae3167732001-03-18 16:59:34 +00001521 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001522 return 1;
1523#endif /* HAVE_USEKEYPAD */
1524
1525}
1526
1527
1528