From my tests, readline works the same for interactive and non-interactive processes. Just changing the example code to use "#include <readline/readline.h>" and linking against GNU readline, rl_event_hook is called periodically in either case.
It's worth noting that GNU readline does rate limit calling rl_event_hook (the documentation says it will not be called more than 10 times a second so long as no input is given; so for my example I made the short a char to not spam the terminal) and that rl_done being set in the rl_event_hook hook will cause readline() to return, but those differences were less significant/could be overcome in other ways for my usage (ie, the rate was unimportant, just that it's called at all, and rl_done behavior can be achieved by setting rl_event_hook to NULL; but just mentioning).
The following reply was made to PR lib/58955; it has been noted by GNATS.
From: Christos Zoulas <christos%zoulas.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: lib-bug-people%netbsd.org@localhost,
gnats-admin%netbsd.org@localhost,
netbsd-bugs%netbsd.org@localhost
Subject: Re: lib/58955: libedit: rl_event_hook not called when output is piped
to another process
Date: Thu, 9 Jan 2025 16:25:16 -0500
--Apple-Mail=_2E891251-9880-4BC2-8546-5DC03EA3B102
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=us-ascii
I am not sure. How does readline behave? If it works for non-interactive =
processes we should change our code.
Best,
christos=
--Apple-Mail=_2E891251-9880-4BC2-8546-5DC03EA3B102
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=signature.asc
Content-Type: application/pgp-signature;
name=signature.asc
Content-Description: Message signed with OpenPGP
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
iF0EARECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCZ4A+vAAKCRBxESqxbLM7
OmyVAJ9kyL1JNCO2qjELSRdcwxYkwxX7OgCdEGXop0mfw3JOMvytJv+j9NN1nKg=
=nTPK
-----END PGP SIGNATURE-----
--Apple-Mail=_2E891251-9880-4BC2-8546-5DC03EA3B102--