make lazyload a run-time configuration option + shuffle a few lines - sfeed_curses - sfeed curses UI (now part of sfeed, development is in sfeed)
HTML git clone git://git.codemadness.org/sfeed_curses
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 12f9a95c2d5dfce1513b65084d67cc54d8c0816b
DIR parent faebbca4b7d9969875e5794ea0c587069406e76a
HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 18 Dec 2020 15:12:41 +0100
make lazyload a run-time configuration option + shuffle a few lines
This option can reduce memory-usage (with a few caveats which are documented).
Diffstat:
M sfeed_curses.1 | 18 ++++++++++++++++--
M sfeed_curses.c | 28 +++++++++-------------------
2 files changed, 25 insertions(+), 21 deletions(-)
---
DIR diff --git a/sfeed_curses.1 b/sfeed_curses.1
@@ -1,4 +1,4 @@
-.Dd November 30, 2020
+.Dd December 18, 2020
.Dt SFEED_CURSES 1
.Os
.Sh NAME
@@ -175,8 +175,9 @@ If set to "1" then before execution it restores the terminal attributes and
.Nm
will wait until the program is finished.
If set to "0" then it will suppress stdout and stderr output.
+For example this option is useful to open a text-mode browser in the same
+terminal.
By default this is set to "0".
-This option is useful to open a text-mode browser in the same terminal.
.It Ev SFEED_YANKER
A program where the url or enclosure field is piped to, to copy it to a
clipboard.
@@ -209,6 +210,19 @@ is also set, if unset the default program used is "sfeed_markread unread".
The marked items are piped to the program.
The program is expected to merge items in a safe/transactional manner.
The program should return the exit status 0 on success or non-zero on failure.
+.It Ev SFEED_LAZYLOAD
+Lazyload items when reading the feed data from files.
+This can reduce memory usage but increases latency when seeking items,
+especially on slower disk drives.
+It can also cause a race-condition issue if the feed data on disk is changed
+while having the UI open and offsets for the lines are different.
+A workaround for the race-condition issue is by sending the SIGHUP signal to
+.Nm
+directly after the data was updated.
+This forces
+.Nm
+to reload the latest feed data and update the correct line offsets.
+By default this is set to "0".
.It Ev SFEED_FEED_PATH
This variable is set by
.Nm
DIR diff --git a/sfeed_curses.c b/sfeed_curses.c
@@ -21,11 +21,6 @@
#include <curses.h>
#include <term.h>
-/* 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). */
-/*#define LAZYLOAD 1*/
-
#define LEN(a) sizeof((a))/sizeof((a)[0])
#define PAD_TRUNCATE_SYMBOL "\xe2\x80\xa6" /* symbol: "ellipsis" */
@@ -53,8 +48,7 @@ static char *markunreadcmd = "sfeed_markread unread"; /* env variable: $SFEED_MA
static int plumberia = 0; /* env variable: $SFEED_PLUMBER_INTERACTIVE */
static int piperia = 1; /* env variable: $SFEED_PIPER_INTERACTIVE */
static int yankeria = 0; /* env variable: $SFEED_YANKER_INTERACTIVE */
-
-static int fixedsidebarwidth = -1; /* fixed sidebar width, < 0 is automatic */
+static int lazyload = 0; /* env variable: $SFEED_LAZYLOAD */
enum {
ATTR_RESET = 0, ATTR_BOLD_ON = 1, ATTR_FAINT_ON = 2, ATTR_REVERSE_ON = 7
@@ -161,8 +155,9 @@ 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 fixedsidebarwidth = -1; /* fixed sidebar width, < 0 is automatic */
static int onlynew = 0; /* show only new in sidebar */
+static int usemouse = 1; /* use xterm mouse tracking */
static struct termios tsave; /* terminal state at startup */
static struct termios tcur;
@@ -1143,8 +1138,7 @@ feed_items_get(struct feed *f, FILE *fp, struct items *itemsret)
if (line[linelen - 1] == '\n')
line[--linelen] = '\0';
-#ifdef LAZYLOAD
- if (f->path) {
+ if (lazyload && f->path) {
linetoitem(line, item);
/* data is ignored here, will be lazy-loaded later. */
@@ -1153,9 +1147,6 @@ feed_items_get(struct feed *f, FILE *fp, struct items *itemsret)
} else {
linetoitem(estrdup(line), item);
}
-#else
- linetoitem(estrdup(line), item);
-#endif
nitems++;
}
@@ -1579,7 +1570,6 @@ feed_row_match(struct pane *p, struct row *row, const char *s)
return (strcasestr(feed->name, s) != NULL);
}
-#ifdef LAZYLOAD
struct row *
item_row_get(struct pane *p, off_t pos)
{
@@ -1612,7 +1602,6 @@ item_row_get(struct pane *p, off_t pos)
}
return itemrow;
}
-#endif
/* Custom formatter for item row. */
char *
@@ -1788,14 +1777,15 @@ main(int argc, char *argv[])
markreadcmd = tmp;
if ((tmp = getenv("SFEED_MARK_UNREAD")))
markunreadcmd = tmp;
- urlfile = getenv("SFEED_URL_FILE");
+ if ((tmp = getenv("SFEED_LAZYLOAD")))
+ lazyload = !strcmp(tmp, "1");
+ urlfile = getenv("SFEED_URL_FILE"); /* can be NULL */
panes[PaneFeeds].row_format = feed_row_format;
panes[PaneFeeds].row_match = feed_row_match;
panes[PaneItems].row_format = item_row_format;
-#ifdef LAZYLOAD
- panes[PaneItems].row_get = item_row_get;
-#endif
+ if (lazyload)
+ panes[PaneItems].row_get = item_row_get;
feeds = ecalloc(argc, sizeof(struct feed));
if (argc == 1) {