From 6e038c7fd510563efc35780e293e25e34ffe3077 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 8 May 2023 20:20:34 -0500 Subject: dirtree: modify drawing of the dirtree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the dirtree drawing structure to be a bit more compact. The dirtree is drawn with one column left for a flag, which indicates if a parent is collapsed or expanded. Only draw the "flag" when the parent is collapsed. Change the flag to a '+' character to match common UI patterns of expanding lists having a '+' box. Don't draw the '>' character in the dirtree. This character is nice in the threaded message view, but clutters up the dirtree. I know this is a matter of preference, but this approach is similar to most other UI tree view and gives the dirtree an extra column of space. The original dirtree looks like this: ┌Inbox ├─>Sub └─>Sub And collapsed: -Inbox This patch changes it to: Inbox ├─Sub └─Sub And collapsed: +Inbox Signed-off-by: Tim Culverhouse Acked-by: Moritz Poldrack --- widgets/dirtree.go | 17 ++++++++--------- widgets/msglist.go | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/widgets/dirtree.go b/widgets/dirtree.go index b0943ae4..41477c5f 100644 --- a/widgets/dirtree.go +++ b/widgets/dirtree.go @@ -275,7 +275,7 @@ func (dt *DirectoryTree) countVisible(list []*types.Thread) (n int) { func (dt *DirectoryTree) displayText(node *types.Thread) string { elems := strings.Split(dt.treeDirs[getAnyUid(node)], dt.pathSeparator) - return fmt.Sprintf("%s%s%s", threadPrefix(node, false), getFlag(node), elems[countLevels(node)]) + return fmt.Sprintf("%s%s%s", threadPrefix(node, false, false), getFlag(node), elems[countLevels(node)]) } func (dt *DirectoryTree) getDirectory(node *types.Thread) string { @@ -471,13 +471,12 @@ func countLevels(node *types.Thread) (level int) { return } -func getFlag(node *types.Thread) (flag string) { - if node != nil && node.FirstChild != nil { - if node.Hidden { - flag = "─" - } else { - flag = "┌" - } +func getFlag(node *types.Thread) string { + if node == nil && node.FirstChild == nil { + return "" } - return + if node.Hidden { + return "+" + } + return "" } diff --git a/widgets/msglist.go b/widgets/msglist.go index 45d2555c..d1bba32f 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -165,7 +165,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { baseSubject := threadSubject(store, thread) data.SetThreading( - threadPrefix(thread, store.ReverseThreadOrder()), + threadPrefix(thread, store.ReverseThreadOrder(), true), baseSubject == lastSubject && sameParent(thread, prevThread) && !isParent(thread), ) lastSubject = baseSubject @@ -427,17 +427,19 @@ func (ml *MessageList) drawEmptyMessage(ctx *ui.Context) { uiConfig.GetStyle(config.STYLE_MSGLIST_DEFAULT), "%s", msg) } -func threadPrefix(t *types.Thread, reverse bool) string { +func threadPrefix(t *types.Thread, reverse bool, point bool) string { var arrow string if t.Parent != nil { - if t.NextSibling != nil { - arrow = "├─>" - } else { - if reverse { - arrow = "┌─>" - } else { - arrow = "└─>" - } + switch { + case t.NextSibling != nil: + arrow = "├─" + case reverse: + arrow = "┌─" + default: + arrow = "└─" + } + if point { + arrow += ">" } } var prefix []string -- cgit v1.2.3-54-g00ecf