summaryrefslogtreecommitdiff
path: root/sfeed_curses.c
AgeCommit message (Collapse)Author
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
2022-01-19fix inconsistencies in commentsHiltjo Posthuma
2022-01-19sfeed_curses: consistency: mousereport: use off_t like the other functionsHiltjo Posthuma
2022-01-19sfeed_curses: line editor: add more clear comments of signal handlingHiltjo Posthuma
2022-01-14sfeed_curses: pedantic fix for UB with an empty URL fileHiltjo Posthuma
When a new URL file is used with no URL entries then NULL is passed to qsort() and bsearch(). This is reported by clang UBsan as undefined behaviour (debatable), but no issue in practise with many implementations. Fix it anyway. To reproduce with clang UBsan: Compile with clang or gcc with CFLAGS and LDFLAGS -fsanitize=undefined touch /tmp/urls # new file which should be empty. SFEED_URL_FILE=/tmp/urls sfeed_curses 2>/tmp/log ^D q cat /tmp/log
2021-11-26sfeed_curses: reuse some functions in utilHiltjo Posthuma
2021-11-26import sfeed_cursesHiltjo Posthuma
Import sfeed_curses into sfeed. The files are based of the commit 8e151ce48b503ad0ff0e24cb1be3bc93d6fbd895