sfeed_curses

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

commit 270546b707c2cccf5e15b6e4923378963093824e
parent 3812fe82c20f338fc726268e03c62a482f26de9d
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue, 30 Jun 2020 11:44:30 +0200

shuffle some global variables and functions

* Order it in: enums, structs, function definitions, variables.
* Try to regroup each type in UI / data a bit too.
* Move `usemouse` and `onlynew` from the configuration. It was not
  intended to change onlynew as the default.

Diffstat:
Msfeed_curses.c | 79+++++++++++++++++++++++++++++++++++++------------------------------------------
1 file changed, 37 insertions(+), 42 deletions(-)

diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -20,13 +20,13 @@ #define LEN(a) sizeof((a))/sizeof((a)[0]) +enum Pane { PaneFeeds, PaneItems, PaneLast }; + enum { FieldUnixTimestamp = 0, FieldTitle, FieldLink, FieldContent, FieldContentType, FieldId, FieldAuthor, FieldEnclosure, FieldLast }; -enum Pane { PaneFeeds, PaneItems, PaneLast }; - struct win { int width; int height; @@ -39,17 +39,6 @@ struct row { void *data; }; -struct scrollbar { - int tickpos; - int ticksize; - int x; /* absolute x position of the window on the screen */ - int y; /* absolute y position of the window on the screen */ - int size; /* absolute size of the bar */ - int focused; /* has focus or not */ - int hidden; /* is visible or not */ - int dirty; /* needs draw update */ -}; - struct pane { int x; /* absolute x position of the window on the screen */ int y; /* absolute y position of the window on the screen */ @@ -67,6 +56,17 @@ struct pane { int (*row_match)(struct pane *, struct row *, const char *); }; +struct scrollbar { + int tickpos; + int ticksize; + int x; /* absolute x position of the window on the screen */ + int y; /* absolute y position of the window on the screen */ + int size; /* absolute size of the bar */ + int focused; /* has focus or not */ + int hidden; /* is visible or not */ + int dirty; /* needs draw update */ +}; + struct statusbar { int x; /* absolute x position of the window on the screen */ int y; /* absolute y position of the window on the screen */ @@ -76,6 +76,26 @@ struct statusbar { int dirty; /* needs draw update */ }; +/* /UI */ + +/* feed info */ +struct feed { + char *name; /* feed name */ + char *path; /* path to feed or NULL from stdin */ + unsigned long totalnew; /* amount of new items per feed */ + unsigned long total; /* total items */ + FILE *fp; /* file pointer */ +}; + +struct item { + char *fields[FieldLast]; + char *line; /* allocated split line */ + time_t timestamp; + struct tm tm; + int isnew; + off_t offset; /* line offset in file */ +}; + #undef err void err(int, const char *, ...); @@ -83,8 +103,6 @@ void alldirty(void); void cleanup(void); void draw(void); void pane_draw(struct pane *); -void pane_setpos(struct pane *p, off_t pos); -void statusbar_draw(struct statusbar *); void sighandler(int); void updategeom(void); void updatesidebar(int); @@ -94,53 +112,30 @@ static struct pane panes[PaneLast]; static struct scrollbar scrollbars[PaneLast]; /* each pane has a scrollbar */ static struct win win; static size_t selpane; +static int usemouse = 1; /* use xterm mouse tracking */ +static int onlynew = 0; /* show only new in sidebar */ static struct termios tsave; /* terminal state at startup */ static struct termios tcur; - static struct winsize winsz; /* window size information */ static int ttyfd = 0; /* fd of tty */ static int devnullfd; - static int needcleanup; -/* feed info */ -struct feed { - char *name; /* feed name */ - char *path; /* path to feed or NULL from stdin */ - unsigned long totalnew; /* amount of new items per feed */ - unsigned long total; /* total items */ - FILE *fp; /* file pointer */ -}; - static struct feed *feeds; static struct feed *curfeed; static size_t nfeeds; /* amount of feeds */ - static time_t comparetime; -struct item { - char *fields[FieldLast]; - char *line; /* allocated split line */ - time_t timestamp; - struct tm tm; - int isnew; - off_t offset; /* line offset in file */ -}; - /* config */ -/* use xterm mouse tracking */ -static int usemouse = 1; -/* show only new in sidebar (default = 0 = all) */ -static int onlynew = 0; /* Allow to lazyload items when a file is specified? This saves memory but increases some latency when seeking items. It also causes issues if the feed is changed while having the UI open (and offsets are changed). */ static int lazyload = 0; -static char *plumber = "xdg-open"; -static char *piper = "less"; +static char *plumber = "xdg-open"; /* environment variable: $SFEED_PLUMBER */ +static char *piper = "less"; /* environment variable: $SFEED_PIPER */ void err(int code, const char *fmt, ...)