blob: 3b79c020cf51d994da34308885ac03b8016402e6 [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:
313
314 if (x < xend)
315 x++;
316 wmove(bottomwin, 0, x);
317 break;
318 case NANO_CONTROL_D:
319 if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
320 memmove(inputbuf + (x - x_left),
321 inputbuf + (x - x_left) + 1,
322 strlen(inputbuf) - (x - x_left) - 1);
323 inputbuf[strlen(inputbuf) - 1] = 0;
324 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000325 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000326 break;
327 case NANO_CONTROL_K:
328 case NANO_CONTROL_U:
329 *inputbuf = 0;
330 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000331 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000332 break;
333 case KEY_BACKSPACE:
334 case KEY_DC:
335 case 127:
336 case NANO_CONTROL_H:
337 if (strlen(inputbuf) > 0) {
338 if (x == (x_left + strlen(inputbuf)))
339 inputbuf[strlen(inputbuf) - 1] = 0;
340 else if (x - x_left) {
341 memmove(inputbuf + (x - x_left) - 1,
342 inputbuf + (x - x_left),
343 strlen(inputbuf) - (x - x_left));
344 inputbuf[strlen(inputbuf) - 1] = 0;
345 }
346 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000347 if (x > strlen(buf))
348 x--;
Chris Allegretta31925e42000-11-02 04:40:39 +0000349 nanoget_repaint(buf, inputbuf, x);
Chris Allegretta04d848e2000-11-05 17:54:41 +0000350 break;
Rocco Corsi06aca1c2001-01-11 05:30:31 +0000351#ifndef DISABLE_TABCOMP
Chris Allegretta04d848e2000-11-05 17:54:41 +0000352 case NANO_CONTROL_I:
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000353 if (allowtabs) {
Chris Allegretta442f2c52000-11-14 17:46:06 +0000354 shift = 0;
355 inputbuf = input_tab(inputbuf, (x - x_left),
Chris Allegrettab5b89ae2000-11-14 18:25:26 +0000356 &tabbed, &shift);
Chris Allegretta442f2c52000-11-14 17:46:06 +0000357 x += shift;
Chris Allegrettae434b452001-01-27 19:25:00 +0000358 if (x - x_left > strlen(inputbuf))
359 x = strlen(inputbuf) + x_left;
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000360 nanoget_repaint(buf, inputbuf, x);
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000361 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000362 break;
Chris Allegrettabe77c612000-11-24 14:00:16 +0000363#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000364 case KEY_LEFT:
365 if (x > strlen(buf))
366 x--;
367 wmove(bottomwin, 0, x);
368 break;
369 case KEY_UP:
370 case KEY_DOWN:
371 break;
372
373 case 27:
374 switch (kbinput = wgetch(edit)) {
375 case 79:
376 switch (kbinput = wgetch(edit)) {
377 case 70:
378 x = x_left + strlen(inputbuf);
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000379 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000380 break;
381 case 72:
382 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000383 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000384 break;
385 }
386 break;
387 case 91:
388 switch (kbinput = wgetch(edit)) {
389 case 'C':
390 if (x < xend)
391 x++;
392 wmove(bottomwin, 0, x);
393 break;
394 case 'D':
395 if (x > strlen(buf))
396 x--;
397 wmove(bottomwin, 0, x);
398 break;
399 case 49:
400 x = x_left;
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000401 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000402 goto skip_126;
403 case 51:
404 if (strlen(inputbuf) > 0
405 && (x - x_left) != strlen(inputbuf)) {
406 memmove(inputbuf + (x - x_left),
407 inputbuf + (x - x_left) + 1,
408 strlen(inputbuf) - (x - x_left) - 1);
409 inputbuf[strlen(inputbuf) - 1] = 0;
410 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000411 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000412 goto skip_126;
413 case 52:
414 x = x_left + strlen(inputbuf);
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000415 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000416 goto skip_126;
417 skip_126:
418 nodelay(edit, TRUE);
419 kbinput = wgetch(edit);
420 if (kbinput == 126 || kbinput == ERR)
421 kbinput = -1;
422 nodelay(edit, FALSE);
423 break;
424 }
425 }
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000426 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000427 break;
428
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000429 default:
430 if (kbinput < 32)
431 break;
Chris Allegretta31925e42000-11-02 04:40:39 +0000432
433 inputlen = strlen(inputbuf);
434 inputbuf = nrealloc(inputbuf, inputlen + 2);
435
436 memmove(&inputbuf[x - x_left + 1],
437 &inputbuf[x - x_left],
438 inputlen - (x - x_left) + 1);
439 inputbuf[x - x_left] = kbinput;
440
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000441 x++;
442
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000443 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000444#ifdef DEBUG
445 fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
446#endif
447 }
448 wrefresh(bottomwin);
449 }
450
Chris Allegretta31925e42000-11-02 04:40:39 +0000451 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000452 free(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000453
Chris Allegretta105da332000-10-31 05:10:10 +0000454 /* Now that the text is editable instead of bracketed, we have to
455 check for answer == def, instead of answer == "" */
Chris Allegrettabf9a8cc2000-11-17 01:37:39 +0000456 if (((ISSET(PICO_MODE)) && !strcmp(answer, "")) ||
457 ((!ISSET(PICO_MODE)) && !strcmp(answer, def)))
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000458 return -2;
459 else
460 return 0;
461}
462
463void horizbar(WINDOW * win, int y)
464{
465 wattron(win, A_REVERSE);
466 mvwaddstr(win, 0, 0, hblank);
467 wattroff(win, A_REVERSE);
468}
469
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000470void titlebar(char *path)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000471{
472 int namelen, space;
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000473 char *what = path;
474
475 if (path == NULL)
476 what = filename;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000477
478 horizbar(topwin, 0);
479 wattron(topwin, A_REVERSE);
480 mvwaddstr(topwin, 0, 3, VERMSG);
481
482 space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
483
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000484 namelen = strlen(what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000485
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000486 if (!strcmp(what, ""))
Chris Allegretta17dcb722001-01-20 21:40:07 +0000487 mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000488 else {
489 if (namelen > space) {
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000490 if (path == NULL)
491 waddstr(topwin, _(" File: ..."));
492 else
493 waddstr(topwin, _(" DIR: ..."));
494 waddstr(topwin, &what[namelen - space]);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000495 } else {
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000496 if (path == NULL)
Chris Allegretta17dcb722001-01-20 21:40:07 +0000497 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), "File: ");
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000498 else
Chris Allegretta17dcb722001-01-20 21:40:07 +0000499 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), " DIR: ");
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000500 waddstr(topwin, what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000501 }
502 }
503 if (ISSET(MODIFIED))
504 mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
505 wattroff(topwin, A_REVERSE);
506 wrefresh(topwin);
507 reset_cursor();
508}
509
510void onekey(char *keystroke, char *desc)
511{
512 char description[80];
513
Chris Allegrettae7034c62000-09-15 03:31:09 +0000514 snprintf(description, 12, " %-10s", desc);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000515 wattron(bottomwin, A_REVERSE);
516 waddstr(bottomwin, keystroke);
517 wattroff(bottomwin, A_REVERSE);
518 waddstr(bottomwin, description);
519}
520
521void clear_bottomwin(void)
522{
523 if (ISSET(NO_HELP))
524 return;
525
526 mvwaddstr(bottomwin, 1, 0, hblank);
527 mvwaddstr(bottomwin, 2, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000528}
529
530void bottombars(shortcut s[], int slen)
531{
532 int i, j, k;
533 char keystr[10];
534
535 if (ISSET(NO_HELP))
536 return;
537
538 /* Determine how many extra spaces are needed to fill the bottom of the screen */
539 k = COLS / 6 - 13;
540
541 clear_bottomwin();
542 wmove(bottomwin, 1, 0);
543 for (i = 0; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000544 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000545 onekey(keystr, s[i].desc);
546
547 for (j = 0; j < k; j++)
548 waddch(bottomwin, ' ');
549 }
550
551 wmove(bottomwin, 2, 0);
552 for (i = 1; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000553 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000554 onekey(keystr, s[i].desc);
555
556 for (j = 0; j < k; j++)
557 waddch(bottomwin, ' ');
558 }
559
560 wrefresh(bottomwin);
561
562}
563
564/* If modified is not already set, set it and update titlebar */
565void set_modified(void)
566{
567 if (!ISSET(MODIFIED)) {
568 SET(MODIFIED);
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000569 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000570 wrefresh(topwin);
571 }
572}
573
Robert Siemborski9d584552000-07-08 00:41:29 +0000574/* And so start the display update routines */
575/* Given a column, this returns the "page" it is on */
576/* "page" in the case of the display columns, means which set of 80 */
577/* characters is viewable (ie: page 1 shows from 1 to COLS) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000578inline int get_page_from_virtual(int virtual)
579{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000580 int page = 2;
581
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000582 if (virtual <= COLS - 2)
583 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000584 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000585
586 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000587 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000588 page++;
589 }
590
591 return page;
592}
593
Robert Siemborski9d584552000-07-08 00:41:29 +0000594/* The inverse of the above function */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000595inline int get_page_start_virtual(int page)
596{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000597 int virtual;
598 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000599 if (page)
600 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000601 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000602}
603
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000604inline int get_page_end_virtual(int page)
605{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000606 return get_page_start_virtual(page) + COLS - 1;
607}
608
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000609#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000610/* This takes care of the case where there is a mark that covers only */
611/* the current line. */
612
Chris Allegrettab275aac2000-07-08 01:22:33 +0000613/* It expects a line with no tab characers (ie: the type that edit_add */
Robert Siemborski9d584552000-07-08 00:41:29 +0000614/* deals with */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000615void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
616 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000617{
Robert Siemborski9d584552000-07-08 00:41:29 +0000618 /*
619 * The general idea is to break the line up into 3 sections: before
620 * the mark, the mark, and after the mark. We then paint each in
621 * turn (for those that are currently visible, of course
622 *
623 * 3 start points: 0 -> begin, begin->end, end->strlen(data)
624 * in data : pre sel post
625 */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000626 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000627 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000628
Robert Siemborskid8510b22000-06-06 23:04:06 +0000629 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000630 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 +0000631
632 /* now fix the start locations & lengths according to the cursor's
633 * position (ie: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000634 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000635 pre_data_len = 0;
636 else
637 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000638
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000639 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000640 begin = this_page_start;
641
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000642 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000643 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000644
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000645 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000646 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000647
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000648 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000649 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000650
Robert Siemborski9d584552000-07-08 00:41:29 +0000651 /* Now calculate the lengths */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000652 sel_data_len = end - begin;
653 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000654
Robert Siemborski9d584552000-07-08 00:41:29 +0000655 /* Paint this line! */
Robert Siemborski53875912000-06-16 04:25:30 +0000656 mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000657 wattron(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000658 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000659 &fileptr->data[begin], sel_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000660 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000661 mvwaddnstr(edit, y, end - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000662 &fileptr->data[end], post_data_len);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000663}
664#endif
665
Robert Siemborski9d584552000-07-08 00:41:29 +0000666/* edit_add takes care of the job of actually painting a line into the
667 * edit window.
668 *
669 * Called only from update_line. Expects a converted-to-not-have-tabs
Robert Siemborski53875912000-06-16 04:25:30 +0000670 * line */
671void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000672 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000673{
674#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000675 /* There are quite a few cases that could take place, we'll deal
676 * with them each in turn */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000677 if (ISSET(MARK_ISSET)
Robert Siemborski9d584552000-07-08 00:41:29 +0000678 && !((fileptr->lineno > mark_beginbuf->lineno
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000679 && fileptr->lineno > current->lineno)
680 || (fileptr->lineno < mark_beginbuf->lineno
681 && fileptr->lineno < current->lineno))) {
682 /* If we get here we are on a line that is atleast
683 * partially selected. The lineno checks above determined
684 * that */
685 if (fileptr != mark_beginbuf && fileptr != current) {
686 /* We are on a completely marked line, paint it all
687 * inverse */
688 wattron(edit, A_REVERSE);
689 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
690 wattroff(edit, A_REVERSE);
691 } else if (fileptr == mark_beginbuf && fileptr == current) {
692 /* Special case, we're still on the same line we started
693 * marking -- so we call our helper function */
694 if (virt_cur_x < virt_mark_beginx) {
695 /* To the right of us is marked */
696 add_marked_sameline(virt_cur_x, virt_mark_beginx,
697 fileptr, yval, virt_cur_x, this_page);
698 } else {
699 /* To the left of us is marked */
700 add_marked_sameline(virt_mark_beginx, virt_cur_x,
701 fileptr, yval, virt_cur_x, this_page);
702 }
703 } else if (fileptr == mark_beginbuf) {
704 /*
705 * we're updating the line that was first marked
706 * but we're not currently on it. So we want to
707 * figur out which half to invert based on our
708 * relative line numbers.
709 *
710 * i.e. If we're above the "beginbuf" line, we want to
711 * mark the left side. Otherwise we're below, so we
712 * mark the right
713 */
714 int target;
715
716 if (mark_beginbuf->lineno > current->lineno)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000717 wattron(edit, A_REVERSE);
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000718
719 target =
720 (virt_mark_beginx <
721 COLS - 1) ? virt_mark_beginx : COLS - 1;
722
723 mvwaddnstr(edit, yval, 0, fileptr->data, target);
724
725 if (mark_beginbuf->lineno < current->lineno)
726 wattron(edit, A_REVERSE);
727 else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000728 wattroff(edit, A_REVERSE);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000729
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000730 target = (COLS - 1) - virt_mark_beginx;
731 if (target < 0)
732 target = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000733
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000734 mvwaddnstr(edit, yval, virt_mark_beginx,
735 &fileptr->data[virt_mark_beginx], target);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000736
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000737 if (mark_beginbuf->lineno < current->lineno)
738 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000739
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000740 } else if (fileptr == current) {
741 /* we're on the cursors line, but it's not the first
742 * one we marked. Similar to the previous logic. */
743 int this_page_start = get_page_start_virtual(this_page),
744 this_page_end = get_page_end_virtual(this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000745
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000746 if (mark_beginbuf->lineno < current->lineno)
747 wattron(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000748
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000749 if (virt_cur_x > COLS - 2) {
750 mvwaddnstr(edit, yval, 0,
751 &fileptr->data[this_page_start],
752 virt_cur_x - this_page_start);
753 } else {
754 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
755 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000756
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000757 if (mark_beginbuf->lineno > current->lineno)
758 wattron(edit, A_REVERSE);
759 else
760 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000761
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000762 if (virt_cur_x > COLS - 2)
763 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
764 &fileptr->data[virt_cur_x],
765 this_page_end - virt_cur_x);
766 else
767 mvwaddnstr(edit, yval, virt_cur_x,
768 &fileptr->data[virt_cur_x], COLS - virt_cur_x);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000769
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000770 if (mark_beginbuf->lineno > current->lineno)
771 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000772 }
773
774 } else
775#endif
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000776 /* Just paint the string (no mark on this line) */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000777 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
Chris Allegretta908805a2000-12-04 04:42:56 +0000778 get_page_end_virtual(this_page) - start + 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000779}
780
781/*
Robert Siemborski9d584552000-07-08 00:41:29 +0000782 * Just update one line in the edit buffer. Basically a wrapper for
783 * edit_add
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000784 *
785 * index gives is a place in the string to update starting from.
786 * Likely args are current_x or 0.
787 */
788void update_line(filestruct * fileptr, int index)
789{
790 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +0000791 int line = 0, col = 0;
792 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
793 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000794 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000795
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000796 if (!fileptr)
797 return;
Robert Siemborski53154a72000-06-18 00:11:03 +0000798
Robert Siemborski53875912000-06-16 04:25:30 +0000799 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000800 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
801 filetmp = filetmp->next)
802 line++;
803
804 mvwaddstr(edit, line, 0, hblank);
805
Robert Siemborski53875912000-06-16 04:25:30 +0000806 /* Next, convert all the tabs to spaces so everything else is easy */
807 index = xpt(fileptr, index);
808
809 realdata = fileptr->data;
810 len = strlen(realdata);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000811 fileptr->data = nmalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +0000812
813 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000814 for (i = 0; i < len; i++) {
815 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +0000816 do {
817 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000818 if (i < current_x)
819 virt_cur_x++;
820 if (i < mark_beginx)
821 virt_mark_beginx++;
Chris Allegretta6d690a32000-08-03 22:51:21 +0000822 } while (pos % tabsize);
Robert Siemborski53875912000-06-16 04:25:30 +0000823 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000824 if (i < current_x)
825 virt_cur_x--;
826 if (i < mark_beginx)
827 virt_mark_beginx--;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000828 } else if (realdata[i] >= 1 && realdata[i] <= 26) {
829 /* Treat control characters as ^letter */
Chris Allegretta6306a112000-09-02 07:55:41 +0000830 fileptr->data[pos++] = '^';
831 fileptr->data[pos++] = realdata[i] + 64;
Robert Siemborski53875912000-06-16 04:25:30 +0000832 } else {
833 fileptr->data[pos++] = realdata[i];
834 }
835 }
836
837 fileptr->data[pos] = '\0';
838
839 /* Now, Paint the line */
840 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000841 /* This handles when the current line is beyond COLS */
842 /* It requires figureing out what page we're at */
843 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000844 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000845
Robert Siemborskia9addc72000-06-17 06:06:35 +0000846 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000847 mvwaddch(edit, line, 0, '$');
848
Chris Allegrettafb62f732000-12-05 11:36:41 +0000849 if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000850 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000851 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000852 /* It's not the current line means that it's at x=0 and page=1 */
853 /* If it is the current line, then we're in the same boat */
854 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000855
Robert Siemborski53875912000-06-16 04:25:30 +0000856 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000857 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000858 }
Robert Siemborski53875912000-06-16 04:25:30 +0000859
860 /* Clean up our mess */
861 tmp = fileptr->data;
862 fileptr->data = realdata;
863 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000864}
865
866void center_cursor(void)
867{
868 current_y = editwinrows / 2;
869 wmove(edit, current_y, current_x);
870}
871
872/* Refresh the screen without changing the position of lines */
873void edit_refresh(void)
874{
Chris Allegrettaed022162000-08-03 16:54:11 +0000875 static int noloop = 0;
Chris Allegretta95b0b522000-07-28 02:58:06 +0000876 int lines = 0, i = 0, currentcheck = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000877 filestruct *temp, *hold = current;
878
879 if (current == NULL)
880 return;
881
882 temp = edittop;
883
884 while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) {
885 hold = temp;
886 update_line(temp, current_x);
Chris Allegretta95b0b522000-07-28 02:58:06 +0000887 if (temp == current)
888 currentcheck = 1;
889
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000890 temp = temp->next;
891 lines++;
892 }
Chris Allegrettaed022162000-08-03 16:54:11 +0000893 /* If noloop == 1, then we already did an edit_update without finishing
894 this function. So we don't run edit_update again */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000895 if (!currentcheck && !noloop) { /* Then current has run off the screen... */
Chris Allegrettada721be2000-07-31 01:26:42 +0000896 edit_update(current, CENTER);
Chris Allegrettaed022162000-08-03 16:54:11 +0000897 noloop = 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000898 } else if (noloop)
Chris Allegrettaed022162000-08-03 16:54:11 +0000899 noloop = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000900
901 if (lines <= editwinrows - 1)
902 while (lines <= editwinrows - 1) {
903 mvwaddstr(edit, lines, i, hblank);
904 lines++;
905 }
906 if (temp == NULL)
907 editbot = hold;
908 else
909 editbot = temp;
910}
911
912/*
Chris Allegrettaf1d33d32000-08-19 03:53:39 +0000913 * Same as above, but touch the window first so everything is redrawn.
914 */
915void edit_refresh_clearok(void)
916{
917 clearok(edit, TRUE);
918 edit_refresh();
919 clearok(edit, FALSE);
920}
921
922/*
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000923 * Nice generic routine to update the edit buffer given a pointer to the
924 * file struct =)
925 */
Chris Allegretta234a34d2000-07-29 04:33:38 +0000926void edit_update(filestruct * fileptr, int topmidbot)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000927{
Robert Siemborski29e9a762000-07-05 03:16:04 +0000928 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000929 filestruct *temp;
930
931 if (fileptr == NULL)
932 return;
933
934 temp = fileptr;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000935 if (topmidbot == 2);
Chris Allegretta234a34d2000-07-29 04:33:38 +0000936 else if (topmidbot == 0)
937 for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++)
938 temp = temp->prev;
939 else
940 for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++)
941 temp = temp->prev;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000942
Robert Siemborski29e9a762000-07-05 03:16:04 +0000943 edittop = temp;
944 fix_editbot();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000945
946 edit_refresh();
947}
948
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000949/* This function updates current based on where current_y is, reset_cursor
950 does the opposite */
951void update_cursor(void)
952{
953 int i = 0;
954
955#ifdef DEBUG
956 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
957 current_x);
958#endif
959
960 current = edittop;
961 while (i <= current_y - 1 && current->next != NULL) {
962 current = current->next;
963 i++;
964 }
965
966#ifdef DEBUG
967 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
968#endif
969
970}
971
972/*
973 * Ask a question on the statusbar. Answer will be stored in answer
974 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
975 * otherwise, the valid shortcut key caught, Def is any editable text we
976 * want to put up by default.
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000977 *
978 * New arg tabs tells whether or not to allow tab completion.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000979 */
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000980int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000981{
982 va_list ap;
983 char foo[133];
984 int ret;
985
986 bottombars(s, slen);
987
988 va_start(ap, msg);
989 vsnprintf(foo, 132, msg, ap);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000990 va_end(ap);
Chris Allegrettaa4d21622000-07-08 23:57:03 +0000991 strncat(foo, ": ", 132);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000992
993 wattron(bottomwin, A_REVERSE);
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000994 ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000995 wattroff(bottomwin, A_REVERSE);
996
997 switch (ret) {
998
999 case NANO_FIRSTLINE_KEY:
1000 do_first_line();
1001 break;
1002 case NANO_LASTLINE_KEY:
1003 do_last_line();
1004 break;
1005 case NANO_CANCEL_KEY:
1006 return -1;
1007 default:
Chris Allegretta5b1faac2000-11-16 19:55:30 +00001008 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001009 }
1010
1011#ifdef DEBUG
1012 fprintf(stderr, _("I got \"%s\"\n"), answer);
1013#endif
1014
1015 return ret;
1016}
1017
1018/*
1019 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
1020 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
1021 */
1022int do_yesno(int all, int leavecursor, char *msg, ...)
1023{
1024 va_list ap;
1025 char foo[133];
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001026 int kbinput, ok = -1, i;
1027 char *yesstr; /* String of yes characters accepted */
1028 char *nostr; /* Same for no */
1029 char *allstr; /* And all, surprise! */
1030 char shortstr[5]; /* Temp string for above */
1031
1032 /* Yes, no and all are strings of any length. Each string consists of
1033 all characters accepted as a valid character for that value.
1034 The first value will be the one displayed in the shortcuts. */
1035 yesstr = _("Yy");
1036 nostr = _("Nn");
1037 allstr = _("Aa");
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001038
1039 /* Write the bottom of the screen */
1040 clear_bottomwin();
1041 wattron(bottomwin, A_REVERSE);
1042 blank_statusbar_refresh();
1043 wattroff(bottomwin, A_REVERSE);
1044
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001045 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001046 if (!ISSET(NO_HELP)) {
1047 wmove(bottomwin, 1, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001048
1049 snprintf(shortstr, 3, " %c", yesstr[0]);
1050 onekey(shortstr, _("Yes"));
1051
1052 if (all) {
1053 snprintf(shortstr, 3, " %c", allstr[0]);
1054 onekey(shortstr, _("All"));
1055 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001056 wmove(bottomwin, 2, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001057
1058 snprintf(shortstr, 3, " %c", nostr[0]);
1059 onekey(shortstr, _("No"));
1060
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001061 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001062 }
1063 va_start(ap, msg);
1064 vsnprintf(foo, 132, msg, ap);
1065 va_end(ap);
1066 wattron(bottomwin, A_REVERSE);
1067 mvwaddstr(bottomwin, 0, 0, foo);
1068 wattroff(bottomwin, A_REVERSE);
1069 wrefresh(bottomwin);
1070
1071 if (leavecursor == 1)
1072 reset_cursor();
1073
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001074 while (ok == -1) {
1075 kbinput = wgetch(edit);
1076
1077 switch (kbinput) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001078 case NANO_CONTROL_C:
1079 ok = -2;
1080 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001081 default:
1082
1083 /* Look for the kbinput in the yes, no and (optinally) all str */
1084 for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++)
1085 ;
1086 if (yesstr[i] != 0) {
1087 ok = 0;
1088 break;
1089 }
1090
1091 for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++)
1092 ;
1093 if (nostr[i] != 0) {
1094 ok = 0;
1095 break;
1096 }
1097
1098 if (all) {
1099 for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++)
1100 ;
1101 if (allstr[i] != 0) {
1102 ok = 2;
1103 break;
1104 }
1105 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001106 }
1107 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001108
1109 /* Then blank the screen */
1110 blank_statusbar_refresh();
1111
1112 if (ok == -2)
1113 return -1;
1114 else
1115 return ok;
1116}
1117
1118void statusbar(char *msg, ...)
1119{
1120 va_list ap;
1121 char foo[133];
1122 int start_x = 0;
1123
1124 va_start(ap, msg);
1125 vsnprintf(foo, 132, msg, ap);
1126 va_end(ap);
1127
Chris Allegretta17dcb722001-01-20 21:40:07 +00001128 start_x = COLS / 2 - strlen(foo) / 2 - 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001129
1130 /* Blank out line */
1131 blank_statusbar();
1132
1133 wmove(bottomwin, 0, start_x);
1134
1135 wattron(bottomwin, A_REVERSE);
1136
1137 waddstr(bottomwin, "[ ");
1138 waddstr(bottomwin, foo);
1139 waddstr(bottomwin, " ]");
1140 wattroff(bottomwin, A_REVERSE);
1141 wrefresh(bottomwin);
1142
1143 if (ISSET(CONSTUPDATE))
1144 statblank = 1;
1145 else
1146 statblank = 25;
1147}
1148
1149void display_main_list(void)
1150{
1151 bottombars(main_list, MAIN_VISIBLE);
1152}
1153
1154int total_refresh(void)
1155{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001156 clearok(edit, TRUE);
1157 clearok(topwin, TRUE);
1158 clearok(bottomwin, TRUE);
1159 wnoutrefresh(edit);
1160 wnoutrefresh(topwin);
1161 wnoutrefresh(bottomwin);
1162 doupdate();
1163 clearok(edit, FALSE);
1164 clearok(topwin, FALSE);
1165 clearok(bottomwin, FALSE);
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001166 edit_refresh();
Chris Allegrettaf4b96012001-01-03 07:11:47 +00001167 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001168 return 1;
1169}
1170
1171void previous_line(void)
1172{
1173 if (current_y > 0)
1174 current_y--;
1175}
1176
1177int do_cursorpos(void)
1178{
1179 filestruct *fileptr;
Chris Allegretta66795ec2000-12-27 04:47:28 +00001180 float linepct = 0.0, bytepct = 0.0;
1181 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001182
1183 if (current == NULL || fileage == NULL)
1184 return 0;
1185
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001186 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1187 fileptr = fileptr->next)
Chris Allegretta66795ec2000-12-27 04:47:28 +00001188 i += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001189
1190 if (fileptr == NULL)
1191 return -1;
1192
Chris Allegretta66795ec2000-12-27 04:47:28 +00001193 i += current_x;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001194
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001195 if (totlines > 0)
1196 linepct = 100 * current->lineno / totlines;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001197
1198 if (totsize > 0)
1199 bytepct = 100 * i / totsize;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001200
1201#ifdef DEBUG
1202 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1203 linepct, bytepct);
1204#endif
1205
1206 statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"),
1207 current->lineno, totlines, linepct, i, totsize, bytepct);
1208 reset_cursor();
1209 return 1;
1210}
1211
1212/* Our broken, non-shortcut list compliant help function.
1213 But hey, it's better than nothing, and it's dynamic! */
1214int do_help(void)
1215{
Rocco Corsiaf5c3022001-01-12 07:51:05 +00001216#ifndef DISABLE_HELP
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001217 char *ptr = help_text, *end;
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001218 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001219 int no_help_flag = 0;
1220
1221 blank_edit();
1222 curs_set(0);
1223 blank_statusbar();
1224
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001225 kp = keypad_on(edit, 1);
1226
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001227 if (ISSET(NO_HELP)) {
1228
Chris Allegretta70444892001-01-07 23:02:02 +00001229 /* Well if we're going to do this, we should at least
1230 do it the right way */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001231 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001232 UNSET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001233 window_init();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001234 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta70444892001-01-07 23:02:02 +00001235
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001236 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001237 bottombars(help_list, HELP_LIST_LEN);
1238
1239 do {
1240 ptr = help_text;
1241 switch (kbinput) {
1242 case NANO_NEXTPAGE_KEY:
1243 case NANO_NEXTPAGE_FKEY:
1244 case KEY_NPAGE:
1245 if (!no_more) {
1246 blank_edit();
1247 page++;
1248 }
1249 break;
1250 case NANO_PREVPAGE_KEY:
1251 case NANO_PREVPAGE_FKEY:
1252 case KEY_PPAGE:
1253 if (page > 1) {
1254 no_more = 0;
1255 blank_edit();
1256 page--;
1257 }
1258 break;
1259 }
1260
1261 /* Calculate where in the text we should be based on the page */
1262 for (i = 1; i < page; i++) {
1263 row = 0;
1264 j = 0;
Chris Allegretta44e73df2000-09-07 03:37:38 +00001265
1266 while (row < editwinrows - 2 && *ptr != '\0') {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001267 if (*ptr == '\n' || j == COLS - 5) {
1268 j = 0;
1269 row++;
1270 }
1271 ptr++;
1272 j++;
1273 }
1274 }
1275
Chris Allegretta44e73df2000-09-07 03:37:38 +00001276 if (i > 1) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001277
Chris Allegretta44e73df2000-09-07 03:37:38 +00001278 }
1279
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001280 i = 0;
1281 j = 0;
1282 while (i < editwinrows && *ptr != '\0') {
1283 end = ptr;
1284 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1285 end++;
1286 j++;
1287 }
1288 if (j == COLS - 5) {
1289
1290 /* Don't print half a word if we've run of of space */
1291 while (*end != ' ' && *end != '\0') {
1292 end--;
1293 j--;
1294 }
1295 }
1296 mvwaddnstr(edit, i, 0, ptr, j);
1297 j = 0;
1298 i++;
1299 if (*end == '\n')
1300 end++;
1301 ptr = end;
1302 }
1303 if (*ptr == '\0') {
1304 no_more = 1;
1305 continue;
1306 }
Chris Allegrettad1627cf2000-12-18 05:03:16 +00001307 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
1308 kbinput != NANO_EXIT_FKEY);
1309
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001310 if (no_help_flag) {
Chris Allegretta70444892001-01-07 23:02:02 +00001311 blank_bottombars();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001312 wrefresh(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001313 SET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001314 window_init();
1315 }
1316 display_main_list();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001317
1318 curs_set(1);
1319 edit_refresh();
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001320 kp = keypad_on(edit, kp);
1321
Chris Allegretta3bc8c722000-12-10 17:03:25 +00001322#elif defined(DISABLE_HELP)
1323 nano_disabled_msg();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001324#endif
1325
1326 return 1;
1327}
1328
1329/* Dump the current file structure to stderr */
1330void dump_buffer(filestruct * inptr)
1331{
1332#ifdef DEBUG
1333 filestruct *fileptr;
1334
1335 if (inptr == fileage)
1336 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1337 else if (inptr == cutbuffer)
1338 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1339 else
1340 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1341
1342 fileptr = inptr;
1343 while (fileptr != NULL) {
1344 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1345 fflush(stderr);
1346 fileptr = fileptr->next;
1347 }
1348#endif /* DEBUG */
1349}
1350
1351void dump_buffer_reverse(filestruct * inptr)
1352{
1353#ifdef DEBUG
1354 filestruct *fileptr;
1355
1356 fileptr = filebot;
1357 while (fileptr != NULL) {
1358 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1359 fflush(stderr);
1360 fileptr = fileptr->prev;
1361 }
1362#endif /* DEBUG */
1363}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001364
1365/* Fix editbot based on the assumption that edittop is correct */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001366void fix_editbot(void)
1367{
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001368 int i;
1369 editbot = edittop;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001370 for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1371 && (editbot != filebot); i++, editbot = editbot->next);
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001372}
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001373
Chris Allegrettafb62f732000-12-05 11:36:41 +00001374/* highlight the current word being replaced or spell checked */
1375void do_replace_highlight(int highlight_flag, char *word)
1376{
1377 char *highlight_word = NULL;
1378 int x, y;
1379
1380 highlight_word = mallocstrcpy(highlight_word, &current->data[current_x]);
1381 highlight_word[strlen(word)] = '\0';
1382
1383 /* adjust output when word extends beyond screen*/
1384
1385 x = xplustabs();
1386 y = get_page_end_virtual(get_page_from_virtual(x)) + 1;
1387
1388 if ((COLS - (y - x) + strlen(word)) > COLS) {
1389 highlight_word[y - x - 1] = '$';
1390 highlight_word[y - x] = '\0';
1391 }
1392
1393 /* OK display the output */
1394
1395 reset_cursor();
1396
1397 if (highlight_flag)
1398 wattron(edit, A_REVERSE);
1399
1400 waddstr(edit, highlight_word);
1401
1402 if (highlight_flag)
1403 wattroff(edit, A_REVERSE);
1404
1405 free(highlight_word);
1406}
1407
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001408#ifdef NANO_EXTRA
Chris Allegretta7cd9f742000-11-25 20:17:28 +00001409#define CREDIT_LEN 45
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001410void do_credits(void)
1411{
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001412 int i, j = 0, k, place = 0, start_x;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001413 char *what;
1414
1415 char *nanotext = _("The nano text editor");
1416 char *version = _("version ");
1417 char *brought = _("Brought to you by:");
1418 char *specialthx = _("Special thanks to:");
1419 char *fsf = _("The Free Software Foundation");
1420 char *ncurses = _("Pavel Curtis, Zeyd Ben-Halim and Eric S. Raymond for ncurses");
1421 char *anyonelse = _("and anyone else we forgot...");
1422 char *thankyou = _("Thank you for using nano!\n");
1423
1424 char *credits[CREDIT_LEN] = {nanotext,
1425 version,
1426 VERSION,
1427 "",
1428 brought,
1429 "Chris Allegretta",
1430 "Jordi Mallach",
1431 "Adam Rogoyski",
1432 "Rob Siemborski",
1433 "Rocco Corsi",
1434 "Ken Tyler",
1435 "Sven Guckes",
1436 "Florian König",
1437 "Pauli Virtanen",
1438 "Daniele Medri",
1439 "Clement Laforet",
1440 "Tedi Heriyanto",
Chris Allegrettaa131c7c2000-11-25 19:59:41 +00001441 "Bill Soudan",
Chris Allegretta7cd9f742000-11-25 20:17:28 +00001442 "Christian Weisgerber",
Chris Allegretta827b15f2001-01-03 02:09:04 +00001443 "Erik Andersen",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001444 "Big Gaute",
1445 "Joshua Jensen",
1446 "",
1447 specialthx,
1448 "Plattsburgh State University",
1449 "Benet Laboratories",
1450 "Amy Allegretta",
1451 "Linda Young",
1452 "Jeremy Robichaud",
1453 "Richard Kolb II",
1454 fsf,
1455 "Linus Torvalds",
1456 ncurses,
1457 anyonelse,
1458 thankyou,
1459 "", "", "", "",
1460 "(c) 2000 Chris Allegretta",
1461 "", "", "", "",
1462 "www.nano-editor.org"
1463 };
1464
1465 curs_set(0);
1466 nodelay(edit, TRUE);
1467 blank_bottombars();
1468 mvwaddstr(topwin, 0, 0, hblank);
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001469 blank_edit();
1470 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001471 wrefresh(bottomwin);
1472 wrefresh(topwin);
1473
1474 while (wgetch(edit) == ERR) {
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001475 for (k = 0; k <= 1; k++) {
1476 blank_edit();
1477 for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); i--) {
1478 mvwaddstr(edit, i * 2 - k, 0, hblank);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001479
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001480 if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
1481 what = credits[place - (editwinrows / 2 - 1 - i)];
1482 else
1483 what = "";
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001484
Chris Allegretta17dcb722001-01-20 21:40:07 +00001485 start_x = COLS / 2 - strlen(what) / 2 - 1;
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001486 mvwaddstr(edit, i * 2 - k, start_x, what);
1487 }
1488 usleep(700000);
1489 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001490 }
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001491 if (j < editwinrows / 2 - 1)
1492 j++;
1493
1494 place++;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001495
1496 if (place >= CREDIT_LEN + editwinrows / 2)
1497 break;
1498 }
1499
1500 nodelay(edit, FALSE);
1501 curs_set(1);
1502 display_main_list();
1503 total_refresh();
1504 }
1505#endif
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001506
1507int keypad_on(WINDOW * win, int new)
1508{
1509
1510/* This is taken right from aumix. Don't sue me */
1511#ifdef HAVE_USEKEYPAD
1512 int old;
1513
1514 old = win->_use_keypad;
1515 keypad(win, new);
1516 return old;
1517#else
1518 keypad(win, new);
1519 return 1;
1520#endif /* HAVE_USEKEYPAD */
1521
1522}
1523
1524
1525