From bcd08235a37b906bc56d1cf37e3156917341c8e4 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 31 Dec 2018 16:54:01 +0100 Subject: [PATCH] Update date format, add status to view --- main.go | 4 ++-- parser/parser.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 0d4b8c3..2006b8e 100644 --- a/main.go +++ b/main.go @@ -69,9 +69,9 @@ func fetchQueueEntries() ([]parser.QEntry, error) { func printQueueEntries(entries []parser.QEntry, writer io.Writer) { tabWriter := tabwriter.NewWriter(writer, 2, 2, 1, ' ', tabwriter.TabIndent) - fmt.Fprintf(tabWriter, "| %s\t| %s\t| %s\t| %s\t| %s\t| %s\t| %s\t| \n", "Date", "Id", "Size", "Sender", "#", "First Recipient", "Reason") + fmt.Fprintf(tabWriter, "| %s\t| %s\t| %s\t| %s\t| %s\t| %s\t| %s\t| %s\t| \n", "Date", "Id", "Status", "Size", "Sender", "#", "First Recipient", "Reason") for _, entry := range entries { - _, writeError := fmt.Fprintf(tabWriter, "| %s\t| %s\t| %d\t| %s\t| {%d}\t| %s\t| %s\t \n", entry.Date, entry.Id, entry.Size, entry.Sender, len(entry.Recipients), entry.Recipients[0], entry.Reason) + _, writeError := fmt.Fprintf(tabWriter, "| %s\t| %s\t| %s\t| %d\t| %s\t| {%d}\t| %s\t| %s\t \n", entry.Date.Format(parser.SortableDateFormat), entry.Id, entry.Status, entry.Size, entry.Sender, len(entry.Recipients), entry.Recipients[0], entry.Reason) if writeError != nil { // A writeError is expected once the reader was closed // This happens when the pager application got terminated diff --git a/parser/parser.go b/parser/parser.go index cfc293b..ef2c063 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -21,10 +21,10 @@ type QEntry struct { Reason string } -const sortableDateFormat = "2006-01-02 15:04:05" +const SortableDateFormat = "2006-01-02 15:04:05" func (m QEntry) ShortString() string { - return fmt.Sprintf("[%s] %s <%s> -> %d recipients (%d bytes)", m.Date.Format(sortableDateFormat), m.Id, m.Sender, len(m.Recipients), m.Size) + return fmt.Sprintf("[%s] %s <%s> -> %d recipients (%d bytes)", m.Date.Format(SortableDateFormat), m.Id, m.Sender, len(m.Recipients), m.Size) } func (m QEntry) String() string { @@ -32,7 +32,7 @@ func (m QEntry) String() string { if len(m.Recipients) > 1 { recipientSuffix = ",..." } - return fmt.Sprintf("[%s] %s <%s> -> {%d}<%s>%s (%s, %d bytes)", m.Date.Format(sortableDateFormat), m.Id, m.Sender, len(m.Recipients), m.Recipients[0], recipientSuffix, m.Status, m.Size) + return fmt.Sprintf("[%s] %s <%s> -> {%d}<%s>%s (%s, %d bytes)", m.Date.Format(SortableDateFormat), m.Id, m.Sender, len(m.Recipients), m.Recipients[0], recipientSuffix, m.Status, m.Size) } func (m QEntry) DetailedString() string { @@ -40,7 +40,7 @@ func (m QEntry) DetailedString() string { if m.Reason == "" { reasonStr = "-/-" } - return fmt.Sprintf("Id: %s\nDate: %s\nStatus: %s\nReason: %s\nSize: %d\nSender: %s\nRecipients: %s", m.Id, m.Date.Format(sortableDateFormat), m.Status, reasonStr, m.Size, m.Sender, strings.Join(m.Recipients, ", ")) + return fmt.Sprintf("Id: %s\nDate: %s\nStatus: %s\nReason: %s\nSize: %d\nSender: %s\nRecipients: %s", m.Id, m.Date.Format(SortableDateFormat), m.Status, reasonStr, m.Size, m.Sender, strings.Join(m.Recipients, ", ")) } func ParseMailQ(dataSource io.Reader) ([]QEntry, error) {