blob: c4fe6b23b4b08c253ee24098b571cfc5a9b726bc [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 *
Chris Allegretta3a24f3f2001-10-24 11:33:54 +00008 * the Free Software Foundation; either version 2, or (at your option) *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00009 * any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
19 * *
20 **************************************************************************/
21
Chris Allegretta6efda542001-04-28 18:03:52 +000022#include "config.h"
23
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000024#include <stdarg.h>
25#include <string.h>
Chris Allegrettadba37ae2000-07-07 05:13:09 +000026#include <stdlib.h>
Chris Allegretta8a0de3b2000-11-24 20:45:14 +000027#include <unistd.h>
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000028#include "proto.h"
29#include "nano.h"
30
31#ifndef NANO_SMALL
32#include <libintl.h>
33#define _(string) gettext(string)
34#else
35#define _(string) (string)
36#endif
37
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +000038
39/* winio.c statics */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000040static int statblank = 0; /* Number of keystrokes left after
Chris Allegretta88520c92001-05-05 17:45:54 +000041 we call statusbar(), before we
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000042 actually blank the statusbar */
Robert Siemborskid8510b22000-06-06 23:04:06 +000043
44/* Local Function Prototypes for only winio.c */
45inline int get_page_from_virtual(int virtual);
46inline int get_page_start_virtual(int page);
47inline int get_page_end_virtual(int page);
48
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000049/* Window I/O */
50
51int do_first_line(void)
52{
53 current = fileage;
54 placewewant = 0;
55 current_x = 0;
Chris Allegretta234a34d2000-07-29 04:33:38 +000056 edit_update(current, CENTER);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000057 return 1;
58}
59
60int do_last_line(void)
61{
62 current = filebot;
63 placewewant = 0;
64 current_x = 0;
Chris Allegretta234a34d2000-07-29 04:33:38 +000065 edit_update(current, CENTER);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000066 return 1;
67}
68
Chris Allegretta88520c92001-05-05 17:45:54 +000069/* Like xplustabs, but for a specific index of a specific filestruct */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000070int xpt(filestruct * fileptr, int index)
71{
72 int i, tabs = 0;
73
74 if (fileptr == NULL || fileptr->data == NULL)
75 return 0;
76
77 for (i = 0; i < index && fileptr->data[i] != 0; i++) {
78 tabs++;
79
80 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta6d690a32000-08-03 22:51:21 +000081 if (tabs % tabsize == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000082 else
Chris Allegretta6d690a32000-08-03 22:51:21 +000083 tabs += tabsize - (tabs % tabsize);
Chris Allegretta4da1fc62000-06-21 03:00:43 +000084 } else if (fileptr->data[i] & 0x80)
Chris Allegretta88520c92001-05-05 17:45:54 +000085 /* Make 8 bit chars only 1 column! */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000086 ;
87 else if (fileptr->data[i] < 32)
88 tabs++;
89 }
90
91 return tabs;
92}
93
94
95/* Return the actual place on the screen of current->data[current_x], which
96 should always be > current_x */
97int xplustabs(void)
98{
99 return xpt(current, current_x);
100}
101
102
Robert Siemborskid8510b22000-06-06 23:04:06 +0000103/* Return what current_x should be, given xplustabs() for the line,
104 * given a start position in the filestruct's data */
105int actual_x_from_start(filestruct * fileptr, int xplus, int start)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000106{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000107 int i, tot = 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000108
109 if (fileptr == NULL || fileptr->data == NULL)
110 return 0;
111
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000112 for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000113 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta6d690a32000-08-03 22:51:21 +0000114 if (tot % tabsize == 0)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000115 tot++;
116 else
Chris Allegretta6d690a32000-08-03 22:51:21 +0000117 tot += tabsize - (tot % tabsize);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000118 } else if (fileptr->data[i] & 0x80)
119 tot++; /* Make 8 bit chars only 1 column (again) */
120 else if (fileptr->data[i] < 32)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000121 tot += 2;
122
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000123#ifdef DEBUG
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000124 fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"),
125 xplus, i);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000126#endif
Robert Siemborskid8510b22000-06-06 23:04:06 +0000127 return i - start;
128}
129
130/* Opposite of xplustabs */
Chris Allegretta6efda542001-04-28 18:03:52 +0000131int actual_x(filestruct * fileptr, int xplus)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000132{
133 return actual_x_from_start(fileptr, xplus, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000134}
135
136/* a strlen with tabs factored in, similar to xplustabs() */
137int strlenpt(char *buf)
138{
139 int i, tabs = 0;
140
141 if (buf == NULL)
142 return 0;
143
144 for (i = 0; buf[i] != 0; i++) {
145 tabs++;
146
147 if (buf[i] == NANO_CONTROL_I) {
Chris Allegretta6d690a32000-08-03 22:51:21 +0000148 if (tabs % tabsize == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000149 else
Chris Allegretta6d690a32000-08-03 22:51:21 +0000150 tabs += tabsize - (tabs % tabsize);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000151 } else if (buf[i] & 0x80)
Chris Allegretta88520c92001-05-05 17:45:54 +0000152 /* Make 8 bit chars only 1 column! */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000153 ;
154 else if (buf[i] < 32)
155 tabs++;
156 }
157
158 return tabs;
159}
160
161
Chris Allegretta88520c92001-05-05 17:45:54 +0000162/* resets current_y, based on the position of current, and puts the cursor at
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000163 (current_y, current_x) */
164void reset_cursor(void)
165{
166 filestruct *ptr = edittop;
167 int x;
168
169 current_y = 0;
170
171 while (ptr != current && ptr != editbot && ptr->next != NULL) {
172 ptr = ptr->next;
173 current_y++;
174 }
175
176 x = xplustabs();
177 if (x <= COLS - 2)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000178 wmove(edit, current_y, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000179 else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000180 wmove(edit, current_y, x -
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000181 get_page_start_virtual(get_page_from_virtual(x)));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000182
183}
184
185void blank_bottombars(void)
186{
187 int i = no_help()? 3 : 1;
188
189 for (; i <= 2; i++)
190 mvwaddstr(bottomwin, i, 0, hblank);
191
192}
193
194void blank_edit(void)
195{
196 int i;
197 for (i = 0; i <= editwinrows - 1; i++)
198 mvwaddstr(edit, i, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000199}
200
201
202void blank_statusbar(void)
203{
204 mvwaddstr(bottomwin, 0, 0, hblank);
205}
206
207void blank_statusbar_refresh(void)
208{
209 blank_statusbar();
210 wrefresh(bottomwin);
211}
212
213void check_statblank(void)
214{
215
216 if (statblank > 1)
217 statblank--;
218 else if (statblank == 1 && !ISSET(CONSTUPDATE)) {
219 statblank--;
220 blank_statusbar_refresh();
221 }
222}
223
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000224/* Repaint the statusbar when getting a character in nanogetstr */
225void nanoget_repaint(char *buf, char *inputbuf, int x)
226{
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000227 int len = strlen(buf);
228 int wid = COLS - len;
229
Chris Allegretta8ce24132001-04-30 11:28:46 +0000230#ifdef ENABLE_COLOR
231 color_on(bottomwin, COLOR_STATUSBAR);
Chris Allegrettab3655b42001-10-22 03:15:31 +0000232#else
233 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000234#endif
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000235 blank_statusbar();
Chris Allegretta8ce24132001-04-30 11:28:46 +0000236
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000237 if (x <= COLS - 1) {
238 /* Black magic */
239 buf[len - 1] = ' ';
Chris Allegretta31925e42000-11-02 04:40:39 +0000240
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000241 mvwaddstr(bottomwin, 0, 0, buf);
242 waddnstr(bottomwin, inputbuf, wid);
243 wmove(bottomwin, 0, (x % COLS));
244 }
245 else {
246 /* Black magic */
247 buf[len - 1] = '$';
Chris Allegretta31925e42000-11-02 04:40:39 +0000248
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000249 mvwaddstr(bottomwin, 0, 0, buf);
250 waddnstr(bottomwin, &inputbuf[wid * ((x - len) / (wid))], wid);
251 wmove(bottomwin, 0, ((x - len) % wid) + len);
252 }
Chris Allegretta8ce24132001-04-30 11:28:46 +0000253
254#ifdef ENABLE_COLOR
255 color_off(bottomwin, COLOR_STATUSBAR);
Chris Allegrettab3655b42001-10-22 03:15:31 +0000256#else
257 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000258#endif
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000259}
260
Chris Allegretta88520c92001-05-05 17:45:54 +0000261/* Get the input from the kb; this should only be called from statusq */
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000262int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
Chris Allegretta2084acc2001-11-29 03:43:08 +0000263 int start_x, int list)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000264{
265 int kbinput = 0, j = 0, x = 0, xend;
Chris Allegrettabe77c612000-11-24 14:00:16 +0000266 int x_left = 0, inputlen, tabbed = 0;
Chris Allegretta31925e42000-11-02 04:40:39 +0000267 char *inputbuf;
Rocco Corsi06aca1c2001-01-11 05:30:31 +0000268#ifndef DISABLE_TABCOMP
Chris Allegrettabe77c612000-11-24 14:00:16 +0000269 int shift = 0;
270#endif
Chris Allegretta31925e42000-11-02 04:40:39 +0000271
Chris Allegretta88b09152001-05-17 11:35:43 +0000272 inputbuf = charalloc(strlen(def) + 1);
Chris Allegretta31925e42000-11-02 04:40:39 +0000273 inputbuf[0] = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000274
275 x_left = strlen(buf);
276 x = strlen(def) + x_left;
277
Chris Allegrettab3655b42001-10-22 03:15:31 +0000278#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000279 currshortcut = s;
280 currslen = slen;
Chris Allegretta6fe61492001-05-21 12:56:25 +0000281#endif
282
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000283 /* Get the input! */
Chris Allegretta31925e42000-11-02 04:40:39 +0000284 if (strlen(def) > 0)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000285 strcpy(inputbuf, def);
Chris Allegretta31925e42000-11-02 04:40:39 +0000286
287 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000288
Chris Allegretta022b96f2000-11-14 17:47:58 +0000289 /* Make sure any editor screen updates are displayed before getting input */
290 wrefresh(edit);
291
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000292 while ((kbinput = wgetch(bottomwin)) != 13) {
293 for (j = 0; j <= slen - 1; j++) {
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000294#ifdef DEBUG
295 fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
296#endif
297
Chris Allegretta658399a2001-06-14 02:54:22 +0000298 if (kbinput == s[j].val && kbinput < 32) {
Chris Allegretta5bf51d32000-11-16 06:01:10 +0000299
Chris Allegrettab3655b42001-10-22 03:15:31 +0000300#ifndef DISABLE_HELP
301 /* Have to do this here, it would be too late to do it in statusq */
302 if (kbinput == NANO_HELP_KEY
303 || kbinput == NANO_HELP_FKEY) {
304 do_help();
305 break;
306 }
307#endif
308
Chris Allegretta5bf51d32000-11-16 06:01:10 +0000309 /* We shouldn't discard the answer it gave, just because
310 we hit a keystroke, GEEZ! */
311 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000312 free(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000313 return s[j].val;
314 }
315 }
316 xend = strlen(buf) + strlen(inputbuf);
317
Chris Allegretta04d848e2000-11-05 17:54:41 +0000318 if (kbinput != '\t')
319 tabbed = 0;
320
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000321 switch (kbinput) {
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000322
323 /* Stuff we want to equate with <enter>, ASCII 13 */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000324 case 343:
Chris Allegrettaf9b6c9b2000-10-18 19:35:59 +0000325 ungetch(13); /* Enter on iris-ansi $TERM, sometimes */
326 break;
Chris Allegretta75155df2000-11-28 23:04:24 +0000327 /* Stuff we want to ignore */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000328#ifdef PDCURSES
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000329 case 541:
330 case 542:
Chris Allegretta72623582000-11-29 23:43:28 +0000331 case 543: /* Right ctrl again */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000332 case 544:
Chris Allegretta72623582000-11-29 23:43:28 +0000333 case 545: /* Right alt again */
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000334 break;
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000335#endif
Chris Allegretta84de5522001-04-12 14:51:48 +0000336#ifndef DISABLE_MOUSE
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000337#ifdef NCURSES_MOUSE_VERSION
338 case KEY_MOUSE:
339 do_mouse();
340 break;
341#endif
342#endif
Chris Allegretta658399a2001-06-14 02:54:22 +0000343 case NANO_HOME_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000344 case KEY_HOME:
345 x = x_left;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000346 break;
Chris Allegretta658399a2001-06-14 02:54:22 +0000347 case NANO_END_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000348 case KEY_END:
349 x = x_left + strlen(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000350 break;
351 case KEY_RIGHT:
Chris Allegretta35dac582001-03-21 15:07:20 +0000352 case NANO_FORWARD_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000353
354 if (x < xend)
355 x++;
356 wmove(bottomwin, 0, x);
357 break;
358 case NANO_CONTROL_D:
359 if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
360 memmove(inputbuf + (x - x_left),
361 inputbuf + (x - x_left) + 1,
362 strlen(inputbuf) - (x - x_left) - 1);
363 inputbuf[strlen(inputbuf) - 1] = 0;
364 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000365 break;
366 case NANO_CONTROL_K:
367 case NANO_CONTROL_U:
368 *inputbuf = 0;
369 x = x_left;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000370 break;
371 case KEY_BACKSPACE:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000372 case 127:
373 case NANO_CONTROL_H:
374 if (strlen(inputbuf) > 0) {
375 if (x == (x_left + strlen(inputbuf)))
376 inputbuf[strlen(inputbuf) - 1] = 0;
377 else if (x - x_left) {
378 memmove(inputbuf + (x - x_left) - 1,
379 inputbuf + (x - x_left),
380 strlen(inputbuf) - (x - x_left));
381 inputbuf[strlen(inputbuf) - 1] = 0;
382 }
383 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000384 if (x > strlen(buf))
385 x--;
Chris Allegretta04d848e2000-11-05 17:54:41 +0000386 break;
Rocco Corsi06aca1c2001-01-11 05:30:31 +0000387#ifndef DISABLE_TABCOMP
Chris Allegretta04d848e2000-11-05 17:54:41 +0000388 case NANO_CONTROL_I:
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000389 if (allowtabs) {
Chris Allegretta442f2c52000-11-14 17:46:06 +0000390 shift = 0;
391 inputbuf = input_tab(inputbuf, (x - x_left),
Chris Allegretta2084acc2001-11-29 03:43:08 +0000392 &tabbed, &shift, &list);
Chris Allegretta442f2c52000-11-14 17:46:06 +0000393 x += shift;
Chris Allegrettae434b452001-01-27 19:25:00 +0000394 if (x - x_left > strlen(inputbuf))
395 x = strlen(inputbuf) + x_left;
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000396 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000397 break;
Chris Allegrettabe77c612000-11-24 14:00:16 +0000398#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000399 case KEY_LEFT:
Chris Allegretta35dac582001-03-21 15:07:20 +0000400 case NANO_BACK_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000401 if (x > strlen(buf))
402 x--;
403 wmove(bottomwin, 0, x);
404 break;
405 case KEY_UP:
406 case KEY_DOWN:
407 break;
408
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000409 case KEY_DC:
410 goto do_deletekey;
411
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000412 case 27:
413 switch (kbinput = wgetch(edit)) {
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000414 case 'O':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000415 switch (kbinput = wgetch(edit)) {
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000416 case 'F':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000417 x = x_left + strlen(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000418 break;
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000419 case 'H':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000420 x = x_left;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000421 break;
422 }
423 break;
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000424 case '[':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000425 switch (kbinput = wgetch(edit)) {
426 case 'C':
427 if (x < xend)
428 x++;
429 wmove(bottomwin, 0, x);
430 break;
431 case 'D':
432 if (x > strlen(buf))
433 x--;
434 wmove(bottomwin, 0, x);
435 break;
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000436 case '1':
437 case '7':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000438 x = x_left;
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000439 goto skip_tilde;
440 case '3':
441 do_deletekey:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000442 if (strlen(inputbuf) > 0
443 && (x - x_left) != strlen(inputbuf)) {
444 memmove(inputbuf + (x - x_left),
445 inputbuf + (x - x_left) + 1,
446 strlen(inputbuf) - (x - x_left) - 1);
447 inputbuf[strlen(inputbuf) - 1] = 0;
448 }
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000449 goto skip_tilde;
450 case '4':
451 case '8':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000452 x = x_left + strlen(inputbuf);
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000453 goto skip_tilde;
454 skip_tilde:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000455 nodelay(edit, TRUE);
456 kbinput = wgetch(edit);
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000457 if (kbinput == '~' || kbinput == ERR)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000458 kbinput = -1;
459 nodelay(edit, FALSE);
460 break;
461 }
Chris Allegretta658399a2001-06-14 02:54:22 +0000462 default:
463
464 for (j = 0; j <= slen - 1; j++) {
465#ifdef DEBUG
466 fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
467#endif
468 if (kbinput == s[j].val || kbinput == s[j].val - 32) {
469
470 /* We hit an Alt key. Do like above. We don't
471 just ungetch the letter and let it get caught
472 above cause that screws the keypad... */
473 answer = mallocstrcpy(answer, inputbuf);
474 free(inputbuf);
475 return s[j].val;
476 }
477 }
478
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000479 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000480 break;
481
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000482 default:
Chris Allegretta658399a2001-06-14 02:54:22 +0000483
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000484 if (kbinput < 32)
485 break;
Chris Allegretta31925e42000-11-02 04:40:39 +0000486
487 inputlen = strlen(inputbuf);
488 inputbuf = nrealloc(inputbuf, inputlen + 2);
489
490 memmove(&inputbuf[x - x_left + 1],
491 &inputbuf[x - x_left],
492 inputlen - (x - x_left) + 1);
493 inputbuf[x - x_left] = kbinput;
494
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000495 x++;
496
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000497#ifdef DEBUG
498 fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
499#endif
500 }
Chris Allegretta386e0512001-10-02 02:57:26 +0000501 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000502 wrefresh(bottomwin);
503 }
504
Chris Allegretta31925e42000-11-02 04:40:39 +0000505 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000506 free(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000507
Chris Allegrettac1049ac2001-08-17 00:03:46 +0000508 /* In pico mode, just check for a blank answer here */
509 if (((ISSET(PICO_MODE)) && !strcmp(answer, "")))
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000510 return -2;
511 else
512 return 0;
513}
514
515void horizbar(WINDOW * win, int y)
516{
517 wattron(win, A_REVERSE);
518 mvwaddstr(win, 0, 0, hblank);
519 wattroff(win, A_REVERSE);
520}
521
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000522void titlebar(char *path)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000523{
524 int namelen, space;
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000525 char *what = path;
526
527 if (path == NULL)
528 what = filename;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000529
Chris Allegretta8ce24132001-04-30 11:28:46 +0000530#ifdef ENABLE_COLOR
531 color_on(topwin, COLOR_TITLEBAR);
532 mvwaddstr(topwin, 0, 0, hblank);
533#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000534 horizbar(topwin, 0);
535 wattron(topwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000536#endif
537
538
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000539 mvwaddstr(topwin, 0, 3, VERMSG);
540
541 space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
542
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000543 namelen = strlen(what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000544
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000545 if (!strcmp(what, ""))
Chris Allegretta17dcb722001-01-20 21:40:07 +0000546 mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000547 else {
548 if (namelen > space) {
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000549 if (path == NULL)
550 waddstr(topwin, _(" File: ..."));
551 else
552 waddstr(topwin, _(" DIR: ..."));
553 waddstr(topwin, &what[namelen - space]);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000554 } else {
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000555 if (path == NULL)
Jordi Mallach9335f912001-12-23 00:03:18 +0000556 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), _("File: "));
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000557 else
Jordi Mallach9335f912001-12-23 00:03:18 +0000558 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), _(" DIR: "));
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000559 waddstr(topwin, what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000560 }
561 }
562 if (ISSET(MODIFIED))
563 mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
Chris Allegretta8ce24132001-04-30 11:28:46 +0000564
565
566#ifdef ENABLE_COLOR
567 color_off(topwin, COLOR_TITLEBAR);
568#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000569 wattroff(topwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000570#endif
571
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000572 wrefresh(topwin);
573 reset_cursor();
574}
575
576void onekey(char *keystroke, char *desc)
577{
578 char description[80];
579
Chris Allegretta658399a2001-06-14 02:54:22 +0000580 snprintf(description, 12 - (strlen(keystroke) - 2), " %-10s", desc);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000581 wattron(bottomwin, A_REVERSE);
582 waddstr(bottomwin, keystroke);
583 wattroff(bottomwin, A_REVERSE);
584 waddstr(bottomwin, description);
585}
586
587void clear_bottomwin(void)
588{
589 if (ISSET(NO_HELP))
590 return;
591
592 mvwaddstr(bottomwin, 1, 0, hblank);
593 mvwaddstr(bottomwin, 2, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000594}
595
596void bottombars(shortcut s[], int slen)
597{
598 int i, j, k;
599 char keystr[10];
600
601 if (ISSET(NO_HELP))
602 return;
603
Chris Allegretta8ce24132001-04-30 11:28:46 +0000604#ifdef ENABLE_COLOR
605 color_on(bottomwin, COLOR_BOTTOMBARS);
606#endif
607
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000608 /* Determine how many extra spaces are needed to fill the bottom of the screen */
Chris Allegretta96eef732001-08-25 16:41:37 +0000609 if (slen < 2)
610 k = COLS / 6 - 13;
611 else
Chris Allegretta7dd18692001-08-26 23:16:44 +0000612 k = COLS / ((slen + (slen %2)) / 2) - 13;
Chris Allegretta96eef732001-08-25 16:41:37 +0000613
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000614
615 clear_bottomwin();
616 wmove(bottomwin, 1, 0);
Chris Allegretta658399a2001-06-14 02:54:22 +0000617
Chris Allegretta5f36c372001-07-16 00:48:53 +0000618 for (i = 0; i <= slen - 1; i += 2) {
Chris Allegretta658399a2001-06-14 02:54:22 +0000619
620 if (s[i].val < 97)
621 snprintf(keystr, 10, "^%c", s[i].val + 64);
622 else
623 snprintf(keystr, 10, "M-%c", s[i].val - 32);
624
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000625 onekey(keystr, s[i].desc);
626
627 for (j = 0; j < k; j++)
628 waddch(bottomwin, ' ');
629 }
630
631 wmove(bottomwin, 2, 0);
632 for (i = 1; i <= slen - 1; i += 2) {
Chris Allegretta658399a2001-06-14 02:54:22 +0000633
634 if (s[i].val < 97)
635 snprintf(keystr, 10, "^%c", s[i].val + 64);
636 else
637 snprintf(keystr, 10, "M-%c", s[i].val - 32);
638
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000639 onekey(keystr, s[i].desc);
640
641 for (j = 0; j < k; j++)
642 waddch(bottomwin, ' ');
643 }
644
Chris Allegretta8ce24132001-04-30 11:28:46 +0000645#ifdef ENABLE_COLOR
646 color_off(bottomwin, COLOR_BOTTOMBARS);
647#endif
648
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000649 wrefresh(bottomwin);
650
651}
652
653/* If modified is not already set, set it and update titlebar */
654void set_modified(void)
655{
656 if (!ISSET(MODIFIED)) {
657 SET(MODIFIED);
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000658 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000659 wrefresh(topwin);
660 }
661}
662
Robert Siemborski9d584552000-07-08 00:41:29 +0000663/* And so start the display update routines */
664/* Given a column, this returns the "page" it is on */
665/* "page" in the case of the display columns, means which set of 80 */
Chris Allegretta88520c92001-05-05 17:45:54 +0000666/* characters is viewable (e.g.: page 1 shows from 1 to COLS) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000667inline int get_page_from_virtual(int virtual)
668{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000669 int page = 2;
670
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000671 if (virtual <= COLS - 2)
672 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000673 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000674
675 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000676 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000677 page++;
678 }
679
680 return page;
681}
682
Robert Siemborski9d584552000-07-08 00:41:29 +0000683/* The inverse of the above function */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000684inline int get_page_start_virtual(int page)
685{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000686 int virtual;
687 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000688 if (page)
689 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000690 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000691}
692
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000693inline int get_page_end_virtual(int page)
694{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000695 return get_page_start_virtual(page) + COLS - 1;
696}
697
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000698#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000699/* This takes care of the case where there is a mark that covers only */
700/* the current line. */
701
Chris Allegretta88520c92001-05-05 17:45:54 +0000702/* It expects a line with no tab characters (i.e.: the type that edit_add */
Robert Siemborski9d584552000-07-08 00:41:29 +0000703/* deals with */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000704void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
705 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000706{
Robert Siemborski9d584552000-07-08 00:41:29 +0000707 /*
708 * The general idea is to break the line up into 3 sections: before
709 * the mark, the mark, and after the mark. We then paint each in
Chris Allegretta88520c92001-05-05 17:45:54 +0000710 * turn (for those that are currently visible, of course)
Robert Siemborski9d584552000-07-08 00:41:29 +0000711 *
712 * 3 start points: 0 -> begin, begin->end, end->strlen(data)
713 * in data : pre sel post
714 */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000715 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000716 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000717
Robert Siemborskid8510b22000-06-06 23:04:06 +0000718 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000719 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 +0000720
721 /* now fix the start locations & lengths according to the cursor's
Chris Allegretta88520c92001-05-05 17:45:54 +0000722 * position (i.e.: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000723 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000724 pre_data_len = 0;
725 else
726 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000727
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000728 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000729 begin = this_page_start;
730
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000731 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000732 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000733
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000734 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000735 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000736
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000737 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000738 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000739
Robert Siemborski9d584552000-07-08 00:41:29 +0000740 /* Now calculate the lengths */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000741 sel_data_len = end - begin;
742 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000743
Chris Allegretta8ce24132001-04-30 11:28:46 +0000744#ifdef ENABLE_COLOR
745 color_on(edit, COLOR_MARKER);
746#else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000747 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000748#endif /* ENABLE_COLOR */
749
Robert Siemborskia9addc72000-06-17 06:06:35 +0000750 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000751 &fileptr->data[begin], sel_data_len);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000752
753#ifdef ENABLE_COLOR
754 color_off(edit, COLOR_MARKER);
755#else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000756 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000757#endif /* ENABLE_COLOR */
758
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000759}
760#endif
761
Robert Siemborski9d584552000-07-08 00:41:29 +0000762/* edit_add takes care of the job of actually painting a line into the
763 * edit window.
764 *
765 * Called only from update_line. Expects a converted-to-not-have-tabs
Robert Siemborski53875912000-06-16 04:25:30 +0000766 * line */
767void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000768 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000769{
Chris Allegretta08893e02001-11-29 02:42:27 +0000770
Chris Allegretta7dd77682001-12-08 19:52:28 +0000771#ifdef ENABLE_COLOR
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000772 colortype *tmpcolor = NULL;
773 colorstr *tmpstr = NULL;
774 int k, paintlen;
775#endif
776
777
778
779 /* Just paint the string in any case (we'll add color or reverse on
780 just the text that needs it */
781 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
782 get_page_end_virtual(this_page) - start + 1);
783
Chris Allegretta7dd77682001-12-08 19:52:28 +0000784#ifdef ENABLE_COLOR
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000785 if (colorstrings != NULL)
786 for (tmpcolor = colorstrings; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
787 for (tmpstr = tmpcolor->str; tmpstr != NULL; tmpstr = tmpstr->next) {
788
789 k = start;
790 regcomp(&search_regexp, tmpstr->val, 0);
791 while (!regexec(&search_regexp, &fileptr->data[k], 1,
792 regmatches, 0)) {
793
794#ifdef DEBUG
795 fprintf(stderr, "Match! (%d chars) \"%s\"\n",
796 regmatches[0].rm_eo - regmatches[0].rm_so,
797 &fileptr->data[k + regmatches[0].rm_so]);
798#endif
799 if (regmatches[0].rm_so < COLS - 1) {
800 if (tmpcolor->bright)
801 wattron(edit, A_BOLD);
802 wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
803
804 if (regmatches[0].rm_eo - regmatches[0].rm_so
805 + k <= COLS)
806 paintlen = regmatches[0].rm_eo - regmatches[0].rm_so;
807 else
808 paintlen = COLS - (regmatches[0].rm_eo
809 - regmatches[0].rm_so);
810
811 mvwaddnstr(edit, yval, regmatches[0].rm_so + k,
812 &fileptr->data[k + regmatches[0].rm_so],
813 paintlen);
814
815
816 }
817
818 if (tmpcolor->bright)
819 wattroff(edit, A_BOLD);
820 wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
821
822 k += regmatches[0].rm_eo;
823 }
824 }
825 }
Chris Allegretta7dd77682001-12-08 19:52:28 +0000826#endif /* ENABLE_COLOR */
827#ifndef NANO_SMALL
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000828
Chris Allegretta88520c92001-05-05 17:45:54 +0000829 /* There are quite a few cases that could take place; we'll deal
Robert Siemborski9d584552000-07-08 00:41:29 +0000830 * with them each in turn */
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000831 if (ISSET(MARK_ISSET) &&
832 !((fileptr->lineno > mark_beginbuf->lineno
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000833 && fileptr->lineno > current->lineno)
834 || (fileptr->lineno < mark_beginbuf->lineno
835 && fileptr->lineno < current->lineno))) {
Chris Allegretta88520c92001-05-05 17:45:54 +0000836 /* If we get here we are on a line that is at least
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000837 * partially selected. The lineno checks above determined
838 * that */
839 if (fileptr != mark_beginbuf && fileptr != current) {
840 /* We are on a completely marked line, paint it all
841 * inverse */
Chris Allegretta8ce24132001-04-30 11:28:46 +0000842#ifdef ENABLE_COLOR
843 color_on(edit, COLOR_MARKER);
844#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000845 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000846#endif /* ENABLE_COLOR */
847
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000848 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000849
850#ifdef ENABLE_COLOR
851 color_off(edit, COLOR_MARKER);
852#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000853 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000854#endif /* ENABLE_COLOR */
855
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000856 } else if (fileptr == mark_beginbuf && fileptr == current) {
857 /* Special case, we're still on the same line we started
858 * marking -- so we call our helper function */
859 if (virt_cur_x < virt_mark_beginx) {
860 /* To the right of us is marked */
861 add_marked_sameline(virt_cur_x, virt_mark_beginx,
862 fileptr, yval, virt_cur_x, this_page);
863 } else {
864 /* To the left of us is marked */
865 add_marked_sameline(virt_mark_beginx, virt_cur_x,
866 fileptr, yval, virt_cur_x, this_page);
867 }
868 } else if (fileptr == mark_beginbuf) {
869 /*
Chris Allegretta88520c92001-05-05 17:45:54 +0000870 * We're updating the line that was first marked,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000871 * but we're not currently on it. So we want to
Robert Siemborskia0238ed2001-03-31 21:46:43 +0000872 * figure out which half to invert based on our
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000873 * relative line numbers.
874 *
Chris Allegretta88520c92001-05-05 17:45:54 +0000875 * I.e. if we're above the "beginbuf" line, we want to
876 * mark the left side. Otherwise, we're below, so we
877 * mark the right.
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000878 */
879 int target;
880
Chris Allegretta8ce24132001-04-30 11:28:46 +0000881 if (mark_beginbuf->lineno > current->lineno) {
882#ifdef ENABLE_COLOR
883 color_on(edit, COLOR_MARKER);
884#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000885 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000886#endif /* ENABLE_COLOR */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000887
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000888 target =
889 (virt_mark_beginx < COLS - 1) ? virt_mark_beginx : COLS - 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000890
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000891 mvwaddnstr(edit, yval, 0, fileptr->data, target);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000892
893#ifdef ENABLE_COLOR
894 color_off(edit, COLOR_MARKER);
895#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000896 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000897#endif /* ENABLE_COLOR */
898
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000899
Chris Allegretta8ce24132001-04-30 11:28:46 +0000900 }
Robert Siemborskid8510b22000-06-06 23:04:06 +0000901
Chris Allegretta8ce24132001-04-30 11:28:46 +0000902 if (mark_beginbuf->lineno < current->lineno) {
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000903#ifdef ENABLE_COLOR
904 color_on(edit, COLOR_MARKER);
905#else
906 wattron(edit, A_REVERSE);
907#endif /* ENABLE_COLOR */
908
909 target = (COLS - 1) - virt_mark_beginx;
910
911 if (target < 0)
912 target = 0;
913
914 mvwaddnstr(edit, yval, virt_mark_beginx,
915 &fileptr->data[virt_mark_beginx], target);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000916
917#ifdef ENABLE_COLOR
918 color_off(edit, COLOR_MARKER);
919#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000920 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000921#endif /* ENABLE_COLOR */
922
923 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000924
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000925 } else if (fileptr == current) {
Chris Allegretta88520c92001-05-05 17:45:54 +0000926 /* We're on the cursor's line, but it's not the first
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000927 * one we marked. Similar to the previous logic. */
928 int this_page_start = get_page_start_virtual(this_page),
929 this_page_end = get_page_end_virtual(this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000930
Chris Allegretta8ce24132001-04-30 11:28:46 +0000931 if (mark_beginbuf->lineno < current->lineno) {
932
933#ifdef ENABLE_COLOR
934 color_on(edit, COLOR_MARKER);
935#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000936 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000937#endif /* ENABLE_COLOR */
938
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000939 if (virt_cur_x > COLS - 2) {
940 mvwaddnstr(edit, yval, 0,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000941 &fileptr->data[this_page_start],
942 virt_cur_x - this_page_start);
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000943 } else
944 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
945
946#ifdef ENABLE_COLOR
947 color_off(edit, COLOR_MARKER);
948#else
949 wattroff(edit, A_REVERSE);
950#endif /* ENABLE_COLOR */
951
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000952 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000953
Chris Allegretta8ce24132001-04-30 11:28:46 +0000954 if (mark_beginbuf->lineno > current->lineno) {
955
956#ifdef ENABLE_COLOR
957 color_on(edit, COLOR_MARKER);
958#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000959 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000960#endif /* ENABLE_COLOR */
961
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000962 if (virt_cur_x > COLS - 2)
963 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000964 &fileptr->data[virt_cur_x],
965 this_page_end - virt_cur_x);
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000966 else
967 mvwaddnstr(edit, yval, virt_cur_x,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000968 &fileptr->data[virt_cur_x], COLS - virt_cur_x);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000969
Chris Allegretta8ce24132001-04-30 11:28:46 +0000970#ifdef ENABLE_COLOR
971 color_off(edit, COLOR_MARKER);
972#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000973 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000974#endif /* ENABLE_COLOR */
975
976 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000977 }
Chris Allegretta08893e02001-11-29 02:42:27 +0000978 }
Chris Allegretta08893e02001-11-29 02:42:27 +0000979#endif
980
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000981}
982
983/*
Robert Siemborski9d584552000-07-08 00:41:29 +0000984 * Just update one line in the edit buffer. Basically a wrapper for
985 * edit_add
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000986 *
Chris Allegretta88520c92001-05-05 17:45:54 +0000987 * index gives us a place in the string to update starting from.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000988 * Likely args are current_x or 0.
989 */
990void update_line(filestruct * fileptr, int index)
991{
992 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +0000993 int line = 0, col = 0;
994 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
995 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000996 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000997
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000998 if (!fileptr)
999 return;
Robert Siemborski53154a72000-06-18 00:11:03 +00001000
Robert Siemborski53875912000-06-16 04:25:30 +00001001 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001002 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
1003 filetmp = filetmp->next)
1004 line++;
1005
1006 mvwaddstr(edit, line, 0, hblank);
1007
Chris Allegretta88520c92001-05-05 17:45:54 +00001008 /* Next, convert all the tabs to spaces, so everything else is easy */
Robert Siemborski53875912000-06-16 04:25:30 +00001009 index = xpt(fileptr, index);
1010
1011 realdata = fileptr->data;
1012 len = strlen(realdata);
Chris Allegretta88b09152001-05-17 11:35:43 +00001013 fileptr->data = charalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +00001014
1015 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001016 for (i = 0; i < len; i++) {
1017 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +00001018 do {
1019 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001020 if (i < current_x)
1021 virt_cur_x++;
1022 if (i < mark_beginx)
1023 virt_mark_beginx++;
Chris Allegretta6d690a32000-08-03 22:51:21 +00001024 } while (pos % tabsize);
Robert Siemborski53875912000-06-16 04:25:30 +00001025 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001026 if (i < current_x)
1027 virt_cur_x--;
1028 if (i < mark_beginx)
1029 virt_mark_beginx--;
Chris Allegretta3c57e502001-12-19 16:20:43 +00001030 } else if (realdata[i] >= 1 && realdata[i] <= 31) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001031 /* Treat control characters as ^letter */
Chris Allegretta6306a112000-09-02 07:55:41 +00001032 fileptr->data[pos++] = '^';
1033 fileptr->data[pos++] = realdata[i] + 64;
Robert Siemborski53875912000-06-16 04:25:30 +00001034 } else {
1035 fileptr->data[pos++] = realdata[i];
1036 }
1037 }
1038
1039 fileptr->data[pos] = '\0';
1040
1041 /* Now, Paint the line */
1042 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +00001043 /* This handles when the current line is beyond COLS */
Chris Allegretta88520c92001-05-05 17:45:54 +00001044 /* It requires figuring out what page we're on */
Robert Siemborskia9addc72000-06-17 06:06:35 +00001045 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +00001046 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001047
Robert Siemborskia9addc72000-06-17 06:06:35 +00001048 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001049 mvwaddch(edit, line, 0, '$');
1050
Chris Allegrettafb62f732000-12-05 11:36:41 +00001051 if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001052 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +00001053 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +00001054 /* It's not the current line means that it's at x=0 and page=1 */
1055 /* If it is the current line, then we're in the same boat */
1056 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001057
Robert Siemborski53875912000-06-16 04:25:30 +00001058 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001059 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +00001060 }
Robert Siemborski53875912000-06-16 04:25:30 +00001061
1062 /* Clean up our mess */
1063 tmp = fileptr->data;
1064 fileptr->data = realdata;
1065 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001066}
1067
1068void center_cursor(void)
1069{
1070 current_y = editwinrows / 2;
1071 wmove(edit, current_y, current_x);
1072}
1073
1074/* Refresh the screen without changing the position of lines */
1075void edit_refresh(void)
1076{
Chris Allegrettaed022162000-08-03 16:54:11 +00001077 static int noloop = 0;
Chris Allegretta95b0b522000-07-28 02:58:06 +00001078 int lines = 0, i = 0, currentcheck = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001079 filestruct *temp, *hold = current;
1080
1081 if (current == NULL)
1082 return;
1083
1084 temp = edittop;
1085
1086 while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) {
1087 hold = temp;
1088 update_line(temp, current_x);
Chris Allegretta95b0b522000-07-28 02:58:06 +00001089 if (temp == current)
1090 currentcheck = 1;
1091
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001092 temp = temp->next;
1093 lines++;
1094 }
Chris Allegrettaed022162000-08-03 16:54:11 +00001095 /* If noloop == 1, then we already did an edit_update without finishing
1096 this function. So we don't run edit_update again */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001097 if (!currentcheck && !noloop) { /* Then current has run off the screen... */
Chris Allegrettada721be2000-07-31 01:26:42 +00001098 edit_update(current, CENTER);
Chris Allegrettaed022162000-08-03 16:54:11 +00001099 noloop = 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001100 } else if (noloop)
Chris Allegrettaed022162000-08-03 16:54:11 +00001101 noloop = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001102
1103 if (lines <= editwinrows - 1)
1104 while (lines <= editwinrows - 1) {
1105 mvwaddstr(edit, lines, i, hblank);
1106 lines++;
1107 }
1108 if (temp == NULL)
1109 editbot = hold;
1110 else
1111 editbot = temp;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001112
1113 /* What the hell are we expecting to update the screen if this isn't
1114 here? luck?? */
1115 wrefresh(edit);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001116}
1117
1118/*
Chris Allegretta88520c92001-05-05 17:45:54 +00001119 * Same as above, but touch the window first, so everything is redrawn.
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001120 */
1121void edit_refresh_clearok(void)
1122{
1123 clearok(edit, TRUE);
1124 edit_refresh();
1125 clearok(edit, FALSE);
1126}
1127
1128/*
Chris Allegretta88520c92001-05-05 17:45:54 +00001129 * Nice generic routine to update the edit buffer, given a pointer to the
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001130 * file struct =)
1131 */
Chris Allegretta2d7893d2001-07-11 02:08:33 +00001132void edit_update(filestruct * fileptr, int topmidbotnone)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001133{
Robert Siemborski29e9a762000-07-05 03:16:04 +00001134 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001135 filestruct *temp;
1136
1137 if (fileptr == NULL)
1138 return;
1139
1140 temp = fileptr;
Chris Allegretta2d7893d2001-07-11 02:08:33 +00001141 if (topmidbotnone == TOP);
1142 else if (topmidbotnone == NONE)
1143 for (i = 0; i <= current_y - 1 && temp->prev != NULL; i++)
1144 temp = temp->prev;
1145 else if (topmidbotnone == BOTTOM)
Chris Allegretta234a34d2000-07-29 04:33:38 +00001146 for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++)
1147 temp = temp->prev;
1148 else
1149 for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++)
1150 temp = temp->prev;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001151
Robert Siemborski29e9a762000-07-05 03:16:04 +00001152 edittop = temp;
1153 fix_editbot();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001154
1155 edit_refresh();
1156}
1157
Chris Allegretta88520c92001-05-05 17:45:54 +00001158/* This function updates current, based on where current_y is; reset_cursor
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001159 does the opposite */
1160void update_cursor(void)
1161{
1162 int i = 0;
1163
1164#ifdef DEBUG
1165 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
1166 current_x);
1167#endif
1168
1169 current = edittop;
1170 while (i <= current_y - 1 && current->next != NULL) {
1171 current = current->next;
1172 i++;
1173 }
1174
1175#ifdef DEBUG
1176 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
1177#endif
1178
1179}
1180
1181/*
1182 * Ask a question on the statusbar. Answer will be stored in answer
1183 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
Chris Allegretta88520c92001-05-05 17:45:54 +00001184 * otherwise, the valid shortcut key caught. Def is any editable text we
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001185 * want to put up by default.
Chris Allegretta7da4e9f2000-11-06 02:57:22 +00001186 *
1187 * New arg tabs tells whether or not to allow tab completion.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001188 */
Chris Allegretta7da4e9f2000-11-06 02:57:22 +00001189int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001190{
1191 va_list ap;
1192 char foo[133];
1193 int ret;
1194
Chris Allegretta2084acc2001-11-29 03:43:08 +00001195#ifndef DISABLE_TABCOMP
1196 int list;
1197#endif
1198
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001199 bottombars(s, slen);
1200
1201 va_start(ap, msg);
1202 vsnprintf(foo, 132, msg, ap);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001203 va_end(ap);
Chris Allegrettaa4d21622000-07-08 23:57:03 +00001204 strncat(foo, ": ", 132);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001205
Chris Allegretta8ce24132001-04-30 11:28:46 +00001206#ifdef ENABLE_COLOR
1207 color_on(bottomwin, COLOR_STATUSBAR);
1208#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001209 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001210#endif
1211
1212
Chris Allegretta2084acc2001-11-29 03:43:08 +00001213#ifndef DISABLE_TABCOMP
1214 ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), list);
1215#else
1216 /* if we've disabled tab completion, the value of list won't be
1217 used at all, so it's safe to use 0 (NULL) as a placeholder */
1218 ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), 0);
1219#endif
Chris Allegretta8ce24132001-04-30 11:28:46 +00001220
1221#ifdef ENABLE_COLOR
1222 color_off(bottomwin, COLOR_STATUSBAR);
1223#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001224 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001225#endif
1226
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001227
1228 switch (ret) {
1229
1230 case NANO_FIRSTLINE_KEY:
1231 do_first_line();
1232 break;
1233 case NANO_LASTLINE_KEY:
1234 do_last_line();
1235 break;
1236 case NANO_CANCEL_KEY:
Chris Allegretta2084acc2001-11-29 03:43:08 +00001237#ifndef DISABLE_TABCOMP
1238 /* if we've done tab completion, there might be a list of
1239 filename matches on the edit window at this point; make sure
1240 they're cleared off */
1241 if (list)
1242 edit_refresh();
1243#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001244 return -1;
1245 default:
Chris Allegretta5b1faac2000-11-16 19:55:30 +00001246 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001247 }
1248
1249#ifdef DEBUG
1250 fprintf(stderr, _("I got \"%s\"\n"), answer);
1251#endif
1252
1253 return ret;
1254}
1255
1256/*
1257 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
1258 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
1259 */
1260int do_yesno(int all, int leavecursor, char *msg, ...)
1261{
1262 va_list ap;
1263 char foo[133];
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001264 int kbinput, ok = -1, i;
1265 char *yesstr; /* String of yes characters accepted */
1266 char *nostr; /* Same for no */
1267 char *allstr; /* And all, surprise! */
1268 char shortstr[5]; /* Temp string for above */
Chris Allegretta84de5522001-04-12 14:51:48 +00001269#ifndef DISABLE_MOUSE
Chris Allegretta235ab192001-04-12 13:24:40 +00001270#ifdef NCURSES_MOUSE_VERSION
1271 MEVENT mevent;
1272#endif
1273#endif
1274
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001275
1276 /* Yes, no and all are strings of any length. Each string consists of
1277 all characters accepted as a valid character for that value.
1278 The first value will be the one displayed in the shortcuts. */
1279 yesstr = _("Yy");
1280 nostr = _("Nn");
1281 allstr = _("Aa");
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001282
1283 /* Write the bottom of the screen */
1284 clear_bottomwin();
Chris Allegretta8ce24132001-04-30 11:28:46 +00001285
1286#ifdef ENABLE_COLOR
1287 color_on(bottomwin, COLOR_BOTTOMBARS);
1288#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001289
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001290 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001291 if (!ISSET(NO_HELP)) {
1292 wmove(bottomwin, 1, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001293
1294 snprintf(shortstr, 3, " %c", yesstr[0]);
1295 onekey(shortstr, _("Yes"));
1296
1297 if (all) {
1298 snprintf(shortstr, 3, " %c", allstr[0]);
1299 onekey(shortstr, _("All"));
1300 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001301 wmove(bottomwin, 2, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001302
1303 snprintf(shortstr, 3, " %c", nostr[0]);
1304 onekey(shortstr, _("No"));
1305
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001306 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001307 }
1308 va_start(ap, msg);
1309 vsnprintf(foo, 132, msg, ap);
1310 va_end(ap);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001311
1312#ifdef ENABLE_COLOR
1313 color_off(bottomwin, COLOR_BOTTOMBARS);
1314 color_on(bottomwin, COLOR_STATUSBAR);
1315#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001316 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001317#endif /* ENABLE_COLOR */
1318
1319 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001320 mvwaddstr(bottomwin, 0, 0, foo);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001321
1322#ifdef ENABLE_COLOR
1323 color_off(bottomwin, COLOR_STATUSBAR);
1324#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001325 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001326#endif
1327
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001328 wrefresh(bottomwin);
1329
1330 if (leavecursor == 1)
1331 reset_cursor();
1332
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001333 while (ok == -1) {
1334 kbinput = wgetch(edit);
1335
1336 switch (kbinput) {
Chris Allegretta84de5522001-04-12 14:51:48 +00001337#ifndef DISABLE_MOUSE
Chris Allegretta235ab192001-04-12 13:24:40 +00001338#ifdef NCURSES_MOUSE_VERSION
1339 case KEY_MOUSE:
1340
1341 /* Look ma! We get to duplicate lots of code from do_mouse!! */
1342 if (getmouse(&mevent) == ERR)
1343 break;
1344 if (!wenclose(bottomwin, mevent.y, mevent.x) || ISSET(NO_HELP))
1345 break;
1346 mevent.y -= editwinrows + 3;
1347 if (mevent.y < 0)
1348 break;
1349 else {
1350
1351 /* Rather than a bunch of if statements, set up a matrix
1352 of possible return keystrokes based on the x and y values */
1353 if (all) {
1354 char yesnosquare[2][2] = {
1355 {yesstr[0], allstr[0]},
1356 {nostr[0], NANO_CONTROL_C }};
1357
1358 ungetch(yesnosquare[mevent.y][mevent.x/(COLS/6)]);
1359 } else {
1360 char yesnosquare[2][2] = {
1361 {yesstr[0], '\0'},
1362 {nostr[0], NANO_CONTROL_C }};
1363
1364 ungetch(yesnosquare[mevent.y][mevent.x/(COLS/6)]);
1365 }
1366 }
1367 break;
1368#endif
1369#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001370 case NANO_CONTROL_C:
1371 ok = -2;
1372 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001373 default:
1374
Chris Allegretta88520c92001-05-05 17:45:54 +00001375 /* Look for the kbinput in the yes, no and (optimally) all str */
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001376 for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++)
1377 ;
1378 if (yesstr[i] != 0) {
Chris Allegrettaea620fe2001-02-18 05:39:41 +00001379 ok = 1;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001380 break;
1381 }
1382
1383 for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++)
1384 ;
1385 if (nostr[i] != 0) {
1386 ok = 0;
1387 break;
1388 }
1389
1390 if (all) {
1391 for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++)
1392 ;
1393 if (allstr[i] != 0) {
1394 ok = 2;
1395 break;
1396 }
1397 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001398 }
1399 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001400
1401 /* Then blank the screen */
1402 blank_statusbar_refresh();
1403
1404 if (ok == -2)
1405 return -1;
1406 else
1407 return ok;
1408}
1409
1410void statusbar(char *msg, ...)
1411{
1412 va_list ap;
1413 char foo[133];
1414 int start_x = 0;
1415
1416 va_start(ap, msg);
1417 vsnprintf(foo, 132, msg, ap);
1418 va_end(ap);
1419
Chris Allegretta17dcb722001-01-20 21:40:07 +00001420 start_x = COLS / 2 - strlen(foo) / 2 - 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001421
1422 /* Blank out line */
1423 blank_statusbar();
1424
1425 wmove(bottomwin, 0, start_x);
1426
Chris Allegretta8ce24132001-04-30 11:28:46 +00001427#ifdef ENABLE_COLOR
1428 color_on(bottomwin, COLOR_STATUSBAR);
1429#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001430 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001431#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001432
1433 waddstr(bottomwin, "[ ");
1434 waddstr(bottomwin, foo);
1435 waddstr(bottomwin, " ]");
Chris Allegretta8ce24132001-04-30 11:28:46 +00001436
1437#ifdef ENABLE_COLOR
1438 color_off(bottomwin, COLOR_STATUSBAR);
1439#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001440 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001441#endif
1442
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001443 wrefresh(bottomwin);
1444
1445 if (ISSET(CONSTUPDATE))
1446 statblank = 1;
1447 else
1448 statblank = 25;
1449}
1450
1451void display_main_list(void)
1452{
1453 bottombars(main_list, MAIN_VISIBLE);
1454}
1455
1456int total_refresh(void)
1457{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001458 clearok(edit, TRUE);
1459 clearok(topwin, TRUE);
1460 clearok(bottomwin, TRUE);
1461 wnoutrefresh(edit);
1462 wnoutrefresh(topwin);
1463 wnoutrefresh(bottomwin);
1464 doupdate();
1465 clearok(edit, FALSE);
1466 clearok(topwin, FALSE);
1467 clearok(bottomwin, FALSE);
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001468 edit_refresh();
Chris Allegrettaf4b96012001-01-03 07:11:47 +00001469 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001470 return 1;
1471}
1472
1473void previous_line(void)
1474{
1475 if (current_y > 0)
1476 current_y--;
1477}
1478
Chris Allegretta2084acc2001-11-29 03:43:08 +00001479int do_cursorpos(int constant)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001480{
1481 filestruct *fileptr;
Chris Allegretta66795ec2000-12-27 04:47:28 +00001482 float linepct = 0.0, bytepct = 0.0;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001483 long i = 0;
Chris Allegretta2084acc2001-11-29 03:43:08 +00001484 static long old_i = -1, old_totsize = -1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001485
1486 if (current == NULL || fileage == NULL)
1487 return 0;
1488
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001489 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1490 fileptr = fileptr->next)
Chris Allegretta66795ec2000-12-27 04:47:28 +00001491 i += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001492
1493 if (fileptr == NULL)
1494 return -1;
1495
Chris Allegretta66795ec2000-12-27 04:47:28 +00001496 i += current_x;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001497
Chris Allegretta2084acc2001-11-29 03:43:08 +00001498 if (old_i == -1)
1499 old_i = i;
1500
1501 if (old_totsize == -1)
1502 old_totsize = totsize;
1503
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001504 if (totlines > 0)
1505 linepct = 100 * current->lineno / totlines;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001506
1507 if (totsize > 0)
1508 bytepct = 100 * i / totsize;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001509
1510#ifdef DEBUG
1511 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1512 linepct, bytepct);
1513#endif
1514
Chris Allegretta2084acc2001-11-29 03:43:08 +00001515 /* if constant is zero, display the position on the statusbar
1516 unconditionally; otherwise, only display the position when the
1517 character values have changed */
1518 if (!constant || (old_i != i || old_totsize != totsize)) {
1519 statusbar(_("line %d of %d (%.0f%%), character %ld of %ld (%.0f%%)"),
1520 current->lineno, totlines, linepct, i, totsize, bytepct);
1521 }
1522
1523 old_i = i;
1524 old_totsize = totsize;
1525
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001526 reset_cursor();
1527 return 1;
1528}
1529
Chris Allegretta2084acc2001-11-29 03:43:08 +00001530int do_cursorpos_void(void)
1531{
1532 return do_cursorpos(0);
1533}
1534
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001535/* Our broken, non-shortcut list compliant help function.
Chris Allegretta88520c92001-05-05 17:45:54 +00001536 But, hey, it's better than nothing, and it's dynamic! */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001537int do_help(void)
1538{
Rocco Corsiaf5c3022001-01-12 07:51:05 +00001539#ifndef DISABLE_HELP
Chris Allegrettab3655b42001-10-22 03:15:31 +00001540 char *ptr, *end;
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001541 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001542 int no_help_flag = 0;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001543 shortcut *oldshortcut;
1544 int oldslen;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001545
1546 blank_edit();
1547 curs_set(0);
Chris Allegrettab3655b42001-10-22 03:15:31 +00001548 wattroff(bottomwin, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001549 blank_statusbar();
1550
Chris Allegrettab3655b42001-10-22 03:15:31 +00001551 help_init();
1552 ptr = help_text;
1553
1554 oldshortcut = currshortcut;
1555 oldslen = currslen;
1556
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001557 currshortcut = help_list;
1558 currslen = HELP_LIST_LEN;
Chris Allegretta6fe61492001-05-21 12:56:25 +00001559
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001560 kp = keypad_on(edit, 1);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001561 kp2 = keypad_on(bottomwin, 1);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001562
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001563 if (ISSET(NO_HELP)) {
1564
Chris Allegretta88520c92001-05-05 17:45:54 +00001565 /* Well, if we're going to do this, we should at least
Chris Allegretta70444892001-01-07 23:02:02 +00001566 do it the right way */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001567 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001568 UNSET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001569 window_init();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001570 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta70444892001-01-07 23:02:02 +00001571
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001572 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001573 bottombars(help_list, HELP_LIST_LEN);
1574
1575 do {
1576 ptr = help_text;
1577 switch (kbinput) {
Chris Allegretta84de5522001-04-12 14:51:48 +00001578#ifndef DISABLE_MOUSE
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001579#ifdef NCURSES_MOUSE_VERSION
1580 case KEY_MOUSE:
1581 do_mouse();
1582 break;
1583#endif
1584#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001585 case NANO_NEXTPAGE_KEY:
1586 case NANO_NEXTPAGE_FKEY:
1587 case KEY_NPAGE:
1588 if (!no_more) {
1589 blank_edit();
1590 page++;
1591 }
1592 break;
1593 case NANO_PREVPAGE_KEY:
1594 case NANO_PREVPAGE_FKEY:
1595 case KEY_PPAGE:
1596 if (page > 1) {
1597 no_more = 0;
1598 blank_edit();
1599 page--;
1600 }
1601 break;
1602 }
1603
Chris Allegretta88520c92001-05-05 17:45:54 +00001604 /* Calculate where in the text we should be, based on the page */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001605 for (i = 1; i < page; i++) {
1606 row = 0;
1607 j = 0;
Chris Allegretta44e73df2000-09-07 03:37:38 +00001608
1609 while (row < editwinrows - 2 && *ptr != '\0') {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001610 if (*ptr == '\n' || j == COLS - 5) {
1611 j = 0;
1612 row++;
1613 }
1614 ptr++;
1615 j++;
1616 }
1617 }
1618
Chris Allegretta44e73df2000-09-07 03:37:38 +00001619 if (i > 1) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001620
Chris Allegretta44e73df2000-09-07 03:37:38 +00001621 }
1622
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001623 i = 0;
1624 j = 0;
1625 while (i < editwinrows && *ptr != '\0') {
1626 end = ptr;
1627 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1628 end++;
1629 j++;
1630 }
1631 if (j == COLS - 5) {
1632
Chris Allegretta88520c92001-05-05 17:45:54 +00001633 /* Don't print half a word if we've run out of space */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001634 while (*end != ' ' && *end != '\0') {
1635 end--;
1636 j--;
1637 }
1638 }
1639 mvwaddnstr(edit, i, 0, ptr, j);
1640 j = 0;
1641 i++;
1642 if (*end == '\n')
1643 end++;
1644 ptr = end;
1645 }
1646 if (*ptr == '\0') {
1647 no_more = 1;
1648 continue;
1649 }
Chris Allegrettad1627cf2000-12-18 05:03:16 +00001650 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
1651 kbinput != NANO_EXIT_FKEY);
1652
Chris Allegrettab3655b42001-10-22 03:15:31 +00001653 currshortcut = oldshortcut;
1654 currslen = oldslen;
1655
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001656 if (no_help_flag) {
Chris Allegretta70444892001-01-07 23:02:02 +00001657 blank_bottombars();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001658 wrefresh(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001659 SET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001660 window_init();
1661 }
Chris Allegrettab3655b42001-10-22 03:15:31 +00001662 else
1663 bottombars(currshortcut, currslen);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001664
1665 curs_set(1);
1666 edit_refresh();
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001667 kp = keypad_on(edit, kp);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001668 kp2 = keypad_on(bottomwin, kp2);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001669
Chris Allegretta3bc8c722000-12-10 17:03:25 +00001670#elif defined(DISABLE_HELP)
1671 nano_disabled_msg();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001672#endif
1673
1674 return 1;
1675}
1676
1677/* Dump the current file structure to stderr */
1678void dump_buffer(filestruct * inptr)
1679{
1680#ifdef DEBUG
1681 filestruct *fileptr;
1682
1683 if (inptr == fileage)
1684 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1685 else if (inptr == cutbuffer)
1686 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1687 else
1688 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1689
1690 fileptr = inptr;
1691 while (fileptr != NULL) {
Chris Allegrettab3655b42001-10-22 03:15:31 +00001692 fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001693 fflush(stderr);
1694 fileptr = fileptr->next;
1695 }
1696#endif /* DEBUG */
1697}
1698
1699void dump_buffer_reverse(filestruct * inptr)
1700{
1701#ifdef DEBUG
1702 filestruct *fileptr;
1703
1704 fileptr = filebot;
1705 while (fileptr != NULL) {
Chris Allegrettab3655b42001-10-22 03:15:31 +00001706 fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001707 fflush(stderr);
1708 fileptr = fileptr->prev;
1709 }
1710#endif /* DEBUG */
1711}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001712
Chris Allegretta88520c92001-05-05 17:45:54 +00001713/* Fix editbot, based on the assumption that edittop is correct */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001714void fix_editbot(void)
1715{
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001716 int i;
1717 editbot = edittop;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001718 for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1719 && (editbot != filebot); i++, editbot = editbot->next);
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001720}
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001721
Chris Allegrettafb62f732000-12-05 11:36:41 +00001722/* highlight the current word being replaced or spell checked */
1723void do_replace_highlight(int highlight_flag, char *word)
1724{
1725 char *highlight_word = NULL;
1726 int x, y;
1727
1728 highlight_word = mallocstrcpy(highlight_word, &current->data[current_x]);
1729 highlight_word[strlen(word)] = '\0';
1730
Chris Allegretta88520c92001-05-05 17:45:54 +00001731 /* adjust output when word extends beyond screen */
Chris Allegrettafb62f732000-12-05 11:36:41 +00001732
1733 x = xplustabs();
1734 y = get_page_end_virtual(get_page_from_virtual(x)) + 1;
1735
1736 if ((COLS - (y - x) + strlen(word)) > COLS) {
1737 highlight_word[y - x - 1] = '$';
1738 highlight_word[y - x] = '\0';
1739 }
1740
1741 /* OK display the output */
1742
1743 reset_cursor();
1744
1745 if (highlight_flag)
1746 wattron(edit, A_REVERSE);
1747
1748 waddstr(edit, highlight_word);
1749
1750 if (highlight_flag)
1751 wattroff(edit, A_REVERSE);
1752
1753 free(highlight_word);
1754}
1755
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001756#ifdef NANO_EXTRA
Chris Allegretta9b3c7e82001-08-25 16:00:53 +00001757#define CREDIT_LEN 48
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001758void do_credits(void)
1759{
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001760 int i, j = 0, k, place = 0, start_x;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001761 char *what;
1762
1763 char *nanotext = _("The nano text editor");
1764 char *version = _("version ");
1765 char *brought = _("Brought to you by:");
1766 char *specialthx = _("Special thanks to:");
1767 char *fsf = _("The Free Software Foundation");
1768 char *ncurses = _("Pavel Curtis, Zeyd Ben-Halim and Eric S. Raymond for ncurses");
1769 char *anyonelse = _("and anyone else we forgot...");
1770 char *thankyou = _("Thank you for using nano!\n");
1771
1772 char *credits[CREDIT_LEN] = {nanotext,
1773 version,
1774 VERSION,
1775 "",
1776 brought,
1777 "Chris Allegretta",
1778 "Jordi Mallach",
1779 "Adam Rogoyski",
1780 "Rob Siemborski",
1781 "Rocco Corsi",
1782 "Ken Tyler",
1783 "Sven Guckes",
1784 "Florian König",
1785 "Pauli Virtanen",
1786 "Daniele Medri",
1787 "Clement Laforet",
1788 "Tedi Heriyanto",
Chris Allegrettaa131c7c2000-11-25 19:59:41 +00001789 "Bill Soudan",
Chris Allegretta7cd9f742000-11-25 20:17:28 +00001790 "Christian Weisgerber",
Chris Allegretta827b15f2001-01-03 02:09:04 +00001791 "Erik Andersen",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001792 "Big Gaute",
1793 "Joshua Jensen",
Chris Allegretta0d471de2001-03-15 14:40:42 +00001794 "Ryan Krebs",
Chris Allegretta7ab3e8f2001-03-22 23:12:22 +00001795 "Albert Chin",
Chris Allegretta9b3c7e82001-08-25 16:00:53 +00001796 "David Lawrence Ramsey",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001797 "",
1798 specialthx,
1799 "Plattsburgh State University",
1800 "Benet Laboratories",
1801 "Amy Allegretta",
1802 "Linda Young",
1803 "Jeremy Robichaud",
1804 "Richard Kolb II",
1805 fsf,
1806 "Linus Torvalds",
1807 ncurses,
1808 anyonelse,
1809 thankyou,
1810 "", "", "", "",
1811 "(c) 2000 Chris Allegretta",
1812 "", "", "", "",
1813 "www.nano-editor.org"
1814 };
1815
1816 curs_set(0);
1817 nodelay(edit, TRUE);
1818 blank_bottombars();
1819 mvwaddstr(topwin, 0, 0, hblank);
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001820 blank_edit();
1821 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001822 wrefresh(bottomwin);
1823 wrefresh(topwin);
1824
1825 while (wgetch(edit) == ERR) {
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001826 for (k = 0; k <= 1; k++) {
1827 blank_edit();
1828 for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); i--) {
1829 mvwaddstr(edit, i * 2 - k, 0, hblank);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001830
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001831 if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
1832 what = credits[place - (editwinrows / 2 - 1 - i)];
1833 else
1834 what = "";
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001835
Chris Allegretta17dcb722001-01-20 21:40:07 +00001836 start_x = COLS / 2 - strlen(what) / 2 - 1;
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001837 mvwaddstr(edit, i * 2 - k, start_x, what);
1838 }
1839 usleep(700000);
1840 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001841 }
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001842 if (j < editwinrows / 2 - 1)
1843 j++;
1844
1845 place++;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001846
1847 if (place >= CREDIT_LEN + editwinrows / 2)
1848 break;
1849 }
1850
1851 nodelay(edit, FALSE);
1852 curs_set(1);
1853 display_main_list();
1854 total_refresh();
1855 }
1856#endif
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001857
Chris Allegrettae3167732001-03-18 16:59:34 +00001858int keypad_on(WINDOW * win, int newval)
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001859{
1860
Chris Allegretta88520c92001-05-05 17:45:54 +00001861/* This is taken right from aumix. Don't sue me. */
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001862#ifdef HAVE_USEKEYPAD
1863 int old;
1864
1865 old = win->_use_keypad;
Chris Allegrettae3167732001-03-18 16:59:34 +00001866 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001867 return old;
1868#else
Chris Allegrettae3167732001-03-18 16:59:34 +00001869 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001870 return 1;
1871#endif /* HAVE_USEKEYPAD */
1872
1873}
1874
1875
1876