From 618a500341d54ec5bec6d035a86b1307ff1dad0a Mon Sep 17 00:00:00 2001 From: Jeffas Date: Wed, 11 Sep 2019 17:37:21 +0100 Subject: Add display of unread messages in dirlist Add an onUpdateDirs handler. This is used to invalidate the dirlist and redraw with the correct number of recent/unread/total messages is shown. A config option and formatting options are provided. --- widgets/dirlist.go | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) (limited to 'widgets') diff --git a/widgets/dirlist.go b/widgets/dirlist.go index ec73082..ef2dd1e 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -1,15 +1,18 @@ package widgets import ( + "fmt" "log" "regexp" "sort" "github.com/gdamore/tcell" + "github.com/mattn/go-runewidth" "git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/lib" "git.sr.ht/~sircmpwn/aerc/lib/ui" + "git.sr.ht/~sircmpwn/aerc/models" "git.sr.ht/~sircmpwn/aerc/worker/types" ) @@ -105,6 +108,92 @@ func (dirlist *DirectoryList) Invalidate() { dirlist.DoInvalidate(dirlist) } +func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen func() string) string { + percent := false + rightJustify := false + formatted := "" + doRightJustify := func(s string) { + formatted = runewidth.FillRight(formatted, width-len(s)) + formatted = runewidth.Truncate(formatted, width-len(s), "…") + } + for _, char := range dirlist.uiConf.DirListFormat { + switch char { + case '%': + if percent { + formatted += string(char) + percent = false + } else { + percent = true + } + case '>': + if percent { + rightJustify = true + } + case 'n': + if percent { + if rightJustify { + doRightJustify(name) + rightJustify = false + } + formatted += name + percent = false + } + case 'r': + if percent { + rString := recentUnseen() + if rightJustify { + doRightJustify(rString) + rightJustify = false + } + formatted += rString + percent = false + } + default: + formatted += string(char) + } + } + return formatted +} + +func (dirlist *DirectoryList) getRUEString(name string) string { + totalUnseen := 0 + totalRecent := 0 + totalExists := 0 + if msgStore, ok := dirlist.MsgStore(name); ok { + for _, msg := range msgStore.Messages { + if msg == nil { + continue + } + seen := false + recent := false + for _, flag := range msg.Flags { + if flag == models.SeenFlag { + seen = true + } else if flag == models.RecentFlag { + recent = true + } + } + if !seen { + if recent { + totalRecent++ + } else { + totalUnseen++ + } + } + } + totalExists = msgStore.DirInfo.Exists + } + rueString := "" + if totalRecent > 0 { + rueString = fmt.Sprintf("%d/%d/%d", totalRecent, totalUnseen, totalExists) + } else if totalUnseen > 0 { + rueString = fmt.Sprintf("%d/%d", totalUnseen, totalExists) + } else if totalExists > 0 { + rueString = fmt.Sprintf("%d", totalExists) + } + return rueString +} + func (dirlist *DirectoryList) Draw(ctx *ui.Context) { ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault) @@ -132,7 +221,12 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) { style = style.Foreground(tcell.ColorGray) } ctx.Fill(0, row, ctx.Width(), 1, ' ', style) - ctx.Printf(0, row, style, "%s", name) + + dirString := dirlist.getDirString(name, ctx.Width(), func() string { + return dirlist.getRUEString(name) + }) + + ctx.Printf(0, row, style, dirString) row++ } } @@ -233,4 +327,7 @@ func (dirlist *DirectoryList) MsgStore(name string) (*lib.MessageStore, bool) { func (dirlist *DirectoryList) SetMsgStore(name string, msgStore *lib.MessageStore) { dirlist.store.SetMessageStore(name, msgStore) + msgStore.OnUpdateDirs(func() { + dirlist.Invalidate() + }) } -- cgit 1.4.1-2-gfad0 a8'>0f851e48 ^
aa2e2155 ^
4a943d4e ^

6f6d458f ^

4a943d4e ^
83c67014 ^
4a943d4e ^





6f6d458f ^
4a943d4e ^



292ccba1 ^

aa2e2155 ^
222c31db ^
c442a5ad ^

62c6d163 ^
292ccba1 ^

c442a5ad ^
292ccba1 ^




4a943d4e ^

6f6d458f ^

4a943d4e ^

83c67014 ^
4a943d4e ^






6f6d458f ^
4a943d4e ^



292ccba1 ^


c442a5ad ^
222c31db ^
292ccba1 ^

c442a5ad ^

292ccba1 ^


4a943d4e ^

6f6d458f ^

4a943d4e ^

83c67014 ^
4a943d4e ^


83c67014 ^
4a943d4e ^




6f6d458f ^
4a943d4e ^



292ccba1 ^


0f851e48 ^

aa2e2155 ^
4a943d4e ^

6f6d458f ^

36c745f8 ^
4a943d4e ^
83c67014 ^
4a943d4e ^

83c67014 ^
4a943d4e ^







292ccba1 ^


c442a5ad ^

292ccba1 ^
c442a5ad ^
292ccba1 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122