diff --git a/main.go b/main.go index b708f8e..26bca7e 100644 --- a/main.go +++ b/main.go @@ -30,11 +30,13 @@ func parseArguments() { mailqCommandArgsPtr := flag.String("mailqCommandArgs", "", "Optional arguments to pass to mailqCommand") interactivePtr := flag.Bool("interactive", false, "Set to true for shell mode") machineFormatPtr := flag.Bool("machineFormat", false, "Set to true to get output suitable for cut/awk/...") + usePagerPtr := flag.Bool("usePager", true, "Use pager to display output?") flag.Parse() settings["mailqCommand"] = *mailqCommandPtr settings["mailqCommandArgs"] = *mailqCommandArgsPtr settings["interactive"] = strconv.FormatBool(*interactivePtr) settings["machineFormat"] = strconv.FormatBool(*machineFormatPtr) + settings["usePager"] = strconv.FormatBool(*usePagerPtr) } func interactiveShell() { @@ -47,13 +49,25 @@ func showQueue() { fmt.Printf("Could not fetch queue entries: %s\n", err.Error()) os.Exit(1) } - pagerReader, pagerWriter := io.Pipe() - pagerDone := make(chan bool) - go launchPager(pagerReader, pagerDone) - queue.PrintHumanReadable(pagerWriter) - pagerWriter.Close() - // Wait for pager to be closed before continuing the main program - <-pagerDone + if settings["usePager"] == "true" { + pagerReader, pagerWriter := io.Pipe() + pagerDone := make(chan bool) + go launchPager(pagerReader, pagerDone) + printQueue(queue, pagerWriter) + pagerWriter.Close() + // Wait for pager to be closed before continuing the main program + <-pagerDone + } else { + printQueue(queue, os.Stdout) + } +} + +func printQueue(queue parser.MailQ, writer io.Writer) { + if settings["machineFormat"] == "true" { + queue.PrintMachineReadable(writer) + } else { + queue.PrintHumanReadable(writer) + } } func launchPager(reader *io.PipeReader, pagerDone chan<- bool) { diff --git a/parser/parser.go b/parser/parser.go index d9dc680..a5b2d9a 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -41,7 +41,7 @@ func (m QEntry) String() string { } func (m QEntry) MachineReadableString() string { - return fmt.Sprintf("%s_%d_%s_%s_%s", m.Id, m.Status, m.Date.Format(SortableDateFormat), m.Size, m.Sender, m.Reason, strings.Join(m.Recipients, ",")) + return fmt.Sprintf("%s_%s_%s_%d_%s_%s_%s", m.Id, m.Status, m.Date.Format(SortableDateFormat), m.Size, m.Sender, m.Reason, strings.Join(m.Recipients, ",")) } func (m QEntry) DetailedString() string {