- nano.c:do_help () - Fix line lengths not being computed properly, causes display glitches most noticeable with < 20 rows. New function nano.c:line_len(). (David Benbennick)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1444 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2003-02-10 03:10:03 +00:00
parent a90d0cf214
commit 4640fe3f57
3 changed files with 42 additions and 33 deletions

View File

@ -21,6 +21,10 @@ CVS code
(David Benbennick). (David Benbennick).
help_init() help_init()
- Fix crashing in do_help when COLS < 23 (David Benbennick). - Fix crashing in do_help when COLS < 23 (David Benbennick).
do_help()
- Fix line lengths not being computed properly, causes display
glitches most noticeable with < 20 rows. New function
nano.c:line_len(). (David Benbennick).
- rcfile.c: - rcfile.c:
colortoint() colortoint()
- Don't bomb after invalid color and print bad color name - Don't bomb after invalid color and print bad color name

View File

@ -472,6 +472,7 @@ void display_main_list(void);
void statusbar(const char *msg, ...); void statusbar(const char *msg, ...);
int do_cursorpos(int constant); int do_cursorpos(int constant);
int do_cursorpos_void(void); int do_cursorpos_void(void);
int line_len(const char *ptr);
int do_help(void); int do_help(void);
int keypad_on(WINDOW *win, int newval); int keypad_on(WINDOW *win, int newval);
void do_replace_highlight(int highlight_flag, const char *word); void do_replace_highlight(int highlight_flag, const char *word);

70
winio.c
View File

@ -1453,12 +1453,38 @@ int do_cursorpos_void(void)
return do_cursorpos(0); return do_cursorpos(0);
} }
/* Calculate the next line of help_text, starting at ptr. */
int line_len(const char *ptr)
{
int j = 0;
while (*ptr != '\n' && *ptr != '\0' && j < COLS - 5) {
ptr++;
j++;
}
if (j == COLS - 5) {
/* Don't wrap at the first of two spaces following a period. */
if (*ptr == ' ' && *(ptr + 1) == ' ')
j++;
/* Don't print half a word if we've run out of space */
while (*ptr != ' ' && j > 0) {
ptr--;
j--;
}
/* Word longer than COLS - 5 chars just gets broken */
if (j == 0)
j = COLS - 5;
}
assert(j >= 0 && j <= COLS - 4 && (j > 0 || *ptr == '\n'));
return j;
}
/* Our shortcut-list-compliant help function, which is /* Our shortcut-list-compliant help function, which is
* better than nothing, and dynamic! */ * better than nothing, and dynamic! */
int do_help(void) int do_help(void)
{ {
#ifndef DISABLE_HELP #ifndef DISABLE_HELP
int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2; int i, page = 0, kbinput = 0, no_more = 0, kp, kp2;
int no_help_flag = 0; int no_help_flag = 0;
const shortcut *oldshortcut; const shortcut *oldshortcut;
@ -1538,7 +1564,7 @@ int do_help(void)
case NANO_PREVPAGE_FKEY: case NANO_PREVPAGE_FKEY:
case KEY_PPAGE: case KEY_PPAGE:
do_pageupkey: do_pageupkey:
if (page > 1) { if (page > 0) {
no_more = 0; no_more = 0;
blank_edit(); blank_edit();
page--; page--;
@ -1547,43 +1573,21 @@ int do_help(void)
} }
/* Calculate where in the text we should be, based on the page */ /* Calculate where in the text we should be, based on the page */
for (i = 1; i < page; i++) { for (i = 1; i < page * (editwinrows - 1); i++) {
row = 0; ptr += line_len(ptr);
j = 0; if (*ptr == '\n')
while (row < editwinrows - 2 && *ptr != '\0') {
if (*ptr == '\n' || j == COLS - 5) {
j = 0;
row++;
}
ptr++; ptr++;
j++;
}
} }
i = 0; for (i = 0; i < editwinrows && *ptr != '\0'; i++) {
j = 0; int j = line_len(ptr);
while (i < editwinrows && *ptr != '\0') {
const char *end = ptr;
while (*end != '\n' && *end != '\0' && j != COLS - 5) {
end++;
j++;
}
if (j == COLS - 5) {
/* Don't print half a word if we've run out of space */
while (*end != ' ' && *end != '\0') {
end--;
j--;
}
}
mvwaddnstr(edit, i, 0, ptr, j); mvwaddnstr(edit, i, 0, ptr, j);
j = 0; ptr += j;
i++; if (*ptr == '\n')
if (*end == '\n') ptr++;
end++;
ptr = end;
} }
if (*ptr == '\0') { if (*ptr == '\0') {
no_more = 1; no_more = 1;
continue; continue;