summaryrefslogtreecommitdiff
path: root/sfeed_curses.c
AgeCommit message (Collapse)Author
2023-07-07sfeed_curses: move one line down when marking an item as read or unreadHiltjo Posthuma
I don't mind either behaviour, but it has been suggested by a few people. For example the mutt mail client also has this behaviour.
2023-05-16improve to use proper includesHiltjo Posthuma
Reduce using some of the unneeded sys/* headers too. This makes it slightly more portable or easier to port also.
2023-05-14sfeed_curses.c: make struct urls static like the other variablesHiltjo Posthuma
2023-05-07iterate on previous commit which adds $SFEED_NEW_MAX_SECSHiltjo Posthuma
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.
2023-05-07sfeed_{curses,frames,gopher,html,plain}: SFEED_NEW_MAX_SECSAlvar Penning
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/*
2023-03-07sfeed_curses: fix (very hard to trigger) memleak when getline() returns EOF ↵Hiltjo Posthuma
for lazyloaded items Fix the code pattern of freeing the line when getline returns -1 but no error flag is set on the stream (such as EOF). Note that on errors (even ENOMEM: out-of-memory) an error flag is set on the stream and the process would exit and clean up all it's resources. This would be very hard to trigger. The following conditions would have to be true: * Lazyloading of items is enabled: SFEED_LAZYLOAD=1 is set. * Items of the feed are read and their offsets stored. * The line is read/lazy-loaded again by it's offset but returns EOF (not a read error) this time. This could maybe happen if the feed file was changed and made smaller while sfeed_curses is running and the remembered offset is now beyond the file. Note that the sfeed_curses(1) man page describes a workaround for a similar condition by sending SIGHUP if the sfeed(5) data was changed to reload the feed file. References: * https://man.openbsd.org/getline "It is the responsibility of the caller to free(3) *lineptr when it is no longer needed. Even when it fails, getdelim() may update *lineptr." * https://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
2023-02-16sfeed_curses: add SUN keys supportHiltjo Posthuma
This fixes the keys on the sun-color console on OpenIndiana/Illumos/OpenSolaris (and other systems using these keys). See also the table: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html Section "Non-Function Keys".
2023-02-16sfeed_curses: add SCO keys for next, prior (CSI I and CSI G)Hiltjo Posthuma
This fixes the page up and page down keys in the cons25 console on DragonFlyBSD. See also the table: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html Section "Non-Function Keys".
2023-02-04fix comment for ASCII symbols for dumb terminalsHiltjo Posthuma
This was a copy-pasta.
2022-08-17sfeed_curses: fix a memleak caused by a mistake in refactoring the codeHiltjo Posthuma
Introduced by a code cleanup/refactor in commit 59ba2ed29bcbe67de6e9ee1e7fb18744f7490c22
2022-07-20slightly improve some commentsHiltjo Posthuma
2022-07-17sfeed_curses: cleanup code for handling read items from an URL fileHiltjo Posthuma
This makes it easier to reuse the code from reading plain-text list of items from a file and uses a struct urls to keep its state in a cleaner way. + some small code-style improvements and reshuffling. Inspired by a question from NRK by mail about implementing a "read later" feature. (A quick local experiment shows it can be done in ~70 lines of added code).
2022-07-05remove __dead codeNRK
this check is already done in util.h and is no longer needed after the `sfeed_curses -> sfeed` merge.
2022-07-05sfeed_curses: write out plumbercmd argument in a verbose mannerHiltjo Posthuma
Write it in a more verbose, clear and C90-style manner. This workarounds a bug in scc too (reported upstream and will be fixed of course). All tools in sfeed can now be compiled with minicurses-mode with the scc compiler and musl libc without any modifications needed. scc: http://www.simple-cc.org/
2022-06-05sfeed_curses: processexit(): remove unneeded code for non-interactive processesHiltjo Posthuma
This was used in commit a58fa45f25da4f18d7b8c1a815884f67b965406f and previous, but the code for non-interactive process cleanup was later removed, so clearing the struct is not not needed anymore, because it is unused.
2022-05-07sfeed_curses: improve commentHiltjo Posthuma
Do not restart the syscall waitpid, explicitly mention not setting SA_RESTART.
2022-05-07sfeed_curses: interrupt waitpid while interactive child program is runningHiltjo Posthuma
This now handles SIGTERM on sfeed_curses properly while an interactive child program is running. Test-case program: https://git.codemadness.org/sfeed_tests/commit/cd4268d4f71b5d7ab0df593d95e70188475d76bb.html
2022-05-05sfeed_curses: close stdin for spawning a plumb program in non-interactive modeHiltjo Posthuma
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.
2022-04-02sfeed_curses: code-style: mouse mode: just use a constantHiltjo Posthuma
No functional change intended. Just slightly more clear.
2022-04-02sfeed_curses: line editor: handle SIGCHLD directlyHiltjo Posthuma
This makes sure when processes exit they are reaped immediately (instead of after closing the line editor).
2022-04-02sfeed_curses: line editor, temporarily disable the mouse when using the line ↵Hiltjo Posthuma
editor This allows pasting in the terminal and also doesnt spam mouse events, which are not useful here.
2022-04-01sfeed_curses: don't use bitmasks to keep the states for signalsHiltjo Posthuma
Reported by Leon Fisher, thanks! "Each signal should have its own sig_atomic_t variable if you want to keep state for all of them independently." A similar issue was referenced in a OpenBSD tech mailinglist thread: https://marc.info/?l=openbsd-tech&m=162940120614641&w=2
2022-04-01sfeed_curses: small code-style changeHiltjo Posthuma
2022-04-01sfeed_curses: improve multiple signal handlingHiltjo Posthuma
Keep a bitmask of the received signals and handle them all. Also handle them in a particular order now.
2022-03-31sfeed_curses: improve waiting on processes and reaping themHiltjo Posthuma
- Wait on the exact process id and get its status. - Handle SIGCHLD explicitly and reap zombie children: ignoring them by using sigaction(SIGCHLD, &sa, NULL); would be racy in this case because sfeed_curses has interactive and non-interactive programs. Note while testing: if the markread program would be slow and in the meantime a plumb process would exit. This signal is now pending and is a zombie process until the SIGCHLD signal can be processed. This is fine. This also fixes a regression from commit 30a70fa2dab1925b0eaea04f67e3f86b360386dd because SIGCHLD was ignored in the parent for interactive processes aswell. This broke reading the exit status of the markread program, reproducable by plumbing an item and then trying to mark it as read (with SFEED_URL_FILE set).
2022-03-28sfeed_curses: fix-up from previous commit: properly initialize struct sigactionHiltjo Posthuma
2022-03-28sfeed_curses: ignore SIGCHLD only for non-interactive programsHiltjo Posthuma
This is a regression from the introduced change. Else wait(&status) returned -1 and status was uninitialized. The status of the returned program in the markread() function is used to visually show it as read/unread. If the program failed it is assumed the program could not mark it and so it is visually unchanged. Just to be sure also initialize status to -1 (which can never happen normally) since the exitstatus range is 0-255. https://man.openbsd.org/wait#ERRORS [ECHILD]: "No status from the terminated child process is available because the calling process has asked the system to discard such status by ignoring the signal SIGCHLD or setting the flag SA_NOCLDWAIT for that signal."
2022-03-27sfeed_curses: remove unneeded ctype.h includeHiltjo Posthuma
2022-03-27Revert "rm sys/types.h include and improve portability"Hiltjo Posthuma
This reverts commit db1dcafd03997127f2cbc82376e2cc8df9b77356. This is needed. Tested on an (old) Slackware 11 install.
2022-03-27sfeed_curses: tiny rewording in commentHiltjo Posthuma
2022-03-27sfeed_curses: processexit: do not set and reset SIGINT for non-interactive ↵Hiltjo Posthuma
plumbing Only set/override it in the interactive case. Also add some comments. No functional change intended.
2022-03-27sfeed_curses: avoid non-interactive plumb process becoming a zombieHiltjo Posthuma
From POSIX: Consequences of Process Termination: https://pubs.opengroup.org/onlinepubs/9699919799/functions/_Exit.html#tag_16_01_03_01 " [XSI] [Option Start] If the parent process of the calling process has set its SA_NOCLDWAIT flag or has set the action for the SIGCHLD signal to SIG_IGN: The process' status information (see Status Information), if any, shall be discarded. The lifetime of the calling process shall end immediately. If SA_NOCLDWAIT is set, it is implementation-defined whether a SIGCHLD signal is sent to the parent process. If a thread in the parent process of the calling process is blocked in wait(), waitpid(), or waitid(), and the parent process has no remaining child processes in the set of waited-for children, the wait(), waitid(), or waitpid() function shall fail and set errno to [ECHILD]. " Noticed on Linux (but not on OpenBSD). To reproduce: - SFEED_PLUMBER_INTERACTIVE=0 SFEED_PLUMBER="less" sfeed_curses ~/.sfeed/feeds/* - Then open and close the child program. - Notice it becoming a zombie or "<defunct>" in the process table.
2022-03-25rm sys/types.h include and improve portabilityHiltjo Posthuma
This include is not needed. It was intended for ssize_t but this is already defined by stdio.h for getline().
2022-03-19sfeed_curses: refactor DEC function key parsingHiltjo Posthuma
First it expected a single digit number, but this way it makes it more easy and logical to add Sun function keys: ESC [ num z For archive/reference Sun function keys relevant to sfeed_curses: num = 214: home 216: page up 220: end 222: page down Noticed on OpenIndiana/Illumos.
2022-03-14sfeed_curses: use ttywrite() for writing to the tty consistentlyHiltjo Posthuma
This should also suppress a compiler warning of an unchecked write() return value.
2022-03-14improve time(NULL) error checkingHiltjo Posthuma
Use errx, time(NULL) does not set errno. For sfeed_curses reset errno so it doesn't print a random error if it failed. POSIX recommends checking against (time_t)-1 on failure. Note that some implementation, like the OpenBSD man page says time() cannot fail.
2022-02-25sfeed_curses: cast character for SFEED_AUTOCMD to unsigned charHiltjo Posthuma
Otherwise a character like \xa0 (160) would be negative and goto the event, since a negative return value in readch() is used for errors or reserved for signal handling. Noticed while testing mouse X10 encoding with extended buttons, like button 7: SFEED_AUTOCMD="l$(printf '\x1b[M\xa0!!')j" ./sfeed_curses ~/.sfeed/feeds/*
2022-02-24sfeed_curses: remove continue in application key handlingHiltjo Posthuma
On an unknown or invalid sequence just use the key handling like the other keys do.
2022-02-24sfeed_curses: fix a redraw when reloading a file when reading from stdinHiltjo Posthuma
When reading data from stdin and changing the URL file externally in some way and then pressing 'R' would not redraw (and highlight/unhighlight) the marked items.
2022-02-24sfeed_curses: die(): use stdio buffered function/macroHiltjo Posthuma
vdprintf() was changed back to vfprintf() in commit 06bb4583, but the write was not changed. Change it to be more consistent and use the stdio buffered functions/macro.
2022-02-24sfeed_curses: fix a wrong comment about the arrow left and right keysHiltjo Posthuma
Add autocmd comment.
2022-02-24sfeed_curses: add keybinds for home key and home and end key in urxvtHiltjo Posthuma
\x1b[1~ home (putty and some terminals). \x1b[7~ urxvt home. \x1b[8~ urxvt end. Refactor repeated code also.
2022-02-19fix a compiler warning with (Net)BSD cursesHiltjo Posthuma
Some curses implementations have tparm(char *) (BSD and older ncurses), some have tparm(const char *). The older POSIX specification had: tparm(char *): https://pubs.opengroup.org/onlinepubs/7908799/xcurses/term.h.html Just cast it to char *. The terminfo variables are defined elsewhere so it should be safe. Also remove an unnecesary cast in minicurses. Hopefully this satisfies all curses variants and versions now.
2022-02-06fix a warning with tparm on some systemsHiltjo Posthuma
Older POSIX standards also defined it as a char * parameter (not const char *) for tparm(). https://pubs.opengroup.org/onlinepubs/7908799/xcurses/term.h.html
2022-02-06add compile-time option to improve output on dumb non-UTF8 terminalsHiltjo Posthuma
This makes atleast feeds with simple ASCII work.
2022-02-06sfeed_curses: write cmd in a more verbose wayHiltjo Posthuma
This fixes a compile error tested with HaikuOS 32-bit (gcc2h, based on gcc 2.95). It also suppresses a false-positive warning of an unused forkexec function in cppcheck.
2022-02-04improve some code commentsHiltjo Posthuma
2022-01-22add feature to go to the next bold row and previous bold row with J and KHiltjo Posthuma
This replaces the current J and K keybind, which was rarely useful. Thanks to IanJ for the suggestion and feedback!
2022-01-19sfeed_curses: code-style: remove variable name in definitionHiltjo Posthuma
2022-01-19sfeed_curses: fix a pedantic sign comparisonHiltjo Posthuma