aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2023-12-27 00:13:45 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-30 15:42:09 +0100
commit36f87135f56fe959b31118928d072a4a51993f22 (patch)
tree0a2a753b60ba2fa9afeb3c4fa92f7ca4e1923003
parent087b331d2e97411b945b95e4f0bb379f0ad7d1ae (diff)
downloadaerc-36f87135f56fe959b31118928d072a4a51993f22.tar.gz
msglist: refactor tree building
Our way of building trees seems absurd: generate a list of prefixes, reverse it, and trim the first element. Change it so the string is built back to front and define the arrows beforehand so they are easier to configure. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
-rw-r--r--app/msglist.go61
1 files changed, 26 insertions, 35 deletions
diff --git a/app/msglist.go b/app/msglist.go
index 40253ed6..7948e6a1 100644
--- a/app/msglist.go
+++ b/app/msglist.go
@@ -2,13 +2,13 @@ package app
import (
"bytes"
- "fmt"
"math"
"strings"
sortthread "github.com/emersion/go-imap-sortthread"
"github.com/emersion/go-message/mail"
"github.com/gdamore/tcell/v2"
+ "github.com/mattn/go-runewidth"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
@@ -419,43 +419,34 @@ func unreadInThread(thread *types.Thread, store *lib.MessageStore) (ctr int) {
func threadPrefix(t *types.Thread, reverse bool, point bool) string {
var arrow string
- if t.Parent != nil {
- switch {
- case t.NextSibling != nil:
- arrow = "├─"
- case reverse:
- arrow = "┌─"
- default:
- arrow = "└─"
- }
- if point {
- arrow += ">"
- }
- }
- var prefix []string
- for n := t; n.Parent != nil; n = n.Parent {
- switch {
- case n.Parent.NextSibling != nil && point:
- prefix = append(prefix, "│ ")
- case n.Parent.NextSibling != nil:
- prefix = append(prefix, "│ ")
- case point:
- prefix = append(prefix, " ")
- default:
- prefix = append(prefix, " ")
+ var tip string
+ if point {
+ tip = ">"
+ }
+ arrowPrefixSibling := "├─" + tip
+ arrowPrefixReverse := "┌─" + tip
+ arrowPrefixEnd := "└─" + tip
+ arrowStem := "│"
+ arrowIndent := strings.Repeat(" ", runewidth.StringWidth(arrowPrefixSibling)-1)
+
+ switch {
+ case t.Parent != nil && t.NextSibling != nil:
+ arrow += arrowPrefixSibling
+ case t.Parent != nil && reverse:
+ arrow += arrowPrefixReverse
+ case t.Parent != nil:
+ arrow += arrowPrefixEnd
+ }
+
+ for n := t.Parent; n != nil && n.Parent != nil; n = n.Parent {
+ if n.NextSibling != nil {
+ arrow = arrowStem + arrowIndent + arrow
+ } else {
+ arrow = " " + arrowIndent + arrow
}
}
- // prefix is now in a reverse order (inside --> outside), so turn it
- for i, j := 0, len(prefix)-1; i < j; i, j = i+1, j-1 {
- prefix[i], prefix[j] = prefix[j], prefix[i]
- }
- // we don't want to indent the first child, hence we strip that level
- if len(prefix) > 0 {
- prefix = prefix[1:]
- }
- ps := strings.Join(prefix, "")
- return fmt.Sprintf("%v%v", ps, arrow)
+ return arrow
}
func sameParent(left, right *types.Thread) bool {