sfeed_curses

[fork] sfeed (atom feed) reader
Log | Files | Refs | README | LICENSE

commit 9479b0a262dfff16c1d81bb3a6880ca216d8526c
parent 895e138a5bcd298524c80112197799c3aae87c5e
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed, 24 Jun 2020 20:20:24 +0200

feed_load: fix an issue of using the previous position and redrawing an invalid row

Validate row positions better and make the pane_row_draw function more robust.

Diffstat:
Msfeed_curses.c | 19++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -468,14 +468,19 @@ plumb(char *url) struct row * pane_row_get(struct pane *p, off_t pos) { + if (pos >= p->nrows) + return NULL; return p->rows + pos; } void pane_row_draw(struct pane *p, off_t pos) { + struct row *row; int r = 0, y; + row = pane_row_get(p, pos); + y = p->y + (pos % p->height); /* relative position on screen */ putp(tparm(cursor_address, y, p->x, 0, 0, 0, 0, 0, 0, 0)); @@ -485,11 +490,14 @@ pane_row_draw(struct pane *p, off_t pos) else putp("\x1b[2;7m"); /* gray, standout */ r = 1; - } else if (p->nrows && pos < p->nrows && p->rows[pos].bold) { + } else if (p->nrows && pos < p->nrows && row && row->bold) { putp("\x1b[1m"); /* bold */ r = 1; } - printpad(p->rows[pos].text, p->width); + if (row) + printpad(row->text, p->width); + else + printpad("", p->width); if (r) putp("\x1b[0m"); } @@ -937,6 +945,9 @@ feed_load(struct feed *f, FILE *fp) for (i = 0; i < nitems; i++) f->totalnew += items[i].isnew; + p->pos = 0; + p->selected = 0; + p->nrows = nitems; p->rows = ecalloc(sizeof(p->rows[0]), nitems + 1); for (i = 0; i < nitems; i++) { row = pane_row_get(p, i); @@ -944,9 +955,7 @@ feed_load(struct feed *f, FILE *fp) row->bold = items[i].isnew; row->data = &items[i]; } - p->nrows = nitems; - pane_setpos(p, 0); - p->selected = 0; + p->dirty = 1; } void