Prettify flags; force column 3's width to 20
Anirudh Oppiliappan x@icyphox.sh
Wed, 07 Jul 2021 20:57:14 +0530
3 files changed,
27 insertions(+),
14 deletions(-)
M
commands/list.go
→
commands/list.go
@@ -4,10 +4,12 @@ import (
"net/mail" "path/filepath" "sort" + "strings" "time" gomaildir "github.com/emersion/go-maildir" "github.com/jedib0t/go-pretty/v6/table" + "github.com/jedib0t/go-pretty/v6/text" "git.icyphox.sh/mx/config" "git.icyphox.sh/mx/maildir"@@ -28,12 +30,15 @@ "ls",
} } -func flagToRune(flags []gomaildir.Flag) []rune { - r := make([]rune, len(flags)) - for i, f := range flags { - r[i] = rune(f) +func flagToString(flags []gomaildir.Flag) []string { + if len(flags) > 0 { + r := make([]string, len(flags)) + for i, f := range flags { + r[i] = maildir.FlagMap[f] + } + return r } - return r + return []string{"N"} } func formatDate(date time.Time) string {@@ -60,7 +65,7 @@ if err != nil {
return nil, err } - strflags := string(flagToRune(flags)) + strflags := strings.Join(flagToString(flags), "") datestr, err := m.GetHeader("Date") date, err := mail.ParseDate(datestr) subject, err := m.GetHeader("Subject")@@ -70,10 +75,13 @@ if err != nil {
return nil, err } + // TODO: remove text.Trim and have this configured in column + // config (WidthMaxEnforcer) + // ref: https://github.com/jedib0t/go-pretty/issues/170 if len(addr.Name) > 0 { - ll.from = addr.Name + ll.from = text.Trim(addr.Name, 20) } else { - ll.from = addr.Address + ll.from = text.Trim(addr.Address, 20) } ll.date = date ll.flags = strflags@@ -103,7 +111,7 @@ lines, err := ll.makeListLines(keys, dir)
for index, line := range lines { tbl.AppendRow(table.Row{ - index, line.flags, line.from, formatDate(line.date), line.subject, + line.flags, index, line.from, formatDate(line.date), line.subject, }) } tbl.Render()
M
commands/table.go
→
commands/table.go
@@ -36,11 +36,9 @@ TopSeparator: " ",
UnfinishedRow: "", }, }) - t.SetColumnConfigs([]table.ColumnConfig{ - {Number: 1}, - {Number: 2}, - {Number: 3, WidthMax: 25, WidthMaxEnforcer: text.Trim}, - }) + // t.SetColumnConfigs([]table.ColumnConfig{ + // {Number: 3, WidthMax: 25, WidthMaxEnforcer: text.Trim}, + // }) t.SetAllowedRowLength(w) return t }
M
maildir/message.go
→
maildir/message.go
@@ -80,3 +80,10 @@
decodedHeader, err := decodeMime(msg.Header.Get(h)) return decodedHeader, err } + +var FlagMap = map[maildir.Flag]string{ + maildir.FlagDraft: "D", + maildir.FlagSeen: "S", + maildir.FlagReplied: "R", + maildir.FlagTrashed: "T", +}