aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-02-27 09:18:14 -0600
committerRobin Jarry <robin@jarry.cc>2023-03-02 22:49:57 +0100
commit49de9b09caccc83adb0d52f0642f2c39a5e6a7e2 (patch)
tree2a9e2cb5bb0d5e87b1b80d07bfef028d402f9fd8 /widgets
parent125137c7b3b53ae621db0fced201181add70d370 (diff)
downloadaerc-49de9b09caccc83adb0d52f0642f2c39a5e6a7e2.tar.gz
ui: parse strings for ansi styles
Parse UI strings for ANSI styles. If there are styles in the string, use those as the display style in tcell. This is in preparation for a template function which can apply arbitrary styles to UI elements. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/dirlist.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index 1e1a8a61..986bd662 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -10,11 +10,10 @@ import (
"time"
"github.com/gdamore/tcell/v2"
- "github.com/mattn/go-runewidth"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
- "git.sr.ht/~rjarry/aerc/lib/format"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
"git.sr.ht/~rjarry/aerc/lib/state"
"git.sr.ht/~rjarry/aerc/lib/templates"
"git.sr.ht/~rjarry/aerc/lib/ui"
@@ -299,20 +298,26 @@ func (dirlist *DirectoryList) renderDir(
}
buf.Reset()
- lwidth := runewidth.StringWidth(left)
- rwidth := runewidth.StringWidth(right)
+ lbuf := parse.ParseANSI(left)
+ lbuf.ApplyAttrs(style)
+ lwidth := lbuf.Len()
+ rbuf := parse.ParseANSI(right)
+ rbuf.ApplyAttrs(style)
+ rwidth := rbuf.Len()
if lwidth+rwidth+1 > width {
if rwidth > 3*width/4 {
rwidth = 3 * width / 4
}
lwidth = width - rwidth - 1
- right = runewidth.FillLeft(right, rwidth)
- right = format.TruncateHead(right, rwidth, "…")
- left = runewidth.FillRight(left, lwidth)
- left = runewidth.Truncate(left, lwidth, "…")
+ right = rbuf.TruncateHead(rwidth, '…')
+ left = lbuf.Truncate(lwidth-1, '…')
} else {
- left = runewidth.FillRight(left, width-rwidth-1)
+ for i := 0; i < (width - lwidth - rwidth - 1); i += 1 {
+ lbuf.Write(' ', tcell.StyleDefault)
+ }
+ left = lbuf.String()
+ right = rbuf.String()
}
return left, right, style