aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Kuehler <keur@xcf.berkeley.edu>2019-10-10 15:27:09 -0700
committerBen Burwell <ben@benburwell.com>2019-10-12 20:57:53 -0400
commit9e47953ebe3bafdfc4d3af4ed26dc7ca6c2053fd (patch)
tree88f0a3b6823b919c73d0d6925c28c300dcee262d
parent41f3bb3bc16b5d7bef7ffe29a8f4b493be7d79fd (diff)
widgets/msglist: Draw each row in a function
This function can be reused by the threading code. Signed-off-by: Kevin Kuehler <keur@xcf.berkeley.edu>
-rw-r--r--widgets/msglist.go98
1 files changed, 54 insertions, 44 deletions
diff --git a/widgets/msglist.go b/widgets/msglist.go
index 5c2d2f4..ac3d6cc 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -71,52 +71,9 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
for i := len(uids) - 1 - ml.scroll; i >= 0; i-- {
uid := uids[i]
- msg := store.Messages[uid]
-
- if row >= ctx.Height() {
+ if ml.drawRow(ctx, uid, i, row, &needsHeaders) {
break
}
-
- if msg == nil {
- needsHeaders = append(needsHeaders, uid)
- ml.spinner.Draw(ctx.Subcontext(0, row, ctx.Width(), 1))
- row += 1
- continue
- }
-
- style := tcell.StyleDefault
-
- // current row
- if row == ml.store.SelectedIndex()-ml.scroll {
- style = style.Reverse(true)
- }
- // deleted message
- if _, ok := store.Deleted[msg.Uid]; ok {
- style = style.Foreground(tcell.ColorGray)
- }
- // unread message
- seen := false
- for _, flag := range msg.Flags {
- if flag == models.SeenFlag {
- seen = true
- }
- }
- if !seen {
- style = style.Bold(true)
- }
-
- ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
- fmtStr, args, err := format.ParseMessageFormat(
- ml.conf.Ui.IndexFormat,
- ml.conf.Ui.TimestampFormat, "", i, msg)
- if err != nil {
- ctx.Printf(0, row, style, "%v", err)
- } else {
- line := fmt.Sprintf(fmtStr, args...)
- line = runewidth.Truncate(line, ctx.Width(), "…")
- ctx.Printf(0, row, style, "%s", line)
- }
-
row += 1
}
@@ -132,6 +89,59 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
}
}
+// Draw one message.
+//
+// Return: If true, don't fetch any more messages
+func (ml *MessageList) drawRow(ctx *ui.Context, uid uint32, number int, row int, needsHeaders *[]uint32) bool {
+ store := ml.store
+ msg := store.Messages[uid]
+
+ if row >= ctx.Height() {
+ return true
+ }
+
+ if msg == nil {
+ *needsHeaders = append(*needsHeaders, uid)
+ ml.spinner.Draw(ctx.Subcontext(0, row, ctx.Width(), 1))
+ return false
+ }
+
+ style := tcell.StyleDefault
+
+ // current row
+ if row == ml.store.SelectedIndex()-ml.scroll {
+ style = style.Reverse(true)
+ }
+ // deleted message
+ if _, ok := store.Deleted[msg.Uid]; ok {
+ style = style.Foreground(tcell.ColorGray)
+ }
+ // unread message
+ seen := false
+ for _, flag := range msg.Flags {
+ if flag == models.SeenFlag {
+ seen = true
+ }
+ }
+ if !seen {
+ style = style.Bold(true)
+ }
+
+ ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
+ fmtStr, args, err := format.ParseMessageFormat(
+ ml.conf.Ui.IndexFormat,
+ ml.conf.Ui.TimestampFormat, "", number, msg)
+ if err != nil {
+ ctx.Printf(0, row, style, "%v", err)
+ } else {
+ line := fmt.Sprintf(fmtStr, args...)
+ line = runewidth.Truncate(line, ctx.Width(), "…")
+ ctx.Printf(0, row, style, "%s", line)
+ }
+
+ return false
+}
+
func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) {
switch event := event.(type) {
case *tcell.EventMouse: