2000-08-06 21:13:45 +00:00
|
|
|
|
/* $Id$ */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
/**************************************************************************
|
|
|
|
|
* winio.c *
|
|
|
|
|
* *
|
2002-01-04 17:57:40 +00:00
|
|
|
|
* Copyright (C) 1999-2002 Chris Allegretta *
|
2000-06-06 05:53:49 +00:00
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
2001-10-24 11:33:54 +00:00
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option) *
|
2000-06-06 05:53:49 +00:00
|
|
|
|
* any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
|
|
|
|
* *
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2001-04-28 18:03:52 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <string.h>
|
2000-07-07 05:13:09 +00:00
|
|
|
|
#include <stdlib.h>
|
2000-11-24 20:45:14 +00:00
|
|
|
|
#include <unistd.h>
|
2000-06-06 05:53:49 +00:00
|
|
|
|
#include "proto.h"
|
|
|
|
|
#include "nano.h"
|
|
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
|
#include <libintl.h>
|
|
|
|
|
#define _(string) gettext(string)
|
|
|
|
|
#else
|
|
|
|
|
#define _(string) (string)
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-02-16 01:49:31 +00:00
|
|
|
|
|
|
|
|
|
/* winio.c statics */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
static int statblank = 0; /* Number of keystrokes left after
|
2001-05-05 17:45:54 +00:00
|
|
|
|
we call statusbar(), before we
|
2000-06-06 05:53:49 +00:00
|
|
|
|
actually blank the statusbar */
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
|
|
|
|
/* Local Function Prototypes for only winio.c */
|
|
|
|
|
inline int get_page_from_virtual(int virtual);
|
|
|
|
|
inline int get_page_start_virtual(int page);
|
|
|
|
|
inline int get_page_end_virtual(int page);
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
/* Window I/O */
|
|
|
|
|
|
|
|
|
|
int do_first_line(void)
|
|
|
|
|
{
|
|
|
|
|
current = fileage;
|
|
|
|
|
placewewant = 0;
|
|
|
|
|
current_x = 0;
|
2000-07-29 04:33:38 +00:00
|
|
|
|
edit_update(current, CENTER);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int do_last_line(void)
|
|
|
|
|
{
|
|
|
|
|
current = filebot;
|
|
|
|
|
placewewant = 0;
|
|
|
|
|
current_x = 0;
|
2000-07-29 04:33:38 +00:00
|
|
|
|
edit_update(current, CENTER);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Like xplustabs, but for a specific index of a specific filestruct */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
int xpt(filestruct * fileptr, int index)
|
|
|
|
|
{
|
|
|
|
|
int i, tabs = 0;
|
|
|
|
|
|
|
|
|
|
if (fileptr == NULL || fileptr->data == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < index && fileptr->data[i] != 0; i++) {
|
|
|
|
|
tabs++;
|
|
|
|
|
|
|
|
|
|
if (fileptr->data[i] == NANO_CONTROL_I) {
|
2000-08-03 22:51:21 +00:00
|
|
|
|
if (tabs % tabsize == 0);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
else
|
2000-08-03 22:51:21 +00:00
|
|
|
|
tabs += tabsize - (tabs % tabsize);
|
2000-06-21 03:00:43 +00:00
|
|
|
|
} else if (fileptr->data[i] & 0x80)
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Make 8 bit chars only 1 column! */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
;
|
2002-03-28 01:59:34 +00:00
|
|
|
|
else if (fileptr->data[i] < 32 || fileptr->data[i] == 127)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
tabs++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tabs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the actual place on the screen of current->data[current_x], which
|
|
|
|
|
should always be > current_x */
|
|
|
|
|
int xplustabs(void)
|
|
|
|
|
{
|
|
|
|
|
return xpt(current, current_x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-06 23:04:06 +00:00
|
|
|
|
/* Return what current_x should be, given xplustabs() for the line,
|
|
|
|
|
* given a start position in the filestruct's data */
|
|
|
|
|
int actual_x_from_start(filestruct * fileptr, int xplus, int start)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
2000-06-06 23:04:06 +00:00
|
|
|
|
int i, tot = 1;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
if (fileptr == NULL || fileptr->data == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++)
|
2000-06-06 23:04:06 +00:00
|
|
|
|
if (fileptr->data[i] == NANO_CONTROL_I) {
|
2000-08-03 22:51:21 +00:00
|
|
|
|
if (tot % tabsize == 0)
|
2000-06-21 03:00:43 +00:00
|
|
|
|
tot++;
|
|
|
|
|
else
|
2000-08-03 22:51:21 +00:00
|
|
|
|
tot += tabsize - (tot % tabsize);
|
2000-06-06 23:04:06 +00:00
|
|
|
|
} else if (fileptr->data[i] & 0x80)
|
|
|
|
|
tot++; /* Make 8 bit chars only 1 column (again) */
|
|
|
|
|
else if (fileptr->data[i] < 32)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
tot += 2;
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-06-21 03:00:43 +00:00
|
|
|
|
fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"),
|
|
|
|
|
xplus, i);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
#endif
|
2000-06-06 23:04:06 +00:00
|
|
|
|
return i - start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Opposite of xplustabs */
|
2001-04-28 18:03:52 +00:00
|
|
|
|
int actual_x(filestruct * fileptr, int xplus)
|
2000-06-06 23:04:06 +00:00
|
|
|
|
{
|
|
|
|
|
return actual_x_from_start(fileptr, xplus, 0);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* a strlen with tabs factored in, similar to xplustabs() */
|
2002-03-05 19:55:55 +00:00
|
|
|
|
int strnlenpt(char *buf, int size)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
|
|
|
|
int i, tabs = 0;
|
|
|
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2002-03-05 19:55:55 +00:00
|
|
|
|
for (i = 0; i < size; i++) {
|
2000-06-06 05:53:49 +00:00
|
|
|
|
tabs++;
|
|
|
|
|
|
|
|
|
|
if (buf[i] == NANO_CONTROL_I) {
|
2000-08-03 22:51:21 +00:00
|
|
|
|
if (tabs % tabsize == 0);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
else
|
2000-08-03 22:51:21 +00:00
|
|
|
|
tabs += tabsize - (tabs % tabsize);
|
2000-06-21 03:00:43 +00:00
|
|
|
|
} else if (buf[i] & 0x80)
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Make 8 bit chars only 1 column! */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
;
|
|
|
|
|
else if (buf[i] < 32)
|
|
|
|
|
tabs++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tabs;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-05 19:55:55 +00:00
|
|
|
|
int strlenpt(char *buf)
|
|
|
|
|
{
|
|
|
|
|
return strnlenpt(buf, strlen(buf));
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* resets current_y, based on the position of current, and puts the cursor at
|
2000-06-06 05:53:49 +00:00
|
|
|
|
(current_y, current_x) */
|
|
|
|
|
void reset_cursor(void)
|
|
|
|
|
{
|
|
|
|
|
filestruct *ptr = edittop;
|
|
|
|
|
int x;
|
|
|
|
|
|
|
|
|
|
current_y = 0;
|
|
|
|
|
|
|
|
|
|
while (ptr != current && ptr != editbot && ptr->next != NULL) {
|
|
|
|
|
ptr = ptr->next;
|
|
|
|
|
current_y++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x = xplustabs();
|
|
|
|
|
if (x <= COLS - 2)
|
2000-06-06 23:04:06 +00:00
|
|
|
|
wmove(edit, current_y, x);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
else
|
2000-06-06 23:04:06 +00:00
|
|
|
|
wmove(edit, current_y, x -
|
2000-06-21 03:00:43 +00:00
|
|
|
|
get_page_start_virtual(get_page_from_virtual(x)));
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void blank_bottombars(void)
|
|
|
|
|
{
|
|
|
|
|
int i = no_help()? 3 : 1;
|
|
|
|
|
|
|
|
|
|
for (; i <= 2; i++)
|
|
|
|
|
mvwaddstr(bottomwin, i, 0, hblank);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void blank_edit(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i <= editwinrows - 1; i++)
|
|
|
|
|
mvwaddstr(edit, i, 0, hblank);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void blank_statusbar(void)
|
|
|
|
|
{
|
|
|
|
|
mvwaddstr(bottomwin, 0, 0, hblank);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void blank_statusbar_refresh(void)
|
|
|
|
|
{
|
|
|
|
|
blank_statusbar();
|
|
|
|
|
wrefresh(bottomwin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void check_statblank(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (statblank > 1)
|
|
|
|
|
statblank--;
|
|
|
|
|
else if (statblank == 1 && !ISSET(CONSTUPDATE)) {
|
|
|
|
|
statblank--;
|
|
|
|
|
blank_statusbar_refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-24 22:25:36 +00:00
|
|
|
|
/* Repaint the statusbar when getting a character in nanogetstr */
|
|
|
|
|
void nanoget_repaint(char *buf, char *inputbuf, int x)
|
|
|
|
|
{
|
2000-11-02 15:30:24 +00:00
|
|
|
|
int len = strlen(buf);
|
|
|
|
|
int wid = COLS - len;
|
2000-11-02 04:40:39 +00:00
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(bottomwin, COLOR_STATUSBAR);
|
2001-10-22 03:15:31 +00:00
|
|
|
|
#else
|
|
|
|
|
wattron(bottomwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
2000-11-02 15:30:24 +00:00
|
|
|
|
blank_statusbar();
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2000-11-02 15:30:24 +00:00
|
|
|
|
if (x <= COLS - 1) {
|
|
|
|
|
/* Black magic */
|
|
|
|
|
buf[len - 1] = ' ';
|
2000-11-02 04:40:39 +00:00
|
|
|
|
|
2000-11-02 15:30:24 +00:00
|
|
|
|
mvwaddstr(bottomwin, 0, 0, buf);
|
|
|
|
|
waddnstr(bottomwin, inputbuf, wid);
|
|
|
|
|
wmove(bottomwin, 0, (x % COLS));
|
2002-01-19 01:59:37 +00:00
|
|
|
|
} else {
|
2000-11-02 15:30:24 +00:00
|
|
|
|
/* Black magic */
|
|
|
|
|
buf[len - 1] = '$';
|
2000-11-02 04:40:39 +00:00
|
|
|
|
|
2000-11-02 15:30:24 +00:00
|
|
|
|
mvwaddstr(bottomwin, 0, 0, buf);
|
|
|
|
|
waddnstr(bottomwin, &inputbuf[wid * ((x - len) / (wid))], wid);
|
|
|
|
|
wmove(bottomwin, 0, ((x - len) % wid) + len);
|
|
|
|
|
}
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(bottomwin, COLOR_STATUSBAR);
|
2001-10-22 03:15:31 +00:00
|
|
|
|
#else
|
|
|
|
|
wattroff(bottomwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
2000-10-24 22:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Get the input from the kb; this should only be called from statusq */
|
2002-02-15 19:17:02 +00:00
|
|
|
|
int nanogetstr(int allowtabs, char *buf, char *def, shortcut *s,
|
2001-11-29 03:43:08 +00:00
|
|
|
|
int start_x, int list)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
2002-02-15 20:08:05 +00:00
|
|
|
|
int kbinput = 0, x = 0, xend, slen;
|
2000-11-24 14:00:16 +00:00
|
|
|
|
int x_left = 0, inputlen, tabbed = 0;
|
2000-11-02 04:40:39 +00:00
|
|
|
|
char *inputbuf;
|
2002-02-15 19:17:02 +00:00
|
|
|
|
shortcut *t;
|
2001-01-11 05:30:31 +00:00
|
|
|
|
#ifndef DISABLE_TABCOMP
|
2000-11-24 14:00:16 +00:00
|
|
|
|
int shift = 0;
|
|
|
|
|
#endif
|
2002-01-19 01:59:37 +00:00
|
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
|
slen = length_of_list(s);
|
2001-05-17 11:35:43 +00:00
|
|
|
|
inputbuf = charalloc(strlen(def) + 1);
|
2000-11-02 04:40:39 +00:00
|
|
|
|
inputbuf[0] = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
x_left = strlen(buf);
|
|
|
|
|
x = strlen(def) + x_left;
|
|
|
|
|
|
2001-10-22 03:15:31 +00:00
|
|
|
|
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
|
2001-04-12 03:01:53 +00:00
|
|
|
|
currshortcut = s;
|
2001-05-21 12:56:25 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
/* Get the input! */
|
2000-11-02 04:40:39 +00:00
|
|
|
|
if (strlen(def) > 0)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
strcpy(inputbuf, def);
|
2000-11-02 04:40:39 +00:00
|
|
|
|
|
|
|
|
|
nanoget_repaint(buf, inputbuf, x);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2000-11-14 17:47:58 +00:00
|
|
|
|
/* Make sure any editor screen updates are displayed before getting input */
|
|
|
|
|
wrefresh(edit);
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
while ((kbinput = wgetch(bottomwin)) != 13) {
|
2002-02-15 19:17:02 +00:00
|
|
|
|
for (t = s; t != NULL; t = t->next) {
|
2001-04-12 03:01:53 +00:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
|
if (kbinput == t->val && kbinput < 32) {
|
2000-11-16 06:01:10 +00:00
|
|
|
|
|
2001-10-22 03:15:31 +00:00
|
|
|
|
#ifndef DISABLE_HELP
|
|
|
|
|
/* Have to do this here, it would be too late to do it in statusq */
|
2002-01-19 01:59:37 +00:00
|
|
|
|
if (kbinput == NANO_HELP_KEY || kbinput == NANO_HELP_FKEY) {
|
2001-10-22 03:15:31 +00:00
|
|
|
|
do_help();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-11-16 06:01:10 +00:00
|
|
|
|
/* We shouldn't discard the answer it gave, just because
|
|
|
|
|
we hit a keystroke, GEEZ! */
|
|
|
|
|
answer = mallocstrcpy(answer, inputbuf);
|
2000-11-02 14:53:46 +00:00
|
|
|
|
free(inputbuf);
|
2002-02-15 19:17:02 +00:00
|
|
|
|
return t->val;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
xend = strlen(buf) + strlen(inputbuf);
|
|
|
|
|
|
2000-11-05 17:54:41 +00:00
|
|
|
|
if (kbinput != '\t')
|
|
|
|
|
tabbed = 0;
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
switch (kbinput) {
|
2001-04-12 03:01:53 +00:00
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
/* Stuff we want to equate with <enter>, ASCII 13 */
|
2000-10-26 01:44:42 +00:00
|
|
|
|
case 343:
|
2000-10-18 19:35:59 +00:00
|
|
|
|
ungetch(13); /* Enter on iris-ansi $TERM, sometimes */
|
|
|
|
|
break;
|
2002-01-19 01:59:37 +00:00
|
|
|
|
/* Stuff we want to ignore */
|
2000-11-16 19:55:30 +00:00
|
|
|
|
#ifdef PDCURSES
|
|
|
|
|
case 541:
|
|
|
|
|
case 542:
|
2002-01-19 01:59:37 +00:00
|
|
|
|
case 543: /* Right ctrl again */
|
2000-11-16 19:55:30 +00:00
|
|
|
|
case 544:
|
2002-01-19 01:59:37 +00:00
|
|
|
|
case 545: /* Right alt again */
|
2001-04-12 03:01:53 +00:00
|
|
|
|
break;
|
|
|
|
|
#endif
|
2001-04-12 14:51:48 +00:00
|
|
|
|
#ifndef DISABLE_MOUSE
|
2001-04-12 03:01:53 +00:00
|
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
|
case KEY_MOUSE:
|
|
|
|
|
do_mouse();
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2000-11-16 19:55:30 +00:00
|
|
|
|
#endif
|
2001-06-14 02:54:22 +00:00
|
|
|
|
case NANO_HOME_KEY:
|
2000-06-06 05:53:49 +00:00
|
|
|
|
case KEY_HOME:
|
|
|
|
|
x = x_left;
|
|
|
|
|
break;
|
2001-06-14 02:54:22 +00:00
|
|
|
|
case NANO_END_KEY:
|
2000-06-06 05:53:49 +00:00
|
|
|
|
case KEY_END:
|
|
|
|
|
x = x_left + strlen(inputbuf);
|
|
|
|
|
break;
|
|
|
|
|
case KEY_RIGHT:
|
2001-03-21 15:07:20 +00:00
|
|
|
|
case NANO_FORWARD_KEY:
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
if (x < xend)
|
|
|
|
|
x++;
|
|
|
|
|
wmove(bottomwin, 0, x);
|
|
|
|
|
break;
|
|
|
|
|
case NANO_CONTROL_D:
|
|
|
|
|
if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
|
|
|
|
|
memmove(inputbuf + (x - x_left),
|
|
|
|
|
inputbuf + (x - x_left) + 1,
|
|
|
|
|
strlen(inputbuf) - (x - x_left) - 1);
|
|
|
|
|
inputbuf[strlen(inputbuf) - 1] = 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NANO_CONTROL_K:
|
|
|
|
|
case NANO_CONTROL_U:
|
|
|
|
|
*inputbuf = 0;
|
|
|
|
|
x = x_left;
|
|
|
|
|
break;
|
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
|
case 127:
|
|
|
|
|
case NANO_CONTROL_H:
|
|
|
|
|
if (strlen(inputbuf) > 0) {
|
|
|
|
|
if (x == (x_left + strlen(inputbuf)))
|
|
|
|
|
inputbuf[strlen(inputbuf) - 1] = 0;
|
|
|
|
|
else if (x - x_left) {
|
|
|
|
|
memmove(inputbuf + (x - x_left) - 1,
|
|
|
|
|
inputbuf + (x - x_left),
|
|
|
|
|
strlen(inputbuf) - (x - x_left));
|
|
|
|
|
inputbuf[strlen(inputbuf) - 1] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-11-05 17:54:41 +00:00
|
|
|
|
if (x > strlen(buf))
|
|
|
|
|
x--;
|
|
|
|
|
break;
|
2001-01-11 05:30:31 +00:00
|
|
|
|
#ifndef DISABLE_TABCOMP
|
2000-11-05 17:54:41 +00:00
|
|
|
|
case NANO_CONTROL_I:
|
2000-11-06 02:57:22 +00:00
|
|
|
|
if (allowtabs) {
|
2000-11-14 17:46:06 +00:00
|
|
|
|
shift = 0;
|
2002-01-19 01:59:37 +00:00
|
|
|
|
inputbuf = input_tab(inputbuf, (x - x_left),
|
|
|
|
|
&tabbed, &shift, &list);
|
2000-11-14 17:46:06 +00:00
|
|
|
|
x += shift;
|
2001-01-27 19:25:00 +00:00
|
|
|
|
if (x - x_left > strlen(inputbuf))
|
|
|
|
|
x = strlen(inputbuf) + x_left;
|
2000-11-06 02:57:22 +00:00
|
|
|
|
}
|
2000-11-05 17:54:41 +00:00
|
|
|
|
break;
|
2000-11-24 14:00:16 +00:00
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
case KEY_LEFT:
|
2001-03-21 15:07:20 +00:00
|
|
|
|
case NANO_BACK_KEY:
|
2000-06-06 05:53:49 +00:00
|
|
|
|
if (x > strlen(buf))
|
|
|
|
|
x--;
|
|
|
|
|
wmove(bottomwin, 0, x);
|
|
|
|
|
break;
|
|
|
|
|
case KEY_UP:
|
|
|
|
|
case KEY_DOWN:
|
|
|
|
|
break;
|
|
|
|
|
|
2001-09-23 01:18:03 +00:00
|
|
|
|
case KEY_DC:
|
|
|
|
|
goto do_deletekey;
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
case 27:
|
|
|
|
|
switch (kbinput = wgetch(edit)) {
|
2001-09-23 01:18:03 +00:00
|
|
|
|
case 'O':
|
2000-06-06 05:53:49 +00:00
|
|
|
|
switch (kbinput = wgetch(edit)) {
|
2001-09-23 01:18:03 +00:00
|
|
|
|
case 'F':
|
2000-06-06 05:53:49 +00:00
|
|
|
|
x = x_left + strlen(inputbuf);
|
|
|
|
|
break;
|
2001-09-23 01:18:03 +00:00
|
|
|
|
case 'H':
|
2000-06-06 05:53:49 +00:00
|
|
|
|
x = x_left;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-09-23 01:18:03 +00:00
|
|
|
|
case '[':
|
2000-06-06 05:53:49 +00:00
|
|
|
|
switch (kbinput = wgetch(edit)) {
|
|
|
|
|
case 'C':
|
|
|
|
|
if (x < xend)
|
|
|
|
|
x++;
|
|
|
|
|
wmove(bottomwin, 0, x);
|
|
|
|
|
break;
|
|
|
|
|
case 'D':
|
|
|
|
|
if (x > strlen(buf))
|
|
|
|
|
x--;
|
|
|
|
|
wmove(bottomwin, 0, x);
|
|
|
|
|
break;
|
2001-09-23 01:18:03 +00:00
|
|
|
|
case '1':
|
|
|
|
|
case '7':
|
2000-06-06 05:53:49 +00:00
|
|
|
|
x = x_left;
|
2001-09-23 01:18:03 +00:00
|
|
|
|
goto skip_tilde;
|
|
|
|
|
case '3':
|
|
|
|
|
do_deletekey:
|
2000-06-06 05:53:49 +00:00
|
|
|
|
if (strlen(inputbuf) > 0
|
|
|
|
|
&& (x - x_left) != strlen(inputbuf)) {
|
|
|
|
|
memmove(inputbuf + (x - x_left),
|
|
|
|
|
inputbuf + (x - x_left) + 1,
|
|
|
|
|
strlen(inputbuf) - (x - x_left) - 1);
|
|
|
|
|
inputbuf[strlen(inputbuf) - 1] = 0;
|
|
|
|
|
}
|
2001-09-23 01:18:03 +00:00
|
|
|
|
goto skip_tilde;
|
|
|
|
|
case '4':
|
|
|
|
|
case '8':
|
2000-06-06 05:53:49 +00:00
|
|
|
|
x = x_left + strlen(inputbuf);
|
2001-09-23 01:18:03 +00:00
|
|
|
|
goto skip_tilde;
|
|
|
|
|
skip_tilde:
|
2000-06-06 05:53:49 +00:00
|
|
|
|
nodelay(edit, TRUE);
|
|
|
|
|
kbinput = wgetch(edit);
|
2001-09-23 01:18:03 +00:00
|
|
|
|
if (kbinput == '~' || kbinput == ERR)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
kbinput = -1;
|
|
|
|
|
nodelay(edit, FALSE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-06-14 02:54:22 +00:00
|
|
|
|
default:
|
|
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
|
for (t = s; t != NULL; t = t->next) {
|
2001-06-14 02:54:22 +00:00
|
|
|
|
#ifdef DEBUG
|
2002-01-19 01:59:37 +00:00
|
|
|
|
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput,
|
|
|
|
|
kbinput);
|
2001-06-14 02:54:22 +00:00
|
|
|
|
#endif
|
2002-02-15 19:17:02 +00:00
|
|
|
|
if (kbinput == t->val || kbinput == t->val - 32) {
|
2001-06-14 02:54:22 +00:00
|
|
|
|
|
|
|
|
|
/* We hit an Alt key. Do like above. We don't
|
|
|
|
|
just ungetch the letter and let it get caught
|
|
|
|
|
above cause that screws the keypad... */
|
|
|
|
|
answer = mallocstrcpy(answer, inputbuf);
|
|
|
|
|
free(inputbuf);
|
2002-02-15 19:17:02 +00:00
|
|
|
|
return t->val;
|
2001-06-14 02:54:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2001-06-14 02:54:22 +00:00
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
if (kbinput < 32)
|
|
|
|
|
break;
|
2000-11-02 04:40:39 +00:00
|
|
|
|
|
|
|
|
|
inputlen = strlen(inputbuf);
|
|
|
|
|
inputbuf = nrealloc(inputbuf, inputlen + 2);
|
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
memmove(&inputbuf[x - x_left + 1],
|
|
|
|
|
&inputbuf[x - x_left], inputlen - (x - x_left) + 1);
|
2000-11-02 04:40:39 +00:00
|
|
|
|
inputbuf[x - x_left] = kbinput;
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
x++;
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2001-10-02 02:57:26 +00:00
|
|
|
|
nanoget_repaint(buf, inputbuf, x);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wrefresh(bottomwin);
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-02 04:40:39 +00:00
|
|
|
|
answer = mallocstrcpy(answer, inputbuf);
|
2000-11-02 14:53:46 +00:00
|
|
|
|
free(inputbuf);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2001-08-17 00:03:46 +00:00
|
|
|
|
/* In pico mode, just check for a blank answer here */
|
2002-01-19 01:59:37 +00:00
|
|
|
|
if (((ISSET(PICO_MODE)) && !strcmp(answer, "")))
|
2000-06-06 05:53:49 +00:00
|
|
|
|
return -2;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void horizbar(WINDOW * win, int y)
|
|
|
|
|
{
|
|
|
|
|
wattron(win, A_REVERSE);
|
|
|
|
|
mvwaddstr(win, 0, 0, hblank);
|
|
|
|
|
wattroff(win, A_REVERSE);
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-03 07:11:47 +00:00
|
|
|
|
void titlebar(char *path)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
|
|
|
|
int namelen, space;
|
2001-01-03 07:11:47 +00:00
|
|
|
|
char *what = path;
|
|
|
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
|
what = filename;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(topwin, COLOR_TITLEBAR);
|
|
|
|
|
mvwaddstr(topwin, 0, 0, hblank);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
horizbar(topwin, 0);
|
|
|
|
|
wattron(topwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
mvwaddstr(topwin, 0, 3, VERMSG);
|
|
|
|
|
|
|
|
|
|
space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
|
|
|
|
|
|
2001-01-03 07:11:47 +00:00
|
|
|
|
namelen = strlen(what);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2001-01-03 07:11:47 +00:00
|
|
|
|
if (!strcmp(what, ""))
|
2001-01-20 21:40:07 +00:00
|
|
|
|
mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
|
2000-06-06 05:53:49 +00:00
|
|
|
|
else {
|
|
|
|
|
if (namelen > space) {
|
2001-01-03 07:11:47 +00:00
|
|
|
|
if (path == NULL)
|
|
|
|
|
waddstr(topwin, _(" File: ..."));
|
|
|
|
|
else
|
|
|
|
|
waddstr(topwin, _(" DIR: ..."));
|
|
|
|
|
waddstr(topwin, &what[namelen - space]);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
} else {
|
2001-01-03 07:11:47 +00:00
|
|
|
|
if (path == NULL)
|
2002-01-19 01:59:37 +00:00
|
|
|
|
mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1),
|
|
|
|
|
_("File: "));
|
2001-01-03 07:11:47 +00:00
|
|
|
|
else
|
2002-01-19 01:59:37 +00:00
|
|
|
|
mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1),
|
|
|
|
|
_(" DIR: "));
|
2001-01-03 07:11:47 +00:00
|
|
|
|
waddstr(topwin, what);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ISSET(MODIFIED))
|
|
|
|
|
mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(topwin, COLOR_TITLEBAR);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wattroff(topwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wrefresh(topwin);
|
|
|
|
|
reset_cursor();
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
|
void onekey(char *keystroke, char *desc, int len)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
2002-02-15 19:17:02 +00:00
|
|
|
|
int i;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
wattron(bottomwin, A_REVERSE);
|
|
|
|
|
waddstr(bottomwin, keystroke);
|
|
|
|
|
wattroff(bottomwin, A_REVERSE);
|
2002-02-15 19:17:02 +00:00
|
|
|
|
waddch(bottomwin, ' ');
|
|
|
|
|
waddnstr(bottomwin, desc, len - 3);
|
|
|
|
|
for (i = strlen(desc); i < len - 3; i++)
|
|
|
|
|
waddch(bottomwin, ' ');
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clear_bottomwin(void)
|
|
|
|
|
{
|
|
|
|
|
if (ISSET(NO_HELP))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mvwaddstr(bottomwin, 1, 0, hblank);
|
|
|
|
|
mvwaddstr(bottomwin, 2, 0, hblank);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
|
void bottombars(shortcut *s)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
2002-02-16 20:03:44 +00:00
|
|
|
|
int i, j, numcols;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
char keystr[10];
|
2002-02-15 19:17:02 +00:00
|
|
|
|
shortcut *t;
|
|
|
|
|
int slen;
|
|
|
|
|
|
|
|
|
|
if (s == main_list)
|
|
|
|
|
slen = MAIN_VISIBLE;
|
|
|
|
|
else
|
|
|
|
|
slen = length_of_list(s);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
if (ISSET(NO_HELP))
|
|
|
|
|
return;
|
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
2001-04-30 11:28:46 +00:00
|
|
|
|
color_on(bottomwin, COLOR_BOTTOMBARS);
|
2002-01-05 02:03:29 +00:00
|
|
|
|
if (!colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].set ||
|
2002-01-19 01:59:37 +00:00
|
|
|
|
colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].fg != COLOR_BLACK)
|
|
|
|
|
wattroff(bottomwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
/* Determine how many extra spaces are needed to fill the bottom of the screen */
|
2001-08-25 16:41:37 +00:00
|
|
|
|
if (slen < 2)
|
2002-02-16 20:03:44 +00:00
|
|
|
|
numcols = 6;
|
2001-08-25 16:41:37 +00:00
|
|
|
|
else
|
2002-02-16 20:03:44 +00:00
|
|
|
|
numcols = (slen + (slen % 2)) / 2;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
clear_bottomwin();
|
2001-06-14 02:54:22 +00:00
|
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
|
t = s;
|
2002-02-16 20:03:44 +00:00
|
|
|
|
for (i = 0; i < numcols; i++) {
|
|
|
|
|
for (j = 0; j <= 1; j++) {
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2002-02-16 20:03:44 +00:00
|
|
|
|
wmove(bottomwin, 1 + j, i * ((COLS - 1) / numcols));
|
2001-06-14 02:54:22 +00:00
|
|
|
|
|
2002-02-16 20:03:44 +00:00
|
|
|
|
if (t->val < 97)
|
|
|
|
|
snprintf(keystr, 10, "^%c", t->val + 64);
|
|
|
|
|
else
|
|
|
|
|
snprintf(keystr, 10, "M-%c", t->val - 32);
|
2001-06-14 02:54:22 +00:00
|
|
|
|
|
2002-02-16 20:03:44 +00:00
|
|
|
|
onekey(keystr, t->desc, (COLS - 1) / numcols);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2002-02-16 20:03:44 +00:00
|
|
|
|
if (t->next == NULL)
|
|
|
|
|
break;
|
|
|
|
|
t = t->next;
|
|
|
|
|
}
|
2002-02-15 19:17:02 +00:00
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
2001-04-30 11:28:46 +00:00
|
|
|
|
color_off(bottomwin, COLOR_BOTTOMBARS);
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wrefresh(bottomwin);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If modified is not already set, set it and update titlebar */
|
|
|
|
|
void set_modified(void)
|
|
|
|
|
{
|
|
|
|
|
if (!ISSET(MODIFIED)) {
|
|
|
|
|
SET(MODIFIED);
|
2001-01-03 07:11:47 +00:00
|
|
|
|
titlebar(NULL);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wrefresh(topwin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-08 00:41:29 +00:00
|
|
|
|
/* And so start the display update routines */
|
|
|
|
|
/* Given a column, this returns the "page" it is on */
|
|
|
|
|
/* "page" in the case of the display columns, means which set of 80 */
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* characters is viewable (e.g.: page 1 shows from 1 to COLS) */
|
2000-06-21 03:00:43 +00:00
|
|
|
|
inline int get_page_from_virtual(int virtual)
|
|
|
|
|
{
|
2000-06-06 23:04:06 +00:00
|
|
|
|
int page = 2;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (virtual <= COLS - 2)
|
|
|
|
|
return 1;
|
2000-06-07 04:40:09 +00:00
|
|
|
|
virtual -= (COLS - 2);
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
|
|
|
|
while (virtual > COLS - 2 - 7) {
|
2000-06-07 04:40:09 +00:00
|
|
|
|
virtual -= (COLS - 2 - 7);
|
2000-06-06 23:04:06 +00:00
|
|
|
|
page++;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-06 23:04:06 +00:00
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-08 00:41:29 +00:00
|
|
|
|
/* The inverse of the above function */
|
2000-06-21 03:00:43 +00:00
|
|
|
|
inline int get_page_start_virtual(int page)
|
|
|
|
|
{
|
2000-06-07 04:40:09 +00:00
|
|
|
|
int virtual;
|
|
|
|
|
virtual = --page * (COLS - 7);
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (page)
|
|
|
|
|
virtual -= 2 * page - 1;
|
2000-06-07 04:40:09 +00:00
|
|
|
|
return virtual;
|
2000-06-06 23:04:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
inline int get_page_end_virtual(int page)
|
|
|
|
|
{
|
2000-06-06 23:04:06 +00:00
|
|
|
|
return get_page_start_virtual(page) + COLS - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
2000-07-08 00:41:29 +00:00
|
|
|
|
/* This takes care of the case where there is a mark that covers only */
|
|
|
|
|
/* the current line. */
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* It expects a line with no tab characters (i.e.: the type that edit_add */
|
2000-07-08 00:41:29 +00:00
|
|
|
|
/* deals with */
|
2000-06-21 03:00:43 +00:00
|
|
|
|
void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
|
|
|
|
|
int virt_cur_x, int this_page)
|
2000-06-06 23:04:06 +00:00
|
|
|
|
{
|
2000-07-08 00:41:29 +00:00
|
|
|
|
/*
|
|
|
|
|
* The general idea is to break the line up into 3 sections: before
|
|
|
|
|
* the mark, the mark, and after the mark. We then paint each in
|
2001-05-05 17:45:54 +00:00
|
|
|
|
* turn (for those that are currently visible, of course)
|
2000-07-08 00:41:29 +00:00
|
|
|
|
*
|
|
|
|
|
* 3 start points: 0 -> begin, begin->end, end->strlen(data)
|
|
|
|
|
* in data : pre sel post
|
|
|
|
|
*/
|
2000-06-21 03:00:43 +00:00
|
|
|
|
int this_page_start = get_page_start_virtual(this_page),
|
2000-06-16 04:25:30 +00:00
|
|
|
|
this_page_end = get_page_end_virtual(this_page);
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
|
|
|
|
/* likewise, 3 data lengths */
|
2000-06-21 03:00:43 +00:00
|
|
|
|
int pre_data_len = begin, sel_data_len = end - begin, post_data_len = 0; /* Determined from the other two */
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
|
|
|
|
/* now fix the start locations & lengths according to the cursor's
|
2001-05-05 17:45:54 +00:00
|
|
|
|
* position (i.e.: our page) */
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (pre_data_len < this_page_start)
|
2000-06-17 06:06:35 +00:00
|
|
|
|
pre_data_len = 0;
|
|
|
|
|
else
|
|
|
|
|
pre_data_len -= this_page_start;
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (begin < this_page_start)
|
2000-06-17 06:06:35 +00:00
|
|
|
|
begin = this_page_start;
|
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (end < this_page_start)
|
2000-06-17 06:06:35 +00:00
|
|
|
|
end = this_page_start;
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (begin > this_page_end)
|
2000-06-17 06:06:35 +00:00
|
|
|
|
begin = this_page_end;
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (end > this_page_end)
|
2000-06-17 06:06:35 +00:00
|
|
|
|
end = this_page_end;
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
2000-07-08 00:41:29 +00:00
|
|
|
|
/* Now calculate the lengths */
|
2000-06-17 06:06:35 +00:00
|
|
|
|
sel_data_len = end - begin;
|
|
|
|
|
post_data_len = this_page_end - end;
|
2000-06-06 23:04:06 +00:00
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(edit, COLOR_MARKER);
|
|
|
|
|
#else
|
2000-06-06 23:04:06 +00:00
|
|
|
|
wattron(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2000-06-17 06:06:35 +00:00
|
|
|
|
mvwaddnstr(edit, y, begin - this_page_start,
|
2000-06-21 03:00:43 +00:00
|
|
|
|
&fileptr->data[begin], sel_data_len);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(edit, COLOR_MARKER);
|
|
|
|
|
#else
|
2000-06-06 23:04:06 +00:00
|
|
|
|
wattroff(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-07-08 00:41:29 +00:00
|
|
|
|
/* edit_add takes care of the job of actually painting a line into the
|
|
|
|
|
* edit window.
|
|
|
|
|
*
|
|
|
|
|
* Called only from update_line. Expects a converted-to-not-have-tabs
|
2000-06-16 04:25:30 +00:00
|
|
|
|
* line */
|
|
|
|
|
void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
|
2000-06-21 03:00:43 +00:00
|
|
|
|
int virt_mark_beginx, int this_page)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2001-12-08 19:52:28 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
2001-12-02 04:55:44 +00:00
|
|
|
|
colortype *tmpcolor = NULL;
|
|
|
|
|
int k, paintlen;
|
2002-01-19 16:52:34 +00:00
|
|
|
|
filestruct *e, *s;
|
|
|
|
|
regoff_t ematch, smatch;
|
2001-12-02 04:55:44 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Just paint the string in any case (we'll add color or reverse on
|
2002-01-19 01:59:37 +00:00
|
|
|
|
just the text that needs it */
|
2001-12-02 04:55:44 +00:00
|
|
|
|
mvwaddnstr(edit, yval, 0, &fileptr->data[start],
|
2002-01-19 01:59:37 +00:00
|
|
|
|
get_page_end_virtual(this_page) - start + 1);
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2001-12-08 19:52:28 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
2001-12-02 04:55:44 +00:00
|
|
|
|
if (colorstrings != NULL)
|
2002-01-19 01:59:37 +00:00
|
|
|
|
for (tmpcolor = colorstrings; tmpcolor != NULL;
|
|
|
|
|
tmpcolor = tmpcolor->next) {
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2002-01-19 16:52:34 +00:00
|
|
|
|
if (tmpcolor->end == NULL) {
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2002-01-19 16:52:34 +00:00
|
|
|
|
/* First, highlight all single-line regexes */
|
|
|
|
|
k = start;
|
2002-03-24 23:19:32 +00:00
|
|
|
|
regcomp(&color_regexp, tmpcolor->start, 0);
|
|
|
|
|
while (!regexec(&color_regexp, &fileptr->data[k], 1,
|
|
|
|
|
colormatches, 0)) {
|
2002-01-19 16:52:34 +00:00
|
|
|
|
|
2002-03-24 23:19:32 +00:00
|
|
|
|
if (colormatches[0].rm_eo - colormatches[0].rm_so < 1) {
|
2002-01-19 16:52:34 +00:00
|
|
|
|
statusbar("Refusing 0 length regex match");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-12-02 04:55:44 +00:00
|
|
|
|
#ifdef DEBUG
|
2002-01-19 16:52:34 +00:00
|
|
|
|
fprintf(stderr, "Match! (%d chars) \"%s\"\n",
|
2002-03-24 23:19:32 +00:00
|
|
|
|
colormatches[0].rm_eo - colormatches[0].rm_so,
|
|
|
|
|
&fileptr->data[k + colormatches[0].rm_so]);
|
2001-12-02 04:55:44 +00:00
|
|
|
|
#endif
|
2002-03-24 23:19:32 +00:00
|
|
|
|
if (colormatches[0].rm_so < COLS - 1) {
|
2002-01-19 16:52:34 +00:00
|
|
|
|
if (tmpcolor->bright)
|
|
|
|
|
wattron(edit, A_BOLD);
|
|
|
|
|
wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
|
|
|
|
|
|
2002-03-24 23:19:32 +00:00
|
|
|
|
if (colormatches[0].rm_eo + k <= COLS)
|
2002-01-19 16:52:34 +00:00
|
|
|
|
paintlen =
|
2002-03-24 23:19:32 +00:00
|
|
|
|
colormatches[0].rm_eo - colormatches[0].rm_so;
|
2002-01-19 16:52:34 +00:00
|
|
|
|
else
|
2002-03-24 23:19:32 +00:00
|
|
|
|
paintlen = COLS - k - colormatches[0].rm_so - 1;
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2002-03-24 23:19:32 +00:00
|
|
|
|
mvwaddnstr(edit, yval, colormatches[0].rm_so + k,
|
|
|
|
|
&fileptr->data[k + colormatches[0].rm_so],
|
2002-01-19 16:52:34 +00:00
|
|
|
|
paintlen);
|
|
|
|
|
|
|
|
|
|
}
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2002-01-19 16:52:34 +00:00
|
|
|
|
if (tmpcolor->bright)
|
|
|
|
|
wattroff(edit, A_BOLD);
|
|
|
|
|
wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2002-03-24 23:19:32 +00:00
|
|
|
|
k += colormatches[0].rm_eo;
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
}
|
2002-01-19 16:52:34 +00:00
|
|
|
|
}
|
|
|
|
|
/* Now, if there's an 'end' somewhere below, and a 'start'
|
|
|
|
|
somewhere above, things get really fun. We have to look
|
|
|
|
|
down for an end, make sure there's not a start before
|
|
|
|
|
the end after us, and then look up for a start,
|
|
|
|
|
and see if there's an end after the start, before us :) */
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
s = fileptr;
|
|
|
|
|
while (s != NULL) {
|
2002-03-24 23:19:32 +00:00
|
|
|
|
regcomp(&color_regexp, tmpcolor->start, 0);
|
2002-01-19 16:52:34 +00:00
|
|
|
|
if (!regexec
|
2002-03-24 23:19:32 +00:00
|
|
|
|
(&color_regexp, s->data, 1, colormatches, 0))
|
2002-01-19 16:52:34 +00:00
|
|
|
|
break;
|
|
|
|
|
s = s->prev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s != NULL) {
|
|
|
|
|
/* We found a start, mark it */
|
2002-03-24 23:19:32 +00:00
|
|
|
|
smatch = colormatches[0].rm_so;
|
2002-01-19 16:52:34 +00:00
|
|
|
|
|
|
|
|
|
e = s;
|
|
|
|
|
while (e != NULL && e != fileptr) {
|
2002-03-24 23:19:32 +00:00
|
|
|
|
regcomp(&color_regexp, tmpcolor->end, 0);
|
2002-01-19 16:52:34 +00:00
|
|
|
|
if (!regexec
|
2002-03-24 23:19:32 +00:00
|
|
|
|
(&color_regexp, e->data, 1, colormatches, 0))
|
2002-01-19 16:52:34 +00:00
|
|
|
|
break;
|
|
|
|
|
e = e->next;
|
|
|
|
|
}
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2002-01-19 16:52:34 +00:00
|
|
|
|
if (e != fileptr)
|
|
|
|
|
continue; /* There's an end before us */
|
|
|
|
|
else { /* Keep looking for an end */
|
|
|
|
|
while (e != NULL) {
|
2002-03-24 23:19:32 +00:00
|
|
|
|
regcomp(&color_regexp, tmpcolor->end, 0);
|
2002-01-19 16:52:34 +00:00
|
|
|
|
if (!regexec
|
2002-03-24 23:19:32 +00:00
|
|
|
|
(&color_regexp, e->data, 1, colormatches,
|
2002-01-19 16:52:34 +00:00
|
|
|
|
0))
|
|
|
|
|
break;
|
|
|
|
|
e = e->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e == NULL)
|
|
|
|
|
continue; /* There's no start before the end :) */
|
|
|
|
|
else { /* Okay, we found an end, mark it! */
|
2002-03-24 23:19:32 +00:00
|
|
|
|
ematch = colormatches[0].rm_eo;
|
2002-01-19 16:52:34 +00:00
|
|
|
|
|
|
|
|
|
while (e != NULL) {
|
2002-03-24 23:19:32 +00:00
|
|
|
|
regcomp(&color_regexp, tmpcolor->end, 0);
|
2002-01-19 16:52:34 +00:00
|
|
|
|
if (!regexec
|
2002-03-24 23:19:32 +00:00
|
|
|
|
(&color_regexp, e->data, 1,
|
|
|
|
|
colormatches, 0))
|
2002-01-19 16:52:34 +00:00
|
|
|
|
break;
|
|
|
|
|
e = e->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e == NULL)
|
|
|
|
|
continue; /* No end, oh well :) */
|
|
|
|
|
|
|
|
|
|
/* Didn't find another end, we must be in the
|
|
|
|
|
middle of a highlighted bit */
|
|
|
|
|
|
|
|
|
|
if (tmpcolor->bright)
|
|
|
|
|
wattron(edit, A_BOLD);
|
|
|
|
|
|
|
|
|
|
wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
|
|
|
|
|
|
|
|
|
|
if (s == fileptr && e == fileptr)
|
|
|
|
|
mvwaddnstr(edit, yval, start + smatch,
|
|
|
|
|
&fileptr->data[start + smatch],
|
|
|
|
|
ematch - smatch);
|
|
|
|
|
else if (s == fileptr)
|
|
|
|
|
mvwaddnstr(edit, yval, start + smatch,
|
|
|
|
|
&fileptr->data[start + smatch],
|
|
|
|
|
COLS - smatch);
|
|
|
|
|
else if (e == fileptr)
|
|
|
|
|
mvwaddnstr(edit, yval, start,
|
|
|
|
|
&fileptr->data[start],
|
|
|
|
|
ematch - start);
|
|
|
|
|
else
|
|
|
|
|
mvwaddnstr(edit, yval, start,
|
|
|
|
|
&fileptr->data[start],
|
|
|
|
|
COLS);
|
|
|
|
|
|
|
|
|
|
if (tmpcolor->bright)
|
|
|
|
|
wattroff(edit, A_BOLD);
|
|
|
|
|
|
|
|
|
|
wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Else go to the next string, yahoo! =) */
|
|
|
|
|
}
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
|
|
|
|
}
|
2002-01-19 16:52:34 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
}
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-12-08 19:52:28 +00:00
|
|
|
|
#ifndef NANO_SMALL
|
2001-12-02 04:55:44 +00:00
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* There are quite a few cases that could take place; we'll deal
|
2000-07-08 00:41:29 +00:00
|
|
|
|
* with them each in turn */
|
2002-01-19 01:59:37 +00:00
|
|
|
|
if (ISSET(MARK_ISSET) &&
|
2001-12-02 04:55:44 +00:00
|
|
|
|
!((fileptr->lineno > mark_beginbuf->lineno
|
2002-01-19 01:59:37 +00:00
|
|
|
|
&& fileptr->lineno > current->lineno)
|
|
|
|
|
|| (fileptr->lineno < mark_beginbuf->lineno
|
|
|
|
|
&& fileptr->lineno < current->lineno))) {
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* If we get here we are on a line that is at least
|
2000-10-26 01:44:42 +00:00
|
|
|
|
* partially selected. The lineno checks above determined
|
|
|
|
|
* that */
|
|
|
|
|
if (fileptr != mark_beginbuf && fileptr != current) {
|
|
|
|
|
/* We are on a completely marked line, paint it all
|
|
|
|
|
* inverse */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(edit, COLOR_MARKER);
|
|
|
|
|
#else
|
2000-10-26 01:44:42 +00:00
|
|
|
|
wattron(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2000-10-26 01:44:42 +00:00
|
|
|
|
mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(edit, COLOR_MARKER);
|
|
|
|
|
#else
|
2000-10-26 01:44:42 +00:00
|
|
|
|
wattroff(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2000-10-26 01:44:42 +00:00
|
|
|
|
} else if (fileptr == mark_beginbuf && fileptr == current) {
|
|
|
|
|
/* Special case, we're still on the same line we started
|
|
|
|
|
* marking -- so we call our helper function */
|
|
|
|
|
if (virt_cur_x < virt_mark_beginx) {
|
|
|
|
|
/* To the right of us is marked */
|
|
|
|
|
add_marked_sameline(virt_cur_x, virt_mark_beginx,
|
|
|
|
|
fileptr, yval, virt_cur_x, this_page);
|
|
|
|
|
} else {
|
|
|
|
|
/* To the left of us is marked */
|
|
|
|
|
add_marked_sameline(virt_mark_beginx, virt_cur_x,
|
|
|
|
|
fileptr, yval, virt_cur_x, this_page);
|
|
|
|
|
}
|
|
|
|
|
} else if (fileptr == mark_beginbuf) {
|
|
|
|
|
/*
|
2001-05-05 17:45:54 +00:00
|
|
|
|
* We're updating the line that was first marked,
|
2000-10-26 01:44:42 +00:00
|
|
|
|
* but we're not currently on it. So we want to
|
2001-03-31 21:46:43 +00:00
|
|
|
|
* figure out which half to invert based on our
|
2000-10-26 01:44:42 +00:00
|
|
|
|
* relative line numbers.
|
|
|
|
|
*
|
2001-05-05 17:45:54 +00:00
|
|
|
|
* I.e. if we're above the "beginbuf" line, we want to
|
|
|
|
|
* mark the left side. Otherwise, we're below, so we
|
|
|
|
|
* mark the right.
|
2000-10-26 01:44:42 +00:00
|
|
|
|
*/
|
|
|
|
|
int target;
|
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
if (mark_beginbuf->lineno > current->lineno) {
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(edit, COLOR_MARKER);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wattron(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2000-10-26 01:44:42 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
target =
|
2002-01-19 01:59:37 +00:00
|
|
|
|
(virt_mark_beginx <
|
|
|
|
|
COLS - 1) ? virt_mark_beginx : COLS - 1;
|
2000-10-26 01:44:42 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
mvwaddnstr(edit, yval, 0, fileptr->data, target);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
2001-12-02 04:55:44 +00:00
|
|
|
|
color_off(edit, COLOR_MARKER);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#else
|
2001-12-02 04:55:44 +00:00
|
|
|
|
wattroff(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mark_beginbuf->lineno < current->lineno) {
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
2001-12-02 04:55:44 +00:00
|
|
|
|
color_on(edit, COLOR_MARKER);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#else
|
2001-12-02 04:55:44 +00:00
|
|
|
|
wattron(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
target = (COLS - 1) - virt_mark_beginx;
|
2000-10-26 01:44:42 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
if (target < 0)
|
|
|
|
|
target = 0;
|
2000-10-26 01:44:42 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
mvwaddnstr(edit, yval, virt_mark_beginx,
|
2002-01-19 01:59:37 +00:00
|
|
|
|
&fileptr->data[virt_mark_beginx], target);
|
2000-10-26 01:44:42 +00:00
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(edit, COLOR_MARKER);
|
|
|
|
|
#else
|
2000-10-26 01:44:42 +00:00
|
|
|
|
wattroff(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
}
|
2000-10-26 01:44:42 +00:00
|
|
|
|
|
|
|
|
|
} else if (fileptr == current) {
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* We're on the cursor's line, but it's not the first
|
2000-10-26 01:44:42 +00:00
|
|
|
|
* one we marked. Similar to the previous logic. */
|
|
|
|
|
int this_page_start = get_page_start_virtual(this_page),
|
|
|
|
|
this_page_end = get_page_end_virtual(this_page);
|
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
if (mark_beginbuf->lineno < current->lineno) {
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(edit, COLOR_MARKER);
|
|
|
|
|
#else
|
2000-10-26 01:44:42 +00:00
|
|
|
|
wattron(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
if (virt_cur_x > COLS - 2) {
|
|
|
|
|
mvwaddnstr(edit, yval, 0,
|
2002-01-19 01:59:37 +00:00
|
|
|
|
&fileptr->data[this_page_start],
|
|
|
|
|
virt_cur_x - this_page_start);
|
2001-12-02 04:55:44 +00:00
|
|
|
|
} else
|
|
|
|
|
mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
2001-12-02 04:55:44 +00:00
|
|
|
|
color_off(edit, COLOR_MARKER);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#else
|
2001-12-02 04:55:44 +00:00
|
|
|
|
wattroff(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mark_beginbuf->lineno > current->lineno) {
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
2001-12-02 04:55:44 +00:00
|
|
|
|
color_on(edit, COLOR_MARKER);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#else
|
2001-12-02 04:55:44 +00:00
|
|
|
|
wattron(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
2001-12-02 04:55:44 +00:00
|
|
|
|
if (virt_cur_x > COLS - 2)
|
|
|
|
|
mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
|
2002-01-19 01:59:37 +00:00
|
|
|
|
&fileptr->data[virt_cur_x],
|
|
|
|
|
this_page_end - virt_cur_x);
|
2001-12-02 04:55:44 +00:00
|
|
|
|
else
|
|
|
|
|
mvwaddnstr(edit, yval, virt_cur_x,
|
2002-01-19 01:59:37 +00:00
|
|
|
|
&fileptr->data[virt_cur_x],
|
|
|
|
|
COLS - virt_cur_x);
|
2000-10-26 01:44:42 +00:00
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(edit, COLOR_MARKER);
|
|
|
|
|
#else
|
2000-10-26 01:44:42 +00:00
|
|
|
|
wattroff(edit, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
2001-11-29 02:42:27 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2000-07-08 00:41:29 +00:00
|
|
|
|
* Just update one line in the edit buffer. Basically a wrapper for
|
|
|
|
|
* edit_add
|
2000-06-06 05:53:49 +00:00
|
|
|
|
*
|
2001-05-05 17:45:54 +00:00
|
|
|
|
* index gives us a place in the string to update starting from.
|
2000-06-06 05:53:49 +00:00
|
|
|
|
* Likely args are current_x or 0.
|
|
|
|
|
*/
|
|
|
|
|
void update_line(filestruct * fileptr, int index)
|
|
|
|
|
{
|
|
|
|
|
filestruct *filetmp;
|
2000-06-16 04:25:30 +00:00
|
|
|
|
int line = 0, col = 0;
|
|
|
|
|
int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
|
|
|
|
|
char *realdata, *tmp;
|
2000-06-21 03:00:43 +00:00
|
|
|
|
int i, pos, len, page;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (!fileptr)
|
|
|
|
|
return;
|
2000-06-18 00:11:03 +00:00
|
|
|
|
|
2000-06-16 04:25:30 +00:00
|
|
|
|
/* First, blank out the line (at a minimum) */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
|
|
|
|
|
filetmp = filetmp->next)
|
|
|
|
|
line++;
|
|
|
|
|
|
|
|
|
|
mvwaddstr(edit, line, 0, hblank);
|
2000-06-16 04:25:30 +00:00
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Next, convert all the tabs to spaces, so everything else is easy */
|
2000-06-16 04:25:30 +00:00
|
|
|
|
index = xpt(fileptr, index);
|
|
|
|
|
|
|
|
|
|
realdata = fileptr->data;
|
|
|
|
|
len = strlen(realdata);
|
2001-05-17 11:35:43 +00:00
|
|
|
|
fileptr->data = charalloc(xpt(fileptr, len) + 1);
|
2000-06-16 04:25:30 +00:00
|
|
|
|
|
|
|
|
|
pos = 0;
|
2000-06-21 03:00:43 +00:00
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
if (realdata[i] == '\t') {
|
2000-06-16 04:25:30 +00:00
|
|
|
|
do {
|
|
|
|
|
fileptr->data[pos++] = ' ';
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (i < current_x)
|
|
|
|
|
virt_cur_x++;
|
|
|
|
|
if (i < mark_beginx)
|
|
|
|
|
virt_mark_beginx++;
|
2000-08-03 22:51:21 +00:00
|
|
|
|
} while (pos % tabsize);
|
2000-06-16 04:25:30 +00:00
|
|
|
|
/* must decrement once to account for tab-is-one-character */
|
2000-06-21 03:00:43 +00:00
|
|
|
|
if (i < current_x)
|
|
|
|
|
virt_cur_x--;
|
|
|
|
|
if (i < mark_beginx)
|
|
|
|
|
virt_mark_beginx--;
|
2002-03-28 01:59:34 +00:00
|
|
|
|
} else if (realdata[i] == 127) {
|
|
|
|
|
/* Treat control characters as ^symbol (ASCII 1 - 31, 127) */
|
|
|
|
|
fileptr->data[pos++] = '^';
|
|
|
|
|
fileptr->data[pos++] = '?';
|
2001-12-19 16:20:43 +00:00
|
|
|
|
} else if (realdata[i] >= 1 && realdata[i] <= 31) {
|
2000-09-02 07:55:41 +00:00
|
|
|
|
fileptr->data[pos++] = '^';
|
|
|
|
|
fileptr->data[pos++] = realdata[i] + 64;
|
2000-06-16 04:25:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
fileptr->data[pos++] = realdata[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileptr->data[pos] = '\0';
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2000-06-16 04:25:30 +00:00
|
|
|
|
/* Now, Paint the line */
|
|
|
|
|
if (current == fileptr && index > COLS - 2) {
|
2000-06-17 06:06:35 +00:00
|
|
|
|
/* This handles when the current line is beyond COLS */
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* It requires figuring out what page we're on */
|
2000-06-17 06:06:35 +00:00
|
|
|
|
page = get_page_from_virtual(index);
|
2000-06-06 23:04:06 +00:00
|
|
|
|
col = get_page_start_virtual(page);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2000-06-17 06:06:35 +00:00
|
|
|
|
edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
mvwaddch(edit, line, 0, '$');
|
|
|
|
|
|
2000-12-05 11:36:41 +00:00
|
|
|
|
if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1)
|
2000-06-21 03:00:43 +00:00
|
|
|
|
mvwaddch(edit, line, COLS - 1, '$');
|
2000-06-06 23:04:06 +00:00
|
|
|
|
} else {
|
2000-06-17 06:06:35 +00:00
|
|
|
|
/* It's not the current line means that it's at x=0 and page=1 */
|
|
|
|
|
/* If it is the current line, then we're in the same boat */
|
|
|
|
|
edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2000-06-16 04:25:30 +00:00
|
|
|
|
if (strlenpt(&filetmp->data[col]) > COLS)
|
2000-06-21 03:00:43 +00:00
|
|
|
|
mvwaddch(edit, line, COLS - 1, '$');
|
2000-06-06 23:04:06 +00:00
|
|
|
|
}
|
2000-06-16 04:25:30 +00:00
|
|
|
|
|
|
|
|
|
/* Clean up our mess */
|
|
|
|
|
tmp = fileptr->data;
|
|
|
|
|
fileptr->data = realdata;
|
|
|
|
|
free(tmp);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void center_cursor(void)
|
|
|
|
|
{
|
|
|
|
|
current_y = editwinrows / 2;
|
|
|
|
|
wmove(edit, current_y, current_x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Refresh the screen without changing the position of lines */
|
|
|
|
|
void edit_refresh(void)
|
|
|
|
|
{
|
2000-08-03 16:54:11 +00:00
|
|
|
|
static int noloop = 0;
|
2002-01-07 14:41:32 +00:00
|
|
|
|
int nlines = 0, i = 0, currentcheck = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
filestruct *temp, *hold = current;
|
|
|
|
|
|
|
|
|
|
if (current == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
temp = edittop;
|
|
|
|
|
|
2002-01-07 14:41:32 +00:00
|
|
|
|
while (nlines <= editwinrows - 1 && nlines <= totlines && temp != NULL) {
|
2000-06-06 05:53:49 +00:00
|
|
|
|
hold = temp;
|
|
|
|
|
update_line(temp, current_x);
|
2000-07-28 02:58:06 +00:00
|
|
|
|
if (temp == current)
|
|
|
|
|
currentcheck = 1;
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
temp = temp->next;
|
2002-01-07 14:41:32 +00:00
|
|
|
|
nlines++;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
2000-08-03 16:54:11 +00:00
|
|
|
|
/* If noloop == 1, then we already did an edit_update without finishing
|
|
|
|
|
this function. So we don't run edit_update again */
|
2000-10-26 01:44:42 +00:00
|
|
|
|
if (!currentcheck && !noloop) { /* Then current has run off the screen... */
|
2000-07-31 01:26:42 +00:00
|
|
|
|
edit_update(current, CENTER);
|
2000-08-03 16:54:11 +00:00
|
|
|
|
noloop = 1;
|
2000-10-26 01:44:42 +00:00
|
|
|
|
} else if (noloop)
|
2000-08-03 16:54:11 +00:00
|
|
|
|
noloop = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2002-01-07 14:41:32 +00:00
|
|
|
|
if (nlines <= editwinrows - 1)
|
|
|
|
|
while (nlines <= editwinrows - 1) {
|
|
|
|
|
mvwaddstr(edit, nlines, i, hblank);
|
|
|
|
|
nlines++;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
if (temp == NULL)
|
|
|
|
|
editbot = hold;
|
|
|
|
|
else
|
|
|
|
|
editbot = temp;
|
2001-10-22 03:15:31 +00:00
|
|
|
|
|
|
|
|
|
/* What the hell are we expecting to update the screen if this isn't
|
2002-01-19 01:59:37 +00:00
|
|
|
|
here? luck?? */
|
2001-10-22 03:15:31 +00:00
|
|
|
|
wrefresh(edit);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-19 03:53:39 +00:00
|
|
|
|
/*
|
2001-05-05 17:45:54 +00:00
|
|
|
|
* Same as above, but touch the window first, so everything is redrawn.
|
2000-08-19 03:53:39 +00:00
|
|
|
|
*/
|
|
|
|
|
void edit_refresh_clearok(void)
|
|
|
|
|
{
|
|
|
|
|
clearok(edit, TRUE);
|
|
|
|
|
edit_refresh();
|
|
|
|
|
clearok(edit, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
/*
|
2001-05-05 17:45:54 +00:00
|
|
|
|
* Nice generic routine to update the edit buffer, given a pointer to the
|
2000-06-06 05:53:49 +00:00
|
|
|
|
* file struct =)
|
|
|
|
|
*/
|
2001-07-11 02:08:33 +00:00
|
|
|
|
void edit_update(filestruct * fileptr, int topmidbotnone)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
2000-07-05 03:16:04 +00:00
|
|
|
|
int i = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
filestruct *temp;
|
|
|
|
|
|
|
|
|
|
if (fileptr == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
temp = fileptr;
|
2001-07-11 02:08:33 +00:00
|
|
|
|
if (topmidbotnone == TOP);
|
|
|
|
|
else if (topmidbotnone == NONE)
|
|
|
|
|
for (i = 0; i <= current_y - 1 && temp->prev != NULL; i++)
|
|
|
|
|
temp = temp->prev;
|
|
|
|
|
else if (topmidbotnone == BOTTOM)
|
2000-07-29 04:33:38 +00:00
|
|
|
|
for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++)
|
|
|
|
|
temp = temp->prev;
|
|
|
|
|
else
|
|
|
|
|
for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++)
|
|
|
|
|
temp = temp->prev;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2000-07-05 03:16:04 +00:00
|
|
|
|
edittop = temp;
|
|
|
|
|
fix_editbot();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
edit_refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* This function updates current, based on where current_y is; reset_cursor
|
2000-06-06 05:53:49 +00:00
|
|
|
|
does the opposite */
|
|
|
|
|
void update_cursor(void)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
|
|
|
|
|
current_x);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
current = edittop;
|
|
|
|
|
while (i <= current_y - 1 && current->next != NULL) {
|
|
|
|
|
current = current->next;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ask a question on the statusbar. Answer will be stored in answer
|
|
|
|
|
* global. Returns -1 on aborted enter, -2 on a blank string, and 0
|
2001-05-05 17:45:54 +00:00
|
|
|
|
* otherwise, the valid shortcut key caught. Def is any editable text we
|
2000-06-06 05:53:49 +00:00
|
|
|
|
* want to put up by default.
|
2000-11-06 02:57:22 +00:00
|
|
|
|
*
|
|
|
|
|
* New arg tabs tells whether or not to allow tab completion.
|
2000-06-06 05:53:49 +00:00
|
|
|
|
*/
|
2002-02-15 19:17:02 +00:00
|
|
|
|
int statusq(int tabs, shortcut *s, char *def, char *msg, ...)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
char foo[133];
|
2002-02-15 20:08:05 +00:00
|
|
|
|
int ret;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2001-11-29 03:43:08 +00:00
|
|
|
|
#ifndef DISABLE_TABCOMP
|
2002-01-05 18:59:54 +00:00
|
|
|
|
int list = 0;
|
2001-11-29 03:43:08 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
|
bottombars(s);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
vsnprintf(foo, 132, msg, ap);
|
|
|
|
|
va_end(ap);
|
2000-07-08 23:57:03 +00:00
|
|
|
|
strncat(foo, ": ", 132);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(bottomwin, COLOR_STATUSBAR);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wattron(bottomwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2001-11-29 03:43:08 +00:00
|
|
|
|
#ifndef DISABLE_TABCOMP
|
2002-02-15 19:17:02 +00:00
|
|
|
|
ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), list);
|
2001-11-29 03:43:08 +00:00
|
|
|
|
#else
|
|
|
|
|
/* if we've disabled tab completion, the value of list won't be
|
|
|
|
|
used at all, so it's safe to use 0 (NULL) as a placeholder */
|
2002-02-15 19:17:02 +00:00
|
|
|
|
ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), 0);
|
2001-11-29 03:43:08 +00:00
|
|
|
|
#endif
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(bottomwin, COLOR_STATUSBAR);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wattroff(bottomwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
|
|
|
|
|
|
case NANO_FIRSTLINE_KEY:
|
|
|
|
|
do_first_line();
|
|
|
|
|
break;
|
|
|
|
|
case NANO_LASTLINE_KEY:
|
|
|
|
|
do_last_line();
|
|
|
|
|
break;
|
|
|
|
|
case NANO_CANCEL_KEY:
|
2001-11-29 03:43:08 +00:00
|
|
|
|
#ifndef DISABLE_TABCOMP
|
|
|
|
|
/* if we've done tab completion, there might be a list of
|
|
|
|
|
filename matches on the edit window at this point; make sure
|
|
|
|
|
they're cleared off */
|
|
|
|
|
if (list)
|
|
|
|
|
edit_refresh();
|
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
return -1;
|
|
|
|
|
default:
|
2000-11-16 19:55:30 +00:00
|
|
|
|
blank_statusbar();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
fprintf(stderr, _("I got \"%s\"\n"), answer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
|
|
|
|
|
* N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
|
|
|
|
|
*/
|
|
|
|
|
int do_yesno(int all, int leavecursor, char *msg, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
char foo[133];
|
2001-02-16 01:49:31 +00:00
|
|
|
|
int kbinput, ok = -1, i;
|
|
|
|
|
char *yesstr; /* String of yes characters accepted */
|
|
|
|
|
char *nostr; /* Same for no */
|
|
|
|
|
char *allstr; /* And all, surprise! */
|
|
|
|
|
char shortstr[5]; /* Temp string for above */
|
2001-04-12 14:51:48 +00:00
|
|
|
|
#ifndef DISABLE_MOUSE
|
2001-04-12 13:24:40 +00:00
|
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
|
MEVENT mevent;
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-02-16 01:49:31 +00:00
|
|
|
|
|
|
|
|
|
/* Yes, no and all are strings of any length. Each string consists of
|
2002-01-19 01:59:37 +00:00
|
|
|
|
all characters accepted as a valid character for that value.
|
|
|
|
|
The first value will be the one displayed in the shortcuts. */
|
2001-02-16 01:49:31 +00:00
|
|
|
|
yesstr = _("Yy");
|
|
|
|
|
nostr = _("Nn");
|
|
|
|
|
allstr = _("Aa");
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
/* Write the bottom of the screen */
|
|
|
|
|
clear_bottomwin();
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(bottomwin, COLOR_BOTTOMBARS);
|
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2000-06-23 01:00:13 +00:00
|
|
|
|
/* Remove gettext call for keybindings until we clear the thing up */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
if (!ISSET(NO_HELP)) {
|
|
|
|
|
wmove(bottomwin, 1, 0);
|
2001-02-16 01:49:31 +00:00
|
|
|
|
|
|
|
|
|
snprintf(shortstr, 3, " %c", yesstr[0]);
|
2002-02-15 19:17:02 +00:00
|
|
|
|
onekey(shortstr, _("Yes"), 16);
|
2001-02-16 01:49:31 +00:00
|
|
|
|
|
|
|
|
|
if (all) {
|
|
|
|
|
snprintf(shortstr, 3, " %c", allstr[0]);
|
2002-02-15 19:17:02 +00:00
|
|
|
|
onekey(shortstr, _("All"), 16);
|
2001-02-16 01:49:31 +00:00
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wmove(bottomwin, 2, 0);
|
2001-02-16 01:49:31 +00:00
|
|
|
|
|
|
|
|
|
snprintf(shortstr, 3, " %c", nostr[0]);
|
2002-02-15 19:17:02 +00:00
|
|
|
|
onekey(shortstr, _("No"), 16);
|
2001-02-16 01:49:31 +00:00
|
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
|
onekey("^C", _("Cancel"), 16);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
vsnprintf(foo, 132, msg, ap);
|
|
|
|
|
va_end(ap);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(bottomwin, COLOR_BOTTOMBARS);
|
|
|
|
|
color_on(bottomwin, COLOR_STATUSBAR);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wattron(bottomwin, A_REVERSE);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
blank_statusbar();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
mvwaddstr(bottomwin, 0, 0, foo);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(bottomwin, COLOR_STATUSBAR);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wattroff(bottomwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wrefresh(bottomwin);
|
|
|
|
|
|
|
|
|
|
if (leavecursor == 1)
|
|
|
|
|
reset_cursor();
|
|
|
|
|
|
|
|
|
|
while (ok == -1) {
|
|
|
|
|
kbinput = wgetch(edit);
|
|
|
|
|
|
|
|
|
|
switch (kbinput) {
|
2001-04-12 14:51:48 +00:00
|
|
|
|
#ifndef DISABLE_MOUSE
|
2001-04-12 13:24:40 +00:00
|
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
|
|
|
|
case KEY_MOUSE:
|
|
|
|
|
|
|
|
|
|
/* Look ma! We get to duplicate lots of code from do_mouse!! */
|
|
|
|
|
if (getmouse(&mevent) == ERR)
|
|
|
|
|
break;
|
|
|
|
|
if (!wenclose(bottomwin, mevent.y, mevent.x) || ISSET(NO_HELP))
|
|
|
|
|
break;
|
|
|
|
|
mevent.y -= editwinrows + 3;
|
|
|
|
|
if (mevent.y < 0)
|
|
|
|
|
break;
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
/* Rather than a bunch of if statements, set up a matrix
|
|
|
|
|
of possible return keystrokes based on the x and y values */
|
|
|
|
|
if (all) {
|
|
|
|
|
char yesnosquare[2][2] = {
|
2002-01-19 01:59:37 +00:00
|
|
|
|
{yesstr[0], allstr[0]},
|
|
|
|
|
{nostr[0], NANO_CONTROL_C}
|
|
|
|
|
};
|
2001-04-12 13:24:40 +00:00
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
ungetch(yesnosquare[mevent.y][mevent.x / (COLS / 6)]);
|
2001-04-12 13:24:40 +00:00
|
|
|
|
} else {
|
|
|
|
|
char yesnosquare[2][2] = {
|
|
|
|
|
{yesstr[0], '\0'},
|
2002-01-19 01:59:37 +00:00
|
|
|
|
{nostr[0], NANO_CONTROL_C}
|
|
|
|
|
};
|
2001-04-12 13:24:40 +00:00
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
ungetch(yesnosquare[mevent.y][mevent.x / (COLS / 6)]);
|
2001-04-12 13:24:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
case NANO_CONTROL_C:
|
|
|
|
|
ok = -2;
|
|
|
|
|
break;
|
2001-02-16 01:49:31 +00:00
|
|
|
|
default:
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Look for the kbinput in the yes, no and (optimally) all str */
|
2002-01-19 01:59:37 +00:00
|
|
|
|
for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++);
|
2001-02-16 01:49:31 +00:00
|
|
|
|
if (yesstr[i] != 0) {
|
2001-02-18 05:39:41 +00:00
|
|
|
|
ok = 1;
|
2002-01-19 01:59:37 +00:00
|
|
|
|
break;
|
2001-02-16 01:49:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++);
|
2001-02-16 01:49:31 +00:00
|
|
|
|
if (nostr[i] != 0) {
|
|
|
|
|
ok = 0;
|
2002-01-19 01:59:37 +00:00
|
|
|
|
break;
|
2001-02-16 01:49:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (all) {
|
2002-01-19 01:59:37 +00:00
|
|
|
|
for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++);
|
2001-02-16 01:49:31 +00:00
|
|
|
|
if (allstr[i] != 0) {
|
|
|
|
|
ok = 2;
|
2002-01-19 01:59:37 +00:00
|
|
|
|
break;
|
2001-02-16 01:49:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Then blank the screen */
|
|
|
|
|
blank_statusbar_refresh();
|
|
|
|
|
|
|
|
|
|
if (ok == -2)
|
|
|
|
|
return -1;
|
|
|
|
|
else
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void statusbar(char *msg, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
char foo[133];
|
|
|
|
|
int start_x = 0;
|
|
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
vsnprintf(foo, 132, msg, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2001-01-20 21:40:07 +00:00
|
|
|
|
start_x = COLS / 2 - strlen(foo) / 2 - 1;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
/* Blank out line */
|
|
|
|
|
blank_statusbar();
|
|
|
|
|
|
|
|
|
|
wmove(bottomwin, 0, start_x);
|
|
|
|
|
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_on(bottomwin, COLOR_STATUSBAR);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wattron(bottomwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
waddstr(bottomwin, "[ ");
|
|
|
|
|
waddstr(bottomwin, foo);
|
|
|
|
|
waddstr(bottomwin, " ]");
|
2001-04-30 11:28:46 +00:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
color_off(bottomwin, COLOR_STATUSBAR);
|
|
|
|
|
#else
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wattroff(bottomwin, A_REVERSE);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
wrefresh(bottomwin);
|
|
|
|
|
|
|
|
|
|
if (ISSET(CONSTUPDATE))
|
|
|
|
|
statblank = 1;
|
|
|
|
|
else
|
|
|
|
|
statblank = 25;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void display_main_list(void)
|
|
|
|
|
{
|
2002-02-15 19:17:02 +00:00
|
|
|
|
bottombars(main_list);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int total_refresh(void)
|
|
|
|
|
{
|
|
|
|
|
clearok(edit, TRUE);
|
|
|
|
|
clearok(topwin, TRUE);
|
|
|
|
|
clearok(bottomwin, TRUE);
|
|
|
|
|
wnoutrefresh(edit);
|
|
|
|
|
wnoutrefresh(topwin);
|
|
|
|
|
wnoutrefresh(bottomwin);
|
|
|
|
|
doupdate();
|
|
|
|
|
clearok(edit, FALSE);
|
|
|
|
|
clearok(topwin, FALSE);
|
|
|
|
|
clearok(bottomwin, FALSE);
|
2000-08-19 03:53:39 +00:00
|
|
|
|
edit_refresh();
|
2001-01-03 07:11:47 +00:00
|
|
|
|
titlebar(NULL);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void previous_line(void)
|
|
|
|
|
{
|
|
|
|
|
if (current_y > 0)
|
|
|
|
|
current_y--;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-29 03:43:08 +00:00
|
|
|
|
int do_cursorpos(int constant)
|
2000-06-06 05:53:49 +00:00
|
|
|
|
{
|
|
|
|
|
filestruct *fileptr;
|
2002-02-12 01:57:24 +00:00
|
|
|
|
float linepct = 0.0, bytepct = 0.0, colpct = 0.0;
|
2002-01-25 21:59:02 +00:00
|
|
|
|
long i = 0, j = 0;
|
2001-11-29 03:43:08 +00:00
|
|
|
|
static long old_i = -1, old_totsize = -1;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
if (current == NULL || fileage == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2001-11-29 03:43:08 +00:00
|
|
|
|
if (old_i == -1)
|
|
|
|
|
old_i = i;
|
|
|
|
|
|
|
|
|
|
if (old_totsize == -1)
|
|
|
|
|
old_totsize = totsize;
|
|
|
|
|
|
2002-03-29 15:15:38 +00:00
|
|
|
|
colpct = 100 * (xplustabs() + 1) / (xpt(current, strlen(current->data)) + 1);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
2002-02-12 01:57:24 +00:00
|
|
|
|
for (fileptr = fileage; fileptr != current && fileptr != NULL;
|
|
|
|
|
fileptr = fileptr->next)
|
|
|
|
|
i += strlen(fileptr->data) + 1;
|
2002-01-25 21:59:02 +00:00
|
|
|
|
|
2002-02-12 01:57:24 +00:00
|
|
|
|
if (fileptr == NULL)
|
|
|
|
|
return -1;
|
2002-01-25 21:59:02 +00:00
|
|
|
|
|
2002-02-12 01:57:24 +00:00
|
|
|
|
i += current_x;
|
2002-01-25 21:59:02 +00:00
|
|
|
|
|
2002-02-12 01:57:24 +00:00
|
|
|
|
j = totsize;
|
2002-01-25 21:59:02 +00:00
|
|
|
|
|
2002-02-12 01:57:24 +00:00
|
|
|
|
if (totsize > 0)
|
|
|
|
|
bytepct = 100 * i / totsize;
|
2002-01-25 21:59:02 +00:00
|
|
|
|
|
|
|
|
|
if (totlines > 0)
|
|
|
|
|
linepct = 100 * current->lineno / totlines;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
|
|
|
|
|
linepct, bytepct);
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-11-29 03:43:08 +00:00
|
|
|
|
/* if constant is zero, display the position on the statusbar
|
|
|
|
|
unconditionally; otherwise, only display the position when the
|
|
|
|
|
character values have changed */
|
|
|
|
|
if (!constant || (old_i != i || old_totsize != totsize)) {
|
2002-01-19 01:59:37 +00:00
|
|
|
|
statusbar(_
|
2002-02-12 01:57:24 +00:00
|
|
|
|
("line %d/%d (%.0f%%), col %ld/%ld (%.0f%%), char %ld/%ld (%.0f%%)"),
|
2002-03-29 15:15:38 +00:00
|
|
|
|
current->lineno, totlines, linepct, xplustabs() + 1,
|
|
|
|
|
xpt(current, strlen(current->data)) + 1, colpct, i, j, bytepct);
|
2001-11-29 03:43:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old_i = i;
|
|
|
|
|
old_totsize = totsize;
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
reset_cursor();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-29 03:43:08 +00:00
|
|
|
|
int do_cursorpos_void(void)
|
|
|
|
|
{
|
|
|
|
|
return do_cursorpos(0);
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
/* Our broken, non-shortcut list compliant help function.
|
2001-05-05 17:45:54 +00:00
|
|
|
|
But, hey, it's better than nothing, and it's dynamic! */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
int do_help(void)
|
|
|
|
|
{
|
2001-01-12 07:51:05 +00:00
|
|
|
|
#ifndef DISABLE_HELP
|
2001-10-22 03:15:31 +00:00
|
|
|
|
char *ptr, *end;
|
2001-04-12 03:01:53 +00:00
|
|
|
|
int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
int no_help_flag = 0;
|
2001-10-22 03:15:31 +00:00
|
|
|
|
shortcut *oldshortcut;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
blank_edit();
|
|
|
|
|
curs_set(0);
|
2001-10-22 03:15:31 +00:00
|
|
|
|
wattroff(bottomwin, A_REVERSE);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
blank_statusbar();
|
|
|
|
|
|
2001-10-22 03:15:31 +00:00
|
|
|
|
help_init();
|
|
|
|
|
ptr = help_text;
|
|
|
|
|
|
|
|
|
|
oldshortcut = currshortcut;
|
|
|
|
|
|
2001-04-12 03:01:53 +00:00
|
|
|
|
currshortcut = help_list;
|
2001-05-21 12:56:25 +00:00
|
|
|
|
|
2001-01-06 18:12:43 +00:00
|
|
|
|
kp = keypad_on(edit, 1);
|
2001-04-12 03:01:53 +00:00
|
|
|
|
kp2 = keypad_on(bottomwin, 1);
|
2001-01-06 18:12:43 +00:00
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
if (ISSET(NO_HELP)) {
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Well, if we're going to do this, we should at least
|
2001-01-07 23:02:02 +00:00
|
|
|
|
do it the right way */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
no_help_flag = 1;
|
2000-06-21 03:00:43 +00:00
|
|
|
|
UNSET(NO_HELP);
|
2001-01-07 23:02:02 +00:00
|
|
|
|
window_init();
|
2002-02-15 19:17:02 +00:00
|
|
|
|
bottombars(help_list);
|
2001-01-07 23:02:02 +00:00
|
|
|
|
|
2000-06-21 03:00:43 +00:00
|
|
|
|
} else
|
2002-02-15 19:17:02 +00:00
|
|
|
|
bottombars(help_list);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
ptr = help_text;
|
|
|
|
|
switch (kbinput) {
|
2001-04-12 14:51:48 +00:00
|
|
|
|
#ifndef DISABLE_MOUSE
|
2001-04-12 03:01:53 +00:00
|
|
|
|
#ifdef NCURSES_MOUSE_VERSION
|
2002-01-19 01:59:37 +00:00
|
|
|
|
case KEY_MOUSE:
|
|
|
|
|
do_mouse();
|
|
|
|
|
break;
|
2001-04-12 03:01:53 +00:00
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
case NANO_NEXTPAGE_KEY:
|
|
|
|
|
case NANO_NEXTPAGE_FKEY:
|
|
|
|
|
case KEY_NPAGE:
|
|
|
|
|
if (!no_more) {
|
|
|
|
|
blank_edit();
|
|
|
|
|
page++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NANO_PREVPAGE_KEY:
|
|
|
|
|
case NANO_PREVPAGE_FKEY:
|
|
|
|
|
case KEY_PPAGE:
|
|
|
|
|
if (page > 1) {
|
|
|
|
|
no_more = 0;
|
|
|
|
|
blank_edit();
|
|
|
|
|
page--;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Calculate where in the text we should be, based on the page */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
for (i = 1; i < page; i++) {
|
|
|
|
|
row = 0;
|
|
|
|
|
j = 0;
|
2000-09-07 03:37:38 +00:00
|
|
|
|
|
|
|
|
|
while (row < editwinrows - 2 && *ptr != '\0') {
|
2000-06-06 05:53:49 +00:00
|
|
|
|
if (*ptr == '\n' || j == COLS - 5) {
|
|
|
|
|
j = 0;
|
|
|
|
|
row++;
|
|
|
|
|
}
|
|
|
|
|
ptr++;
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-07 03:37:38 +00:00
|
|
|
|
if (i > 1) {
|
2000-10-26 01:44:42 +00:00
|
|
|
|
|
2000-09-07 03:37:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
i = 0;
|
|
|
|
|
j = 0;
|
|
|
|
|
while (i < editwinrows && *ptr != '\0') {
|
|
|
|
|
end = ptr;
|
|
|
|
|
while (*end != '\n' && *end != '\0' && j != COLS - 5) {
|
|
|
|
|
end++;
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
if (j == COLS - 5) {
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Don't print half a word if we've run out of space */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
while (*end != ' ' && *end != '\0') {
|
|
|
|
|
end--;
|
|
|
|
|
j--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mvwaddnstr(edit, i, 0, ptr, j);
|
|
|
|
|
j = 0;
|
|
|
|
|
i++;
|
|
|
|
|
if (*end == '\n')
|
|
|
|
|
end++;
|
|
|
|
|
ptr = end;
|
|
|
|
|
}
|
|
|
|
|
if (*ptr == '\0') {
|
|
|
|
|
no_more = 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2002-01-19 01:59:37 +00:00
|
|
|
|
} while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
|
|
|
|
|
kbinput != NANO_EXIT_FKEY);
|
2000-12-18 05:03:16 +00:00
|
|
|
|
|
2001-10-22 03:15:31 +00:00
|
|
|
|
currshortcut = oldshortcut;
|
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
if (no_help_flag) {
|
2001-01-07 23:02:02 +00:00
|
|
|
|
blank_bottombars();
|
2000-06-21 03:00:43 +00:00
|
|
|
|
wrefresh(bottomwin);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
SET(NO_HELP);
|
2001-01-07 23:02:02 +00:00
|
|
|
|
window_init();
|
2002-01-19 01:59:37 +00:00
|
|
|
|
} else
|
2002-02-15 19:17:02 +00:00
|
|
|
|
bottombars(currshortcut);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
|
|
curs_set(1);
|
|
|
|
|
edit_refresh();
|
2001-01-06 18:12:43 +00:00
|
|
|
|
kp = keypad_on(edit, kp);
|
2001-04-12 03:01:53 +00:00
|
|
|
|
kp2 = keypad_on(bottomwin, kp2);
|
2001-01-06 18:12:43 +00:00
|
|
|
|
|
2000-12-10 17:03:25 +00:00
|
|
|
|
#elif defined(DISABLE_HELP)
|
|
|
|
|
nano_disabled_msg();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Dump the current file structure to stderr */
|
|
|
|
|
void dump_buffer(filestruct * inptr)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
filestruct *fileptr;
|
|
|
|
|
|
|
|
|
|
if (inptr == fileage)
|
|
|
|
|
fprintf(stderr, _("Dumping file buffer to stderr...\n"));
|
|
|
|
|
else if (inptr == cutbuffer)
|
|
|
|
|
fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
|
|
|
|
|
else
|
|
|
|
|
fprintf(stderr, _("Dumping a buffer to stderr...\n"));
|
|
|
|
|
|
|
|
|
|
fileptr = inptr;
|
|
|
|
|
while (fileptr != NULL) {
|
2001-10-22 03:15:31 +00:00
|
|
|
|
fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
fflush(stderr);
|
|
|
|
|
fileptr = fileptr->next;
|
|
|
|
|
}
|
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dump_buffer_reverse(filestruct * inptr)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
filestruct *fileptr;
|
|
|
|
|
|
|
|
|
|
fileptr = filebot;
|
|
|
|
|
while (fileptr != NULL) {
|
2001-10-22 03:15:31 +00:00
|
|
|
|
fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
fflush(stderr);
|
|
|
|
|
fileptr = fileptr->prev;
|
|
|
|
|
}
|
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
}
|
2000-07-04 02:35:19 +00:00
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* Fix editbot, based on the assumption that edittop is correct */
|
2000-10-26 01:44:42 +00:00
|
|
|
|
void fix_editbot(void)
|
|
|
|
|
{
|
2000-07-04 02:35:19 +00:00
|
|
|
|
int i;
|
|
|
|
|
editbot = edittop;
|
2000-10-26 01:44:42 +00:00
|
|
|
|
for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
|
|
|
|
|
&& (editbot != filebot); i++, editbot = editbot->next);
|
2000-07-04 02:35:19 +00:00
|
|
|
|
}
|
2000-11-24 20:45:14 +00:00
|
|
|
|
|
2000-12-05 11:36:41 +00:00
|
|
|
|
/* highlight the current word being replaced or spell checked */
|
|
|
|
|
void do_replace_highlight(int highlight_flag, char *word)
|
|
|
|
|
{
|
|
|
|
|
char *highlight_word = NULL;
|
|
|
|
|
int x, y;
|
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
highlight_word =
|
|
|
|
|
mallocstrcpy(highlight_word, ¤t->data[current_x]);
|
2000-12-05 11:36:41 +00:00
|
|
|
|
highlight_word[strlen(word)] = '\0';
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* adjust output when word extends beyond screen */
|
2000-12-05 11:36:41 +00:00
|
|
|
|
|
|
|
|
|
x = xplustabs();
|
|
|
|
|
y = get_page_end_virtual(get_page_from_virtual(x)) + 1;
|
|
|
|
|
|
|
|
|
|
if ((COLS - (y - x) + strlen(word)) > COLS) {
|
|
|
|
|
highlight_word[y - x - 1] = '$';
|
|
|
|
|
highlight_word[y - x] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* OK display the output */
|
|
|
|
|
|
|
|
|
|
reset_cursor();
|
2002-01-19 01:59:37 +00:00
|
|
|
|
|
2000-12-05 11:36:41 +00:00
|
|
|
|
if (highlight_flag)
|
|
|
|
|
wattron(edit, A_REVERSE);
|
|
|
|
|
|
|
|
|
|
waddstr(edit, highlight_word);
|
|
|
|
|
|
|
|
|
|
if (highlight_flag)
|
|
|
|
|
wattroff(edit, A_REVERSE);
|
|
|
|
|
|
|
|
|
|
free(highlight_word);
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-24 20:45:14 +00:00
|
|
|
|
#ifdef NANO_EXTRA
|
2002-03-16 01:03:41 +00:00
|
|
|
|
#define CREDIT_LEN 52
|
2000-11-24 20:45:14 +00:00
|
|
|
|
void do_credits(void)
|
|
|
|
|
{
|
2000-11-25 18:21:37 +00:00
|
|
|
|
int i, j = 0, k, place = 0, start_x;
|
2000-11-24 20:45:14 +00:00
|
|
|
|
char *what;
|
|
|
|
|
|
|
|
|
|
char *nanotext = _("The nano text editor");
|
|
|
|
|
char *version = _("version ");
|
|
|
|
|
char *brought = _("Brought to you by:");
|
|
|
|
|
char *specialthx = _("Special thanks to:");
|
|
|
|
|
char *fsf = _("The Free Software Foundation");
|
2002-03-16 01:03:41 +00:00
|
|
|
|
char *ncurses = _("For ncurses:");
|
2000-11-24 20:45:14 +00:00
|
|
|
|
char *anyonelse = _("and anyone else we forgot...");
|
|
|
|
|
char *thankyou = _("Thank you for using nano!\n");
|
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
char *credits[CREDIT_LEN] = { nanotext,
|
|
|
|
|
version,
|
|
|
|
|
VERSION,
|
|
|
|
|
"",
|
|
|
|
|
brought,
|
|
|
|
|
"Chris Allegretta",
|
|
|
|
|
"Jordi Mallach",
|
|
|
|
|
"Adam Rogoyski",
|
|
|
|
|
"Rob Siemborski",
|
|
|
|
|
"Rocco Corsi",
|
2002-02-15 19:17:02 +00:00
|
|
|
|
"David Lawrence Ramsey",
|
2002-01-19 01:59:37 +00:00
|
|
|
|
"Ken Tyler",
|
|
|
|
|
"Sven Guckes",
|
|
|
|
|
"Florian K<>nig",
|
|
|
|
|
"Pauli Virtanen",
|
|
|
|
|
"Daniele Medri",
|
|
|
|
|
"Clement Laforet",
|
|
|
|
|
"Tedi Heriyanto",
|
|
|
|
|
"Bill Soudan",
|
|
|
|
|
"Christian Weisgerber",
|
|
|
|
|
"Erik Andersen",
|
|
|
|
|
"Big Gaute",
|
|
|
|
|
"Joshua Jensen",
|
|
|
|
|
"Ryan Krebs",
|
|
|
|
|
"Albert Chin",
|
|
|
|
|
"",
|
|
|
|
|
specialthx,
|
|
|
|
|
"Plattsburgh State University",
|
|
|
|
|
"Benet Laboratories",
|
|
|
|
|
"Amy Allegretta",
|
|
|
|
|
"Linda Young",
|
|
|
|
|
"Jeremy Robichaud",
|
|
|
|
|
"Richard Kolb II",
|
|
|
|
|
fsf,
|
|
|
|
|
"Linus Torvalds",
|
|
|
|
|
ncurses,
|
2002-03-16 01:03:41 +00:00
|
|
|
|
"Thomas Dickey",
|
|
|
|
|
"Pavel Curtis",
|
|
|
|
|
"Zeyd Ben-Halim",
|
|
|
|
|
"Eric S. Raymond",
|
2002-01-19 01:59:37 +00:00
|
|
|
|
anyonelse,
|
|
|
|
|
thankyou,
|
|
|
|
|
"", "", "", "",
|
|
|
|
|
"(c) 1999-2002 Chris Allegretta",
|
|
|
|
|
"", "", "", "",
|
|
|
|
|
"www.nano-editor.org"
|
2000-11-24 20:45:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
curs_set(0);
|
|
|
|
|
nodelay(edit, TRUE);
|
|
|
|
|
blank_bottombars();
|
|
|
|
|
mvwaddstr(topwin, 0, 0, hblank);
|
2000-11-25 18:21:37 +00:00
|
|
|
|
blank_edit();
|
|
|
|
|
wrefresh(edit);
|
2000-11-24 20:45:14 +00:00
|
|
|
|
wrefresh(bottomwin);
|
|
|
|
|
wrefresh(topwin);
|
|
|
|
|
|
|
|
|
|
while (wgetch(edit) == ERR) {
|
2000-11-25 18:21:37 +00:00
|
|
|
|
for (k = 0; k <= 1; k++) {
|
|
|
|
|
blank_edit();
|
2002-01-19 01:59:37 +00:00
|
|
|
|
for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j);
|
|
|
|
|
i--) {
|
2000-11-25 18:21:37 +00:00
|
|
|
|
mvwaddstr(edit, i * 2 - k, 0, hblank);
|
|
|
|
|
|
|
|
|
|
if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
|
|
|
|
|
what = credits[place - (editwinrows / 2 - 1 - i)];
|
|
|
|
|
else
|
|
|
|
|
what = "";
|
|
|
|
|
|
2001-01-20 21:40:07 +00:00
|
|
|
|
start_x = COLS / 2 - strlen(what) / 2 - 1;
|
2000-11-25 18:21:37 +00:00
|
|
|
|
mvwaddstr(edit, i * 2 - k, start_x, what);
|
|
|
|
|
}
|
|
|
|
|
usleep(700000);
|
|
|
|
|
wrefresh(edit);
|
2000-11-24 20:45:14 +00:00
|
|
|
|
}
|
|
|
|
|
if (j < editwinrows / 2 - 1)
|
|
|
|
|
j++;
|
|
|
|
|
|
|
|
|
|
place++;
|
|
|
|
|
|
|
|
|
|
if (place >= CREDIT_LEN + editwinrows / 2)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nodelay(edit, FALSE);
|
|
|
|
|
curs_set(1);
|
|
|
|
|
display_main_list();
|
|
|
|
|
total_refresh();
|
2002-01-19 01:59:37 +00:00
|
|
|
|
}
|
2000-11-24 20:45:14 +00:00
|
|
|
|
#endif
|
2001-01-06 18:12:43 +00:00
|
|
|
|
|
2002-01-19 01:59:37 +00:00
|
|
|
|
int keypad_on(WINDOW * win, int newval)
|
2001-01-06 18:12:43 +00:00
|
|
|
|
{
|
|
|
|
|
|
2001-05-05 17:45:54 +00:00
|
|
|
|
/* This is taken right from aumix. Don't sue me. */
|
2001-01-06 18:12:43 +00:00
|
|
|
|
#ifdef HAVE_USEKEYPAD
|
2002-01-19 01:59:37 +00:00
|
|
|
|
int old;
|
2001-01-06 18:12:43 +00:00
|
|
|
|
|
|
|
|
|
old = win->_use_keypad;
|
2001-03-18 16:59:34 +00:00
|
|
|
|
keypad(win, newval);
|
2001-01-06 18:12:43 +00:00
|
|
|
|
return old;
|
|
|
|
|
#else
|
2001-03-18 16:59:34 +00:00
|
|
|
|
keypad(win, newval);
|
2001-01-06 18:12:43 +00:00
|
|
|
|
return 1;
|
2002-01-19 01:59:37 +00:00
|
|
|
|
#endif /* HAVE_USEKEYPAD */
|
2001-01-06 18:12:43 +00:00
|
|
|
|
|
|
|
|
|
}
|