- Fix constant curos updates from obliterating other system messages, and fix statusbar message length. Affects files.c:load_open_file(), nano.c:main(), search.c:findnextstr(), winio.c:statusbar() and do_cursorpos() (David Benbennick)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1403 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2003-01-28 01:16:47 +00:00
parent 416896efcd
commit d26ab913f1
5 changed files with 49 additions and 58 deletions

View File

@ -12,6 +12,11 @@ CVS Code -
of nanogetstr with keys like ^Y and ^V. New arg of nanogetstr with keys like ^Y and ^V. New arg
resetpos to nanogetstr(), added static int resetpos to nanogetstr(), added static int
resetpos in statusq() (bug found by DLR). resetpos in statusq() (bug found by DLR).
- Fix constant curos updates from obliterating other
system messages, and fix statusbar message length.
Affects files.c:load_open_file(), nano.c:main(),
search.c:findnextstr(), winio.c:statusbar() and
do_cursorpos() (David Benbennick).
- cut.c: - cut.c:
do_cut_text() do_cut_text()
- Fix incorrect cursor location when cutting long lines - Fix incorrect cursor location when cutting long lines

View File

@ -840,13 +840,6 @@ int load_open_file(void)
clearok(topwin, FALSE); clearok(topwin, FALSE);
titlebar(NULL); titlebar(NULL);
/* if we're constantly displaying the cursor position and
DISABLE_CURPOS isn't set, update it (and do so unconditionally,
in the rare case that the character count is the same but the
line count isn't) */
if (ISSET(CONSTUPDATE) && !ISSET(DISABLE_CURPOS))
do_cursorpos(0);
/* now we're done */ /* now we're done */
return 0; return 0;
} }

8
nano.c
View File

@ -3451,6 +3451,9 @@ int main(int argc, char *argv[])
int keyhandled = 0; /* Have we handled the keystroke yet? */ int keyhandled = 0; /* Have we handled the keystroke yet? */
int kbinput; /* Input from keyboard */ int kbinput; /* Input from keyboard */
if (ISSET(CONSTUPDATE))
do_cursorpos(1);
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)) #if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
currshortcut = main_list; currshortcut = main_list;
#endif #endif
@ -3751,11 +3754,6 @@ int main(int argc, char *argv[])
do_char(kbinput); do_char(kbinput);
} }
if (ISSET(DISABLE_CURPOS))
UNSET(DISABLE_CURPOS);
else if (ISSET(CONSTUPDATE))
do_cursorpos(1);
reset_cursor(); reset_cursor();
wrefresh(edit); wrefresh(edit);
} }

View File

@ -270,10 +270,8 @@ filestruct *findnextstr(int quiet, int bracket_mode,
return NULL; return NULL;
fileptr = fileage; fileptr = fileage;
search_offscreen = 1; search_offscreen = 1;
if (!quiet) { if (!quiet)
statusbar(_("Search Wrapped")); statusbar(_("Search Wrapped"));
SET(DISABLE_CURPOS);
}
} }
/* Original start line reached */ /* Original start line reached */
@ -324,10 +322,8 @@ filestruct *findnextstr(int quiet, int bracket_mode,
return NULL; return NULL;
fileptr = filebot; fileptr = filebot;
search_offscreen = 1; search_offscreen = 1;
if (!quiet) { if (!quiet)
statusbar(_("Search Wrapped")); statusbar(_("Search Wrapped"));
SET(DISABLE_CURPOS);
}
} }
/* Original start line reached */ /* Original start line reached */
if (fileptr == begin) if (fileptr == begin)

79
winio.c
View File

@ -1417,67 +1417,66 @@ void statusbar(const char *msg, ...)
wrefresh(bottomwin); wrefresh(bottomwin);
if (ISSET(CONSTUPDATE)) SET(DISABLE_CURPOS);
statblank = 1; statblank = 26;
else
statblank = 25;
} }
/*
* If constant is false, the user typed ^C so we unconditionally display
* the cursor position. Otherwise, we display it only if the character
* position changed, and DISABLE_CURPOS is not set.
*
* If constant and DISABLE_CURPOS is set, we unset it and update old_i and
* old_totsize. That way, we leave the current statusbar alone, but next
* time we will display. */
int do_cursorpos(int constant) int do_cursorpos(int constant)
{ {
filestruct *fileptr; const filestruct *fileptr;
float linepct = 0.0, bytepct = 0.0, colpct = 0.0; unsigned long i = 0;
long i = 0, j = 0; static unsigned long old_i = 0;
static long old_i = -1, old_totsize = -1; static long old_totsize = -1;
if (current == NULL || fileage == NULL) assert(current != NULL && fileage != NULL && totlines != 0);
return 0;
if (old_i == -1)
old_i = i;
if (old_totsize == -1) if (old_totsize == -1)
old_totsize = totsize; old_totsize = totsize;
colpct = 100 * (xplustabs() + 1) / (strlenpt(current->data) + 1); for (fileptr = fileage; fileptr != current; fileptr = fileptr->next) {
assert(fileptr != NULL);
for (fileptr = fileage; fileptr != current && fileptr != NULL;
fileptr = fileptr->next)
i += strlen(fileptr->data) + 1; i += strlen(fileptr->data) + 1;
}
if (fileptr == NULL)
return -1;
i += current_x; i += current_x;
j = totsize; if (constant && ISSET(DISABLE_CURPOS)) {
UNSET(DISABLE_CURPOS);
old_i = i;
old_totsize = totsize;
return 0;
}
if (totsize > 0) /* if constant is false, display the position on the statusbar
bytepct = 100 * i / totsize;
if (totlines > 0)
linepct = 100 * current->lineno / totlines;
#ifdef DEBUG
fprintf(stderr, "%s: linepct = %f, bytepct = %f\n",
"do_cursorpos()", linepct, bytepct);
#endif
/* if constant is zero, display the position on the statusbar
unconditionally; otherwise, only display the position when the unconditionally; otherwise, only display the position when the
character values have changed */ character values have changed */
if (!constant || (old_i != i || old_totsize != totsize)) { if (!constant || old_i != i || old_totsize != totsize) {
statusbar(_ unsigned long xpt = xplustabs() + 1;
("line %d/%d (%.0f%%), col %ld/%ld (%.0f%%), char %ld/%ld (%.0f%%)"), unsigned long cur_len = strlenpt(current->data) + 1;
current->lineno, totlines, linepct, xplustabs() + 1, int linepct = 100 * current->lineno / totlines;
strlenpt(current->data) + 1, colpct, i, j, bytepct); int colpct = 100 * xpt / cur_len;
int bytepct = totsize == 0 ? 0 : 100 * i / totsize;
statusbar(
_("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%ld (%d%%)"),
current->lineno, totlines, linepct,
xpt, cur_len, colpct,
i, totsize, bytepct);
UNSET(DISABLE_CURPOS);
} }
old_i = i; old_i = i;
old_totsize = totsize; old_totsize = totsize;
reset_cursor(); reset_cursor();
return 1; return 0;
} }
int do_cursorpos_void(void) int do_cursorpos_void(void)