~emersion/hut-dev

pager: completely write output when not on terminal v1 PROPOSED

Jens Schmidt: 1
 pager: completely write output when not on terminal

 1 files changed, 5 insertions(+), 7 deletions(-)
We don't want to DoS the server, so no, can't make this optional.
I understand, thanks.  Some follow-up questions:

1. Would you accept a patch explaining the background in the man
   page?
2. And what about providing automatic cursor management in command
   graphql?  Would you reject that for the same (DoS) reason?
3. After all, to some extent this is security by obscurity, isn't
   it?  If I script some automatic cursor management around graphql,
   for example, I'm free to do that, anyway.  Or is your concern
   more directed towards the unwary user than the evil one?
Thanks again.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/hut-dev/patches/51762/mbox | git am -3
Learn more about email & git

[PATCH] pager: completely write output when not on terminal Export this patch

The main loop in function pagerify stop when the pager is not
running any longer or when the paged functions wants to stop,
whichever comes sooner.  With the previous singleWritePager, only
one cycle of the loop would ever be executed, since the
singleWritePager claims not to be running after the first write.

This change replaces the singleWritePager by a
completeWritePager, which is always ready to write.  This fixes
issue 3. described [here].

[here]: https://lists.sr.ht/~sircmpwn/sr.ht-discuss/%3Cb902e7d6-4d10-44e0-ba04-41f755b736ef@vodafonemail.de%3E
---
 pager.go | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/pager.go b/pager.go
index e6b85fd..9789bc4 100644
--- a/pager.go
+++ b/pager.go
@@ -17,7 +17,7 @@ type pager interface {

func newPager() pager {
	if !termfmt.IsTerminal() {
		return &singleWritePager{os.Stdout, true}
		return &completeWritePager{os.Stdout}
	}

	name, ok := os.LookupEnv("PAGER")
@@ -69,18 +69,16 @@ func pagerify(fn pagerifyFn) {
	}
}

type singleWritePager struct {
type completeWritePager struct {
	io.WriteCloser
	running bool
}

func (p *singleWritePager) Write(b []byte) (int, error) {
	p.running = false
func (p *completeWritePager) Write(b []byte) (int, error) {
	return p.WriteCloser.Write(b)
}

func (p *singleWritePager) Running() bool {
	return p.running
func (p *completeWritePager) Running() bool {
	return true
}

type cmdPager struct {
-- 
2.39.2
Except, of course, the current single-write behavior is intended
to keep web server load low.  Is it documented, then?  Could we
make the new behavior optional, then?