aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/msgviewer.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-09-11 17:34:51 +0200
committerRobin Jarry <robin@jarry.cc>2023-09-19 16:49:59 +0200
commitde0b75d191f4f789d3870dae00871244d20aaf10 (patch)
tree8604ebfd38f0903df7a951471743cfd07dccd21d /widgets/msgviewer.go
parent20e425406541e3fc7c4decad3da9373d378c7164 (diff)
downloadaerc-de0b75d191f4f789d3870dae00871244d20aaf10.tar.gz
msgviewer: add styles for part selector
Allow styling the part selector mime type and (if any) attachment filename. Remove custom alignment code since now both can be differentiated easily with colors and/or attributes. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r--widgets/msgviewer.go52
1 files changed, 19 insertions, 33 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index c94d57a3..41cb639e 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -422,18 +422,32 @@ func (ps *PartSwitcher) Draw(ctx *ui.Context) {
ps.parts[ps.selected].Draw(ctx)
return
}
+
+ var styleSwitcher, styleFile, styleMime tcell.Style
+
// TODO: cap height and add scrolling for messages with many parts
ps.height = ctx.Height()
y := ctx.Height() - height
for i, part := range ps.parts {
- style := ps.mv.uiConfig.GetStyle(config.STYLE_DEFAULT)
if ps.selected == i {
- style = ps.mv.uiConfig.GetStyleSelected(config.STYLE_DEFAULT)
+ styleSwitcher = ps.mv.uiConfig.GetStyleSelected(config.STYLE_PART_SWITCHER)
+ styleFile = ps.mv.uiConfig.GetStyleSelected(config.STYLE_PART_FILENAME)
+ styleMime = ps.mv.uiConfig.GetStyleSelected(config.STYLE_PART_MIMETYPE)
+ } else {
+ styleSwitcher = ps.mv.uiConfig.GetStyle(config.STYLE_PART_SWITCHER)
+ styleFile = ps.mv.uiConfig.GetStyle(config.STYLE_PART_FILENAME)
+ styleMime = ps.mv.uiConfig.GetStyle(config.STYLE_PART_MIMETYPE)
}
- ctx.Fill(0, y+i, ctx.Width(), 1, ' ', style)
+ ctx.Fill(0, y+i, ctx.Width(), 1, ' ', styleSwitcher)
left := len(part.index) * 2
- name := formatMessagePart(part.part.FullMIMEType(), part.part.FileName(), ctx.Width()-left)
- ctx.Printf(left, y+i, style, "%s", name)
+ if part.part.FileName() != "" {
+ name := runewidth.Truncate(part.part.FileName(),
+ ctx.Width()-left-1, "…")
+ left += ctx.Printf(left, y+i, styleFile, "%s ", name)
+ }
+ t := "(" + part.part.FullMIMEType() + ")"
+ t = runewidth.Truncate(t, ctx.Width()-left, "…")
+ ctx.Printf(left, y+i, styleMime, "%s", t)
}
ps.parts[ps.selected].Draw(ctx.Subcontext(
0, 0, ctx.Width(), ctx.Height()-height))
@@ -500,34 +514,6 @@ func (ps *PartSwitcher) Cleanup() {
}
}
-func formatMessagePart(mime, filename string, width int) string {
- lname := runewidth.StringWidth(filename)
- lmime := runewidth.StringWidth(mime)
-
- switch {
- case width <= 0:
- return ""
-
- case filename == "":
- return runewidth.Truncate(mime, width, "…")
-
- case lname+lmime+3 <= width:
- // simple scenario - everything fits
- return fmt.Sprintf("%s (%s)",
- runewidth.FillRight(filename, width-lmime-3), mime)
-
- case lname+3 < width:
- // file name fits + we have space for parentheses and at least
- // one symbol of mime
- return fmt.Sprintf("%s (%s)", filename,
- runewidth.Truncate(mime, width-lname-3, "…"))
-
- default:
- // ok, we don't have space even for the file name
- return runewidth.Truncate(filename, width, "…")
- }
-}
-
func (mv *MessageViewer) Event(event tcell.Event) bool {
return mv.switcher.Event(event)
}