in do_cursorpos(), if constant is TRUE, only display the cursor position

when disable_cursorpos is FALSE; don't refuse to display it when the
cursor position hasn't changed, as that doesn't always keep it properly
updated


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2791 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2005-06-28 20:04:14 +00:00
parent a96c819b50
commit 4e05b755ed
2 changed files with 24 additions and 33 deletions

View File

@ -353,6 +353,10 @@ CVS code -
takes up, in case it's UTF-8. (DLR) takes up, in case it's UTF-8. (DLR)
do_cursorpos() do_cursorpos()
- Properly display the value of totsize as unsigned. (DLR) - Properly display the value of totsize as unsigned. (DLR)
- If constant is TRUE, only display the cursor position when
disable_cursorpos is FALSE. Don't refuse to display it when
the cursor position hasn't changed, as that doesn't always
keep it properly updated. (DLR, found by Mike Frysinger)
do_help() do_help()
- Don't treat NANO_CANCEL_KEY as NANO_EXIT_KEY anymore, for - Don't treat NANO_CANCEL_KEY as NANO_EXIT_KEY anymore, for
consistency. (DLR) consistency. (DLR)

View File

@ -3767,25 +3767,22 @@ void display_main_list(void)
bottombars(main_list); bottombars(main_list);
} }
/* If constant is FALSE, the user typed Ctrl-C, so we unconditionally /* If constant is TRUE, we display the current cursor position only if
* display the cursor position. Otherwise, we display it only if the * disable_cursorpos is FALSE. Otherwise, we display it
* character position changed and disable_cursorpos is FALSE. * unconditionally and set disable_cursorpos to FALSE. If constant is
* * TRUE and disable_cursorpos is TRUE, we also set disable_cursorpos to
* If constant is TRUE and disable_cursorpos is TRUE, we set the latter * FALSE, so that we leave the current statusbar alone this time, and
* to FALSE and update old_i and old_totsize. That way, we leave the * display the current cursor position next time. */
* current statusbar alone, but next time we will display. */
void do_cursorpos(bool constant) void do_cursorpos(bool constant)
{ {
char c; char c;
filestruct *f; filestruct *f;
size_t i = 0; size_t i, cur_xpt = xplustabs() + 1;
static size_t old_i = 0, old_totsize = (size_t)-1; size_t cur_lenpt = strlenpt(current->data) + 1;
int linepct, colpct, charpct;
assert(current != NULL && fileage != NULL && totlines != 0); assert(current != NULL && fileage != NULL && totlines != 0);
if (old_totsize == (size_t)-1)
old_totsize = totsize;
c = current->data[current_x]; c = current->data[current_x];
f = current->next; f = current->next;
current->data[current_x] = '\0'; current->data[current_x] = '\0';
@ -3800,32 +3797,22 @@ void do_cursorpos(bool constant)
if (constant && disable_cursorpos) { if (constant && disable_cursorpos) {
disable_cursorpos = FALSE; disable_cursorpos = FALSE;
old_i = i;
old_totsize = totsize;
return; return;
} }
/* If constant is FALSE, display the position on the statusbar /* Display the current cursor position on the statusbar, and set
* unconditionally. Otherwise, only display the position when the * disable_cursorpos to FALSE. */
* character values have changed. Finally, if disable_cursorpos is linepct = 100 * current->lineno / totlines;
* TRUE, set it to FALSE. */ colpct = 100 * cur_xpt / cur_lenpt;
if (!constant || old_i != i || old_totsize != totsize) { charpct = (totsize == 0) ? 0 : 100 * i / totsize;
size_t xpt = xplustabs() + 1;
size_t cur_len = strlenpt(current->data) + 1;
int linepct = 100 * current->lineno / totlines;
int colpct = 100 * xpt / cur_len;
int bytepct = (totsize == 0) ? 0 : 100 * i / totsize;
statusbar( statusbar(
_("line %ld/%lu (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"), _("line %ld/%lu (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"),
(long)current->lineno, (unsigned long)totlines, linepct, (long)current->lineno, (unsigned long)totlines, linepct,
(unsigned long)xpt, (unsigned long)cur_len, colpct, (unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct,
(unsigned long)i, (unsigned long)totsize, bytepct); (unsigned long)i, (unsigned long)totsize, charpct);
disable_cursorpos = FALSE;
}
old_i = i; disable_cursorpos = FALSE;
old_totsize = totsize;
} }
void do_cursorpos_void(void) void do_cursorpos_void(void)