diff --git a/main.go b/main.go index a44aa6b..219b95b 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "io" "os" "os/exec" "strconv" @@ -22,6 +23,7 @@ func main() { if settings["interactive"] == "true" { interactiveShell() } + fmt.Printf("I am done.\n") } func parseArguments() { @@ -50,8 +52,28 @@ func showQueue() { fmt.Printf("Error reading: %s\n", err.Error()) os.Exit(1) } + reader, writer := io.Pipe() + pagerDone := make(chan bool) + go launchPager(reader, pagerDone) for _, entry := range entries { - fmt.Printf("%s\n", entry.String()) + fmt.Fprintf(writer, "%s\n", entry.String()) + } + writer.Close() + // Wait for pager to be closed before continuing the main program + <-pagerDone +} + +func launchPager(reader *io.PipeReader, pagerDone chan<- bool) { + cmd := exec.Command("less") + cmd.Stdin = reader + cmd.Stdout = os.Stdout + if err := cmd.Start(); err != nil { + fmt.Printf("Error launching pager: %s\n", err.Error()) + } + if err := cmd.Wait(); err != nil { + fmt.Printf("Error terminating pager: %s\n", err.Error()) + } else { + pagerDone <- true } }