On Sat, Jan 21, 2017 at 4:07 PM, James Aguilar <aguilar.ja...@gmail.com> wrote:
> If you don't know or care about pagers and process management, you can stop
> reading now.
>
> Background: I have a program that compile my code each time I modify it. It
> produces logs continuously on a terminal.
>
> I'm trying to write a go program to wrap this program so that each compile
> log is opened in a pager, and so that when a new compile starts, the pager
> for the previous compile is automatically closed. Essentially, I'm trying to
> change the program from doing (pseudo-shell)
>
> while true; do
>   awaitChange
>   build
> end
>
> to:
>
> while true; do
>   awaitChange
>   kill $!
>   build | less &  # <--- except less should be in the foreground of the
> terminal
>   to_kill=$!
> end
>
> There are wrinkles: I don't control the program that executes this loop. So
> I wrote a go program to process the input and separate it into a series of
> output buffers based on a regexp. I've gotten it to the point where I can
> start and kill less, and feed it the separated inputs.
>
> My problem: less is not behaving as it would if you ran it on the
> commandline. The arrow keys don't work, ^C either does nothing (on the first
> run of less) or interrupts the parent program, etc.
>
> I believe my mistake is that I am not correctly putting less into the
> foreground. I also suspect that I'm not correctly moving my go program back
> into the foreground each time I kill the child less process. I'm wondering
> if anyone knows the magical incantation that is required to make this work
> properly. My current code is here (with the compiler replaced by a random
> number generator, since it is proprietary to the company I work for). I have
> marked with TODOs the things I think are not working correctly.
>
> https://play.golang.org/p/Xv0y-Ln7aC
>
> Any ideas what I'm doing wrong here?

Your program seems to work for me, so I guess I misunderstand what the
problem is.

I ran `go build foo.go; ./foo`.  It prints a series of random numbers
from 0 to 99, fed into less.  When it prints a number 95 to 99, it
restarts less.  When it prints enough numbers to fill my terminal, I
see the `less` prompt (a colon).  I can use arrows, space, etc.
Eventually that instance of less is killed and a new one starts.
Hitting ^C just causes `less` to beep.  Hitting `q` causes less and
the main program to exit.

What do you see?  (Note that you shouldn't use `go run` for a program
like this.)

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to