diff options
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r-- | widgets/msgviewer.go | 52 |
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) } |