blob: 6d1da81d8ae9bbc539e58d5bb14dc4f7b83746cb [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
22#include <stdarg.h>
23#include <string.h>
Chris Allegrettadba37ae2000-07-07 05:13:09 +000024#include <stdlib.h>
Chris Allegretta8a0de3b2000-11-24 20:45:14 +000025#include <unistd.h>
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +000026#include <ctype.h>
Chris Allegretta6232d662002-05-12 19:52:15 +000027#include <assert.h>
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +000028#include "config.h"
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000029#include "proto.h"
30#include "nano.h"
31
Chris Allegretta6232d662002-05-12 19:52:15 +000032#ifdef ENABLE_NLS
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000033#include <libintl.h>
34#define _(string) gettext(string)
35#else
36#define _(string) (string)
37#endif
38
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +000039
40/* winio.c statics */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000041static int statblank = 0; /* Number of keystrokes left after
Chris Allegretta88520c92001-05-05 17:45:54 +000042 we call statusbar(), before we
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000043 actually blank the statusbar */
Robert Siemborskid8510b22000-06-06 23:04:06 +000044
45/* Local Function Prototypes for only winio.c */
46inline int get_page_from_virtual(int virtual);
47inline int get_page_start_virtual(int page);
48inline int get_page_end_virtual(int page);
49
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000050/* Window I/O */
51
52int do_first_line(void)
53{
54 current = fileage;
55 placewewant = 0;
56 current_x = 0;
Chris Allegretta234a34d2000-07-29 04:33:38 +000057 edit_update(current, CENTER);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000058 return 1;
59}
60
61int do_last_line(void)
62{
63 current = filebot;
64 placewewant = 0;
65 current_x = 0;
Chris Allegretta234a34d2000-07-29 04:33:38 +000066 edit_update(current, CENTER);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000067 return 1;
68}
69
Chris Allegretta88520c92001-05-05 17:45:54 +000070/* Like xplustabs, but for a specific index of a specific filestruct */
David Lawrence Ramseyc5967552002-06-21 03:20:06 +000071int xpt(const filestruct *fileptr, int index)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000072{
73 int i, tabs = 0;
74
75 if (fileptr == NULL || fileptr->data == NULL)
76 return 0;
77
78 for (i = 0; i < index && fileptr->data[i] != 0; i++) {
79 tabs++;
80
81 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta6d690a32000-08-03 22:51:21 +000082 if (tabs % tabsize == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000083 else
Chris Allegretta6d690a32000-08-03 22:51:21 +000084 tabs += tabsize - (tabs % tabsize);
Chris Allegretta4da1fc62000-06-21 03:00:43 +000085 } else if (fileptr->data[i] & 0x80)
Chris Allegretta88520c92001-05-05 17:45:54 +000086 /* Make 8 bit chars only 1 column! */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000087 ;
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +000088 else if (iscntrl((int) fileptr->data[i]))
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000089 tabs++;
90 }
91
92 return tabs;
93}
94
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000095/* 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
Robert Siemborskid8510b22000-06-06 23:04:06 +0000102/* Return what current_x should be, given xplustabs() for the line,
103 * given a start position in the filestruct's data */
104int actual_x_from_start(filestruct * fileptr, int xplus, int start)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000105{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000106 int i, tot = 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000107
108 if (fileptr == NULL || fileptr->data == NULL)
109 return 0;
110
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000111 for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000112 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta4dc03d52002-05-11 03:04:44 +0000113 if (tot % tabsize != 0)
Chris Allegretta6d690a32000-08-03 22:51:21 +0000114 tot += tabsize - (tot % tabsize);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000115 } else if (fileptr->data[i] & 0x80)
116 tot++; /* Make 8 bit chars only 1 column (again) */
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000117 else if (iscntrl((int) fileptr->data[i])) {
Chris Allegretta4dc03d52002-05-11 03:04:44 +0000118 i++;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000119 tot += 2;
Chris Allegretta4dc03d52002-05-11 03:04:44 +0000120 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000121
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000122 if (i > strlen(fileptr->data))
123 i = strlen(fileptr->data);
124
125 /* see if we're in the x-plus-tabs column of xplus; if not, look
126 for the closest column to it */
127 if (xpt(fileptr, i) < xplus) {
128 while (xpt(fileptr, i) < xplus && i < strlen(fileptr->data))
129 i++;
130 }
131 else if (xpt(fileptr, i) > xplus) {
132 while (xpt(fileptr, i) > xplus && i > start)
133 i--;
134 }
135
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000136#ifdef DEBUG
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000137 fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"),
138 xplus, i);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000139#endif
Chris Allegretta4dc03d52002-05-11 03:04:44 +0000140
Robert Siemborskid8510b22000-06-06 23:04:06 +0000141 return i - start;
142}
143
144/* Opposite of xplustabs */
Chris Allegretta6efda542001-04-28 18:03:52 +0000145int actual_x(filestruct * fileptr, int xplus)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000146{
147 return actual_x_from_start(fileptr, xplus, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000148}
149
150/* a strlen with tabs factored in, similar to xplustabs() */
Chris Allegrettad4fa0d32002-03-05 19:55:55 +0000151int strnlenpt(char *buf, int size)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000152{
153 int i, tabs = 0;
154
155 if (buf == NULL)
156 return 0;
157
Chris Allegrettad4fa0d32002-03-05 19:55:55 +0000158 for (i = 0; i < size; i++) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000159 tabs++;
160
161 if (buf[i] == NANO_CONTROL_I) {
Chris Allegretta6d690a32000-08-03 22:51:21 +0000162 if (tabs % tabsize == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000163 else
Chris Allegretta6d690a32000-08-03 22:51:21 +0000164 tabs += tabsize - (tabs % tabsize);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000165 } else if (buf[i] & 0x80)
Chris Allegretta88520c92001-05-05 17:45:54 +0000166 /* Make 8 bit chars only 1 column! */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000167 ;
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000168 else if (iscntrl((int) buf[i]))
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000169 tabs++;
170 }
171
172 return tabs;
173}
174
Chris Allegrettad4fa0d32002-03-05 19:55:55 +0000175int strlenpt(char *buf)
176{
177 return strnlenpt(buf, strlen(buf));
178}
179
Chris Allegretta88520c92001-05-05 17:45:54 +0000180/* resets current_y, based on the position of current, and puts the cursor at
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000181 (current_y, current_x) */
182void reset_cursor(void)
183{
184 filestruct *ptr = edittop;
185 int x;
186
187 current_y = 0;
188
189 while (ptr != current && ptr != editbot && ptr->next != NULL) {
190 ptr = ptr->next;
191 current_y++;
192 }
193
194 x = xplustabs();
195 if (x <= COLS - 2)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000196 wmove(edit, current_y, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000197 else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000198 wmove(edit, current_y, x -
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000199 get_page_start_virtual(get_page_from_virtual(x)));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000200
201}
202
203void blank_bottombars(void)
204{
205 int i = no_help()? 3 : 1;
206
207 for (; i <= 2; i++)
208 mvwaddstr(bottomwin, i, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000209}
210
211void blank_edit(void)
212{
213 int i;
214 for (i = 0; i <= editwinrows - 1; i++)
215 mvwaddstr(edit, i, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000216}
217
218
219void blank_statusbar(void)
220{
221 mvwaddstr(bottomwin, 0, 0, hblank);
222}
223
224void blank_statusbar_refresh(void)
225{
226 blank_statusbar();
227 wrefresh(bottomwin);
228}
229
230void check_statblank(void)
231{
232
233 if (statblank > 1)
234 statblank--;
235 else if (statblank == 1 && !ISSET(CONSTUPDATE)) {
236 statblank--;
237 blank_statusbar_refresh();
238 }
239}
240
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000241/* Repaint the statusbar when getting a character in nanogetstr */
242void nanoget_repaint(char *buf, char *inputbuf, int x)
243{
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000244 int len = strlen(buf);
245 int wid = COLS - len;
246
Chris Allegretta8ce24132001-04-30 11:28:46 +0000247#ifdef ENABLE_COLOR
248 color_on(bottomwin, COLOR_STATUSBAR);
Chris Allegrettab3655b42001-10-22 03:15:31 +0000249#else
250 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000251#endif
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000252 blank_statusbar();
Chris Allegretta8ce24132001-04-30 11:28:46 +0000253
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000254 if (x <= COLS - 1) {
255 /* Black magic */
256 buf[len - 1] = ' ';
Chris Allegretta31925e42000-11-02 04:40:39 +0000257
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000258 mvwaddstr(bottomwin, 0, 0, buf);
259 waddnstr(bottomwin, inputbuf, wid);
260 wmove(bottomwin, 0, (x % COLS));
Chris Allegretta598106e2002-01-19 01:59:37 +0000261 } else {
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000262 /* Black magic */
263 buf[len - 1] = '$';
Chris Allegretta31925e42000-11-02 04:40:39 +0000264
Chris Allegretta0d1e8d62000-11-02 15:30:24 +0000265 mvwaddstr(bottomwin, 0, 0, buf);
266 waddnstr(bottomwin, &inputbuf[wid * ((x - len) / (wid))], wid);
267 wmove(bottomwin, 0, ((x - len) % wid) + len);
268 }
Chris Allegretta8ce24132001-04-30 11:28:46 +0000269
270#ifdef ENABLE_COLOR
271 color_off(bottomwin, COLOR_STATUSBAR);
Chris Allegrettab3655b42001-10-22 03:15:31 +0000272#else
273 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000274#endif
Chris Allegrettaa0e957b2000-10-24 22:25:36 +0000275}
276
Chris Allegretta88520c92001-05-05 17:45:54 +0000277/* Get the input from the kb; this should only be called from statusq */
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000278int nanogetstr(int allowtabs, char *buf, char *def, shortcut *s,
Chris Allegretta2084acc2001-11-29 03:43:08 +0000279 int start_x, int list)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000280{
Chris Allegretta9caa1932002-02-15 20:08:05 +0000281 int kbinput = 0, x = 0, xend, slen;
Chris Allegrettabe77c612000-11-24 14:00:16 +0000282 int x_left = 0, inputlen, tabbed = 0;
Chris Allegretta31925e42000-11-02 04:40:39 +0000283 char *inputbuf;
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000284 shortcut *t;
Rocco Corsi06aca1c2001-01-11 05:30:31 +0000285#ifndef DISABLE_TABCOMP
Chris Allegrettabe77c612000-11-24 14:00:16 +0000286 int shift = 0;
287#endif
Chris Allegretta598106e2002-01-19 01:59:37 +0000288
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000289 slen = length_of_list(s);
Chris Allegretta88b09152001-05-17 11:35:43 +0000290 inputbuf = charalloc(strlen(def) + 1);
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000291 inputbuf[0] = '\0';
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000292
293 x_left = strlen(buf);
294 x = strlen(def) + x_left;
295
Chris Allegrettab3655b42001-10-22 03:15:31 +0000296#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000297 currshortcut = s;
Chris Allegretta6fe61492001-05-21 12:56:25 +0000298#endif
299
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000300 /* Get the input! */
Chris Allegretta31925e42000-11-02 04:40:39 +0000301 if (strlen(def) > 0)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000302 strcpy(inputbuf, def);
Chris Allegretta31925e42000-11-02 04:40:39 +0000303
304 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000305
Chris Allegretta022b96f2000-11-14 17:47:58 +0000306 /* Make sure any editor screen updates are displayed before getting input */
307 wrefresh(edit);
308
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000309 while ((kbinput = wgetch(bottomwin)) != 13) {
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000310 for (t = s; t != NULL; t = t->next) {
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000311#ifdef DEBUG
312 fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
313#endif
314
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000315 if (kbinput == t->val && kbinput < 32) {
Chris Allegretta5bf51d32000-11-16 06:01:10 +0000316
Chris Allegrettab3655b42001-10-22 03:15:31 +0000317#ifndef DISABLE_HELP
318 /* Have to do this here, it would be too late to do it in statusq */
Chris Allegretta598106e2002-01-19 01:59:37 +0000319 if (kbinput == NANO_HELP_KEY || kbinput == NANO_HELP_FKEY) {
Chris Allegrettab3655b42001-10-22 03:15:31 +0000320 do_help();
321 break;
322 }
323#endif
324
Chris Allegretta5bf51d32000-11-16 06:01:10 +0000325 /* We shouldn't discard the answer it gave, just because
326 we hit a keystroke, GEEZ! */
327 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000328 free(inputbuf);
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000329 return t->val;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000330 }
331 }
332 xend = strlen(buf) + strlen(inputbuf);
333
Chris Allegretta04d848e2000-11-05 17:54:41 +0000334 if (kbinput != '\t')
335 tabbed = 0;
336
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000337 switch (kbinput) {
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000338
Chris Allegretta598106e2002-01-19 01:59:37 +0000339 /* Stuff we want to equate with <enter>, ASCII 13 */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +0000340 case 343:
Chris Allegrettaf9b6c9b2000-10-18 19:35:59 +0000341 ungetch(13); /* Enter on iris-ansi $TERM, sometimes */
342 break;
Chris Allegretta598106e2002-01-19 01:59:37 +0000343 /* Stuff we want to ignore */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000344#ifdef PDCURSES
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000345 case 541:
346 case 542:
Chris Allegretta598106e2002-01-19 01:59:37 +0000347 case 543: /* Right ctrl again */
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000348 case 544:
Chris Allegretta598106e2002-01-19 01:59:37 +0000349 case 545: /* Right alt again */
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000350 break;
Chris Allegretta5b1faac2000-11-16 19:55:30 +0000351#endif
Chris Allegretta84de5522001-04-12 14:51:48 +0000352#ifndef DISABLE_MOUSE
Chris Allegretta6b58acd2001-04-12 03:01:53 +0000353#ifdef NCURSES_MOUSE_VERSION
354 case KEY_MOUSE:
355 do_mouse();
356 break;
357#endif
358#endif
Chris Allegretta658399a2001-06-14 02:54:22 +0000359 case NANO_HOME_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000360 case KEY_HOME:
361 x = x_left;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000362 break;
Chris Allegretta658399a2001-06-14 02:54:22 +0000363 case NANO_END_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000364 case KEY_END:
365 x = x_left + strlen(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000366 break;
367 case KEY_RIGHT:
Chris Allegretta35dac582001-03-21 15:07:20 +0000368 case NANO_FORWARD_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000369
370 if (x < xend)
371 x++;
372 wmove(bottomwin, 0, x);
373 break;
374 case NANO_CONTROL_D:
375 if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
376 memmove(inputbuf + (x - x_left),
377 inputbuf + (x - x_left) + 1,
378 strlen(inputbuf) - (x - x_left) - 1);
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000379 inputbuf[strlen(inputbuf) - 1] = '\0';
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000380 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000381 break;
382 case NANO_CONTROL_K:
383 case NANO_CONTROL_U:
384 *inputbuf = 0;
385 x = x_left;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000386 break;
387 case KEY_BACKSPACE:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000388 case 127:
389 case NANO_CONTROL_H:
390 if (strlen(inputbuf) > 0) {
391 if (x == (x_left + strlen(inputbuf)))
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000392 inputbuf[strlen(inputbuf) - 1] = '\0';
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000393 else if (x - x_left) {
394 memmove(inputbuf + (x - x_left) - 1,
395 inputbuf + (x - x_left),
396 strlen(inputbuf) - (x - x_left));
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000397 inputbuf[strlen(inputbuf) - 1] = '\0';
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000398 }
399 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000400 if (x > strlen(buf))
401 x--;
Chris Allegretta04d848e2000-11-05 17:54:41 +0000402 break;
Rocco Corsi06aca1c2001-01-11 05:30:31 +0000403#ifndef DISABLE_TABCOMP
Chris Allegretta04d848e2000-11-05 17:54:41 +0000404 case NANO_CONTROL_I:
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000405 if (allowtabs) {
Chris Allegretta442f2c52000-11-14 17:46:06 +0000406 shift = 0;
Chris Allegretta598106e2002-01-19 01:59:37 +0000407 inputbuf = input_tab(inputbuf, (x - x_left),
408 &tabbed, &shift, &list);
Chris Allegretta442f2c52000-11-14 17:46:06 +0000409 x += shift;
Chris Allegrettae434b452001-01-27 19:25:00 +0000410 if (x - x_left > strlen(inputbuf))
411 x = strlen(inputbuf) + x_left;
Chris Allegretta7da4e9f2000-11-06 02:57:22 +0000412 }
Chris Allegretta04d848e2000-11-05 17:54:41 +0000413 break;
Chris Allegrettabe77c612000-11-24 14:00:16 +0000414#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000415 case KEY_LEFT:
Chris Allegretta35dac582001-03-21 15:07:20 +0000416 case NANO_BACK_KEY:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000417 if (x > strlen(buf))
418 x--;
419 wmove(bottomwin, 0, x);
420 break;
421 case KEY_UP:
422 case KEY_DOWN:
423 break;
424
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000425 case KEY_DC:
426 goto do_deletekey;
427
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000428 case 27:
429 switch (kbinput = wgetch(edit)) {
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000430 case 'O':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000431 switch (kbinput = wgetch(edit)) {
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000432 case 'F':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000433 x = x_left + strlen(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000434 break;
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000435 case 'H':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000436 x = x_left;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000437 break;
438 }
439 break;
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000440 case '[':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000441 switch (kbinput = wgetch(edit)) {
442 case 'C':
443 if (x < xend)
444 x++;
445 wmove(bottomwin, 0, x);
446 break;
447 case 'D':
448 if (x > strlen(buf))
449 x--;
450 wmove(bottomwin, 0, x);
451 break;
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000452 case '1':
453 case '7':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000454 x = x_left;
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000455 goto skip_tilde;
456 case '3':
457 do_deletekey:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000458 if (strlen(inputbuf) > 0
459 && (x - x_left) != strlen(inputbuf)) {
460 memmove(inputbuf + (x - x_left),
461 inputbuf + (x - x_left) + 1,
462 strlen(inputbuf) - (x - x_left) - 1);
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000463 inputbuf[strlen(inputbuf) - 1] = '\0';
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000464 }
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000465 goto skip_tilde;
466 case '4':
467 case '8':
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000468 x = x_left + strlen(inputbuf);
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000469 goto skip_tilde;
470 skip_tilde:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000471 nodelay(edit, TRUE);
472 kbinput = wgetch(edit);
Chris Allegrettace78c1e2001-09-23 01:18:03 +0000473 if (kbinput == '~' || kbinput == ERR)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000474 kbinput = -1;
475 nodelay(edit, FALSE);
476 break;
477 }
Chris Allegretta658399a2001-06-14 02:54:22 +0000478 default:
479
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000480 for (t = s; t != NULL; t = t->next) {
Chris Allegretta658399a2001-06-14 02:54:22 +0000481#ifdef DEBUG
Chris Allegretta598106e2002-01-19 01:59:37 +0000482 fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput,
483 kbinput);
Chris Allegretta658399a2001-06-14 02:54:22 +0000484#endif
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000485 if (kbinput == t->val || kbinput == t->val - 32) {
Chris Allegretta658399a2001-06-14 02:54:22 +0000486
487 /* We hit an Alt key. Do like above. We don't
488 just ungetch the letter and let it get caught
489 above cause that screws the keypad... */
490 answer = mallocstrcpy(answer, inputbuf);
491 free(inputbuf);
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000492 return t->val;
Chris Allegretta658399a2001-06-14 02:54:22 +0000493 }
494 }
495
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000496 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000497 break;
498
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000499 default:
Chris Allegretta658399a2001-06-14 02:54:22 +0000500
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000501 if (kbinput < 32)
502 break;
Chris Allegretta31925e42000-11-02 04:40:39 +0000503
504 inputlen = strlen(inputbuf);
505 inputbuf = nrealloc(inputbuf, inputlen + 2);
506
Chris Allegretta598106e2002-01-19 01:59:37 +0000507 memmove(&inputbuf[x - x_left + 1],
508 &inputbuf[x - x_left], inputlen - (x - x_left) + 1);
Chris Allegretta31925e42000-11-02 04:40:39 +0000509 inputbuf[x - x_left] = kbinput;
510
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000511 x++;
512
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000513#ifdef DEBUG
514 fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
515#endif
516 }
Chris Allegretta386e0512001-10-02 02:57:26 +0000517 nanoget_repaint(buf, inputbuf, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000518 wrefresh(bottomwin);
519 }
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000520#ifndef DISABLE_TABCOMP
521 /* if we've done tab completion, there might be a list of filename
522 matches on the edit window at this point; make sure they're
523 cleared off */
524 if (list)
525 edit_refresh();
526#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000527
Chris Allegretta31925e42000-11-02 04:40:39 +0000528 answer = mallocstrcpy(answer, inputbuf);
Chris Allegretta92d2bab2000-11-02 14:53:46 +0000529 free(inputbuf);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000530
Chris Allegrettac1049ac2001-08-17 00:03:46 +0000531 /* In pico mode, just check for a blank answer here */
Chris Allegretta4dc03d52002-05-11 03:04:44 +0000532 if (ISSET(PICO_MODE) && answer[0] == '\0')
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000533 return -2;
534 else
535 return 0;
536}
537
538void horizbar(WINDOW * win, int y)
539{
540 wattron(win, A_REVERSE);
541 mvwaddstr(win, 0, 0, hblank);
542 wattroff(win, A_REVERSE);
543}
544
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000545void titlebar(char *path)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000546{
547 int namelen, space;
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000548 char *what = path;
549
550 if (path == NULL)
551 what = filename;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000552
Chris Allegretta8ce24132001-04-30 11:28:46 +0000553#ifdef ENABLE_COLOR
554 color_on(topwin, COLOR_TITLEBAR);
555 mvwaddstr(topwin, 0, 0, hblank);
556#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000557 horizbar(topwin, 0);
558 wattron(topwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000559#endif
560
David Lawrence Ramseyc5967552002-06-21 03:20:06 +0000561 mvwaddnstr(topwin, 0, 2, VERMSG, COLS - 3);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000562
563 space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
564
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000565 namelen = strlen(what);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000566
David Lawrence Ramseyc5967552002-06-21 03:20:06 +0000567 if (space > 0) {
568 if (what[0] == '\0')
569 mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
570 else {
571 if (namelen > space) {
572 if (path == NULL)
573 waddstr(topwin, _(" File: ..."));
574 else
575 waddstr(topwin, _(" DIR: ..."));
576 waddstr(topwin, &what[namelen - space]);
577 } else {
578 if (path == NULL)
579 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1),
580 _("File: "));
581 else
582 mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1),
583 _(" DIR: "));
584 waddstr(topwin, what);
585 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000586 }
David Lawrence Ramseyc5967552002-06-21 03:20:06 +0000587 } /* If we don't have space, we shouldn't bother */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000588 if (ISSET(MODIFIED))
David Lawrence Ramseyc5967552002-06-21 03:20:06 +0000589 mvwaddstr(topwin, 0, COLS - 11, _(" Modified "));
Chris Allegretta4dc03d52002-05-11 03:04:44 +0000590 else if (ISSET(VIEW_MODE))
David Lawrence Ramseyc5967552002-06-21 03:20:06 +0000591 mvwaddstr(topwin, 0, COLS - 11, _(" View "));
Chris Allegretta8ce24132001-04-30 11:28:46 +0000592
593#ifdef ENABLE_COLOR
594 color_off(topwin, COLOR_TITLEBAR);
595#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000596 wattroff(topwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000597#endif
598
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000599 wrefresh(topwin);
600 reset_cursor();
601}
602
Chris Allegretta6232d662002-05-12 19:52:15 +0000603/* Write a shortcut key to the help area at the bottom of the window.
604 * keystroke is e.g. "^G" and desc is e.g. "Get Help".
605 * We are careful to write exactly len characters, even if len is
606 * very small and keystroke and desc are long. */
607static void onekey(const char *keystroke, const char *desc, int len)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000608{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000609 wattron(bottomwin, A_REVERSE);
Chris Allegretta6232d662002-05-12 19:52:15 +0000610 waddnstr(bottomwin, keystroke, len);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000611 wattroff(bottomwin, A_REVERSE);
Chris Allegretta6232d662002-05-12 19:52:15 +0000612 len -= strlen(keystroke);
613 if (len > 0) {
614 waddch(bottomwin, ' ');
615 len--;
616 waddnstr(bottomwin, desc, len);
617 len -= strlen(desc);
618 for (; len > 0; len--)
619 waddch(bottomwin, ' ');
620 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000621}
622
623void clear_bottomwin(void)
624{
625 if (ISSET(NO_HELP))
626 return;
627
628 mvwaddstr(bottomwin, 1, 0, hblank);
629 mvwaddstr(bottomwin, 2, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000630}
631
Chris Allegretta6232d662002-05-12 19:52:15 +0000632void bottombars(const shortcut *s)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000633{
Chris Allegrettabc72e362002-02-16 20:03:44 +0000634 int i, j, numcols;
Chris Allegretta6232d662002-05-12 19:52:15 +0000635 char keystr[4];
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000636 int slen;
637
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000638 if (ISSET(NO_HELP))
639 return;
640
Chris Allegretta6232d662002-05-12 19:52:15 +0000641 if (s == main_list) {
642 slen = MAIN_VISIBLE;
643 assert(MAIN_VISIBLE <= length_of_list(s));
644 } else
645 slen = length_of_list(s);
646
Chris Allegretta598106e2002-01-19 01:59:37 +0000647#ifdef ENABLE_COLOR
Chris Allegretta8ce24132001-04-30 11:28:46 +0000648 color_on(bottomwin, COLOR_BOTTOMBARS);
Chris Allegretta66577ac2002-01-05 02:03:29 +0000649 if (!colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].set ||
Chris Allegretta598106e2002-01-19 01:59:37 +0000650 colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].fg != COLOR_BLACK)
651 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000652#endif
653
Chris Allegretta6232d662002-05-12 19:52:15 +0000654 /* There will be this many columns of shortcuts */
655 numcols = (slen + (slen % 2)) / 2;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000656
657 clear_bottomwin();
Chris Allegretta658399a2001-06-14 02:54:22 +0000658
Chris Allegrettabc72e362002-02-16 20:03:44 +0000659 for (i = 0; i < numcols; i++) {
660 for (j = 0; j <= 1; j++) {
Chris Allegretta658399a2001-06-14 02:54:22 +0000661
Chris Allegretta6232d662002-05-12 19:52:15 +0000662 wmove(bottomwin, 1 + j, i * (COLS / numcols));
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000663
Chris Allegretta6232d662002-05-12 19:52:15 +0000664#ifndef NANO_SMALL
665 if (s->val == NANO_CONTROL_SPACE)
666 strcpy(keystr, "^ ");
Chris Allegrettabc72e362002-02-16 20:03:44 +0000667 else
Chris Allegretta6232d662002-05-12 19:52:15 +0000668#endif /* !NANO_SMALL */
669 if (s->val > 0) {
670 if (s->val < 64)
671 sprintf(keystr, "^%c", s->val + 64);
672 else
673 sprintf(keystr, "M-%c", s->val - 32);
674 } else if (s->altval > 0)
675 sprintf(keystr, "M-%c", s->altval);
Chris Allegretta658399a2001-06-14 02:54:22 +0000676
Chris Allegretta6232d662002-05-12 19:52:15 +0000677 onekey(keystr, s->desc, COLS / numcols);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000678
Chris Allegretta6232d662002-05-12 19:52:15 +0000679 s = s->next;
680 if (s == NULL)
681 goto break_completely_out;
682 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000683 }
Chris Allegretta6232d662002-05-12 19:52:15 +0000684break_completely_out:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000685
Chris Allegretta598106e2002-01-19 01:59:37 +0000686#ifdef ENABLE_COLOR
Chris Allegretta8ce24132001-04-30 11:28:46 +0000687 color_off(bottomwin, COLOR_BOTTOMBARS);
688#endif
689
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000690 wrefresh(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000691}
692
693/* If modified is not already set, set it and update titlebar */
694void set_modified(void)
695{
696 if (!ISSET(MODIFIED)) {
697 SET(MODIFIED);
Chris Allegrettaf4b96012001-01-03 07:11:47 +0000698 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000699 wrefresh(topwin);
700 }
701}
702
Robert Siemborski9d584552000-07-08 00:41:29 +0000703/* And so start the display update routines */
704/* Given a column, this returns the "page" it is on */
705/* "page" in the case of the display columns, means which set of 80 */
Chris Allegretta88520c92001-05-05 17:45:54 +0000706/* characters is viewable (e.g.: page 1 shows from 1 to COLS) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000707inline int get_page_from_virtual(int virtual)
708{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000709 int page = 2;
710
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000711 if (virtual <= COLS - 2)
712 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000713 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000714
715 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000716 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000717 page++;
718 }
719
720 return page;
721}
722
Robert Siemborski9d584552000-07-08 00:41:29 +0000723/* The inverse of the above function */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000724inline int get_page_start_virtual(int page)
725{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000726 int virtual;
727 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000728 if (page)
729 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000730 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000731}
732
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000733inline int get_page_end_virtual(int page)
734{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000735 return get_page_start_virtual(page) + COLS - 1;
736}
737
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000738#ifndef NANO_SMALL
Robert Siemborski9d584552000-07-08 00:41:29 +0000739/* This takes care of the case where there is a mark that covers only */
740/* the current line. */
741
Chris Allegretta88520c92001-05-05 17:45:54 +0000742/* It expects a line with no tab characters (i.e.: the type that edit_add */
Robert Siemborski9d584552000-07-08 00:41:29 +0000743/* deals with */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000744void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
745 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000746{
Robert Siemborski9d584552000-07-08 00:41:29 +0000747 /*
748 * The general idea is to break the line up into 3 sections: before
749 * the mark, the mark, and after the mark. We then paint each in
Chris Allegretta88520c92001-05-05 17:45:54 +0000750 * turn (for those that are currently visible, of course)
Robert Siemborski9d584552000-07-08 00:41:29 +0000751 *
752 * 3 start points: 0 -> begin, begin->end, end->strlen(data)
753 * in data : pre sel post
754 */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000755 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000756 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000757
Robert Siemborskid8510b22000-06-06 23:04:06 +0000758 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000759 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 +0000760
761 /* now fix the start locations & lengths according to the cursor's
Chris Allegretta88520c92001-05-05 17:45:54 +0000762 * position (i.e.: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000763 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000764 pre_data_len = 0;
765 else
766 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000767
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000768 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000769 begin = this_page_start;
770
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000771 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000772 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000773
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000774 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000775 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000776
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000777 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000778 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000779
Robert Siemborski9d584552000-07-08 00:41:29 +0000780 /* Now calculate the lengths */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000781 sel_data_len = end - begin;
782 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000783
Chris Allegretta8ce24132001-04-30 11:28:46 +0000784#ifdef ENABLE_COLOR
785 color_on(edit, COLOR_MARKER);
786#else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000787 wattron(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +0000788#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +0000789
Robert Siemborskia9addc72000-06-17 06:06:35 +0000790 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000791 &fileptr->data[begin], sel_data_len);
Chris Allegretta8ce24132001-04-30 11:28:46 +0000792
793#ifdef ENABLE_COLOR
794 color_off(edit, COLOR_MARKER);
795#else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000796 wattroff(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +0000797#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +0000798
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000799}
800#endif
801
Robert Siemborski9d584552000-07-08 00:41:29 +0000802/* edit_add takes care of the job of actually painting a line into the
803 * edit window.
804 *
805 * Called only from update_line. Expects a converted-to-not-have-tabs
Robert Siemborski53875912000-06-16 04:25:30 +0000806 * line */
807void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000808 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000809{
Chris Allegretta08893e02001-11-29 02:42:27 +0000810
Chris Allegretta7dd77682001-12-08 19:52:28 +0000811#ifdef ENABLE_COLOR
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000812 colortype *tmpcolor = NULL;
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000813 int k, paintlen;
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000814 filestruct *e, *s;
815 regoff_t ematch, smatch;
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000816#endif
817
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000818 /* Just paint the string in any case (we'll add color or reverse on
Chris Allegretta598106e2002-01-19 01:59:37 +0000819 just the text that needs it */
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000820 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
Chris Allegretta598106e2002-01-19 01:59:37 +0000821 get_page_end_virtual(this_page) - start + 1);
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000822
Chris Allegretta7dd77682001-12-08 19:52:28 +0000823#ifdef ENABLE_COLOR
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000824 if (colorstrings != NULL)
Chris Allegretta598106e2002-01-19 01:59:37 +0000825 for (tmpcolor = colorstrings; tmpcolor != NULL;
826 tmpcolor = tmpcolor->next) {
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000827
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000828 if (tmpcolor->end == NULL) {
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000829
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000830 /* First, highlight all single-line regexes */
831 k = start;
Chris Allegretta3533a342002-03-24 23:19:32 +0000832 regcomp(&color_regexp, tmpcolor->start, 0);
833 while (!regexec(&color_regexp, &fileptr->data[k], 1,
834 colormatches, 0)) {
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000835
Chris Allegretta3533a342002-03-24 23:19:32 +0000836 if (colormatches[0].rm_eo - colormatches[0].rm_so < 1) {
Chris Allegretta7c27be42002-05-05 23:03:54 +0000837 statusbar(_("Refusing 0 length regex match"));
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000838 break;
839 }
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000840#ifdef DEBUG
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000841 fprintf(stderr, _("Match! (%d chars) \"%s\"\n"),
Chris Allegretta3533a342002-03-24 23:19:32 +0000842 colormatches[0].rm_eo - colormatches[0].rm_so,
843 &fileptr->data[k + colormatches[0].rm_so]);
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000844#endif
Chris Allegretta3533a342002-03-24 23:19:32 +0000845 if (colormatches[0].rm_so < COLS - 1) {
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000846 if (tmpcolor->bright)
847 wattron(edit, A_BOLD);
848 wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
849
Chris Allegretta7c27be42002-05-05 23:03:54 +0000850 if (colormatches[0].rm_eo + k <= COLS) {
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000851 paintlen =
Chris Allegretta3533a342002-03-24 23:19:32 +0000852 colormatches[0].rm_eo - colormatches[0].rm_so;
Chris Allegretta7c27be42002-05-05 23:03:54 +0000853#ifdef DEBUG
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000854 fprintf(stderr, _("paintlen (%d) = eo (%d) - so (%d)\n"),
Chris Allegretta7c27be42002-05-05 23:03:54 +0000855 paintlen, colormatches[0].rm_eo, colormatches[0].rm_so);
856#endif
857
858 }
859 else {
Chris Allegretta3533a342002-03-24 23:19:32 +0000860 paintlen = COLS - k - colormatches[0].rm_so - 1;
Chris Allegretta7c27be42002-05-05 23:03:54 +0000861#ifdef DEBUG
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000862 fprintf(stderr, _("paintlen (%d) = COLS (%d) - k (%d), - rm.so (%d) - 1\n"),
Chris Allegretta7c27be42002-05-05 23:03:54 +0000863 paintlen, COLS, k, colormatches[0].rm_so);
864#endif
865 }
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000866
Chris Allegretta3533a342002-03-24 23:19:32 +0000867 mvwaddnstr(edit, yval, colormatches[0].rm_so + k,
868 &fileptr->data[k + colormatches[0].rm_so],
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000869 paintlen);
870
871 }
872
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000873 if (tmpcolor->bright)
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000874 wattroff(edit, A_BOLD);
875 wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000876
Chris Allegretta3533a342002-03-24 23:19:32 +0000877 k += colormatches[0].rm_eo;
Chris Allegretta598106e2002-01-19 01:59:37 +0000878
879 }
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000880 regfree(&color_regexp);
881
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000882 }
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000883 /* Now, if there's an 'end' somewhere below, and a 'start'
884 somewhere above, things get really fun. We have to look
885 down for an end, make sure there's not a start before
886 the end after us, and then look up for a start,
887 and see if there's an end after the start, before us :) */
888 else {
889
890 s = fileptr;
891 while (s != NULL) {
Chris Allegretta3533a342002-03-24 23:19:32 +0000892 regcomp(&color_regexp, tmpcolor->start, 0);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000893 if (!regexec
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000894 (&color_regexp, s->data, 1, colormatches, 0)) {
895 regfree(&color_regexp);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000896 break;
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000897 }
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000898 s = s->prev;
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000899 regfree(&color_regexp);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000900 }
901
902 if (s != NULL) {
903 /* We found a start, mark it */
Chris Allegretta3533a342002-03-24 23:19:32 +0000904 smatch = colormatches[0].rm_so;
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000905
906 e = s;
907 while (e != NULL && e != fileptr) {
Chris Allegretta3533a342002-03-24 23:19:32 +0000908 regcomp(&color_regexp, tmpcolor->end, 0);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000909 if (!regexec
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000910 (&color_regexp, e->data, 1, colormatches, 0)) {
911 regfree(&color_regexp);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000912 break;
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000913 }
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000914 e = e->next;
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000915 regfree(&color_regexp);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000916 }
917
918 if (e != fileptr)
919 continue; /* There's an end before us */
920 else { /* Keep looking for an end */
921 while (e != NULL) {
Chris Allegretta3533a342002-03-24 23:19:32 +0000922 regcomp(&color_regexp, tmpcolor->end, 0);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000923 if (!regexec
Chris Allegretta3533a342002-03-24 23:19:32 +0000924 (&color_regexp, e->data, 1, colormatches,
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000925 0)) {
926 regfree(&color_regexp);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000927 break;
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000928 }
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000929 e = e->next;
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000930 regfree(&color_regexp);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000931 }
932
933 if (e == NULL)
934 continue; /* There's no start before the end :) */
935 else { /* Okay, we found an end, mark it! */
Chris Allegretta3533a342002-03-24 23:19:32 +0000936 ematch = colormatches[0].rm_eo;
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000937
938 while (e != NULL) {
Chris Allegretta3533a342002-03-24 23:19:32 +0000939 regcomp(&color_regexp, tmpcolor->end, 0);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000940 if (!regexec
Chris Allegretta3533a342002-03-24 23:19:32 +0000941 (&color_regexp, e->data, 1,
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000942 colormatches, 0)) {
943 regfree(&color_regexp);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000944 break;
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000945 } e = e->next;
946 regfree(&color_regexp);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000947 }
948
949 if (e == NULL)
950 continue; /* No end, oh well :) */
951
952 /* Didn't find another end, we must be in the
953 middle of a highlighted bit */
954
955 if (tmpcolor->bright)
956 wattron(edit, A_BOLD);
957
958 wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
959
Chris Allegretta7c27be42002-05-05 23:03:54 +0000960 if (s == fileptr && e == fileptr && ematch < COLS) {
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000961 mvwaddnstr(edit, yval, start + smatch,
962 &fileptr->data[start + smatch],
963 ematch - smatch);
Chris Allegretta7c27be42002-05-05 23:03:54 +0000964#ifdef DEBUG
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +0000965 fprintf(stderr, _("start = %d, smatch = %d, ematch = %d\n"), start,
Chris Allegretta7c27be42002-05-05 23:03:54 +0000966 smatch, ematch);
967#endif
968
969 } else if (s == fileptr)
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000970 mvwaddnstr(edit, yval, start + smatch,
971 &fileptr->data[start + smatch],
972 COLS - smatch);
973 else if (e == fileptr)
974 mvwaddnstr(edit, yval, start,
975 &fileptr->data[start],
Chris Allegretta7c27be42002-05-05 23:03:54 +0000976 COLS - start);
Chris Allegretta6c1e6612002-01-19 16:52:34 +0000977 else
978 mvwaddnstr(edit, yval, start,
979 &fileptr->data[start],
980 COLS);
981
982 if (tmpcolor->bright)
983 wattroff(edit, A_BOLD);
984
985 wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
986
987 }
988
989 }
990
991 /* Else go to the next string, yahoo! =) */
992 }
993
994 }
995
Chris Allegretta2fa11b82001-12-02 04:55:44 +0000996 }
Chris Allegretta3674c1d2002-05-12 20:43:49 +0000997
Chris Allegretta598106e2002-01-19 01:59:37 +0000998#endif /* ENABLE_COLOR */
Chris Allegretta7dd77682001-12-08 19:52:28 +0000999#ifndef NANO_SMALL
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001000
Chris Allegretta88520c92001-05-05 17:45:54 +00001001 /* There are quite a few cases that could take place; we'll deal
Robert Siemborski9d584552000-07-08 00:41:29 +00001002 * with them each in turn */
Chris Allegretta598106e2002-01-19 01:59:37 +00001003 if (ISSET(MARK_ISSET) &&
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001004 !((fileptr->lineno > mark_beginbuf->lineno
Chris Allegretta598106e2002-01-19 01:59:37 +00001005 && fileptr->lineno > current->lineno)
1006 || (fileptr->lineno < mark_beginbuf->lineno
1007 && fileptr->lineno < current->lineno))) {
Chris Allegretta88520c92001-05-05 17:45:54 +00001008 /* If we get here we are on a line that is at least
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001009 * partially selected. The lineno checks above determined
1010 * that */
1011 if (fileptr != mark_beginbuf && fileptr != current) {
1012 /* We are on a completely marked line, paint it all
1013 * inverse */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001014#ifdef ENABLE_COLOR
1015 color_on(edit, COLOR_MARKER);
1016#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001017 wattron(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001018#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001019
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001020 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001021
1022#ifdef ENABLE_COLOR
1023 color_off(edit, COLOR_MARKER);
1024#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001025 wattroff(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001026#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001027
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001028 } else if (fileptr == mark_beginbuf && fileptr == current) {
1029 /* Special case, we're still on the same line we started
1030 * marking -- so we call our helper function */
1031 if (virt_cur_x < virt_mark_beginx) {
1032 /* To the right of us is marked */
1033 add_marked_sameline(virt_cur_x, virt_mark_beginx,
1034 fileptr, yval, virt_cur_x, this_page);
1035 } else {
1036 /* To the left of us is marked */
1037 add_marked_sameline(virt_mark_beginx, virt_cur_x,
1038 fileptr, yval, virt_cur_x, this_page);
1039 }
1040 } else if (fileptr == mark_beginbuf) {
1041 /*
Chris Allegretta88520c92001-05-05 17:45:54 +00001042 * We're updating the line that was first marked,
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001043 * but we're not currently on it. So we want to
Robert Siemborskia0238ed2001-03-31 21:46:43 +00001044 * figure out which half to invert based on our
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001045 * relative line numbers.
1046 *
Chris Allegretta88520c92001-05-05 17:45:54 +00001047 * I.e. if we're above the "beginbuf" line, we want to
1048 * mark the left side. Otherwise, we're below, so we
1049 * mark the right.
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001050 */
1051 int target;
1052
Chris Allegretta8ce24132001-04-30 11:28:46 +00001053 if (mark_beginbuf->lineno > current->lineno) {
1054#ifdef ENABLE_COLOR
1055 color_on(edit, COLOR_MARKER);
1056#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001057 wattron(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001058#endif /* ENABLE_COLOR */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001059
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001060 target =
Chris Allegretta598106e2002-01-19 01:59:37 +00001061 (virt_mark_beginx <
1062 COLS - 1) ? virt_mark_beginx : COLS - 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001063
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001064 mvwaddnstr(edit, yval, 0, fileptr->data, target);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001065
1066#ifdef ENABLE_COLOR
1067 color_off(edit, COLOR_MARKER);
1068#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001069 wattroff(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001070#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001071
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001072
Chris Allegretta8ce24132001-04-30 11:28:46 +00001073 }
Robert Siemborskid8510b22000-06-06 23:04:06 +00001074
Chris Allegretta8ce24132001-04-30 11:28:46 +00001075 if (mark_beginbuf->lineno < current->lineno) {
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001076#ifdef ENABLE_COLOR
1077 color_on(edit, COLOR_MARKER);
1078#else
1079 wattron(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001080#endif /* ENABLE_COLOR */
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001081
1082 target = (COLS - 1) - virt_mark_beginx;
1083
1084 if (target < 0)
1085 target = 0;
1086
1087 mvwaddnstr(edit, yval, virt_mark_beginx,
Chris Allegretta598106e2002-01-19 01:59:37 +00001088 &fileptr->data[virt_mark_beginx], target);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001089
1090#ifdef ENABLE_COLOR
1091 color_off(edit, COLOR_MARKER);
1092#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001093 wattroff(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001094#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001095
1096 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001097
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001098 } else if (fileptr == current) {
Chris Allegretta88520c92001-05-05 17:45:54 +00001099 /* We're on the cursor's line, but it's not the first
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001100 * one we marked. Similar to the previous logic. */
1101 int this_page_start = get_page_start_virtual(this_page),
1102 this_page_end = get_page_end_virtual(this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001103
Chris Allegretta8ce24132001-04-30 11:28:46 +00001104 if (mark_beginbuf->lineno < current->lineno) {
1105
1106#ifdef ENABLE_COLOR
1107 color_on(edit, COLOR_MARKER);
1108#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001109 wattron(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001110#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001111
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001112 if (virt_cur_x > COLS - 2) {
1113 mvwaddnstr(edit, yval, 0,
Chris Allegretta598106e2002-01-19 01:59:37 +00001114 &fileptr->data[this_page_start],
1115 virt_cur_x - this_page_start);
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001116 } else
1117 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
1118
1119#ifdef ENABLE_COLOR
1120 color_off(edit, COLOR_MARKER);
1121#else
1122 wattroff(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001123#endif /* ENABLE_COLOR */
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001124
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001125 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001126
Chris Allegretta8ce24132001-04-30 11:28:46 +00001127 if (mark_beginbuf->lineno > current->lineno) {
1128
1129#ifdef ENABLE_COLOR
1130 color_on(edit, COLOR_MARKER);
1131#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001132 wattron(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001133#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001134
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001135 if (virt_cur_x > COLS - 2)
1136 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
Chris Allegretta598106e2002-01-19 01:59:37 +00001137 &fileptr->data[virt_cur_x],
1138 this_page_end - virt_cur_x);
Chris Allegretta2fa11b82001-12-02 04:55:44 +00001139 else
1140 mvwaddnstr(edit, yval, virt_cur_x,
Chris Allegretta598106e2002-01-19 01:59:37 +00001141 &fileptr->data[virt_cur_x],
1142 COLS - virt_cur_x);
Robert Siemborskid8510b22000-06-06 23:04:06 +00001143
Chris Allegretta8ce24132001-04-30 11:28:46 +00001144#ifdef ENABLE_COLOR
1145 color_off(edit, COLOR_MARKER);
1146#else
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001147 wattroff(edit, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001148#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001149
1150 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001151 }
Chris Allegretta08893e02001-11-29 02:42:27 +00001152 }
Chris Allegretta08893e02001-11-29 02:42:27 +00001153#endif
1154
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001155}
1156
1157/*
Robert Siemborski9d584552000-07-08 00:41:29 +00001158 * Just update one line in the edit buffer. Basically a wrapper for
1159 * edit_add
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001160 *
Chris Allegretta88520c92001-05-05 17:45:54 +00001161 * index gives us a place in the string to update starting from.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001162 * Likely args are current_x or 0.
1163 */
1164void update_line(filestruct * fileptr, int index)
1165{
1166 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +00001167 int line = 0, col = 0;
1168 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
1169 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001170 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001171
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001172 if (!fileptr)
1173 return;
Robert Siemborski53154a72000-06-18 00:11:03 +00001174
Robert Siemborski53875912000-06-16 04:25:30 +00001175 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001176 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
1177 filetmp = filetmp->next)
1178 line++;
1179
1180 mvwaddstr(edit, line, 0, hblank);
1181
Chris Allegretta88520c92001-05-05 17:45:54 +00001182 /* Next, convert all the tabs to spaces, so everything else is easy */
Robert Siemborski53875912000-06-16 04:25:30 +00001183 index = xpt(fileptr, index);
1184
1185 realdata = fileptr->data;
1186 len = strlen(realdata);
Chris Allegretta88b09152001-05-17 11:35:43 +00001187 fileptr->data = charalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +00001188
1189 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001190 for (i = 0; i < len; i++) {
1191 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +00001192 do {
1193 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001194 if (i < current_x)
1195 virt_cur_x++;
1196 if (i < mark_beginx)
1197 virt_mark_beginx++;
Chris Allegretta6d690a32000-08-03 22:51:21 +00001198 } while (pos % tabsize);
Robert Siemborski53875912000-06-16 04:25:30 +00001199 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001200 if (i < current_x)
1201 virt_cur_x--;
1202 if (i < mark_beginx)
1203 virt_mark_beginx--;
Chris Allegretta2598c662002-03-28 01:59:34 +00001204 } else if (realdata[i] == 127) {
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +00001205 /* Treat control characters as ^symbol (ASCII 1 - 31 omitting
1206 10, 127) */
Chris Allegretta2598c662002-03-28 01:59:34 +00001207 fileptr->data[pos++] = '^';
1208 fileptr->data[pos++] = '?';
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +00001209 if (i < current_x)
1210 virt_cur_x++;
1211 if (i < mark_beginx)
1212 virt_mark_beginx++;
1213 } else if (realdata[i] >= 1 && realdata[i] <= 31 && realdata[i] != 10) {
Chris Allegretta6306a112000-09-02 07:55:41 +00001214 fileptr->data[pos++] = '^';
1215 fileptr->data[pos++] = realdata[i] + 64;
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +00001216 if (i < current_x)
1217 virt_cur_x++;
1218 if (i < mark_beginx)
1219 virt_mark_beginx++;
1220 } else if (realdata[i] == 10) {
1221 /* Treat newlines (ASCII 10's) embedded in a line as encoded
1222 nulls (ASCII 0's); the line in question should be run
1223 through unsunder() before reaching here */
1224 fileptr->data[pos++] = '^';
1225 fileptr->data[pos++] = '@';
1226 if (i < current_x)
1227 virt_cur_x++;
1228 if (i < mark_beginx)
1229 virt_mark_beginx++;
Robert Siemborski53875912000-06-16 04:25:30 +00001230 } else {
1231 fileptr->data[pos++] = realdata[i];
1232 }
1233 }
1234
1235 fileptr->data[pos] = '\0';
1236
Chris Allegretta4dc03d52002-05-11 03:04:44 +00001237 /* Now, paint the line */
Robert Siemborski53875912000-06-16 04:25:30 +00001238 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +00001239 /* This handles when the current line is beyond COLS */
Chris Allegretta88520c92001-05-05 17:45:54 +00001240 /* It requires figuring out what page we're on */
Robert Siemborskia9addc72000-06-17 06:06:35 +00001241 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +00001242 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001243
Robert Siemborskia9addc72000-06-17 06:06:35 +00001244 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001245 mvwaddch(edit, line, 0, '$');
1246
Chris Allegrettafb62f732000-12-05 11:36:41 +00001247 if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001248 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +00001249 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +00001250 /* It's not the current line means that it's at x=0 and page=1 */
1251 /* If it is the current line, then we're in the same boat */
1252 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001253
Robert Siemborski53875912000-06-16 04:25:30 +00001254 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001255 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +00001256 }
Robert Siemborski53875912000-06-16 04:25:30 +00001257
1258 /* Clean up our mess */
1259 tmp = fileptr->data;
1260 fileptr->data = realdata;
1261 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001262}
1263
1264void center_cursor(void)
1265{
1266 current_y = editwinrows / 2;
1267 wmove(edit, current_y, current_x);
1268}
1269
1270/* Refresh the screen without changing the position of lines */
1271void edit_refresh(void)
1272{
Chris Allegrettaed022162000-08-03 16:54:11 +00001273 static int noloop = 0;
Chris Allegretta3d0739c2002-01-07 14:41:32 +00001274 int nlines = 0, i = 0, currentcheck = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001275 filestruct *temp, *hold = current;
1276
1277 if (current == NULL)
1278 return;
1279
1280 temp = edittop;
1281
Chris Allegretta3d0739c2002-01-07 14:41:32 +00001282 while (nlines <= editwinrows - 1 && nlines <= totlines && temp != NULL) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001283 hold = temp;
1284 update_line(temp, current_x);
Chris Allegretta95b0b522000-07-28 02:58:06 +00001285 if (temp == current)
1286 currentcheck = 1;
1287
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001288 temp = temp->next;
Chris Allegretta3d0739c2002-01-07 14:41:32 +00001289 nlines++;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001290 }
Chris Allegrettaed022162000-08-03 16:54:11 +00001291 /* If noloop == 1, then we already did an edit_update without finishing
1292 this function. So we don't run edit_update again */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001293 if (!currentcheck && !noloop) { /* Then current has run off the screen... */
Chris Allegrettada721be2000-07-31 01:26:42 +00001294 edit_update(current, CENTER);
Chris Allegrettaed022162000-08-03 16:54:11 +00001295 noloop = 1;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001296 } else if (noloop)
Chris Allegrettaed022162000-08-03 16:54:11 +00001297 noloop = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001298
Chris Allegretta3d0739c2002-01-07 14:41:32 +00001299 if (nlines <= editwinrows - 1)
1300 while (nlines <= editwinrows - 1) {
1301 mvwaddstr(edit, nlines, i, hblank);
1302 nlines++;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001303 }
1304 if (temp == NULL)
1305 editbot = hold;
1306 else
1307 editbot = temp;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001308
1309 /* What the hell are we expecting to update the screen if this isn't
Chris Allegretta598106e2002-01-19 01:59:37 +00001310 here? luck?? */
Chris Allegrettab3655b42001-10-22 03:15:31 +00001311 wrefresh(edit);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001312}
1313
1314/*
Chris Allegretta88520c92001-05-05 17:45:54 +00001315 * Same as above, but touch the window first, so everything is redrawn.
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001316 */
1317void edit_refresh_clearok(void)
1318{
1319 clearok(edit, TRUE);
1320 edit_refresh();
1321 clearok(edit, FALSE);
1322}
1323
1324/*
Chris Allegretta88520c92001-05-05 17:45:54 +00001325 * Nice generic routine to update the edit buffer, given a pointer to the
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001326 * file struct =)
1327 */
Chris Allegretta2d7893d2001-07-11 02:08:33 +00001328void edit_update(filestruct * fileptr, int topmidbotnone)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001329{
Robert Siemborski29e9a762000-07-05 03:16:04 +00001330 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001331 filestruct *temp;
1332
1333 if (fileptr == NULL)
1334 return;
1335
1336 temp = fileptr;
Chris Allegretta2d7893d2001-07-11 02:08:33 +00001337 if (topmidbotnone == TOP);
1338 else if (topmidbotnone == NONE)
1339 for (i = 0; i <= current_y - 1 && temp->prev != NULL; i++)
1340 temp = temp->prev;
1341 else if (topmidbotnone == BOTTOM)
Chris Allegretta234a34d2000-07-29 04:33:38 +00001342 for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++)
1343 temp = temp->prev;
1344 else
1345 for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++)
1346 temp = temp->prev;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001347
Robert Siemborski29e9a762000-07-05 03:16:04 +00001348 edittop = temp;
1349 fix_editbot();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001350
1351 edit_refresh();
1352}
1353
Chris Allegretta88520c92001-05-05 17:45:54 +00001354/* This function updates current, based on where current_y is; reset_cursor
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001355 does the opposite */
1356void update_cursor(void)
1357{
1358 int i = 0;
1359
1360#ifdef DEBUG
1361 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
1362 current_x);
1363#endif
1364
1365 current = edittop;
1366 while (i <= current_y - 1 && current->next != NULL) {
1367 current = current->next;
1368 i++;
1369 }
1370
1371#ifdef DEBUG
1372 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
1373#endif
1374
1375}
1376
1377/*
1378 * Ask a question on the statusbar. Answer will be stored in answer
1379 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
Chris Allegretta88520c92001-05-05 17:45:54 +00001380 * otherwise, the valid shortcut key caught. Def is any editable text we
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001381 * want to put up by default.
Chris Allegretta7da4e9f2000-11-06 02:57:22 +00001382 *
1383 * New arg tabs tells whether or not to allow tab completion.
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001384 */
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001385int statusq(int tabs, shortcut *s, char *def, char *msg, ...)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001386{
1387 va_list ap;
1388 char foo[133];
Chris Allegretta9caa1932002-02-15 20:08:05 +00001389 int ret;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001390
Chris Allegretta2084acc2001-11-29 03:43:08 +00001391#ifndef DISABLE_TABCOMP
Chris Allegrettaa16e4e92002-01-05 18:59:54 +00001392 int list = 0;
Chris Allegretta2084acc2001-11-29 03:43:08 +00001393#endif
1394
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001395 bottombars(s);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001396
1397 va_start(ap, msg);
1398 vsnprintf(foo, 132, msg, ap);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001399 va_end(ap);
Chris Allegrettaa4d21622000-07-08 23:57:03 +00001400 strncat(foo, ": ", 132);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001401
Chris Allegretta8ce24132001-04-30 11:28:46 +00001402#ifdef ENABLE_COLOR
1403 color_on(bottomwin, COLOR_STATUSBAR);
1404#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001405 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001406#endif
1407
1408
Chris Allegretta2084acc2001-11-29 03:43:08 +00001409#ifndef DISABLE_TABCOMP
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001410 ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), list);
Chris Allegretta2084acc2001-11-29 03:43:08 +00001411#else
1412 /* if we've disabled tab completion, the value of list won't be
1413 used at all, so it's safe to use 0 (NULL) as a placeholder */
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001414 ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), 0);
Chris Allegretta2084acc2001-11-29 03:43:08 +00001415#endif
Chris Allegretta8ce24132001-04-30 11:28:46 +00001416
1417#ifdef ENABLE_COLOR
1418 color_off(bottomwin, COLOR_STATUSBAR);
1419#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001420 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001421#endif
1422
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001423
1424 switch (ret) {
1425
1426 case NANO_FIRSTLINE_KEY:
1427 do_first_line();
1428 break;
1429 case NANO_LASTLINE_KEY:
1430 do_last_line();
1431 break;
1432 case NANO_CANCEL_KEY:
Chris Allegretta2084acc2001-11-29 03:43:08 +00001433#ifndef DISABLE_TABCOMP
1434 /* if we've done tab completion, there might be a list of
1435 filename matches on the edit window at this point; make sure
1436 they're cleared off */
1437 if (list)
1438 edit_refresh();
1439#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001440 return -1;
1441 default:
Chris Allegretta5b1faac2000-11-16 19:55:30 +00001442 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001443 }
1444
1445#ifdef DEBUG
1446 fprintf(stderr, _("I got \"%s\"\n"), answer);
1447#endif
1448
1449 return ret;
1450}
1451
1452/*
1453 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
1454 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
1455 */
1456int do_yesno(int all, int leavecursor, char *msg, ...)
1457{
1458 va_list ap;
1459 char foo[133];
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001460 int kbinput, ok = -1, i;
1461 char *yesstr; /* String of yes characters accepted */
1462 char *nostr; /* Same for no */
1463 char *allstr; /* And all, surprise! */
Chris Allegretta84de5522001-04-12 14:51:48 +00001464#ifndef DISABLE_MOUSE
Chris Allegretta235ab192001-04-12 13:24:40 +00001465#ifdef NCURSES_MOUSE_VERSION
1466 MEVENT mevent;
1467#endif
1468#endif
1469
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001470
1471 /* Yes, no and all are strings of any length. Each string consists of
Chris Allegretta598106e2002-01-19 01:59:37 +00001472 all characters accepted as a valid character for that value.
1473 The first value will be the one displayed in the shortcuts. */
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001474 yesstr = _("Yy");
1475 nostr = _("Nn");
1476 allstr = _("Aa");
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001477
1478 /* Write the bottom of the screen */
1479 clear_bottomwin();
Chris Allegretta8ce24132001-04-30 11:28:46 +00001480
1481#ifdef ENABLE_COLOR
1482 color_on(bottomwin, COLOR_BOTTOMBARS);
1483#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001484
Jordi Mallach0b0fc492000-06-23 01:00:13 +00001485 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001486 if (!ISSET(NO_HELP)) {
Chris Allegretta6232d662002-05-12 19:52:15 +00001487 char shortstr[3]; /* Temp string for Y, N, A */
1488
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001489 wmove(bottomwin, 1, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001490
Chris Allegretta6232d662002-05-12 19:52:15 +00001491 sprintf(shortstr, " %c", yesstr[0]);
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001492 onekey(shortstr, _("Yes"), 16);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001493
1494 if (all) {
Chris Allegretta6232d662002-05-12 19:52:15 +00001495 shortstr[1] = allstr[0];
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001496 onekey(shortstr, _("All"), 16);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001497 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001498 wmove(bottomwin, 2, 0);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001499
Chris Allegretta6232d662002-05-12 19:52:15 +00001500 shortstr[1] = nostr[0];
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001501 onekey(shortstr, _("No"), 16);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001502
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001503 onekey("^C", _("Cancel"), 16);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001504 }
1505 va_start(ap, msg);
1506 vsnprintf(foo, 132, msg, ap);
1507 va_end(ap);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001508
1509#ifdef ENABLE_COLOR
1510 color_off(bottomwin, COLOR_BOTTOMBARS);
1511 color_on(bottomwin, COLOR_STATUSBAR);
1512#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001513 wattron(bottomwin, A_REVERSE);
Chris Allegretta598106e2002-01-19 01:59:37 +00001514#endif /* ENABLE_COLOR */
Chris Allegretta8ce24132001-04-30 11:28:46 +00001515
1516 blank_statusbar();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001517 mvwaddstr(bottomwin, 0, 0, foo);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001518
1519#ifdef ENABLE_COLOR
1520 color_off(bottomwin, COLOR_STATUSBAR);
1521#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001522 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001523#endif
1524
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001525 wrefresh(bottomwin);
1526
1527 if (leavecursor == 1)
1528 reset_cursor();
1529
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001530 while (ok == -1) {
1531 kbinput = wgetch(edit);
1532
1533 switch (kbinput) {
Chris Allegretta84de5522001-04-12 14:51:48 +00001534#ifndef DISABLE_MOUSE
Chris Allegretta235ab192001-04-12 13:24:40 +00001535#ifdef NCURSES_MOUSE_VERSION
1536 case KEY_MOUSE:
1537
1538 /* Look ma! We get to duplicate lots of code from do_mouse!! */
1539 if (getmouse(&mevent) == ERR)
1540 break;
1541 if (!wenclose(bottomwin, mevent.y, mevent.x) || ISSET(NO_HELP))
1542 break;
1543 mevent.y -= editwinrows + 3;
1544 if (mevent.y < 0)
1545 break;
1546 else {
1547
1548 /* Rather than a bunch of if statements, set up a matrix
1549 of possible return keystrokes based on the x and y values */
1550 if (all) {
1551 char yesnosquare[2][2] = {
Chris Allegretta598106e2002-01-19 01:59:37 +00001552 {yesstr[0], allstr[0]},
1553 {nostr[0], NANO_CONTROL_C}
1554 };
Chris Allegretta235ab192001-04-12 13:24:40 +00001555
Chris Allegretta598106e2002-01-19 01:59:37 +00001556 ungetch(yesnosquare[mevent.y][mevent.x / (COLS / 6)]);
Chris Allegretta235ab192001-04-12 13:24:40 +00001557 } else {
1558 char yesnosquare[2][2] = {
1559 {yesstr[0], '\0'},
Chris Allegretta598106e2002-01-19 01:59:37 +00001560 {nostr[0], NANO_CONTROL_C}
1561 };
Chris Allegretta235ab192001-04-12 13:24:40 +00001562
Chris Allegretta598106e2002-01-19 01:59:37 +00001563 ungetch(yesnosquare[mevent.y][mevent.x / (COLS / 6)]);
Chris Allegretta235ab192001-04-12 13:24:40 +00001564 }
1565 }
1566 break;
1567#endif
1568#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001569 case NANO_CONTROL_C:
1570 ok = -2;
1571 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001572 default:
1573
Chris Allegretta88520c92001-05-05 17:45:54 +00001574 /* Look for the kbinput in the yes, no and (optimally) all str */
Chris Allegretta598106e2002-01-19 01:59:37 +00001575 for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001576 if (yesstr[i] != 0) {
Chris Allegrettaea620fe2001-02-18 05:39:41 +00001577 ok = 1;
Chris Allegretta598106e2002-01-19 01:59:37 +00001578 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001579 }
1580
Chris Allegretta598106e2002-01-19 01:59:37 +00001581 for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001582 if (nostr[i] != 0) {
1583 ok = 0;
Chris Allegretta598106e2002-01-19 01:59:37 +00001584 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001585 }
1586
1587 if (all) {
Chris Allegretta598106e2002-01-19 01:59:37 +00001588 for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++);
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001589 if (allstr[i] != 0) {
1590 ok = 2;
Chris Allegretta598106e2002-01-19 01:59:37 +00001591 break;
Chris Allegretta4ce8e3b2001-02-16 01:49:31 +00001592 }
1593 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001594 }
1595 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001596
1597 /* Then blank the screen */
1598 blank_statusbar_refresh();
1599
1600 if (ok == -2)
1601 return -1;
1602 else
1603 return ok;
1604}
1605
1606void statusbar(char *msg, ...)
1607{
1608 va_list ap;
1609 char foo[133];
1610 int start_x = 0;
1611
1612 va_start(ap, msg);
1613 vsnprintf(foo, 132, msg, ap);
1614 va_end(ap);
1615
Chris Allegretta17dcb722001-01-20 21:40:07 +00001616 start_x = COLS / 2 - strlen(foo) / 2 - 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001617
1618 /* Blank out line */
1619 blank_statusbar();
1620
1621 wmove(bottomwin, 0, start_x);
1622
Chris Allegretta8ce24132001-04-30 11:28:46 +00001623#ifdef ENABLE_COLOR
1624 color_on(bottomwin, COLOR_STATUSBAR);
1625#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001626 wattron(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001627#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001628
1629 waddstr(bottomwin, "[ ");
1630 waddstr(bottomwin, foo);
1631 waddstr(bottomwin, " ]");
Chris Allegretta8ce24132001-04-30 11:28:46 +00001632
1633#ifdef ENABLE_COLOR
1634 color_off(bottomwin, COLOR_STATUSBAR);
1635#else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001636 wattroff(bottomwin, A_REVERSE);
Chris Allegretta8ce24132001-04-30 11:28:46 +00001637#endif
1638
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001639 wrefresh(bottomwin);
1640
1641 if (ISSET(CONSTUPDATE))
1642 statblank = 1;
1643 else
1644 statblank = 25;
1645}
1646
1647void display_main_list(void)
1648{
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001649 bottombars(main_list);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001650}
1651
1652int total_refresh(void)
1653{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001654 clearok(edit, TRUE);
1655 clearok(topwin, TRUE);
1656 clearok(bottomwin, TRUE);
1657 wnoutrefresh(edit);
1658 wnoutrefresh(topwin);
1659 wnoutrefresh(bottomwin);
1660 doupdate();
1661 clearok(edit, FALSE);
1662 clearok(topwin, FALSE);
1663 clearok(bottomwin, FALSE);
Chris Allegrettaf1d33d32000-08-19 03:53:39 +00001664 edit_refresh();
Chris Allegrettaf4b96012001-01-03 07:11:47 +00001665 titlebar(NULL);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001666 return 1;
1667}
1668
1669void previous_line(void)
1670{
1671 if (current_y > 0)
1672 current_y--;
1673}
1674
Chris Allegretta2084acc2001-11-29 03:43:08 +00001675int do_cursorpos(int constant)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001676{
1677 filestruct *fileptr;
Chris Allegrettaf27c6972002-02-12 01:57:24 +00001678 float linepct = 0.0, bytepct = 0.0, colpct = 0.0;
Chris Allegretta14b3ca92002-01-25 21:59:02 +00001679 long i = 0, j = 0;
Chris Allegretta2084acc2001-11-29 03:43:08 +00001680 static long old_i = -1, old_totsize = -1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001681
1682 if (current == NULL || fileage == NULL)
1683 return 0;
1684
Chris Allegretta2084acc2001-11-29 03:43:08 +00001685 if (old_i == -1)
1686 old_i = i;
1687
1688 if (old_totsize == -1)
1689 old_totsize = totsize;
1690
Chris Allegrettaf3a07b22002-03-29 15:15:38 +00001691 colpct = 100 * (xplustabs() + 1) / (xpt(current, strlen(current->data)) + 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001692
Chris Allegrettaf27c6972002-02-12 01:57:24 +00001693 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1694 fileptr = fileptr->next)
1695 i += strlen(fileptr->data) + 1;
Chris Allegretta14b3ca92002-01-25 21:59:02 +00001696
Chris Allegrettaf27c6972002-02-12 01:57:24 +00001697 if (fileptr == NULL)
1698 return -1;
Chris Allegretta14b3ca92002-01-25 21:59:02 +00001699
Chris Allegrettaf27c6972002-02-12 01:57:24 +00001700 i += current_x;
Chris Allegretta14b3ca92002-01-25 21:59:02 +00001701
Chris Allegrettaf27c6972002-02-12 01:57:24 +00001702 j = totsize;
Chris Allegretta14b3ca92002-01-25 21:59:02 +00001703
Chris Allegrettaf27c6972002-02-12 01:57:24 +00001704 if (totsize > 0)
1705 bytepct = 100 * i / totsize;
Chris Allegretta14b3ca92002-01-25 21:59:02 +00001706
1707 if (totlines > 0)
1708 linepct = 100 * current->lineno / totlines;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001709
1710#ifdef DEBUG
1711 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1712 linepct, bytepct);
1713#endif
1714
Chris Allegretta2084acc2001-11-29 03:43:08 +00001715 /* if constant is zero, display the position on the statusbar
1716 unconditionally; otherwise, only display the position when the
1717 character values have changed */
1718 if (!constant || (old_i != i || old_totsize != totsize)) {
Chris Allegretta598106e2002-01-19 01:59:37 +00001719 statusbar(_
Chris Allegrettaf27c6972002-02-12 01:57:24 +00001720 ("line %d/%d (%.0f%%), col %ld/%ld (%.0f%%), char %ld/%ld (%.0f%%)"),
Chris Allegrettaf3a07b22002-03-29 15:15:38 +00001721 current->lineno, totlines, linepct, xplustabs() + 1,
1722 xpt(current, strlen(current->data)) + 1, colpct, i, j, bytepct);
Chris Allegretta2084acc2001-11-29 03:43:08 +00001723 }
1724
1725 old_i = i;
1726 old_totsize = totsize;
1727
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001728 reset_cursor();
1729 return 1;
1730}
1731
Chris Allegretta2084acc2001-11-29 03:43:08 +00001732int do_cursorpos_void(void)
1733{
1734 return do_cursorpos(0);
1735}
1736
David Lawrence Ramseyc5967552002-06-21 03:20:06 +00001737/* Our shortcut-list-compliant help function, which is
1738 * better than nothing, and dynamic! */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001739int do_help(void)
1740{
Rocco Corsiaf5c3022001-01-12 07:51:05 +00001741#ifndef DISABLE_HELP
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001742 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001743 int no_help_flag = 0;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001744 shortcut *oldshortcut;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001745
1746 blank_edit();
1747 curs_set(0);
Chris Allegrettab3655b42001-10-22 03:15:31 +00001748 wattroff(bottomwin, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001749 blank_statusbar();
1750
David Lawrence Ramseyc5967552002-06-21 03:20:06 +00001751 /* set help_text as the string to display */
Chris Allegrettab3655b42001-10-22 03:15:31 +00001752 help_init();
David Lawrence Ramseyc5967552002-06-21 03:20:06 +00001753 assert(help_text != NULL);
Chris Allegrettab3655b42001-10-22 03:15:31 +00001754
1755 oldshortcut = currshortcut;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001756
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001757 currshortcut = help_list;
Chris Allegretta6fe61492001-05-21 12:56:25 +00001758
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001759 kp = keypad_on(edit, 1);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001760 kp2 = keypad_on(bottomwin, 1);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001761
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001762 if (ISSET(NO_HELP)) {
1763
Chris Allegretta88520c92001-05-05 17:45:54 +00001764 /* Well, if we're going to do this, we should at least
Chris Allegretta70444892001-01-07 23:02:02 +00001765 do it the right way */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001766 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001767 UNSET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001768 window_init();
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001769 bottombars(help_list);
Chris Allegretta70444892001-01-07 23:02:02 +00001770
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001771 } else
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001772 bottombars(help_list);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001773
1774 do {
David Lawrence Ramseyc5967552002-06-21 03:20:06 +00001775 const char *ptr = help_text;
1776
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001777 switch (kbinput) {
Chris Allegretta84de5522001-04-12 14:51:48 +00001778#ifndef DISABLE_MOUSE
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001779#ifdef NCURSES_MOUSE_VERSION
Chris Allegretta598106e2002-01-19 01:59:37 +00001780 case KEY_MOUSE:
1781 do_mouse();
1782 break;
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001783#endif
1784#endif
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +00001785 case 27:
1786 kbinput = wgetch(edit);
1787 switch(kbinput) {
1788 case '[':
1789 kbinput = wgetch(edit);
1790 switch(kbinput) {
1791 case '5': /* Alt-[-5 = Page Up */
1792 wgetch(edit);
1793 goto do_pageupkey;
1794 break;
1795 case 'V': /* Alt-[-V = Page Up in Hurd Console */
1796 case 'I': /* Alt-[-I = Page Up - FreeBSD Console */
1797 goto do_pageupkey;
1798 break;
1799 case '6': /* Alt-[-6 = Page Down */
1800 wgetch(edit);
1801 goto do_pagedownkey;
1802 break;
1803 case 'U': /* Alt-[-U = Page Down in Hurd Console */
1804 case 'G': /* Alt-[-G = Page Down - FreeBSD Console */
1805 goto do_pagedownkey;
1806 break;
1807 }
1808 break;
1809 }
1810 break;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001811 case NANO_NEXTPAGE_KEY:
1812 case NANO_NEXTPAGE_FKEY:
1813 case KEY_NPAGE:
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +00001814 do_pagedownkey:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001815 if (!no_more) {
1816 blank_edit();
1817 page++;
1818 }
1819 break;
1820 case NANO_PREVPAGE_KEY:
1821 case NANO_PREVPAGE_FKEY:
1822 case KEY_PPAGE:
David Lawrence Ramseyf21cd102002-06-13 00:40:19 +00001823 do_pageupkey:
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001824 if (page > 1) {
1825 no_more = 0;
1826 blank_edit();
1827 page--;
1828 }
1829 break;
1830 }
1831
Chris Allegretta88520c92001-05-05 17:45:54 +00001832 /* Calculate where in the text we should be, based on the page */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001833 for (i = 1; i < page; i++) {
1834 row = 0;
1835 j = 0;
Chris Allegretta44e73df2000-09-07 03:37:38 +00001836
1837 while (row < editwinrows - 2 && *ptr != '\0') {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001838 if (*ptr == '\n' || j == COLS - 5) {
1839 j = 0;
1840 row++;
1841 }
1842 ptr++;
1843 j++;
1844 }
1845 }
1846
1847 i = 0;
1848 j = 0;
1849 while (i < editwinrows && *ptr != '\0') {
David Lawrence Ramseyc5967552002-06-21 03:20:06 +00001850 const char *end = ptr;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001851 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1852 end++;
1853 j++;
1854 }
1855 if (j == COLS - 5) {
1856
Chris Allegretta88520c92001-05-05 17:45:54 +00001857 /* Don't print half a word if we've run out of space */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001858 while (*end != ' ' && *end != '\0') {
1859 end--;
1860 j--;
1861 }
1862 }
1863 mvwaddnstr(edit, i, 0, ptr, j);
1864 j = 0;
1865 i++;
1866 if (*end == '\n')
1867 end++;
1868 ptr = end;
1869 }
1870 if (*ptr == '\0') {
1871 no_more = 1;
1872 continue;
1873 }
Chris Allegretta598106e2002-01-19 01:59:37 +00001874 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
1875 kbinput != NANO_EXIT_FKEY);
Chris Allegrettad1627cf2000-12-18 05:03:16 +00001876
Chris Allegrettab3655b42001-10-22 03:15:31 +00001877 currshortcut = oldshortcut;
Chris Allegrettab3655b42001-10-22 03:15:31 +00001878
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001879 if (no_help_flag) {
Chris Allegretta70444892001-01-07 23:02:02 +00001880 blank_bottombars();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001881 wrefresh(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001882 SET(NO_HELP);
Chris Allegretta70444892001-01-07 23:02:02 +00001883 window_init();
Chris Allegretta598106e2002-01-19 01:59:37 +00001884 } else
Chris Allegrettaa8c22572002-02-15 19:17:02 +00001885 bottombars(currshortcut);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001886
1887 curs_set(1);
1888 edit_refresh();
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001889 kp = keypad_on(edit, kp);
Chris Allegretta6b58acd2001-04-12 03:01:53 +00001890 kp2 = keypad_on(bottomwin, kp2);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00001891
Chris Allegretta3bc8c722000-12-10 17:03:25 +00001892#elif defined(DISABLE_HELP)
1893 nano_disabled_msg();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001894#endif
1895
David Lawrence Ramseyc5967552002-06-21 03:20:06 +00001896 /* The help_init() at the beginning allocated help_text, which has
1897 now been written to screen. */
1898 free(help_text);
1899 help_text = NULL;
1900
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001901 return 1;
1902}
1903
1904/* Dump the current file structure to stderr */
1905void dump_buffer(filestruct * inptr)
1906{
1907#ifdef DEBUG
1908 filestruct *fileptr;
1909
1910 if (inptr == fileage)
1911 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1912 else if (inptr == cutbuffer)
1913 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1914 else
1915 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1916
1917 fileptr = inptr;
1918 while (fileptr != NULL) {
Chris Allegrettab3655b42001-10-22 03:15:31 +00001919 fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001920 fflush(stderr);
1921 fileptr = fileptr->next;
1922 }
1923#endif /* DEBUG */
1924}
1925
1926void dump_buffer_reverse(filestruct * inptr)
1927{
1928#ifdef DEBUG
1929 filestruct *fileptr;
1930
1931 fileptr = filebot;
1932 while (fileptr != NULL) {
Chris Allegrettab3655b42001-10-22 03:15:31 +00001933 fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001934 fflush(stderr);
1935 fileptr = fileptr->prev;
1936 }
1937#endif /* DEBUG */
1938}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001939
Chris Allegretta88520c92001-05-05 17:45:54 +00001940/* Fix editbot, based on the assumption that edittop is correct */
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001941void fix_editbot(void)
1942{
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001943 int i;
1944 editbot = edittop;
Chris Allegrettabd9e7c32000-10-26 01:44:42 +00001945 for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1946 && (editbot != filebot); i++, editbot = editbot->next);
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001947}
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001948
Chris Allegrettafb62f732000-12-05 11:36:41 +00001949/* highlight the current word being replaced or spell checked */
1950void do_replace_highlight(int highlight_flag, char *word)
1951{
1952 char *highlight_word = NULL;
1953 int x, y;
1954
Chris Allegretta598106e2002-01-19 01:59:37 +00001955 highlight_word =
1956 mallocstrcpy(highlight_word, &current->data[current_x]);
Chris Allegrettafb62f732000-12-05 11:36:41 +00001957 highlight_word[strlen(word)] = '\0';
1958
Chris Allegretta88520c92001-05-05 17:45:54 +00001959 /* adjust output when word extends beyond screen */
Chris Allegrettafb62f732000-12-05 11:36:41 +00001960
1961 x = xplustabs();
1962 y = get_page_end_virtual(get_page_from_virtual(x)) + 1;
1963
1964 if ((COLS - (y - x) + strlen(word)) > COLS) {
1965 highlight_word[y - x - 1] = '$';
1966 highlight_word[y - x] = '\0';
1967 }
1968
1969 /* OK display the output */
1970
1971 reset_cursor();
Chris Allegretta598106e2002-01-19 01:59:37 +00001972
Chris Allegrettafb62f732000-12-05 11:36:41 +00001973 if (highlight_flag)
1974 wattron(edit, A_REVERSE);
1975
1976 waddstr(edit, highlight_word);
1977
1978 if (highlight_flag)
1979 wattroff(edit, A_REVERSE);
1980
1981 free(highlight_word);
1982}
1983
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001984#ifdef NANO_EXTRA
Chris Allegrettadce44ab2002-03-16 01:03:41 +00001985#define CREDIT_LEN 52
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001986void do_credits(void)
1987{
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00001988 int i, j = 0, k, place = 0, start_x;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001989 char *what;
1990
1991 char *nanotext = _("The nano text editor");
1992 char *version = _("version ");
1993 char *brought = _("Brought to you by:");
1994 char *specialthx = _("Special thanks to:");
1995 char *fsf = _("The Free Software Foundation");
Chris Allegrettadce44ab2002-03-16 01:03:41 +00001996 char *ncurses = _("For ncurses:");
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00001997 char *anyonelse = _("and anyone else we forgot...");
1998 char *thankyou = _("Thank you for using nano!\n");
1999
Chris Allegretta598106e2002-01-19 01:59:37 +00002000 char *credits[CREDIT_LEN] = { nanotext,
2001 version,
2002 VERSION,
2003 "",
2004 brought,
2005 "Chris Allegretta",
2006 "Jordi Mallach",
2007 "Adam Rogoyski",
2008 "Rob Siemborski",
2009 "Rocco Corsi",
Chris Allegrettaa8c22572002-02-15 19:17:02 +00002010 "David Lawrence Ramsey",
Chris Allegretta598106e2002-01-19 01:59:37 +00002011 "Ken Tyler",
2012 "Sven Guckes",
2013 "Florian König",
2014 "Pauli Virtanen",
2015 "Daniele Medri",
2016 "Clement Laforet",
2017 "Tedi Heriyanto",
2018 "Bill Soudan",
2019 "Christian Weisgerber",
2020 "Erik Andersen",
2021 "Big Gaute",
2022 "Joshua Jensen",
2023 "Ryan Krebs",
2024 "Albert Chin",
Chris Allegretta598106e2002-01-19 01:59:37 +00002025 "",
2026 specialthx,
2027 "Plattsburgh State University",
2028 "Benet Laboratories",
2029 "Amy Allegretta",
2030 "Linda Young",
2031 "Jeremy Robichaud",
2032 "Richard Kolb II",
2033 fsf,
2034 "Linus Torvalds",
2035 ncurses,
Chris Allegrettadce44ab2002-03-16 01:03:41 +00002036 "Thomas Dickey",
2037 "Pavel Curtis",
2038 "Zeyd Ben-Halim",
2039 "Eric S. Raymond",
Chris Allegretta598106e2002-01-19 01:59:37 +00002040 anyonelse,
2041 thankyou,
2042 "", "", "", "",
2043 "(c) 1999-2002 Chris Allegretta",
2044 "", "", "", "",
2045 "www.nano-editor.org"
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00002046 };
2047
2048 curs_set(0);
2049 nodelay(edit, TRUE);
2050 blank_bottombars();
2051 mvwaddstr(topwin, 0, 0, hblank);
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00002052 blank_edit();
2053 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00002054 wrefresh(bottomwin);
2055 wrefresh(topwin);
2056
2057 while (wgetch(edit) == ERR) {
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00002058 for (k = 0; k <= 1; k++) {
2059 blank_edit();
Chris Allegretta598106e2002-01-19 01:59:37 +00002060 for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j);
2061 i--) {
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00002062 mvwaddstr(edit, i * 2 - k, 0, hblank);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00002063
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00002064 if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
2065 what = credits[place - (editwinrows / 2 - 1 - i)];
2066 else
2067 what = "";
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00002068
Chris Allegretta17dcb722001-01-20 21:40:07 +00002069 start_x = COLS / 2 - strlen(what) / 2 - 1;
Chris Allegretta8b4ca4a2000-11-25 18:21:37 +00002070 mvwaddstr(edit, i * 2 - k, start_x, what);
2071 }
2072 usleep(700000);
2073 wrefresh(edit);
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00002074 }
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00002075 if (j < editwinrows / 2 - 1)
2076 j++;
2077
2078 place++;
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00002079
2080 if (place >= CREDIT_LEN + editwinrows / 2)
2081 break;
2082 }
2083
2084 nodelay(edit, FALSE);
2085 curs_set(1);
2086 display_main_list();
2087 total_refresh();
Chris Allegretta598106e2002-01-19 01:59:37 +00002088}
Chris Allegretta8a0de3b2000-11-24 20:45:14 +00002089#endif
Chris Allegrettac08f50d2001-01-06 18:12:43 +00002090
Chris Allegretta598106e2002-01-19 01:59:37 +00002091int keypad_on(WINDOW * win, int newval)
Chris Allegrettac08f50d2001-01-06 18:12:43 +00002092{
2093
Chris Allegretta88520c92001-05-05 17:45:54 +00002094/* This is taken right from aumix. Don't sue me. */
Chris Allegrettac08f50d2001-01-06 18:12:43 +00002095#ifdef HAVE_USEKEYPAD
Chris Allegretta598106e2002-01-19 01:59:37 +00002096 int old;
Chris Allegrettac08f50d2001-01-06 18:12:43 +00002097
2098 old = win->_use_keypad;
Chris Allegrettae3167732001-03-18 16:59:34 +00002099 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00002100 return old;
2101#else
Chris Allegrettae3167732001-03-18 16:59:34 +00002102 keypad(win, newval);
Chris Allegrettac08f50d2001-01-06 18:12:43 +00002103 return 1;
Chris Allegretta598106e2002-01-19 01:59:37 +00002104#endif /* HAVE_USEKEYPAD */
Chris Allegrettac08f50d2001-01-06 18:12:43 +00002105
2106}