blob: d1a41cb2b0f3cb3b967c176e480b96e9762fe542 [file] [log] [blame]
Chris Allegretta11b00112000-08-06 21:13:45 +00001/* $Id$ */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00002/**************************************************************************
3 * winio.c *
4 * *
Jordi Mallach8ae57892002-01-04 17:57:40 +00005 * Copyright (C) 1999-2002 Chris Allegretta *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00006 * 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);
Chris Allegretta66577ac2002-01-05 02:03:29 +0000606 if (!colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].set ||
607 colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].fg != COLOR_BLACK)
608 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000609#endif
610
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000611 /* Determine how many extra spaces are needed to fill the bottom of the screen */
Chris Allegretta96eef732001-08-25 16:41:37 +0000612 if (slen < 2)
613 k = COLS / 6 - 13;
614 else
Chris Allegretta7dd18692001-08-26 23:16:44 +0000615 k = COLS / ((slen + (slen %2)) / 2) - 13;
Chris Allegretta96eef732001-08-25 16:41:37 +0000616
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000617
618 clear_bottomwin();
619 wmove(bottomwin, 1, 0);
Chris Allegretta658399a2001-06-14 02:54:22 +0000620
Chris Allegretta5f36c372001-07-16 00:48:53 +0000621 for (i = 0; i <= slen - 1; i += 2) {
Chris Allegretta658399a2001-06-14 02:54:22 +0000622
623 if (s[i].val < 97)
624 snprintf(keystr, 10, "^%c", s[i].val + 64);
625 else
626 snprintf(keystr, 10, "M-%c", s[i].val - 32);
627
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000628 onekey(keystr, s[i].desc);
629
630 for (j = 0; j < k; j++)
631 waddch(bottomwin, ' ');
632 }
633
634 wmove(bottomwin, 2, 0);
635 for (i = 1; i <= slen - 1; i += 2) {
Chris Allegretta658399a2001-06-14 02:54:22 +0000636
637 if (s[i].val < 97)
638 snprintf(keystr, 10, "^%c", s[i].val + 64);
639 else
640 snprintf(keystr, 10, "M-%c", s[i].val - 32);
641
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000642 onekey(keystr, s[i].desc);
643
644 for (j = 0; j < k; j++)
645 waddch(bottomwin, ' ');
646 }
647
Chris Allegretta8ce24132001-04-30 11:28:46 +0000648#ifdef ENABLE_COLOR
649 color_off(bottomwin, COLOR_BOTTOMBARS);
650#endif
651
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000652 wrefresh(bottomwin);
653
654}
655
656/* If modified is not already set, set it and update titlebar */
657void set_modified(void)
658{
659 if (!ISSET(MODIFIED)) {
660 SET(MODIFIED);
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000661 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000662 wrefresh(topwin);
663 }
664}
665
Robert Siemborski9d584552000-07-08 00:41:29 +0000666/* And so start the display update routines */
667/* Given a column, this returns the "page" it is on */
668/* "page" in the case of the display columns, means which set of 80 */
Chris Allegretta88520c92001-05-05 17:45:54 +0000669/* characters is viewable (e.g.: page 1 shows from 1 to COLS) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000670inline int get_page_from_virtual(int virtual)
671{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000672 int page = 2;
673
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000674 if (virtual <= COLS - 2)
675 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000676 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000677
678 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000679 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000680 page++;
681 }
682
683 return page;
684}
685
Robert Siemborski9d584552000-07-08 00:41:29 +0000686/* The inverse of the above function */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000687inline int get_page_start_virtual(int page)
688{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000689 int virtual;
690 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000691 if (page)
692 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000693 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000694}
695
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000696inline int get_page_end_virtual(int page)
697{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000698 return get_page_start_virtual(page) + COLS - 1;
699}
700
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000701#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000702/* This takes care of the case where there is a mark that covers only */
703/* the current line. */
704
Chris Allegretta88520c92001-05-05 17:45:54 +0000705/* It expects a line with no tab characters (i.e.: the type that edit_add */
Robert Siemborski9d584552000-07-08 00:41:29 +0000706/* deals with */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000707void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
708 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000709{
Robert Siemborski9d584552000-07-08 00:41:29 +0000710 /*
711 * The general idea is to break the line up into 3 sections: before
712 * the mark, the mark, and after the mark. We then paint each in
Chris Allegretta88520c92001-05-05 17:45:54 +0000713 * turn (for those that are currently visible, of course)
Robert Siemborski9d584552000-07-08 00:41:29 +0000714 *
715 * 3 start points: 0 -> begin, begin->end, end->strlen(data)
716 * in data : pre sel post
717 */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000718 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000719 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000720
Robert Siemborskid8510b22000-06-06 23:04:06 +0000721 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000722 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 +0000723
724 /* now fix the start locations & lengths according to the cursor's
Chris Allegretta88520c92001-05-05 17:45:54 +0000725 * position (i.e.: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000726 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000727 pre_data_len = 0;
728 else
729 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000730
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000731 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000732 begin = this_page_start;
733
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000734 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000735 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000736
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000737 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000738 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000739
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000740 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000741 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000742
Robert Siemborski9d584552000-07-08 00:41:29 +0000743 /* Now calculate the lengths */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000744 sel_data_len = end - begin;
745 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000746
Chris Allegretta8ce24132001-04-30 11:28:46 +0000747#ifdef ENABLE_COLOR
748 color_on(edit, COLOR_MARKER);
749#else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000750 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000751#endif /* ENABLE_COLOR */
752
Robert Siemborskia9addc72000-06-17 06:06:35 +0000753 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000754 &fileptr->data[begin], sel_data_len);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000755
756#ifdef ENABLE_COLOR
757 color_off(edit, COLOR_MARKER);
758#else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000759 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000760#endif /* ENABLE_COLOR */
761
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000762}
763#endif
764
Robert Siemborski9d584552000-07-08 00:41:29 +0000765/* edit_add takes care of the job of actually painting a line into the
766 * edit window.
767 *
768 * Called only from update_line. Expects a converted-to-not-have-tabs
Robert Siemborski53875912000-06-16 04:25:30 +0000769 * line */
770void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000771 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000772{
Chris Allegretta08893e02001-11-29 02:42:27 +0000773
Chris Allegretta7dd77682001-12-08 19:52:28 +0000774#ifdef ENABLE_COLOR
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000775 colortype *tmpcolor = NULL;
776 colorstr *tmpstr = NULL;
777 int k, paintlen;
778#endif
779
780
781
782 /* Just paint the string in any case (we'll add color or reverse on
783 just the text that needs it */
784 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
785 get_page_end_virtual(this_page) - start + 1);
786
Chris Allegretta7dd77682001-12-08 19:52:28 +0000787#ifdef ENABLE_COLOR
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000788 if (colorstrings != NULL)
789 for (tmpcolor = colorstrings; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
790 for (tmpstr = tmpcolor->str; tmpstr != NULL; tmpstr = tmpstr->next) {
791
792 k = start;
793 regcomp(&search_regexp, tmpstr->val, 0);
794 while (!regexec(&search_regexp, &fileptr->data[k], 1,
795 regmatches, 0)) {
796
797#ifdef DEBUG
798 fprintf(stderr, "Match! (%d chars) \"%s\"\n",
799 regmatches[0].rm_eo - regmatches[0].rm_so,
800 &fileptr->data[k + regmatches[0].rm_so]);
801#endif
802 if (regmatches[0].rm_so < COLS - 1) {
803 if (tmpcolor->bright)
804 wattron(edit, A_BOLD);
805 wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
806
Chris Allegretta1bf8f5e2002-01-05 03:30:10 +0000807 if (regmatches[0].rm_eo + k <= COLS)
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000808 paintlen = regmatches[0].rm_eo - regmatches[0].rm_so;
809 else
Chris Allegretta1bf8f5e2002-01-05 03:30:10 +0000810 paintlen = COLS - k - regmatches[0].rm_so - 1;
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000811
812 mvwaddnstr(edit, yval, regmatches[0].rm_so + k,
813 &fileptr->data[k + regmatches[0].rm_so],
814 paintlen);
815
816
817 }
818
819 if (tmpcolor->bright)
820 wattroff(edit, A_BOLD);
821 wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
822
823 k += regmatches[0].rm_eo;
824 }
825 }
826 }
Chris Allegretta7dd77682001-12-08 19:52:28 +0000827#endif /* ENABLE_COLOR */
828#ifndef NANO_SMALL
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000829
Chris Allegretta88520c92001-05-05 17:45:54 +0000830 /* There are quite a few cases that could take place; we'll deal
Robert Siemborski9d584552000-07-08 00:41:29 +0000831 * with them each in turn */
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000832 if (ISSET(MARK_ISSET) &&
833 !((fileptr->lineno > mark_beginbuf->lineno
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000834 && fileptr->lineno > current->lineno)
835 || (fileptr->lineno < mark_beginbuf->lineno
836 && fileptr->lineno < current->lineno))) {
Chris Allegretta88520c92001-05-05 17:45:54 +0000837 /* If we get here we are on a line that is at least
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000838 * partially selected. The lineno checks above determined
839 * that */
840 if (fileptr != mark_beginbuf && fileptr != current) {
841 /* We are on a completely marked line, paint it all
842 * inverse */
Chris Allegretta8ce24132001-04-30 11:28:46 +0000843#ifdef ENABLE_COLOR
844 color_on(edit, COLOR_MARKER);
845#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000846 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000847#endif /* ENABLE_COLOR */
848
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000849 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000850
851#ifdef ENABLE_COLOR
852 color_off(edit, COLOR_MARKER);
853#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000854 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000855#endif /* ENABLE_COLOR */
856
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000857 } else if (fileptr == mark_beginbuf && fileptr == current) {
858 /* Special case, we're still on the same line we started
859 * marking -- so we call our helper function */
860 if (virt_cur_x < virt_mark_beginx) {
861 /* To the right of us is marked */
862 add_marked_sameline(virt_cur_x, virt_mark_beginx,
863 fileptr, yval, virt_cur_x, this_page);
864 } else {
865 /* To the left of us is marked */
866 add_marked_sameline(virt_mark_beginx, virt_cur_x,
867 fileptr, yval, virt_cur_x, this_page);
868 }
869 } else if (fileptr == mark_beginbuf) {
870 /*
Chris Allegretta88520c92001-05-05 17:45:54 +0000871 * We're updating the line that was first marked,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000872 * but we're not currently on it. So we want to
Robert Siemborskia0238ed2001-03-31 21:46:43 +0000873 * figure out which half to invert based on our
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000874 * relative line numbers.
875 *
Chris Allegretta88520c92001-05-05 17:45:54 +0000876 * I.e. if we're above the "beginbuf" line, we want to
877 * mark the left side. Otherwise, we're below, so we
878 * mark the right.
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000879 */
880 int target;
881
Chris Allegretta8ce24132001-04-30 11:28:46 +0000882 if (mark_beginbuf->lineno > current->lineno) {
883#ifdef ENABLE_COLOR
884 color_on(edit, COLOR_MARKER);
885#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000886 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000887#endif /* ENABLE_COLOR */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000888
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000889 target =
890 (virt_mark_beginx < COLS - 1) ? virt_mark_beginx : COLS - 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000891
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000892 mvwaddnstr(edit, yval, 0, fileptr->data, target);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000893
894#ifdef ENABLE_COLOR
895 color_off(edit, COLOR_MARKER);
896#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000897 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000898#endif /* ENABLE_COLOR */
899
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000900
Chris Allegretta8ce24132001-04-30 11:28:46 +0000901 }
Robert Siemborskid8510b22000-06-06 23:04:06 +0000902
Chris Allegretta8ce24132001-04-30 11:28:46 +0000903 if (mark_beginbuf->lineno < current->lineno) {
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000904#ifdef ENABLE_COLOR
905 color_on(edit, COLOR_MARKER);
906#else
907 wattron(edit, A_REVERSE);
908#endif /* ENABLE_COLOR */
909
910 target = (COLS - 1) - virt_mark_beginx;
911
912 if (target < 0)
913 target = 0;
914
915 mvwaddnstr(edit, yval, virt_mark_beginx,
916 &fileptr->data[virt_mark_beginx], target);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000917
918#ifdef ENABLE_COLOR
919 color_off(edit, COLOR_MARKER);
920#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000921 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000922#endif /* ENABLE_COLOR */
923
924 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000925
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000926 } else if (fileptr == current) {
Chris Allegretta88520c92001-05-05 17:45:54 +0000927 /* We're on the cursor's line, but it's not the first
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000928 * one we marked. Similar to the previous logic. */
929 int this_page_start = get_page_start_virtual(this_page),
930 this_page_end = get_page_end_virtual(this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000931
Chris Allegretta8ce24132001-04-30 11:28:46 +0000932 if (mark_beginbuf->lineno < current->lineno) {
933
934#ifdef ENABLE_COLOR
935 color_on(edit, COLOR_MARKER);
936#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000937 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000938#endif /* ENABLE_COLOR */
939
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000940 if (virt_cur_x > COLS - 2) {
941 mvwaddnstr(edit, yval, 0,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000942 &fileptr->data[this_page_start],
943 virt_cur_x - this_page_start);
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000944 } else
945 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
946
947#ifdef ENABLE_COLOR
948 color_off(edit, COLOR_MARKER);
949#else
950 wattroff(edit, A_REVERSE);
951#endif /* ENABLE_COLOR */
952
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000953 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000954
Chris Allegretta8ce24132001-04-30 11:28:46 +0000955 if (mark_beginbuf->lineno > current->lineno) {
956
957#ifdef ENABLE_COLOR
958 color_on(edit, COLOR_MARKER);
959#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000960 wattron(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000961#endif /* ENABLE_COLOR */
962
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000963 if (virt_cur_x > COLS - 2)
964 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000965 &fileptr->data[virt_cur_x],
966 this_page_end - virt_cur_x);
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000967 else
968 mvwaddnstr(edit, yval, virt_cur_x,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000969 &fileptr->data[virt_cur_x], COLS - virt_cur_x);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000970
Chris Allegretta8ce24132001-04-30 11:28:46 +0000971#ifdef ENABLE_COLOR
972 color_off(edit, COLOR_MARKER);
973#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000974 wattroff(edit, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000975#endif /* ENABLE_COLOR */
976
977 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000978 }
Chris Allegretta08893e02001-11-29 02:42:27 +0000979 }
Chris Allegretta08893e02001-11-29 02:42:27 +0000980#endif
981
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000982}
983
984/*
Robert Siemborski9d584552000-07-08 00:41:29 +0000985 * Just update one line in the edit buffer. Basically a wrapper for
986 * edit_add
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000987 *
Chris Allegretta88520c92001-05-05 17:45:54 +0000988 * index gives us a place in the string to update starting from.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000989 * Likely args are current_x or 0.
990 */
991void update_line(filestruct * fileptr, int index)
992{
993 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +0000994 int line = 0, col = 0;
995 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
996 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000997 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000998
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000999 if (!fileptr)
1000 return;
Robert Siemborski53154a72000-06-18 00:11:03 +00001001
Robert Siemborski53875912000-06-16 04:25:30 +00001002 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001003 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
1004 filetmp = filetmp->next)
1005 line++;
1006
1007 mvwaddstr(edit, line, 0, hblank);
1008
Chris Allegretta88520c92001-05-05 17:45:54 +00001009 /* Next, convert all the tabs to spaces, so everything else is easy */
Robert Siemborski53875912000-06-16 04:25:30 +00001010 index = xpt(fileptr, index);
1011
1012 realdata = fileptr->data;
1013 len = strlen(realdata);
Chris Allegretta88b09152001-05-17 11:35:43 +00001014 fileptr->data = charalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +00001015
1016 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001017 for (i = 0; i < len; i++) {
1018 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +00001019 do {
1020 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001021 if (i < current_x)
1022 virt_cur_x++;
1023 if (i < mark_beginx)
1024 virt_mark_beginx++;
Chris Allegretta6d690a32000-08-03 22:51:21 +00001025 } while (pos % tabsize);
Robert Siemborski53875912000-06-16 04:25:30 +00001026 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001027 if (i < current_x)
1028 virt_cur_x--;
1029 if (i < mark_beginx)
1030 virt_mark_beginx--;
Chris Allegretta3c57e502001-12-19 16:20:43 +00001031 } else if (realdata[i] >= 1 && realdata[i] <= 31) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001032 /* Treat control characters as ^letter */
Chris Allegretta6306a112000-09-02 07:55:41 +00001033 fileptr->data[pos++] = '^';
1034 fileptr->data[pos++] = realdata[i] + 64;
Robert Siemborski53875912000-06-16 04:25:30 +00001035 } else {
1036 fileptr->data[pos++] = realdata[i];
1037 }
1038 }
1039
1040 fileptr->data[pos] = '\0';
1041
1042 /* Now, Paint the line */
1043 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +00001044 /* This handles when the current line is beyond COLS */
Chris Allegretta88520c92001-05-05 17:45:54 +00001045 /* It requires figuring out what page we're on */
Robert Siemborskia9addc72000-06-17 06:06:35 +00001046 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +00001047 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001048
Robert Siemborskia9addc72000-06-17 06:06:35 +00001049 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001050 mvwaddch(edit, line, 0, '$');
1051
Chris Allegrettafb62f732000-12-05 11:36:41 +00001052 if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001053 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +00001054 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +00001055 /* It's not the current line means that it's at x=0 and page=1 */
1056 /* If it is the current line, then we're in the same boat */
1057 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001058
Robert Siemborski53875912000-06-16 04:25:30 +00001059 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001060 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +00001061 }
Robert Siemborski53875912000-06-16 04:25:30 +00001062
1063 /* Clean up our mess */
1064 tmp = fileptr->data;
1065 fileptr->data = realdata;
1066 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001067}
1068
1069void center_cursor(void)
1070{
1071 current_y = editwinrows / 2;
1072 wmove(edit, current_y, current_x);
1073}
1074
1075/* Refresh the screen without changing the position of lines */
1076void edit_refresh(void)
1077{
Chris Allegrettaed022162000-08-03 16:54:11 +00001078 static int noloop = 0;
Chris Allegretta3d0739c2002-01-07 14:41:32 +00001079 int nlines = 0, i = 0, currentcheck = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001080 filestruct *temp, *hold = current;
1081
1082 if (current == NULL)
1083 return;
1084
1085 temp = edittop;
1086
Chris Allegretta3d0739c2002-01-07 14:41:32 +00001087 while (nlines <= editwinrows - 1 && nlines <= totlines && temp != NULL) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001088 hold = temp;
1089 update_line(temp, current_x);
Chris Allegretta95b0b522000-07-28 02:58:06 +00001090 if (temp == current)
1091 currentcheck = 1;
1092
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001093 temp = temp->next;
Chris Allegretta3d0739c2002-01-07 14:41:32 +00001094 nlines++;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001095 }
Chris Allegrettaed022162000-08-03 16:54:11 +00001096 /* If noloop == 1, then we already did an edit_update without finishing
1097 this function. So we don't run edit_update again */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001098 if (!currentcheck && !noloop) { /* Then current has run off the screen... */
Chris Allegrettada721be2000-07-31 01:26:42 +00001099 edit_update(current, CENTER);
Chris Allegrettaed022162000-08-03 16:54:11 +00001100 noloop = 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001101 } else if (noloop)
Chris Allegrettaed022162000-08-03 16:54:11 +00001102 noloop = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001103
Chris Allegretta3d0739c2002-01-07 14:41:32 +00001104 if (nlines <= editwinrows - 1)
1105 while (nlines <= editwinrows - 1) {
1106 mvwaddstr(edit, nlines, i, hblank);
1107 nlines++;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001108 }
1109 if (temp == NULL)
1110 editbot = hold;
1111 else
1112 editbot = temp;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001113
1114 /* What the hell are we expecting to update the screen if this isn't
1115 here? luck?? */
1116 wrefresh(edit);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001117}
1118
1119/*
Chris Allegretta88520c92001-05-05 17:45:54 +00001120 * Same as above, but touch the window first, so everything is redrawn.
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001121 */
1122void edit_refresh_clearok(void)
1123{
1124 clearok(edit, TRUE);
1125 edit_refresh();
1126 clearok(edit, FALSE);
1127}
1128
1129/*
Chris Allegretta88520c92001-05-05 17:45:54 +00001130 * Nice generic routine to update the edit buffer, given a pointer to the
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001131 * file struct =)
1132 */
Chris Allegretta2d7893d2001-07-11 02:08:33 +00001133void edit_update(filestruct * fileptr, int topmidbotnone)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001134{
Robert Siemborski29e9a762000-07-05 03:16:04 +00001135 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001136 filestruct *temp;
1137
1138 if (fileptr == NULL)
1139 return;
1140
1141 temp = fileptr;
Chris Allegretta2d7893d2001-07-11 02:08:33 +00001142 if (topmidbotnone == TOP);
1143 else if (topmidbotnone == NONE)
1144 for (i = 0; i <= current_y - 1 && temp->prev != NULL; i++)
1145 temp = temp->prev;
1146 else if (topmidbotnone == BOTTOM)
Chris Allegretta234a34d2000-07-29 04:33:38 +00001147 for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++)
1148 temp = temp->prev;
1149 else
1150 for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++)
1151 temp = temp->prev;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001152
Robert Siemborski29e9a762000-07-05 03:16:04 +00001153 edittop = temp;
1154 fix_editbot();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001155
1156 edit_refresh();
1157}
1158
Chris Allegretta88520c92001-05-05 17:45:54 +00001159/* This function updates current, based on where current_y is; reset_cursor
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001160 does the opposite */
1161void update_cursor(void)
1162{
1163 int i = 0;
1164
1165#ifdef DEBUG
1166 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
1167 current_x);
1168#endif
1169
1170 current = edittop;
1171 while (i <= current_y - 1 && current->next != NULL) {
1172 current = current->next;
1173 i++;
1174 }
1175
1176#ifdef DEBUG
1177 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
1178#endif
1179
1180}
1181
1182/*
1183 * Ask a question on the statusbar. Answer will be stored in answer
1184 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
Chris Allegretta88520c92001-05-05 17:45:54 +00001185 * otherwise, the valid shortcut key caught. Def is any editable text we
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001186 * want to put up by default.
Chris Allegretta7da4e9f2000-11-06 02:57:22 +00001187 *
1188 * New arg tabs tells whether or not to allow tab completion.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001189 */
Chris Allegretta7da4e9f2000-11-06 02:57:22 +00001190int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001191{
1192 va_list ap;
1193 char foo[133];
1194 int ret;
1195
Chris Allegretta2084acc2001-11-29 03:43:08 +00001196#ifndef DISABLE_TABCOMP
Chris Allegrettaa16e4e92002-01-05 18:59:54 +00001197 int list = 0;
Chris Allegretta2084acc2001-11-29 03:43:08 +00001198#endif
1199
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001200 bottombars(s, slen);
1201
1202 va_start(ap, msg);
1203 vsnprintf(foo, 132, msg, ap);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001204 va_end(ap);
Chris Allegrettaa4d21622000-07-08 23:57:03 +00001205 strncat(foo, ": ", 132);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001206
Chris Allegretta8ce24132001-04-30 11:28:46 +00001207#ifdef ENABLE_COLOR
1208 color_on(bottomwin, COLOR_STATUSBAR);
1209#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001210 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001211#endif
1212
1213
Chris Allegretta2084acc2001-11-29 03:43:08 +00001214#ifndef DISABLE_TABCOMP
1215 ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), list);
1216#else
1217 /* if we've disabled tab completion, the value of list won't be
1218 used at all, so it's safe to use 0 (NULL) as a placeholder */
1219 ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), 0);
1220#endif
Chris Allegretta8ce24132001-04-30 11:28:46 +00001221
1222#ifdef ENABLE_COLOR
1223 color_off(bottomwin, COLOR_STATUSBAR);
1224#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001225 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001226#endif
1227
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001228
1229 switch (ret) {
1230
1231 case NANO_FIRSTLINE_KEY:
1232 do_first_line();
1233 break;
1234 case NANO_LASTLINE_KEY:
1235 do_last_line();
1236 break;
1237 case NANO_CANCEL_KEY:
Chris Allegretta2084acc2001-11-29 03:43:08 +00001238#ifndef DISABLE_TABCOMP
1239 /* if we've done tab completion, there might be a list of
1240 filename matches on the edit window at this point; make sure
1241 they're cleared off */
1242 if (list)
1243 edit_refresh();
1244#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001245 return -1;
1246 default:
Chris Allegretta5b1faac2000-11-16 19:55:30 +00001247 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001248 }
1249
1250#ifdef DEBUG
1251 fprintf(stderr, _("I got \"%s\"\n"), answer);
1252#endif
1253
1254 return ret;
1255}
1256
1257/*
1258 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
1259 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
1260 */
1261int do_yesno(int all, int leavecursor, char *msg, ...)
1262{
1263 va_list ap;
1264 char foo[133];
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001265 int kbinput, ok = -1, i;
1266 char *yesstr; /* String of yes characters accepted */
1267 char *nostr; /* Same for no */
1268 char *allstr; /* And all, surprise! */
1269 char shortstr[5]; /* Temp string for above */
Chris Allegretta84de5522001-04-12 14:51:48 +00001270#ifndef DISABLE_MOUSE
Chris Allegretta235ab192001-04-12 13:24:40 +00001271#ifdef NCURSES_MOUSE_VERSION
1272 MEVENT mevent;
1273#endif
1274#endif
1275
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001276
1277 /* Yes, no and all are strings of any length. Each string consists of
1278 all characters accepted as a valid character for that value.
1279 The first value will be the one displayed in the shortcuts. */
1280 yesstr = _("Yy");
1281 nostr = _("Nn");
1282 allstr = _("Aa");
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001283
1284 /* Write the bottom of the screen */
1285 clear_bottomwin();
Chris Allegretta8ce24132001-04-30 11:28:46 +00001286
1287#ifdef ENABLE_COLOR
1288 color_on(bottomwin, COLOR_BOTTOMBARS);
1289#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001290
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001291 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001292 if (!ISSET(NO_HELP)) {
1293 wmove(bottomwin, 1, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001294
1295 snprintf(shortstr, 3, " %c", yesstr[0]);
1296 onekey(shortstr, _("Yes"));
1297
1298 if (all) {
1299 snprintf(shortstr, 3, " %c", allstr[0]);
1300 onekey(shortstr, _("All"));
1301 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001302 wmove(bottomwin, 2, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001303
1304 snprintf(shortstr, 3, " %c", nostr[0]);
1305 onekey(shortstr, _("No"));
1306
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001307 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001308 }
1309 va_start(ap, msg);
1310 vsnprintf(foo, 132, msg, ap);
1311 va_end(ap);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001312
1313#ifdef ENABLE_COLOR
1314 color_off(bottomwin, COLOR_BOTTOMBARS);
1315 color_on(bottomwin, COLOR_STATUSBAR);
1316#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001317 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001318#endif /* ENABLE_COLOR */
1319
1320 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001321 mvwaddstr(bottomwin, 0, 0, foo);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001322
1323#ifdef ENABLE_COLOR
1324 color_off(bottomwin, COLOR_STATUSBAR);
1325#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001326 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001327#endif
1328
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001329 wrefresh(bottomwin);
1330
1331 if (leavecursor == 1)
1332 reset_cursor();
1333
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001334 while (ok == -1) {
1335 kbinput = wgetch(edit);
1336
1337 switch (kbinput) {
Chris Allegretta84de5522001-04-12 14:51:48 +00001338#ifndef DISABLE_MOUSE
Chris Allegretta235ab192001-04-12 13:24:40 +00001339#ifdef NCURSES_MOUSE_VERSION
1340 case KEY_MOUSE:
1341
1342 /* Look ma! We get to duplicate lots of code from do_mouse!! */
1343 if (getmouse(&mevent) == ERR)
1344 break;
1345 if (!wenclose(bottomwin, mevent.y, mevent.x) || ISSET(NO_HELP))
1346 break;
1347 mevent.y -= editwinrows + 3;
1348 if (mevent.y < 0)
1349 break;
1350 else {
1351
1352 /* Rather than a bunch of if statements, set up a matrix
1353 of possible return keystrokes based on the x and y values */
1354 if (all) {
1355 char yesnosquare[2][2] = {
1356 {yesstr[0], allstr[0]},
1357 {nostr[0], NANO_CONTROL_C }};
1358
1359 ungetch(yesnosquare[mevent.y][mevent.x/(COLS/6)]);
1360 } else {
1361 char yesnosquare[2][2] = {
1362 {yesstr[0], '\0'},
1363 {nostr[0], NANO_CONTROL_C }};
1364
1365 ungetch(yesnosquare[mevent.y][mevent.x/(COLS/6)]);
1366 }
1367 }
1368 break;
1369#endif
1370#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001371 case NANO_CONTROL_C:
1372 ok = -2;
1373 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001374 default:
1375
Chris Allegretta88520c92001-05-05 17:45:54 +00001376 /* Look for the kbinput in the yes, no and (optimally) all str */
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001377 for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++)
1378 ;
1379 if (yesstr[i] != 0) {
Chris Allegrettaea620fe2001-02-18 05:39:41 +00001380 ok = 1;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001381 break;
1382 }
1383
1384 for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++)
1385 ;
1386 if (nostr[i] != 0) {
1387 ok = 0;
1388 break;
1389 }
1390
1391 if (all) {
1392 for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++)
1393 ;
1394 if (allstr[i] != 0) {
1395 ok = 2;
1396 break;
1397 }
1398 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001399 }
1400 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001401
1402 /* Then blank the screen */
1403 blank_statusbar_refresh();
1404
1405 if (ok == -2)
1406 return -1;
1407 else
1408 return ok;
1409}
1410
1411void statusbar(char *msg, ...)
1412{
1413 va_list ap;
1414 char foo[133];
1415 int start_x = 0;
1416
1417 va_start(ap, msg);
1418 vsnprintf(foo, 132, msg, ap);
1419 va_end(ap);
1420
Chris Allegretta17dcb722001-01-20 21:40:07 +00001421 start_x = COLS / 2 - strlen(foo) / 2 - 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001422
1423 /* Blank out line */
1424 blank_statusbar();
1425
1426 wmove(bottomwin, 0, start_x);
1427
Chris Allegretta8ce24132001-04-30 11:28:46 +00001428#ifdef ENABLE_COLOR
1429 color_on(bottomwin, COLOR_STATUSBAR);
1430#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001431 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001432#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001433
1434 waddstr(bottomwin, "[ ");
1435 waddstr(bottomwin, foo);
1436 waddstr(bottomwin, " ]");
Chris Allegretta8ce24132001-04-30 11:28:46 +00001437
1438#ifdef ENABLE_COLOR
1439 color_off(bottomwin, COLOR_STATUSBAR);
1440#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001441 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001442#endif
1443
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001444 wrefresh(bottomwin);
1445
1446 if (ISSET(CONSTUPDATE))
1447 statblank = 1;
1448 else
1449 statblank = 25;
1450}
1451
1452void display_main_list(void)
1453{
1454 bottombars(main_list, MAIN_VISIBLE);
1455}
1456
1457int total_refresh(void)
1458{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001459 clearok(edit, TRUE);
1460 clearok(topwin, TRUE);
1461 clearok(bottomwin, TRUE);
1462 wnoutrefresh(edit);
1463 wnoutrefresh(topwin);
1464 wnoutrefresh(bottomwin);
1465 doupdate();
1466 clearok(edit, FALSE);
1467 clearok(topwin, FALSE);
1468 clearok(bottomwin, FALSE);
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001469 edit_refresh();
Chris Allegrettaf4b96012001-01-03 07:11:47 +00001470 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001471 return 1;
1472}
1473
1474void previous_line(void)
1475{
1476 if (current_y > 0)
1477 current_y--;
1478}
1479
Chris Allegretta2084acc2001-11-29 03:43:08 +00001480int do_cursorpos(int constant)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001481{
1482 filestruct *fileptr;
Chris Allegretta66795ec2000-12-27 04:47:28 +00001483 float linepct = 0.0, bytepct = 0.0;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001484 long i = 0;
Chris Allegretta2084acc2001-11-29 03:43:08 +00001485 static long old_i = -1, old_totsize = -1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001486
1487 if (current == NULL || fileage == NULL)
1488 return 0;
1489
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001490 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1491 fileptr = fileptr->next)
Chris Allegretta66795ec2000-12-27 04:47:28 +00001492 i += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001493
1494 if (fileptr == NULL)
1495 return -1;
1496
Chris Allegretta66795ec2000-12-27 04:47:28 +00001497 i += current_x;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001498
Chris Allegretta2084acc2001-11-29 03:43:08 +00001499 if (old_i == -1)
1500 old_i = i;
1501
1502 if (old_totsize == -1)
1503 old_totsize = totsize;
1504
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001505 if (totlines > 0)
1506 linepct = 100 * current->lineno / totlines;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001507
1508 if (totsize > 0)
1509 bytepct = 100 * i / totsize;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001510
1511#ifdef DEBUG
1512 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1513 linepct, bytepct);
1514#endif
1515
Chris Allegretta2084acc2001-11-29 03:43:08 +00001516 /* if constant is zero, display the position on the statusbar
1517 unconditionally; otherwise, only display the position when the
1518 character values have changed */
1519 if (!constant || (old_i != i || old_totsize != totsize)) {
1520 statusbar(_("line %d of %d (%.0f%%), character %ld of %ld (%.0f%%)"),
1521 current->lineno, totlines, linepct, i, totsize, bytepct);
1522 }
1523
1524 old_i = i;
1525 old_totsize = totsize;
1526
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001527 reset_cursor();
1528 return 1;
1529}
1530
Chris Allegretta2084acc2001-11-29 03:43:08 +00001531int do_cursorpos_void(void)
1532{
1533 return do_cursorpos(0);
1534}
1535
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001536/* Our broken, non-shortcut list compliant help function.
Chris Allegretta88520c92001-05-05 17:45:54 +00001537 But, hey, it's better than nothing, and it's dynamic! */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001538int do_help(void)
1539{
Rocco Corsiaf5c3022001-01-12 07:51:05 +00001540#ifndef DISABLE_HELP
Chris Allegrettab3655b42001-10-22 03:15:31 +00001541 char *ptr, *end;
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001542 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001543 int no_help_flag = 0;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001544 shortcut *oldshortcut;
1545 int oldslen;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001546
1547 blank_edit();
1548 curs_set(0);
Chris Allegrettab3655b42001-10-22 03:15:31 +00001549 wattroff(bottomwin, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001550 blank_statusbar();
1551
Chris Allegrettab3655b42001-10-22 03:15:31 +00001552 help_init();
1553 ptr = help_text;
1554
1555 oldshortcut = currshortcut;
1556 oldslen = currslen;
1557
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001558 currshortcut = help_list;
1559 currslen = HELP_LIST_LEN;
Chris Allegretta6fe61492001-05-21 12:56:25 +00001560
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001561 kp = keypad_on(edit, 1);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001562 kp2 = keypad_on(bottomwin, 1);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001563
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001564 if (ISSET(NO_HELP)) {
1565
Chris Allegretta88520c92001-05-05 17:45:54 +00001566 /* Well, if we're going to do this, we should at least
Chris Allegretta70444892001-01-07 23:02:02 +00001567 do it the right way */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001568 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001569 UNSET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001570 window_init();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001571 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta70444892001-01-07 23:02:02 +00001572
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001573 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001574 bottombars(help_list, HELP_LIST_LEN);
1575
1576 do {
1577 ptr = help_text;
1578 switch (kbinput) {
Chris Allegretta84de5522001-04-12 14:51:48 +00001579#ifndef DISABLE_MOUSE
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001580#ifdef NCURSES_MOUSE_VERSION
1581 case KEY_MOUSE:
1582 do_mouse();
1583 break;
1584#endif
1585#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001586 case NANO_NEXTPAGE_KEY:
1587 case NANO_NEXTPAGE_FKEY:
1588 case KEY_NPAGE:
1589 if (!no_more) {
1590 blank_edit();
1591 page++;
1592 }
1593 break;
1594 case NANO_PREVPAGE_KEY:
1595 case NANO_PREVPAGE_FKEY:
1596 case KEY_PPAGE:
1597 if (page > 1) {
1598 no_more = 0;
1599 blank_edit();
1600 page--;
1601 }
1602 break;
1603 }
1604
Chris Allegretta88520c92001-05-05 17:45:54 +00001605 /* Calculate where in the text we should be, based on the page */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001606 for (i = 1; i < page; i++) {
1607 row = 0;
1608 j = 0;
Chris Allegretta44e73df2000-09-07 03:37:38 +00001609
1610 while (row < editwinrows - 2 && *ptr != '\0') {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001611 if (*ptr == '\n' || j == COLS - 5) {
1612 j = 0;
1613 row++;
1614 }
1615 ptr++;
1616 j++;
1617 }
1618 }
1619
Chris Allegretta44e73df2000-09-07 03:37:38 +00001620 if (i > 1) {
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001621
Chris Allegretta44e73df2000-09-07 03:37:38 +00001622 }
1623
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001624 i = 0;
1625 j = 0;
1626 while (i < editwinrows && *ptr != '\0') {
1627 end = ptr;
1628 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1629 end++;
1630 j++;
1631 }
1632 if (j == COLS - 5) {
1633
Chris Allegretta88520c92001-05-05 17:45:54 +00001634 /* Don't print half a word if we've run out of space */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001635 while (*end != ' ' && *end != '\0') {
1636 end--;
1637 j--;
1638 }
1639 }
1640 mvwaddnstr(edit, i, 0, ptr, j);
1641 j = 0;
1642 i++;
1643 if (*end == '\n')
1644 end++;
1645 ptr = end;
1646 }
1647 if (*ptr == '\0') {
1648 no_more = 1;
1649 continue;
1650 }
Chris Allegrettad1627cf2000-12-18 05:03:16 +00001651 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
1652 kbinput != NANO_EXIT_FKEY);
1653
Chris Allegrettab3655b42001-10-22 03:15:31 +00001654 currshortcut = oldshortcut;
1655 currslen = oldslen;
1656
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001657 if (no_help_flag) {
Chris Allegretta70444892001-01-07 23:02:02 +00001658 blank_bottombars();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001659 wrefresh(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001660 SET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001661 window_init();
1662 }
Chris Allegrettab3655b42001-10-22 03:15:31 +00001663 else
1664 bottombars(currshortcut, currslen);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001665
1666 curs_set(1);
1667 edit_refresh();
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001668 kp = keypad_on(edit, kp);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001669 kp2 = keypad_on(bottomwin, kp2);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001670
Chris Allegretta3bc8c722000-12-10 17:03:25 +00001671#elif defined(DISABLE_HELP)
1672 nano_disabled_msg();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001673#endif
1674
1675 return 1;
1676}
1677
1678/* Dump the current file structure to stderr */
1679void dump_buffer(filestruct * inptr)
1680{
1681#ifdef DEBUG
1682 filestruct *fileptr;
1683
1684 if (inptr == fileage)
1685 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1686 else if (inptr == cutbuffer)
1687 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1688 else
1689 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1690
1691 fileptr = inptr;
1692 while (fileptr != NULL) {
Chris Allegrettab3655b42001-10-22 03:15:31 +00001693 fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001694 fflush(stderr);
1695 fileptr = fileptr->next;
1696 }
1697#endif /* DEBUG */
1698}
1699
1700void dump_buffer_reverse(filestruct * inptr)
1701{
1702#ifdef DEBUG
1703 filestruct *fileptr;
1704
1705 fileptr = filebot;
1706 while (fileptr != NULL) {
Chris Allegrettab3655b42001-10-22 03:15:31 +00001707 fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001708 fflush(stderr);
1709 fileptr = fileptr->prev;
1710 }
1711#endif /* DEBUG */
1712}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001713
Chris Allegretta88520c92001-05-05 17:45:54 +00001714/* Fix editbot, based on the assumption that edittop is correct */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001715void fix_editbot(void)
1716{
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001717 int i;
1718 editbot = edittop;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001719 for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1720 && (editbot != filebot); i++, editbot = editbot->next);
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001721}
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001722
Chris Allegrettafb62f732000-12-05 11:36:41 +00001723/* highlight the current word being replaced or spell checked */
1724void do_replace_highlight(int highlight_flag, char *word)
1725{
1726 char *highlight_word = NULL;
1727 int x, y;
1728
1729 highlight_word = mallocstrcpy(highlight_word, &current->data[current_x]);
1730 highlight_word[strlen(word)] = '\0';
1731
Chris Allegretta88520c92001-05-05 17:45:54 +00001732 /* adjust output when word extends beyond screen */
Chris Allegrettafb62f732000-12-05 11:36:41 +00001733
1734 x = xplustabs();
1735 y = get_page_end_virtual(get_page_from_virtual(x)) + 1;
1736
1737 if ((COLS - (y - x) + strlen(word)) > COLS) {
1738 highlight_word[y - x - 1] = '$';
1739 highlight_word[y - x] = '\0';
1740 }
1741
1742 /* OK display the output */
1743
1744 reset_cursor();
1745
1746 if (highlight_flag)
1747 wattron(edit, A_REVERSE);
1748
1749 waddstr(edit, highlight_word);
1750
1751 if (highlight_flag)
1752 wattroff(edit, A_REVERSE);
1753
1754 free(highlight_word);
1755}
1756
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001757#ifdef NANO_EXTRA
Chris Allegretta9b3c7e82001-08-25 16:00:53 +00001758#define CREDIT_LEN 48
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001759void do_credits(void)
1760{
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001761 int i, j = 0, k, place = 0, start_x;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001762 char *what;
1763
1764 char *nanotext = _("The nano text editor");
1765 char *version = _("version ");
1766 char *brought = _("Brought to you by:");
1767 char *specialthx = _("Special thanks to:");
1768 char *fsf = _("The Free Software Foundation");
1769 char *ncurses = _("Pavel Curtis, Zeyd Ben-Halim and Eric S. Raymond for ncurses");
1770 char *anyonelse = _("and anyone else we forgot...");
1771 char *thankyou = _("Thank you for using nano!\n");
1772
1773 char *credits[CREDIT_LEN] = {nanotext,
1774 version,
1775 VERSION,
1776 "",
1777 brought,
1778 "Chris Allegretta",
1779 "Jordi Mallach",
1780 "Adam Rogoyski",
1781 "Rob Siemborski",
1782 "Rocco Corsi",
1783 "Ken Tyler",
1784 "Sven Guckes",
1785 "Florian König",
1786 "Pauli Virtanen",
1787 "Daniele Medri",
1788 "Clement Laforet",
1789 "Tedi Heriyanto",
Chris Allegrettaa131c7c2000-11-25 19:59:41 +00001790 "Bill Soudan",
Chris Allegretta7cd9f742000-11-25 20:17:28 +00001791 "Christian Weisgerber",
Chris Allegretta827b15f2001-01-03 02:09:04 +00001792 "Erik Andersen",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001793 "Big Gaute",
1794 "Joshua Jensen",
Chris Allegretta0d471de2001-03-15 14:40:42 +00001795 "Ryan Krebs",
Chris Allegretta7ab3e8f2001-03-22 23:12:22 +00001796 "Albert Chin",
Chris Allegretta9b3c7e82001-08-25 16:00:53 +00001797 "David Lawrence Ramsey",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001798 "",
1799 specialthx,
1800 "Plattsburgh State University",
1801 "Benet Laboratories",
1802 "Amy Allegretta",
1803 "Linda Young",
1804 "Jeremy Robichaud",
1805 "Richard Kolb II",
1806 fsf,
1807 "Linus Torvalds",
1808 ncurses,
1809 anyonelse,
1810 thankyou,
1811 "", "", "", "",
Jordi Mallach8ae57892002-01-04 17:57:40 +00001812 "(c) 1999-2002 Chris Allegretta",
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001813 "", "", "", "",
1814 "www.nano-editor.org"
1815 };
1816
1817 curs_set(0);
1818 nodelay(edit, TRUE);
1819 blank_bottombars();
1820 mvwaddstr(topwin, 0, 0, hblank);
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001821 blank_edit();
1822 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001823 wrefresh(bottomwin);
1824 wrefresh(topwin);
1825
1826 while (wgetch(edit) == ERR) {
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001827 for (k = 0; k <= 1; k++) {
1828 blank_edit();
1829 for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); i--) {
1830 mvwaddstr(edit, i * 2 - k, 0, hblank);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001831
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001832 if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
1833 what = credits[place - (editwinrows / 2 - 1 - i)];
1834 else
1835 what = "";
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001836
Chris Allegretta17dcb722001-01-20 21:40:07 +00001837 start_x = COLS / 2 - strlen(what) / 2 - 1;
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001838 mvwaddstr(edit, i * 2 - k, start_x, what);
1839 }
1840 usleep(700000);
1841 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001842 }
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001843 if (j < editwinrows / 2 - 1)
1844 j++;
1845
1846 place++;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001847
1848 if (place >= CREDIT_LEN + editwinrows / 2)
1849 break;
1850 }
1851
1852 nodelay(edit, FALSE);
1853 curs_set(1);
1854 display_main_list();
1855 total_refresh();
1856 }
1857#endif
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001858
Chris Allegrettae3167732001-03-18 16:59:34 +00001859int keypad_on(WINDOW * win, int newval)
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001860{
1861
Chris Allegretta88520c92001-05-05 17:45:54 +00001862/* This is taken right from aumix. Don't sue me. */
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001863#ifdef HAVE_USEKEYPAD
1864 int old;
1865
1866 old = win->_use_keypad;
Chris Allegrettae3167732001-03-18 16:59:34 +00001867 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001868 return old;
1869#else
Chris Allegrettae3167732001-03-18 16:59:34 +00001870 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001871 return 1;
1872#endif /* HAVE_USEKEYPAD */
1873
1874}
1875
1876
1877