Use pager to display results
This commit is contained in:
parent
6619bd86ce
commit
f48e4c9f60
24
main.go
24
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -22,6 +23,7 @@ func main() {
|
||||||
if settings["interactive"] == "true" {
|
if settings["interactive"] == "true" {
|
||||||
interactiveShell()
|
interactiveShell()
|
||||||
}
|
}
|
||||||
|
fmt.Printf("I am done.\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseArguments() {
|
func parseArguments() {
|
||||||
|
@ -50,8 +52,28 @@ func showQueue() {
|
||||||
fmt.Printf("Error reading: %s\n", err.Error())
|
fmt.Printf("Error reading: %s\n", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
reader, writer := io.Pipe()
|
||||||
|
pagerDone := make(chan bool)
|
||||||
|
go launchPager(reader, pagerDone)
|
||||||
for _, entry := range entries {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue