From 2da4d2fa7fd289752b81e5ca504040cff3d9fdcf Mon Sep 17 00:00:00 2001 From: Christos Margiolis Date: Fri, 13 May 2022 16:29:42 +0300 Subject: [PATCH] implement bookmarking --- sfeed_curses.1 | 8 ++++++++ sfeed_curses.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/sfeed_curses.1 b/sfeed_curses.1 index be68d92..6138aee 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -129,6 +129,12 @@ This program can be specified with Pipe the TAB-Separated Value field for yanking the enclosure to a program. This program can be specified with .Ev SFEED_YANKER . +.It b +Bookmark the current selection's URL/Enclosure field and title in TAB-separated +format. +This will only work when +.Ev SFEED_BOOKMARK_FILE +is set. .It r Mark item as read. This will only work when @@ -234,6 +240,8 @@ The value specified is a plain-text file containing a list of read URLs, one URL per line. This URL is matched on the link field if it is set, otherwise it is matched on the id field. +.It Ev SFEED_BOOKMARK_FILE +A file where pressing "b" will save the selection to. .It Ev SFEED_MARK_READ A program to mark items as read if .Ev SFEED_URL_FILE diff --git a/sfeed_curses.c b/sfeed_curses.c index a38a25e..fbcbe22 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -180,6 +180,7 @@ static char *pipercmd = "sfeed_content"; /* env variable: $SFEED_PIPER */ static char *yankercmd = "xclip -r"; /* env variable: $SFEED_YANKER */ static char *markreadcmd = "sfeed_markread read"; /* env variable: $SFEED_MARK_READ */ static char *markunreadcmd = "sfeed_markread unread"; /* env variable: $SFEED_MARK_UNREAD */ +static char *bookmarkfile; /* env variable: $SFEED_BOOKMARK_FILE */ static char *cmdenv; /* env variable: $SFEED_AUTOCMD */ static int plumberia = 0; /* env variable: $SFEED_PLUMBER_INTERACTIVE */ static int piperia = 1; /* env variable: $SFEED_PIPER_INTERACTIVE */ @@ -1467,6 +1468,30 @@ feed_yank_selected_item(struct pane *p, int field) pipeitem(yankercmd, item, field, yankeria); } +void +feed_bookmark_item(struct pane *p) +{ + struct row *row; + struct item *item; + FILE *fp; + const char *url; + + if (!(row = pane_row_get(p, p->pos))) + return; + if (bookmarkfile == NULL) + return; + if ((fp = fopen(bookmarkfile, "a")) == NULL) + return; + item = row->data; + markread(p, p->pos, p->pos, 1); + if (*item->fields[FieldLink] != '\0') + url = item->fields[FieldLink]; + else + url = item->fields[FieldEnclosure]; + fprintf(fp, "%s\t%s\n", url, item->fields[FieldTitle]); + fclose(fp); +} + /* calculate optimal (default) size */ int getsidebarsizedefault(void) @@ -1991,6 +2016,7 @@ main(int argc, char *argv[]) if ((tmp = getenv("SFEED_LAZYLOAD"))) lazyload = !strcmp(tmp, "1"); urlfile = getenv("SFEED_URL_FILE"); /* can be NULL */ + bookmarkfile = getenv("SFEED_BOOKMARK_FILE"); /* can be NULL */ cmdenv = getenv("SFEED_AUTOCMD"); /* can be NULL */ setlayout(argc <= 1 ? LayoutMonocle : LayoutVertical); @@ -2264,6 +2290,10 @@ nextpage: if (selpane == PaneItems) feed_plumb_selected_item(&panes[selpane], FieldEnclosure); break; + case 'b': + if (selpane == PaneItems) + feed_bookmark_item(&panes[selpane]); + break; case 'm': /* toggle mouse mode */ usemouse = !usemouse; mousemode(usemouse); -- 2.42.0