From d14aac682c5d52e3dacaadd13f4e5dd459c5bb9c Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 24 Feb 2022 00:49:18 +0100 Subject: sfeed_curses.1: clarify the 'R' keybind or SIGHUP will reload the url file also ... if it is set of course. --- sfeed_curses.1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'sfeed_curses.1') diff --git a/sfeed_curses.1 b/sfeed_curses.1 index f507475..703d7a3 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -1,4 +1,4 @@ -.Dd February 4, 2022 +.Dd February 24, 2022 .Dt SFEED_CURSES 1 .Os .Sh NAME @@ -83,6 +83,9 @@ Go to the next feed in the feeds pane and open it. Redraw screen. .It R Reload all feed files which were specified as arguments on startup. +If +.Ev SFEED_URL_FILE +is set, it will reload the URLs from this file also. .It m Toggle mouse-mode. It supports xterm X10 and extended SGR encoding. @@ -182,6 +185,9 @@ Switch to the feeds pane. .Bl -tag -width Ds .It SIGHUP Reload all feed files which were specified as arguments on startup. +If +.Ev SFEED_URL_FILE +is set, it will reload the URLs from this file also. .It SIGINT Interrupt: when searching it cancels the line editor, otherwise it quits. .It SIGTERM -- cgit v1.2.3 From c3f5dcec10b0ce7042cca38c90f54e86d1297cb6 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 10 Apr 2022 18:28:33 +0200 Subject: sfeed_curses.1: fix typo: automaticly -> automatically Noticed by the Debian scanner for typos (typo-in-manual-page): https://mentors.debian.net/package/sfeed/ --- sfeed_curses.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sfeed_curses.1') diff --git a/sfeed_curses.1 b/sfeed_curses.1 index 703d7a3..c981c00 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -98,7 +98,7 @@ height by 1 column. Use a fixed sidebar size for the current layout and increase the fixed width or height by 1 column. .It = -Reset the sidebar size to automaticly adjust for the current layout. +Reset the sidebar size to automatically adjust for the current layout. With the vertical layout the width is the longest feed name with the item counts right-aligned. With the horizontal layout the height is half of the window height (minus the -- cgit v1.2.3 From f0ca847fca5100dd98fbbed9c49b08ba5f310ac5 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 4 May 2022 18:28:10 +0200 Subject: sfeed_curses.1: more details about signals and (non-)interactive programs - SIGINT: reword, canceling the line editor is the exception. - Document the order of signal handling. - Document interactive and non-interactive behaviour in a separate section and in more detail. Remove repetition for each *_INTERACTIVE environment variable. - Document SIGINT and SIGTERM exit status. - Typo: "statusbar" -> "status bar". - Reword a few sentences. With additional changes and feedback from adc, thanks! --- sfeed_curses.1 | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'sfeed_curses.1') diff --git a/sfeed_curses.1 b/sfeed_curses.1 index c981c00..30d6543 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -1,4 +1,4 @@ -.Dd February 24, 2022 +.Dd May 4, 2022 .Dt SFEED_CURSES 1 .Os .Sh NAME @@ -102,7 +102,7 @@ Reset the sidebar size to automatically adjust for the current layout. With the vertical layout the width is the longest feed name with the item counts right-aligned. With the horizontal layout the height is half of the window height (minus the -statusbar) or otherwise the total amount of visible feeds, whichever fits the +status bar) or otherwise the total amount of visible feeds, whichever fits the best. .It t Toggle showing only feeds with new items in the sidebar. @@ -188,13 +188,19 @@ Reload all feed files which were specified as arguments on startup. If .Ev SFEED_URL_FILE is set, it will reload the URLs from this file also. +Cancels the line editor and handles the signal if received during a search. .It SIGINT -Interrupt: when searching it cancels the line editor, otherwise it quits. +Interrupt: quit. +When searching, it only cancels the line editor and doesn't quit. .It SIGTERM Quit .It SIGWINCH Resize the pane dimensions relative to the terminal size. +When searching, it handles the signal after closing the line editor. .El +.Pp +Signals are handled in the following order: SIGCHLD, SIGTERM, SIGINT, SIGHUP, +SIGWINCH. .Sh ENVIRONMENT VARIABLES .Bl -tag -width Ds .It Ev SFEED_AUTOCMD @@ -206,22 +212,13 @@ A program where the whole TAB-Separated Value line is piped to. By default this is "sfeed_content". .It Ev SFEED_PIPER_INTERACTIVE Handle the program interactively in the same terminal or not. -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. By default this is set to "1". .It Ev SFEED_PLUMBER A program that receives the link URL or enclosure URL as a parameter. By default this is "xdg-open". .It Ev SFEED_PLUMBER_INTERACTIVE Handle the program interactively in the same terminal or not. -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. +This option can be useful to open a text-mode browser in the same terminal. By default this is set to "0". .It Ev SFEED_YANKER A program where the URL or enclosure field is piped to, to copy it to a @@ -229,10 +226,6 @@ clipboard. By default this is "xclip -r". .It Ev SFEED_YANKER_INTERACTIVE Handle the program interactively in the same terminal or not. -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. By default this is set to "0". .It Ev SFEED_URL_FILE If this variable is set then a different mode is used to mark items as read, @@ -267,10 +260,10 @@ 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 +after the data was updated. +This makes .Nm -to reload the latest feed data and update the correct line offsets. +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 @@ -279,8 +272,27 @@ when a feed is loaded. If the data was read from stdin this variable is unset. It can be used by the plumb or pipe program for scripting purposes. .El +.Sh INTERACTIVE AND NON-INTERACTIVE PROGRAMS +.Nm +can pipe content, plumb and yank interactively or in a non-interactive manner. +In interactive mode +.Nm +waits until the process exits. +Stdout and stderr of the program are written as output. +It stores and restores the terminal attributes before and after executing the +program. +The signals SIGHUP and SIGWINCH will be handled after +.Nm +has waited on the program. +SIGINT is ignored while waiting on the program. +.Pp +In non-interactive mode +.Nm +doesn't wait until the process exits. +Stdout and stderr of the program are not written as output. .Sh EXIT STATUS .Ex -std +The exit status is 130 on SIGINT and 143 on SIGTERM. .Sh EXAMPLES .Bd -literal sfeed_curses ~/.sfeed/feeds/* -- cgit v1.2.3 From 78e54359372d02d17e9ab453c7bc0cd725b807f2 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 5 May 2022 06:28:11 +0200 Subject: sfeed_curses: close stdin for spawning a plumb program in non-interactive mode This is only for plumbing in non-interactive mode in forkexec(), but not piping content. Probably obvious what the descriptors are, but also add a few comments to dup2 of the file descriptors (stdin, stdout, stderr). To reproduce a behaviour: Plumb script: #!/bin/sh dmenu Then launch it: SFEED_PLUMB_INTERACTIVE=0 SFEED_PLUMB=thescript sfeed_curses ~/.sfeed/feeds/* The program now waits on input while in non-interactive mode and only seems to hang. After: The program starts but just has no input passed to it. --- sfeed_curses.1 | 3 ++- sfeed_curses.c | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'sfeed_curses.1') diff --git a/sfeed_curses.1 b/sfeed_curses.1 index 30d6543..be68d92 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -1,4 +1,4 @@ -.Dd May 4, 2022 +.Dd May 5, 2022 .Dt SFEED_CURSES 1 .Os .Sh NAME @@ -290,6 +290,7 @@ In non-interactive mode .Nm doesn't wait until the process exits. Stdout and stderr of the program are not written as output. +When plumbing an URL then stdin is closed also. .Sh EXIT STATUS .Ex -std The exit status is 130 on SIGINT and 143 on SIGTERM. diff --git a/sfeed_curses.c b/sfeed_curses.c index d09f8a0..78071b7 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -604,8 +604,8 @@ pipeitem(const char *cmd, struct item *item, int field, int interactive) die("fork"); case 0: if (!interactive) { - dup2(devnullfd, 1); - dup2(devnullfd, 2); + dup2(devnullfd, 1); /* stdout */ + dup2(devnullfd, 2); /* stderr */ } errno = 0; @@ -642,8 +642,9 @@ forkexec(char *argv[], int interactive) die("fork"); case 0: if (!interactive) { - dup2(devnullfd, 1); - dup2(devnullfd, 2); + dup2(devnullfd, 0); /* stdin */ + dup2(devnullfd, 1); /* stdout */ + dup2(devnullfd, 2); /* stderr */ } if (execvp(argv[0], argv) == -1) _exit(1); @@ -1847,8 +1848,8 @@ markread(struct pane *p, off_t from, off_t to, int isread) case -1: die("fork"); case 0: - dup2(devnullfd, 1); - dup2(devnullfd, 2); + dup2(devnullfd, 1); /* stdout */ + dup2(devnullfd, 2); /* stderr */ errno = 0; if (!(fp = popen(cmd, "w"))) -- cgit v1.2.3 From d77bd7c1e0b38b3320134fed0f496182bf1354e7 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 20 Dec 2022 22:22:39 +0100 Subject: sfeed_curses.1: small rewording and tweaks in the example --- sfeed_curses.1 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'sfeed_curses.1') diff --git a/sfeed_curses.1 b/sfeed_curses.1 index be68d92..94ffd4c 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -1,4 +1,4 @@ -.Dd May 5, 2022 +.Dd December 20, 2022 .Dt SFEED_CURSES 1 .Os .Sh NAME @@ -312,24 +312,26 @@ sfeed_curses ~/.sfeed/feeds/* Which does the following: .Bl -enum .It +Set commands to execute automatically: +.Pp Set the current layout to a horizontal mode ('2' keybind'). Showing a feeds sidebar on the top and the feed items on the bottom. -.It +.Pp Toggle showing only feeds with new items in the sidebar ('t' keybind). -.It +.Pp Go to the first row in the current panel ('g' keybind). -.It +.Pp Load the current selected feed ('o' keybind'). .It Set a file to use for managing read and unread items. -This file is a plain-text file containing a list of read URLs, one URL per -line. +This is a plain-text file containing a list of read URLs, one URL per line. .It Check if this file for managing the read and unread items exists. If it doesn't exist yet then create an empty file. .It Start -.Nm . +.Nm +and read the specified feed files. .El .Sh SEE ALSO .Xr sfeed 1 , -- cgit v1.2.3 From 6e4136753bd0faa15c198118b05c529d96d908c5 Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Mon, 24 Apr 2023 22:01:23 +0200 Subject: sfeed_{curses,frames,gopher,html,plain}: SFEED_NEW_MAX_SECS By introducing the new environment variable $SFEED_NEW_MAX_SECS in all sfeed_* utilities marking feeds as new based on comparing their age, it is now possible to override this age limit. This allows, for example, to be notified about new feeds within the last hour with SFEED_NEW_MAX_SECS=3600 sfeed_plain ~/.sfeed/feeds/* while creating a beautiful web report for last week's news by SFEED_NEW_MAX_SECS=604800 sfeed_html ~/.sfeed/feeds/* --- README | 10 ++++++---- sfeed_curses.1 | 4 ++++ sfeed_curses.c | 11 ++++++++--- sfeed_frames.1 | 7 +++++++ sfeed_frames.c | 15 ++++++++++++--- sfeed_gopher.1 | 4 ++++ sfeed_gopher.c | 15 ++++++++++++--- sfeed_html.1 | 7 +++++++ sfeed_html.c | 15 ++++++++++++--- sfeed_plain.1 | 7 +++++++ sfeed_plain.c | 16 +++++++++++++--- 11 files changed, 92 insertions(+), 19 deletions(-) (limited to 'sfeed_curses.1') diff --git a/README b/README index 6892e89..313ab4c 100644 --- a/README +++ b/README @@ -289,10 +289,12 @@ Just like the other format programs included in sfeed you can run it like this: sfeed_curses < ~/.sfeed/feeds/xkcd -By default sfeed_curses marks the items of the last day as new/bold. To manage -read/unread items in a different way a plain-text file with a list of the read -URLs can be used. To enable this behaviour the path to this file can be -specified by setting the environment variable $SFEED_URL_FILE to the URL file: +By default sfeed_curses marks the items of the last day as new/bold. This limit +might be overridden by setting the environment variable $SFEED_NEW_MAX_SECS to +the desired maximum in seconds. To manage read/unread items in a different way +a plain-text file with a list of the read URLs can be used. To enable this +behaviour the path to this file can be specified by setting the environment +variable $SFEED_URL_FILE to the URL file: export SFEED_URL_FILE="$HOME/.sfeed/urls" [ -f "$SFEED_URL_FILE" ] || touch "$SFEED_URL_FILE" diff --git a/sfeed_curses.1 b/sfeed_curses.1 index 94ffd4c..b3cccf2 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -30,6 +30,7 @@ arguments are specified then the data is read from stdin and the feed name is .Pp Items with a timestamp from the last day compared to the system time at the time of loading the feed are marked as new and bold. +This value might be overridden through environment variables. There is also an alternative mode available to mark items as read by matching it against a list of URLs from a plain-text file. Items with an enclosure are marked with a @ symbol. @@ -207,6 +208,9 @@ SIGWINCH. Read and process a sequence of keys as input commands from this environment variable first, afterwards it reads from the tty as usual. This can be useful to automate certain actions at the start. +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. .It Ev SFEED_PIPER A program where the whole TAB-Separated Value line is piped to. By default this is "sfeed_content". diff --git a/sfeed_curses.c b/sfeed_curses.c index 1abb046..cce608e 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -191,6 +191,7 @@ 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 lazyload = 0; /* env variable: $SFEED_LAZYLOAD */ +static int newmaxsecs = 86400; /* env variable: $SFEED_NEW_MAX_SECS */ int ttywritef(const char *fmt, ...) @@ -1322,8 +1323,7 @@ feeds_load(struct feed *feeds, size_t nfeeds) errno = 0; if ((comparetime = time(NULL)) == (time_t)-1) die("time"); - /* 1 day is old news */ - comparetime -= 86400; + comparetime -= newmaxsecs; for (i = 0; i < nfeeds; i++) { f = &feeds[i]; @@ -1967,7 +1967,7 @@ main(int argc, char *argv[]) struct pane *p; struct feed *f; struct row *row; - char *name, *tmp; + char *name, *tmp, *endptr; char *search = NULL; /* search text */ int button, ch, fd, i, keymask, release, x, y; off_t pos; @@ -1997,6 +1997,11 @@ main(int argc, char *argv[]) markunreadcmd = tmp; if ((tmp = getenv("SFEED_LAZYLOAD"))) lazyload = !strcmp(tmp, "1"); + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + newmaxsecs = (int) strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || newmaxsecs <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + } urlfile = getenv("SFEED_URL_FILE"); /* can be NULL */ cmdenv = getenv("SFEED_AUTOCMD"); /* can be NULL */ diff --git a/sfeed_frames.1 b/sfeed_frames.1 index e29498b..976d5ed 100644 --- a/sfeed_frames.1 +++ b/sfeed_frames.1 @@ -23,6 +23,7 @@ file is not written. Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. Items are marked as new using a bold markup. +This value might be overridden through environment variables. .Pp There is an example style.css stylesheet file included in the distribution. .Sh FILES WRITTEN @@ -37,6 +38,12 @@ feeds. The HTML file of the menu frame which contains navigation "anchor" links (like "#feedname") to the feed names in items.html. .El +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_frames.c b/sfeed_frames.c index 178a4a2..e52abd1 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -77,8 +77,9 @@ int main(int argc, char *argv[]) { FILE *fpindex, *fpitems, *fpmenu = NULL, *fp; - char *name; + char *name, *tmp, *endptr; int i, showsidebar = (argc > 1); + long l; struct feed *f; if (pledge("stdio rpath wpath cpath", NULL) == -1) @@ -89,8 +90,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } /* write main index page */ if (!(fpindex = fopen("index.html", "wb"))) diff --git a/sfeed_gopher.1 b/sfeed_gopher.1 index 43a11c7..f602d2c 100644 --- a/sfeed_gopher.1 +++ b/sfeed_gopher.1 @@ -32,6 +32,7 @@ written to stdout and no files are written. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. +This value might be overridden through environment variables. Items are marked as new with the prefix "N" at the start of the line. .Sh ENVIRONMENT .Bl -tag -width Ds @@ -45,6 +46,9 @@ The default is "127.0.0.1". .It Ev SFEED_GOPHER_PORT This environment variable can be used as the Gopher Port field. The default is "70". +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. .El .Sh EXIT STATUS .Ex -std diff --git a/sfeed_gopher.c b/sfeed_gopher.c index f62c6ed..007a244 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -122,8 +122,9 @@ int main(int argc, char *argv[]) { FILE *fpitems, *fpindex, *fp; - char *name, *p; + char *name, *p, *tmp, *endptr; int i; + long l; if (argc == 1) { if (pledge("stdio", NULL) == -1) @@ -139,8 +140,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } if ((p = getenv("SFEED_GOPHER_HOST"))) host = p; diff --git a/sfeed_html.1 b/sfeed_html.1 index efeb289..98784c5 100644 --- a/sfeed_html.1 +++ b/sfeed_html.1 @@ -26,9 +26,16 @@ is empty. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. +This value might be overridden through environment variables. Items are marked as new using a bold markup. .Pp There is an example style.css stylesheet file included in the distribution. +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_html.c b/sfeed_html.c index ce96687..89506be 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -78,9 +78,10 @@ int main(int argc, char *argv[]) { struct feed *f; - char *name; + char *name, *tmp, *endptr; FILE *fp; int i; + long l; if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); @@ -89,8 +90,16 @@ main(int argc, char *argv[]) err(1, "calloc"); if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } fputs("\n" "\n" diff --git a/sfeed_plain.1 b/sfeed_plain.1 index 466ae41..93ed41d 100644 --- a/sfeed_plain.1 +++ b/sfeed_plain.1 @@ -26,6 +26,7 @@ is empty. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are marked as new. +This value might be overridden through environment variables. Items are marked as new with the prefix "N" at the start of the line. .Pp .Nm @@ -39,6 +40,12 @@ per rune, using .Xr mbtowc 3 and .Xr wcwidth 3 . +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_plain.c b/sfeed_plain.c index 8b1f00f..c790ec4 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -52,8 +53,9 @@ int main(int argc, char *argv[]) { FILE *fp; - char *name; + char *name, *tmp, *endptr; int i; + long l; if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); @@ -65,8 +67,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } if (argc == 1) { printfeed(stdin, ""); -- cgit v1.2.3 From bdcbf8589716c047a732db3cc349ee6114ccc25f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 7 May 2023 12:39:26 +0200 Subject: iterate on previous commit which adds $SFEED_NEW_MAX_SECS Separate the common pattern to get the time to compare new items in format tools to the new util function: getcomparetime(). Some changes and notes: - Change it so it is OK to set this value to 0 or negative (in the future). - sfeed_curses: truncating newmaxsecs to an int would limit the value too much. - Just use strtotime() and parse the value to time_t. This is a signed long (32-bit, until 2038) or signed long long (64-bit) on most platforms. - sfeed_curses gets the comparison time on reload aswell and it needs errno = 0, because it uses die(). time() is not guaranteed to set an errno if it fails. - Rename environment variable to $SFEED_NEW_AGE. --- README | 6 +++--- sfeed_curses.1 | 2 +- sfeed_curses.c | 13 +++---------- sfeed_frames.1 | 2 +- sfeed_frames.c | 17 +++-------------- sfeed_gopher.1 | 2 +- sfeed_gopher.c | 17 +++-------------- sfeed_html.1 | 2 +- sfeed_html.c | 17 +++-------------- sfeed_plain.1 | 2 +- sfeed_plain.c | 18 +++--------------- util.c | 18 ++++++++++++++++++ util.h | 1 + 13 files changed, 42 insertions(+), 75 deletions(-) (limited to 'sfeed_curses.1') diff --git a/README b/README index 313ab4c..427435d 100644 --- a/README +++ b/README @@ -290,9 +290,9 @@ Just like the other format programs included in sfeed you can run it like this: sfeed_curses < ~/.sfeed/feeds/xkcd By default sfeed_curses marks the items of the last day as new/bold. This limit -might be overridden by setting the environment variable $SFEED_NEW_MAX_SECS to -the desired maximum in seconds. To manage read/unread items in a different way -a plain-text file with a list of the read URLs can be used. To enable this +might be overridden by setting the environment variable $SFEED_NEW_AGE to the +desired maximum in seconds. To manage read/unread items in a different way a +plain-text file with a list of the read URLs can be used. To enable this behaviour the path to this file can be specified by setting the environment variable $SFEED_URL_FILE to the URL file: diff --git a/sfeed_curses.1 b/sfeed_curses.1 index b3cccf2..56b2a92 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -208,7 +208,7 @@ SIGWINCH. Read and process a sequence of keys as input commands from this environment variable first, afterwards it reads from the tty as usual. This can be useful to automate certain actions at the start. -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .It Ev SFEED_PIPER diff --git a/sfeed_curses.c b/sfeed_curses.c index cce608e..b6f995f 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -191,7 +191,6 @@ 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 lazyload = 0; /* env variable: $SFEED_LAZYLOAD */ -static int newmaxsecs = 86400; /* env variable: $SFEED_NEW_MAX_SECS */ int ttywritef(const char *fmt, ...) @@ -1321,9 +1320,8 @@ feeds_load(struct feed *feeds, size_t nfeeds) size_t i; errno = 0; - if ((comparetime = time(NULL)) == (time_t)-1) - die("time"); - comparetime -= newmaxsecs; + if ((comparetime = getcomparetime()) == (time_t)-1) + die("getcomparetime"); for (i = 0; i < nfeeds; i++) { f = &feeds[i]; @@ -1967,7 +1965,7 @@ main(int argc, char *argv[]) struct pane *p; struct feed *f; struct row *row; - char *name, *tmp, *endptr; + char *name, *tmp; char *search = NULL; /* search text */ int button, ch, fd, i, keymask, release, x, y; off_t pos; @@ -1997,11 +1995,6 @@ main(int argc, char *argv[]) markunreadcmd = tmp; if ((tmp = getenv("SFEED_LAZYLOAD"))) lazyload = !strcmp(tmp, "1"); - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - newmaxsecs = (int) strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || newmaxsecs <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - } urlfile = getenv("SFEED_URL_FILE"); /* can be NULL */ cmdenv = getenv("SFEED_AUTOCMD"); /* can be NULL */ diff --git a/sfeed_frames.1 b/sfeed_frames.1 index 976d5ed..455c1db 100644 --- a/sfeed_frames.1 +++ b/sfeed_frames.1 @@ -40,7 +40,7 @@ The HTML file of the menu frame which contains navigation "anchor" links (like .El .Sh ENVIRONMENT VARIABLES .Bl -tag -width Ds -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .El diff --git a/sfeed_frames.c b/sfeed_frames.c index e52abd1..b2f75cf 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -77,9 +77,8 @@ int main(int argc, char *argv[]) { FILE *fpindex, *fpitems, *fpmenu = NULL, *fp; - char *name, *tmp, *endptr; + char *name; int i, showsidebar = (argc > 1); - long l; struct feed *f; if (pledge("stdio rpath wpath cpath", NULL) == -1) @@ -88,18 +87,8 @@ main(int argc, char *argv[]) if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); /* write main index page */ if (!(fpindex = fopen("index.html", "wb"))) diff --git a/sfeed_gopher.1 b/sfeed_gopher.1 index f602d2c..bc45121 100644 --- a/sfeed_gopher.1 +++ b/sfeed_gopher.1 @@ -46,7 +46,7 @@ The default is "127.0.0.1". .It Ev SFEED_GOPHER_PORT This environment variable can be used as the Gopher Port field. The default is "70". -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .El diff --git a/sfeed_gopher.c b/sfeed_gopher.c index 007a244..78e1f12 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -122,9 +122,8 @@ int main(int argc, char *argv[]) { FILE *fpitems, *fpindex, *fp; - char *name, *p, *tmp, *endptr; + char *name, *p; int i; - long l; if (argc == 1) { if (pledge("stdio", NULL) == -1) @@ -138,18 +137,8 @@ main(int argc, char *argv[]) err(1, "pledge"); } - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); if ((p = getenv("SFEED_GOPHER_HOST"))) host = p; diff --git a/sfeed_html.1 b/sfeed_html.1 index 98784c5..e517a63 100644 --- a/sfeed_html.1 +++ b/sfeed_html.1 @@ -32,7 +32,7 @@ Items are marked as new using a bold markup. There is an example style.css stylesheet file included in the distribution. .Sh ENVIRONMENT VARIABLES .Bl -tag -width Ds -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .El diff --git a/sfeed_html.c b/sfeed_html.c index 89506be..9269413 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -78,28 +78,17 @@ int main(int argc, char *argv[]) { struct feed *f; - char *name, *tmp, *endptr; + char *name; FILE *fp; int i; - long l; if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); fputs("\n" "\n" diff --git a/sfeed_plain.1 b/sfeed_plain.1 index 93ed41d..2e8e6ad 100644 --- a/sfeed_plain.1 +++ b/sfeed_plain.1 @@ -42,7 +42,7 @@ and .Xr wcwidth 3 . .Sh ENVIRONMENT VARIABLES .Bl -tag -width Ds -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .El diff --git a/sfeed_plain.c b/sfeed_plain.c index c790ec4..f8ce7ec 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -53,9 +52,8 @@ int main(int argc, char *argv[]) { FILE *fp; - char *name, *tmp, *endptr; + char *name; int i; - long l; if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); @@ -65,18 +63,8 @@ main(int argc, char *argv[]) if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); if (argc == 1) { printfeed(stdin, ""); diff --git a/util.c b/util.c index 0b7da06..e5aec3b 100644 --- a/util.c +++ b/util.c @@ -318,6 +318,24 @@ strtotime(const char *s, time_t *t) return 0; } +time_t +getcomparetime(void) +{ + time_t now, t; + char *p; + + if ((now = time(NULL)) == (time_t)-1) + return (time_t)-1; + + if ((p = getenv("SFEED_NEW_AGE"))) { + if (strtotime(p, &t) == -1) + return (time_t)-1; + return now - t; + } + + return now - 86400; /* 1 day is old news */ +} + /* Escape characters below as HTML 2.0 / XML 1.0. */ void xmlencode(const char *s, FILE *fp) diff --git a/util.h b/util.h index 9138de7..3ce5e41 100644 --- a/util.h +++ b/util.h @@ -71,6 +71,7 @@ int uri_makeabs(struct uri *, struct uri *, struct uri *); int uri_parse(const char *, struct uri *); void checkfileerror(FILE *, const char *, int); +time_t getcomparetime(void); void parseline(char *, char *[FieldLast]); void printutf8pad(FILE *, const char *, size_t, int); int strtotime(const char *, time_t *); -- cgit v1.2.3 From f2e7a3fca1c05599456a60494fff61bb7b1ecf4e Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 31 Jul 2023 18:58:40 +0200 Subject: fix typo: current -> currently Reported by Allan Wind, thanks! --- sfeed_curses.1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sfeed_curses.1') diff --git a/sfeed_curses.1 b/sfeed_curses.1 index 56b2a92..4b2afbd 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -141,12 +141,12 @@ This will only work when .Ev SFEED_URL_FILE is set. .It f -Mark all items of the current loaded feed as read. +Mark all items of the currently loaded feed as read. This will only work when .Ev SFEED_URL_FILE is set. .It F -Mark all items of the current loaded feed as unread. +Mark all items of the currently loaded feed as unread. This will only work when .Ev SFEED_URL_FILE is set. @@ -325,7 +325,7 @@ Toggle showing only feeds with new items in the sidebar ('t' keybind). .Pp Go to the first row in the current panel ('g' keybind). .Pp -Load the current selected feed ('o' keybind'). +Load the currently selected feed ('o' keybind'). .It Set a file to use for managing read and unread items. This is a plain-text file containing a list of read URLs, one URL per line. -- cgit v1.2.3 From 3eb8fb2bb4fec18cc3e82b52086368bc837a41bd Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 1 Aug 2023 18:55:49 +0200 Subject: sfeed_curses.1: fix 2 typos --- sfeed_curses.1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sfeed_curses.1') diff --git a/sfeed_curses.1 b/sfeed_curses.1 index 4b2afbd..d40d453 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -1,4 +1,4 @@ -.Dd December 20, 2022 +.Dd August 1, 2023 .Dt SFEED_CURSES 1 .Os .Sh NAME @@ -318,14 +318,14 @@ Which does the following: .It Set commands to execute automatically: .Pp -Set the current layout to a horizontal mode ('2' keybind'). +Set the current layout to a horizontal mode ('2' keybind). Showing a feeds sidebar on the top and the feed items on the bottom. .Pp Toggle showing only feeds with new items in the sidebar ('t' keybind). .Pp Go to the first row in the current panel ('g' keybind). .Pp -Load the currently selected feed ('o' keybind'). +Load the currently selected feed ('o' keybind). .It Set a file to use for managing read and unread items. This is a plain-text file containing a list of read URLs, one URL per line. -- cgit v1.2.3