aboutsummaryrefslogtreecommitdiff
path: root/widgets/msglist.go
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/msglist.go')
-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: