blob: 0e981c82542f400eb4bab87ce543f86e0a4f1263 [file] [log] [blame]
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001/**************************************************************************
2 * winio.c *
3 * *
4 * Copyright (C) 1999 Chris Allegretta *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 1, or (at your option) *
8 * any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
18 * *
19 **************************************************************************/
20
21#include <stdarg.h>
22#include <string.h>
23#include "config.h"
24#include "proto.h"
25#include "nano.h"
26
27#ifndef NANO_SMALL
28#include <libintl.h>
29#define _(string) gettext(string)
30#else
31#define _(string) (string)
32#endif
33
34static int statblank = 0; /* Number of keystrokes left after
35 we call statubar() before we
36 actually blank the statusbar */
Robert Siemborskid8510b22000-06-06 23:04:06 +000037
38/* Local Function Prototypes for only winio.c */
39inline int get_page_from_virtual(int virtual);
40inline int get_page_start_virtual(int page);
41inline int get_page_end_virtual(int page);
42
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000043/* Window I/O */
44
45int do_first_line(void)
46{
47 current = fileage;
48 placewewant = 0;
49 current_x = 0;
50 edit_update(current);
51 return 1;
52}
53
54int do_last_line(void)
55{
56 current = filebot;
57 placewewant = 0;
58 current_x = 0;
59 edit_update(current);
60 return 1;
61}
62
63/* Like xplustabs, but for a specifc index of a speficific filestruct */
64int xpt(filestruct * fileptr, int index)
65{
66 int i, tabs = 0;
67
68 if (fileptr == NULL || fileptr->data == NULL)
69 return 0;
70
71 for (i = 0; i < index && fileptr->data[i] != 0; i++) {
72 tabs++;
73
74 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta6724a7e2000-06-19 23:19:07 +000075 if (tabs % TABSIZE == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000076 else
Chris Allegretta6724a7e2000-06-19 23:19:07 +000077 tabs += TABSIZE - (tabs % TABSIZE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +000078 } else if (fileptr->data[i] & 0x80)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000079 /* Make 8 bit chars only 1 collumn! */
80 ;
81 else if (fileptr->data[i] < 32)
82 tabs++;
83 }
84
85 return tabs;
86}
87
88
89/* Return the actual place on the screen of current->data[current_x], which
90 should always be > current_x */
91int xplustabs(void)
92{
93 return xpt(current, current_x);
94}
95
96
Robert Siemborskid8510b22000-06-06 23:04:06 +000097/* Return what current_x should be, given xplustabs() for the line,
98 * given a start position in the filestruct's data */
99int actual_x_from_start(filestruct * fileptr, int xplus, int start)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000100{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000101 int i, tot = 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000102
103 if (fileptr == NULL || fileptr->data == NULL)
104 return 0;
105
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000106 for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000107 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000108 if (tot % TABSIZE == 0)
109 tot++;
110 else
111 tot += TABSIZE - (tot % TABSIZE);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000112 } else if (fileptr->data[i] & 0x80)
113 tot++; /* Make 8 bit chars only 1 column (again) */
114 else if (fileptr->data[i] < 32)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000115 tot += 2;
116
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000117#ifdef DEBUG
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000118 fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"),
119 xplus, i);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000120#endif
Robert Siemborskid8510b22000-06-06 23:04:06 +0000121 return i - start;
122}
123
124/* Opposite of xplustabs */
125inline int actual_x(filestruct * fileptr, int xplus)
126{
127 return actual_x_from_start(fileptr, xplus, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000128}
129
130/* a strlen with tabs factored in, similar to xplustabs() */
131int strlenpt(char *buf)
132{
133 int i, tabs = 0;
134
135 if (buf == NULL)
136 return 0;
137
138 for (i = 0; buf[i] != 0; i++) {
139 tabs++;
140
141 if (buf[i] == NANO_CONTROL_I) {
Chris Allegretta6724a7e2000-06-19 23:19:07 +0000142 if (tabs % TABSIZE == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000143 else
Chris Allegretta6724a7e2000-06-19 23:19:07 +0000144 tabs += TABSIZE - (tabs % TABSIZE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000145 } else if (buf[i] & 0x80)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000146 /* Make 8 bit chars only 1 collumn! */
147 ;
148 else if (buf[i] < 32)
149 tabs++;
150 }
151
152 return tabs;
153}
154
155
156/* resets current_y based on the position of current and puts the cursor at
157 (current_y, current_x) */
158void reset_cursor(void)
159{
160 filestruct *ptr = edittop;
161 int x;
162
163 current_y = 0;
164
165 while (ptr != current && ptr != editbot && ptr->next != NULL) {
166 ptr = ptr->next;
167 current_y++;
168 }
169
170 x = xplustabs();
171 if (x <= COLS - 2)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000172 wmove(edit, current_y, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000173 else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000174 wmove(edit, current_y, x -
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000175 get_page_start_virtual(get_page_from_virtual(x)));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000176
177}
178
179void blank_bottombars(void)
180{
181 int i = no_help()? 3 : 1;
182
183 for (; i <= 2; i++)
184 mvwaddstr(bottomwin, i, 0, hblank);
185
186}
187
188void blank_edit(void)
189{
190 int i;
191 for (i = 0; i <= editwinrows - 1; i++)
192 mvwaddstr(edit, i, 0, hblank);
193 wrefresh(edit);
194}
195
196
197void blank_statusbar(void)
198{
199 mvwaddstr(bottomwin, 0, 0, hblank);
200}
201
202void blank_statusbar_refresh(void)
203{
204 blank_statusbar();
205 wrefresh(bottomwin);
206}
207
208void check_statblank(void)
209{
210
211 if (statblank > 1)
212 statblank--;
213 else if (statblank == 1 && !ISSET(CONSTUPDATE)) {
214 statblank--;
215 blank_statusbar_refresh();
216 }
217}
218
219/* Get the input from the kb, this should only be called from statusq */
220int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x)
221{
222 int kbinput = 0, j = 0, x = 0, xend;
223 int x_left = 0;
224 char inputstr[132], inputbuf[132] = "";
225
226 blank_statusbar();
227 mvwaddstr(bottomwin, 0, 0, buf);
228 if (strlen(def) > 0)
229 waddstr(bottomwin, def);
230 wrefresh(bottomwin);
231
232 x_left = strlen(buf);
233 x = strlen(def) + x_left;
234
235 /* Get the input! */
236 if (strlen(def) > 0) {
237 strcpy(answer, def);
238 strcpy(inputbuf, def);
239 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000240
241 while ((kbinput = wgetch(bottomwin)) != 13) {
242 for (j = 0; j <= slen - 1; j++) {
243 if (kbinput == s[j].val) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000244 strcpy(answer, "");
245 return s[j].val;
246 }
247 }
248 xend = strlen(buf) + strlen(inputbuf);
249
250 switch (kbinput) {
251 case KEY_HOME:
252 x = x_left;
253 blank_statusbar();
254 mvwaddstr(bottomwin, 0, 0, buf);
255 waddstr(bottomwin, inputbuf);
256 wmove(bottomwin, 0, x);
257 break;
258 case KEY_END:
259 x = x_left + strlen(inputbuf);
260 blank_statusbar();
261 mvwaddstr(bottomwin, 0, 0, buf);
262 waddstr(bottomwin, inputbuf);
263 wmove(bottomwin, 0, x);
264 break;
265 case KEY_RIGHT:
266
267 if (x < xend)
268 x++;
269 wmove(bottomwin, 0, x);
270 break;
271 case NANO_CONTROL_D:
272 if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
273 memmove(inputbuf + (x - x_left),
274 inputbuf + (x - x_left) + 1,
275 strlen(inputbuf) - (x - x_left) - 1);
276 inputbuf[strlen(inputbuf) - 1] = 0;
277 }
278 blank_statusbar();
279 mvwaddstr(bottomwin, 0, 0, buf);
280 waddstr(bottomwin, inputbuf);
281 wmove(bottomwin, 0, x);
282 break;
283 case NANO_CONTROL_K:
284 case NANO_CONTROL_U:
285 *inputbuf = 0;
286 x = x_left;
287 blank_statusbar();
288 mvwaddstr(bottomwin, 0, 0, buf);
289 waddstr(bottomwin, inputbuf);
290 wmove(bottomwin, 0, x);
291 break;
292 case KEY_BACKSPACE:
293 case KEY_DC:
294 case 127:
295 case NANO_CONTROL_H:
296 if (strlen(inputbuf) > 0) {
297 if (x == (x_left + strlen(inputbuf)))
298 inputbuf[strlen(inputbuf) - 1] = 0;
299 else if (x - x_left) {
300 memmove(inputbuf + (x - x_left) - 1,
301 inputbuf + (x - x_left),
302 strlen(inputbuf) - (x - x_left));
303 inputbuf[strlen(inputbuf) - 1] = 0;
304 }
305 }
306 blank_statusbar();
307 mvwaddstr(bottomwin, 0, 0, buf);
308 waddstr(bottomwin, inputbuf);
309 case KEY_LEFT:
310 if (x > strlen(buf))
311 x--;
312 wmove(bottomwin, 0, x);
313 break;
314 case KEY_UP:
315 case KEY_DOWN:
316 break;
317
318 case 27:
319 switch (kbinput = wgetch(edit)) {
320 case 79:
321 switch (kbinput = wgetch(edit)) {
322 case 70:
323 x = x_left + strlen(inputbuf);
324 blank_statusbar();
325 mvwaddstr(bottomwin, 0, 0, buf);
326 waddstr(bottomwin, inputbuf);
327 wmove(bottomwin, 0, x);
328 break;
329 case 72:
330 x = x_left;
331 blank_statusbar();
332 mvwaddstr(bottomwin, 0, 0, buf);
333 waddstr(bottomwin, inputbuf);
334 wmove(bottomwin, 0, x);
335 break;
336 }
337 break;
338 case 91:
339 switch (kbinput = wgetch(edit)) {
340 case 'C':
341 if (x < xend)
342 x++;
343 wmove(bottomwin, 0, x);
344 break;
345 case 'D':
346 if (x > strlen(buf))
347 x--;
348 wmove(bottomwin, 0, x);
349 break;
350 case 49:
351 x = x_left;
352 blank_statusbar();
353 mvwaddstr(bottomwin, 0, 0, buf);
354 waddstr(bottomwin, inputbuf);
355 wmove(bottomwin, 0, x);
356 goto skip_126;
357 case 51:
358 if (strlen(inputbuf) > 0
359 && (x - x_left) != strlen(inputbuf)) {
360 memmove(inputbuf + (x - x_left),
361 inputbuf + (x - x_left) + 1,
362 strlen(inputbuf) - (x - x_left) - 1);
363 inputbuf[strlen(inputbuf) - 1] = 0;
364 }
365 blank_statusbar();
366 mvwaddstr(bottomwin, 0, 0, buf);
367 waddstr(bottomwin, inputbuf);
368 wmove(bottomwin, 0, x);
369 goto skip_126;
370 case 52:
371 x = x_left + strlen(inputbuf);
372 blank_statusbar();
373 mvwaddstr(bottomwin, 0, 0, buf);
374 waddstr(bottomwin, inputbuf);
375 wmove(bottomwin, 0, x);
376 goto skip_126;
377 skip_126:
378 nodelay(edit, TRUE);
379 kbinput = wgetch(edit);
380 if (kbinput == 126 || kbinput == ERR)
381 kbinput = -1;
382 nodelay(edit, FALSE);
383 break;
384 }
385 }
386 blank_statusbar();
387 mvwaddstr(bottomwin, 0, 0, buf);
388 waddstr(bottomwin, inputbuf);
389 wmove(bottomwin, 0, x);
390 break;
391
392
393 default:
394 if (kbinput < 32)
395 break;
396 strcpy(inputstr, inputbuf);
397 inputstr[x - strlen(buf)] = kbinput;
398 strcpy(&inputstr[x - strlen(buf) + 1],
399 &inputbuf[x - strlen(buf)]);
400 strcpy(inputbuf, inputstr);
401 x++;
402
403 mvwaddstr(bottomwin, 0, 0, buf);
404 waddstr(bottomwin, inputbuf);
405 wmove(bottomwin, 0, x);
406
407#ifdef DEBUG
408 fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
409#endif
410 }
411 wrefresh(bottomwin);
412 }
413
414 strncpy(answer, inputbuf, 132);
415
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000416 if (!strcmp(answer, ""))
417 return -2;
418 else
419 return 0;
420}
421
422void horizbar(WINDOW * win, int y)
423{
424 wattron(win, A_REVERSE);
425 mvwaddstr(win, 0, 0, hblank);
426 wattroff(win, A_REVERSE);
427}
428
429void titlebar(void)
430{
431 int namelen, space;
432
433 horizbar(topwin, 0);
434 wattron(topwin, A_REVERSE);
435 mvwaddstr(topwin, 0, 3, VERMSG);
436
437 space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
438
439 namelen = strlen(filename);
440
441 if (!strcmp(filename, ""))
442 mvwaddstr(topwin, 0, center_x - 6, _("New Buffer"));
443 else {
444 if (namelen > space) {
445 waddstr(topwin, _(" File: ..."));
446 waddstr(topwin, &filename[namelen - space]);
447 } else {
448 mvwaddstr(topwin, 0, center_x - (namelen / 2 + 1), "File: ");
449 waddstr(topwin, filename);
450 }
451 }
452 if (ISSET(MODIFIED))
453 mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
454 wattroff(topwin, A_REVERSE);
455 wrefresh(topwin);
456 reset_cursor();
457}
458
459void onekey(char *keystroke, char *desc)
460{
461 char description[80];
462
463 snprintf(description, 12, " %-11s", desc);
464 wattron(bottomwin, A_REVERSE);
465 waddstr(bottomwin, keystroke);
466 wattroff(bottomwin, A_REVERSE);
467 waddstr(bottomwin, description);
468}
469
470void clear_bottomwin(void)
471{
472 if (ISSET(NO_HELP))
473 return;
474
475 mvwaddstr(bottomwin, 1, 0, hblank);
476 mvwaddstr(bottomwin, 2, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000477}
478
479void bottombars(shortcut s[], int slen)
480{
481 int i, j, k;
482 char keystr[10];
483
484 if (ISSET(NO_HELP))
485 return;
486
487 /* Determine how many extra spaces are needed to fill the bottom of the screen */
488 k = COLS / 6 - 13;
489
490 clear_bottomwin();
491 wmove(bottomwin, 1, 0);
492 for (i = 0; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000493 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000494 onekey(keystr, s[i].desc);
495
496 for (j = 0; j < k; j++)
497 waddch(bottomwin, ' ');
498 }
499
500 wmove(bottomwin, 2, 0);
501 for (i = 1; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000502 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000503 onekey(keystr, s[i].desc);
504
505 for (j = 0; j < k; j++)
506 waddch(bottomwin, ' ');
507 }
508
509 wrefresh(bottomwin);
510
511}
512
513/* If modified is not already set, set it and update titlebar */
514void set_modified(void)
515{
516 if (!ISSET(MODIFIED)) {
517 SET(MODIFIED);
518 titlebar();
519 wrefresh(topwin);
520 }
521}
522
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000523inline int get_page_from_virtual(int virtual)
524{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000525 int page = 2;
526
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000527 if (virtual <= COLS - 2)
528 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000529 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000530
531 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000532 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000533 page++;
534 }
535
536 return page;
537}
538
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000539inline int get_page_start_virtual(int page)
540{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000541 int virtual;
542 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000543 if (page)
544 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000545 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000546}
547
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000548inline int get_page_end_virtual(int page)
549{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000550 return get_page_start_virtual(page) + COLS - 1;
551}
552
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000553#ifndef NANO_SMALL
Robert Siemborski53875912000-06-16 04:25:30 +0000554/* Called only from edit_add, and therefore expects a
555 * converted-to-only-spaces line */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000556void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
557 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000558{
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000559 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000560 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000561
562 /* 3 start points: 0 -> begin, begin->end, end->strlen(data) */
563 /* in data : pre sel post */
Robert Siemborskid8510b22000-06-06 23:04:06 +0000564 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000565 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 +0000566
567 /* now fix the start locations & lengths according to the cursor's
568 * position (ie: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000569 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000570 pre_data_len = 0;
571 else
572 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000573
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000574 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000575 begin = this_page_start;
576
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000577 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000578 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000579
Robert Siemborskid8510b22000-06-06 23:04:06 +0000580 /* we don't care about end, because it will just get cropped
581 * due to length */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000582 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000583 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000584
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000585 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000586 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000587
Robert Siemborskia9addc72000-06-17 06:06:35 +0000588 sel_data_len = end - begin;
589 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000590
Robert Siemborski53875912000-06-16 04:25:30 +0000591 mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000592 wattron(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000593 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000594 &fileptr->data[begin], sel_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000595 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000596 mvwaddnstr(edit, y, end - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000597 &fileptr->data[end], post_data_len);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000598}
599#endif
600
Robert Siemborski53875912000-06-16 04:25:30 +0000601/* Called only from update_line. Expects a converted-to-not-have-tabs
602 * line */
603void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000604 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000605{
606#ifndef NANO_SMALL
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000607 if (ISSET(MARK_ISSET)) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000608 if ((fileptr->lineno > mark_beginbuf->lineno
609 && fileptr->lineno > current->lineno)
610 || (fileptr->lineno < mark_beginbuf->lineno
611 && fileptr->lineno < current->lineno)) {
612
613 /* We're on a normal, unselected line */
Robert Siemborski53875912000-06-16 04:25:30 +0000614 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000615 } else {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000616 if (fileptr != mark_beginbuf && fileptr != current) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000617 /* We're on selected text */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000618 wattron(edit, A_REVERSE);
Robert Siemborski53875912000-06-16 04:25:30 +0000619 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000620 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000621 } else if (fileptr == mark_beginbuf && fileptr == current) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000622 /* Special case, we're still on the same line we started
Robert Siemborskia9addc72000-06-17 06:06:35 +0000623 * marking */
Robert Siemborski53875912000-06-16 04:25:30 +0000624 if (virt_cur_x < virt_mark_beginx)
625 add_marked_sameline(virt_cur_x, virt_mark_beginx,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000626 fileptr, yval, virt_cur_x,
627 this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000628 else
Robert Siemborski53875912000-06-16 04:25:30 +0000629 add_marked_sameline(virt_mark_beginx, virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000630 fileptr, yval, virt_cur_x,
631 this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000632 } else if (fileptr == mark_beginbuf) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000633 /* we're updating the line that was first marked */
Robert Siemborskid8510b22000-06-06 23:04:06 +0000634 int target;
635
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000636 if (mark_beginbuf->lineno > current->lineno)
637 wattron(edit, A_REVERSE);
638
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000639 target =
640 (virt_mark_beginx <
641 COLS - 1) ? virt_mark_beginx : COLS - 1;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000642
Robert Siemborski53875912000-06-16 04:25:30 +0000643 mvwaddnstr(edit, yval, 0, fileptr->data, target);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000644
645 if (mark_beginbuf->lineno < current->lineno)
646 wattron(edit, A_REVERSE);
647 else
648 wattroff(edit, A_REVERSE);
649
Robert Siemborski53875912000-06-16 04:25:30 +0000650 target = (COLS - 1) - virt_mark_beginx;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000651 if (target < 0)
652 target = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000653
Robert Siemborski53875912000-06-16 04:25:30 +0000654 mvwaddnstr(edit, yval, virt_mark_beginx,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000655 &fileptr->data[virt_mark_beginx], target);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000656
657 if (mark_beginbuf->lineno < current->lineno)
658 wattroff(edit, A_REVERSE);
659
660 } else if (fileptr == current) {
Robert Siemborskid8510b22000-06-06 23:04:06 +0000661 /* we're on the cursors line, but it's not the first
662 * one we marked... */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000663 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborskid8510b22000-06-06 23:04:06 +0000664 this_page_end = get_page_end_virtual(this_page);
665
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000666 if (mark_beginbuf->lineno < current->lineno)
667 wattron(edit, A_REVERSE);
668
Robert Siemborski53875912000-06-16 04:25:30 +0000669 if (virt_cur_x > COLS - 2) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000670 mvwaddnstr(edit, yval, 0,
671 &fileptr->data[this_page_start],
672 virt_cur_x - this_page_start);
Robert Siemborski53875912000-06-16 04:25:30 +0000673 } else {
674 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
675 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000676
677 if (mark_beginbuf->lineno > current->lineno)
678 wattron(edit, A_REVERSE);
679 else
680 wattroff(edit, A_REVERSE);
681
Robert Siemborskia9addc72000-06-17 06:06:35 +0000682 if (virt_cur_x > COLS - 2)
Robert Siemborski53875912000-06-16 04:25:30 +0000683 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
684 &fileptr->data[virt_cur_x],
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000685 this_page_end - virt_cur_x);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000686 else
Robert Siemborski53875912000-06-16 04:25:30 +0000687 mvwaddnstr(edit, yval, virt_cur_x,
688 &fileptr->data[virt_cur_x],
689 COLS - virt_cur_x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000690
691 if (mark_beginbuf->lineno > current->lineno)
692 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000693 }
694 }
695
696 } else
697#endif
Robert Siemborskia9addc72000-06-17 06:06:35 +0000698 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000699 get_page_end_virtual(this_page) - start);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000700}
701
702/*
703 * Just update one line in the edit buffer
704 *
705 * index gives is a place in the string to update starting from.
706 * Likely args are current_x or 0.
707 */
708void update_line(filestruct * fileptr, int index)
709{
710 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +0000711 int line = 0, col = 0;
712 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
713 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000714 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000715
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000716 if (!fileptr)
717 return;
Robert Siemborski53154a72000-06-18 00:11:03 +0000718
Robert Siemborski53875912000-06-16 04:25:30 +0000719 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000720 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
721 filetmp = filetmp->next)
722 line++;
723
724 mvwaddstr(edit, line, 0, hblank);
725
Robert Siemborski53875912000-06-16 04:25:30 +0000726 /* Next, convert all the tabs to spaces so everything else is easy */
727 index = xpt(fileptr, index);
728
729 realdata = fileptr->data;
730 len = strlen(realdata);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000731 fileptr->data = nmalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +0000732
733 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000734 for (i = 0; i < len; i++) {
735 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +0000736 do {
737 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000738 if (i < current_x)
739 virt_cur_x++;
740 if (i < mark_beginx)
741 virt_mark_beginx++;
742 } while (pos % TABSIZE);
Robert Siemborski53875912000-06-16 04:25:30 +0000743 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000744 if (i < current_x)
745 virt_cur_x--;
746 if (i < mark_beginx)
747 virt_mark_beginx--;
Robert Siemborski53875912000-06-16 04:25:30 +0000748 } else {
749 fileptr->data[pos++] = realdata[i];
750 }
751 }
752
753 fileptr->data[pos] = '\0';
754
755 /* Now, Paint the line */
756 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000757 /* This handles when the current line is beyond COLS */
758 /* It requires figureing out what page we're at */
759 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000760 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000761
Robert Siemborskia9addc72000-06-17 06:06:35 +0000762 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000763 mvwaddch(edit, line, 0, '$');
764
Robert Siemborskid8510b22000-06-06 23:04:06 +0000765 if (strlenpt(fileptr->data) > get_page_end_virtual(page))
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000766 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000767 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000768 /* It's not the current line means that it's at x=0 and page=1 */
769 /* If it is the current line, then we're in the same boat */
770 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000771
Robert Siemborski53875912000-06-16 04:25:30 +0000772 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000773 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000774 }
Robert Siemborski53875912000-06-16 04:25:30 +0000775
776 /* Clean up our mess */
777 tmp = fileptr->data;
778 fileptr->data = realdata;
779 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000780}
781
782void center_cursor(void)
783{
784 current_y = editwinrows / 2;
785 wmove(edit, current_y, current_x);
786}
787
788/* Refresh the screen without changing the position of lines */
789void edit_refresh(void)
790{
791 int lines = 0, i = 0;
792 filestruct *temp, *hold = current;
793
794 if (current == NULL)
795 return;
796
797 temp = edittop;
798
799 while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) {
800 hold = temp;
801 update_line(temp, current_x);
802 temp = temp->next;
803 lines++;
804 }
805
806 if (lines <= editwinrows - 1)
807 while (lines <= editwinrows - 1) {
808 mvwaddstr(edit, lines, i, hblank);
809 lines++;
810 }
811 if (temp == NULL)
812 editbot = hold;
813 else
814 editbot = temp;
815}
816
817/*
818 * Nice generic routine to update the edit buffer given a pointer to the
819 * file struct =)
820 */
821void edit_update(filestruct * fileptr)
822{
823
824 int lines = 0, i = 0;
825 filestruct *temp;
826
827 if (fileptr == NULL)
828 return;
829
830 temp = fileptr;
831 while (i <= editwinrows / 2 && temp->prev != NULL) {
832 i++;
833 temp = temp->prev;
834 }
835 edittop = temp;
836
837 while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL
838 && temp != filebot) {
839 temp = temp->next;
840 lines++;
841 }
842 editbot = temp;
843
844 edit_refresh();
845}
846
847/* Now we want to update the screen using this struct as the top of the edit buffer */
848void edit_update_top(filestruct * fileptr)
849{
850 int i;
851 filestruct *temp = fileptr;
852
Chris Allegretta1e57e682000-07-03 04:24:39 +0000853 if (fileptr == NULL)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000854 return;
855
856 i = 0;
857 while (i <= editwinrows / 2 && temp->next != NULL) {
858 i++;
859 temp = temp->next;
860 }
861 edit_update(temp);
862}
863
864/* And also for the bottom... */
865void edit_update_bot(filestruct * fileptr)
866{
867 int i;
868 filestruct *temp = fileptr;
869
870 i = 0;
871 while (i <= editwinrows / 2 - 1 && temp->prev != NULL) {
872 i++;
873 temp = temp->prev;
874 }
875 edit_update(temp);
876}
877
878/* This function updates current based on where current_y is, reset_cursor
879 does the opposite */
880void update_cursor(void)
881{
882 int i = 0;
883
884#ifdef DEBUG
885 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
886 current_x);
887#endif
888
889 current = edittop;
890 while (i <= current_y - 1 && current->next != NULL) {
891 current = current->next;
892 i++;
893 }
894
895#ifdef DEBUG
896 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
897#endif
898
899}
900
901/*
902 * Ask a question on the statusbar. Answer will be stored in answer
903 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
904 * otherwise, the valid shortcut key caught, Def is any editable text we
905 * want to put up by default.
906 */
907int statusq(shortcut s[], int slen, char *def, char *msg, ...)
908{
909 va_list ap;
910 char foo[133];
911 int ret;
912
913 bottombars(s, slen);
914
915 va_start(ap, msg);
916 vsnprintf(foo, 132, msg, ap);
917 strncat(foo, ": ", 132);
918 va_end(ap);
919
920 wattron(bottomwin, A_REVERSE);
921 ret = nanogetstr(foo, def, s, slen, (strlen(foo) + 3));
922 wattroff(bottomwin, A_REVERSE);
923
924 switch (ret) {
925
926 case NANO_FIRSTLINE_KEY:
927 do_first_line();
928 break;
929 case NANO_LASTLINE_KEY:
930 do_last_line();
931 break;
932 case NANO_CANCEL_KEY:
933 return -1;
934 default:
935 blank_statusbar_refresh();
936 }
937
938#ifdef DEBUG
939 fprintf(stderr, _("I got \"%s\"\n"), answer);
940#endif
941
942 return ret;
943}
944
945/*
946 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
947 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
948 */
949int do_yesno(int all, int leavecursor, char *msg, ...)
950{
951 va_list ap;
952 char foo[133];
953 int kbinput, ok = -1;
954
955 /* Write the bottom of the screen */
956 clear_bottomwin();
957 wattron(bottomwin, A_REVERSE);
958 blank_statusbar_refresh();
959 wattroff(bottomwin, A_REVERSE);
960
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000961 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000962 if (!ISSET(NO_HELP)) {
963 wmove(bottomwin, 1, 0);
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000964 onekey(" Y", _("Yes"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000965 if (all)
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000966 onekey(" A", _("All"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000967 wmove(bottomwin, 2, 0);
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000968 onekey(" N", _("No"));
969 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000970 }
971 va_start(ap, msg);
972 vsnprintf(foo, 132, msg, ap);
973 va_end(ap);
974 wattron(bottomwin, A_REVERSE);
975 mvwaddstr(bottomwin, 0, 0, foo);
976 wattroff(bottomwin, A_REVERSE);
977 wrefresh(bottomwin);
978
979 if (leavecursor == 1)
980 reset_cursor();
981
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000982 while (ok == -1) {
983 kbinput = wgetch(edit);
984
985 switch (kbinput) {
986 case 'Y':
987 case 'y':
988 ok = 1;
989 break;
990 case 'N':
991 case 'n':
992 ok = 0;
993 break;
994 case 'A':
995 case 'a':
996 if (all)
997 ok = 2;
998 break;
999 case NANO_CONTROL_C:
1000 ok = -2;
1001 break;
1002 }
1003 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001004
1005 /* Then blank the screen */
1006 blank_statusbar_refresh();
1007
1008 if (ok == -2)
1009 return -1;
1010 else
1011 return ok;
1012}
1013
1014void statusbar(char *msg, ...)
1015{
1016 va_list ap;
1017 char foo[133];
1018 int start_x = 0;
1019
1020 va_start(ap, msg);
1021 vsnprintf(foo, 132, msg, ap);
1022 va_end(ap);
1023
1024 start_x = center_x - strlen(foo) / 2 - 1;
1025
1026 /* Blank out line */
1027 blank_statusbar();
1028
1029 wmove(bottomwin, 0, start_x);
1030
1031 wattron(bottomwin, A_REVERSE);
1032
1033 waddstr(bottomwin, "[ ");
1034 waddstr(bottomwin, foo);
1035 waddstr(bottomwin, " ]");
1036 wattroff(bottomwin, A_REVERSE);
1037 wrefresh(bottomwin);
1038
1039 if (ISSET(CONSTUPDATE))
1040 statblank = 1;
1041 else
1042 statblank = 25;
1043}
1044
1045void display_main_list(void)
1046{
1047 bottombars(main_list, MAIN_VISIBLE);
1048}
1049
1050int total_refresh(void)
1051{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001052 clearok(edit, TRUE);
1053 clearok(topwin, TRUE);
1054 clearok(bottomwin, TRUE);
1055 wnoutrefresh(edit);
1056 wnoutrefresh(topwin);
1057 wnoutrefresh(bottomwin);
1058 doupdate();
1059 clearok(edit, FALSE);
1060 clearok(topwin, FALSE);
1061 clearok(bottomwin, FALSE);
1062
1063 return 1;
1064}
1065
1066void previous_line(void)
1067{
1068 if (current_y > 0)
1069 current_y--;
1070}
1071
1072int do_cursorpos(void)
1073{
1074 filestruct *fileptr;
1075 float linepct, bytepct;
1076 int i, tot = 0;
1077
1078 if (current == NULL || fileage == NULL)
1079 return 0;
1080
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001081 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1082 fileptr = fileptr->next)
1083 tot += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001084
1085 if (fileptr == NULL)
1086 return -1;
1087
1088 i = tot + current_x;;
1089
1090 for (fileptr = current->next; fileptr != NULL; fileptr = fileptr->next)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001091 tot += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001092
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001093 if (totlines > 0)
1094 linepct = 100 * current->lineno / totlines;
1095 else
1096 linepct = 0;
1097
1098 if (totsize > 0)
1099 bytepct = 100 * i / totsize;
1100 else
1101 bytepct = 0;
1102
1103#ifdef DEBUG
1104 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1105 linepct, bytepct);
1106#endif
1107
1108 statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"),
1109 current->lineno, totlines, linepct, i, totsize, bytepct);
1110 reset_cursor();
1111 return 1;
1112}
1113
1114/* Our broken, non-shortcut list compliant help function.
1115 But hey, it's better than nothing, and it's dynamic! */
1116int do_help(void)
1117{
1118#ifndef NANO_SMALL
1119 char *ptr = help_text, *end;
1120 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0;
1121 int no_help_flag = 0;
1122
1123 blank_edit();
1124 curs_set(0);
1125 blank_statusbar();
1126
1127 if (ISSET(NO_HELP)) {
1128
1129 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001130 delwin(bottomwin);
1131 bottomwin = newwin(3, COLS, LINES - 3, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001132 keypad(bottomwin, TRUE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001133
1134 editwinrows -= no_help();
1135 UNSET(NO_HELP);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001136 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001137 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001138 bottombars(help_list, HELP_LIST_LEN);
1139
1140 do {
1141 ptr = help_text;
1142 switch (kbinput) {
1143 case NANO_NEXTPAGE_KEY:
1144 case NANO_NEXTPAGE_FKEY:
1145 case KEY_NPAGE:
1146 if (!no_more) {
1147 blank_edit();
1148 page++;
1149 }
1150 break;
1151 case NANO_PREVPAGE_KEY:
1152 case NANO_PREVPAGE_FKEY:
1153 case KEY_PPAGE:
1154 if (page > 1) {
1155 no_more = 0;
1156 blank_edit();
1157 page--;
1158 }
1159 break;
1160 }
1161
1162 /* Calculate where in the text we should be based on the page */
1163 for (i = 1; i < page; i++) {
1164 row = 0;
1165 j = 0;
1166 while (row < editwinrows && *ptr != '\0') {
1167 if (*ptr == '\n' || j == COLS - 5) {
1168 j = 0;
1169 row++;
1170 }
1171 ptr++;
1172 j++;
1173 }
1174 }
1175
1176 i = 0;
1177 j = 0;
1178 while (i < editwinrows && *ptr != '\0') {
1179 end = ptr;
1180 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1181 end++;
1182 j++;
1183 }
1184 if (j == COLS - 5) {
1185
1186 /* Don't print half a word if we've run of of space */
1187 while (*end != ' ' && *end != '\0') {
1188 end--;
1189 j--;
1190 }
1191 }
1192 mvwaddnstr(edit, i, 0, ptr, j);
1193 j = 0;
1194 i++;
1195 if (*end == '\n')
1196 end++;
1197 ptr = end;
1198 }
1199 if (*ptr == '\0') {
1200 no_more = 1;
1201 continue;
1202 }
1203 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY);
1204
1205 if (no_help_flag) {
1206 werase(bottomwin);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001207 wrefresh(bottomwin);
1208 delwin(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001209 SET(NO_HELP);
1210 bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0);
1211 keypad(bottomwin, TRUE);
1212 editwinrows += no_help();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001213 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001214 display_main_list();
1215
1216 curs_set(1);
1217 edit_refresh();
1218#else
1219 nano_small_msg();
1220#endif
1221
1222 return 1;
1223}
1224
1225/* Dump the current file structure to stderr */
1226void dump_buffer(filestruct * inptr)
1227{
1228#ifdef DEBUG
1229 filestruct *fileptr;
1230
1231 if (inptr == fileage)
1232 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1233 else if (inptr == cutbuffer)
1234 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1235 else
1236 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1237
1238 fileptr = inptr;
1239 while (fileptr != NULL) {
1240 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1241 fflush(stderr);
1242 fileptr = fileptr->next;
1243 }
1244#endif /* DEBUG */
1245}
1246
1247void dump_buffer_reverse(filestruct * inptr)
1248{
1249#ifdef DEBUG
1250 filestruct *fileptr;
1251
1252 fileptr = filebot;
1253 while (fileptr != NULL) {
1254 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1255 fflush(stderr);
1256 fileptr = fileptr->prev;
1257 }
1258#endif /* DEBUG */
1259}