aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Kuehler <keur@xcf.berkeley.edu>2019-10-28 12:07:02 -0700
committerBen Burwell <ben@benburwell.com>2019-10-29 11:07:31 -0400
commit75ee7826e16a63f296a04774cf49fb855f70f69c (patch)
treec5fd7a035d0df555f54c545afdaefb36c8a32d92
parentfad17adfefce95234856fb558becd73fb61c830b (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: