aerc

Working clone of aerc-mail.org
git clone git://git.danielmoch.com/aerc.git
Log | Files | Refs | README | LICENSE

commit 0897413a3e7b7707e6e597077d1621e586180f3b
parent 511fea39449b6db551151da86d914bf7ab3b3713
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 20 May 2019 16:49:39 -0400

Implement :next-part, :prev-part

Diffstat:
Acommands/msgview/next-part.go | 43+++++++++++++++++++++++++++++++++++++++++++
Mconfig/binds.conf | 2++
Mwidgets/msgviewer.go | 33+++++++++++++++++++++++++++++++--
3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/commands/msgview/next-part.go b/commands/msgview/next-part.go @@ -0,0 +1,43 @@ +package msgview + +import ( + "errors" + "fmt" + "strconv" + + "git.sr.ht/~sircmpwn/aerc/widgets" +) + +func init() { + register("next-part", NextPrevPart) + register("prev-part", NextPrevPart) +} + +func nextPrevPartUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) +} + +func NextPrevPart(aerc *widgets.Aerc, args []string) error { + if len(args) > 2 { + return nextPrevPartUsage(args[0]) + } + var ( + n int = 1 + err error + ) + if len(args) > 1 { + n, err = strconv.Atoi(args[1]) + if err != nil { + return nextPrevPartUsage(args[0]) + } + } + mv, _ := aerc.SelectedTab().(*widgets.MessageViewer) + for ; n > 0; n-- { + if args[0] == "prev-part" { + mv.PreviousPart() + } else { + mv.NextPart() + } + } + return nil +} diff --git a/config/binds.conf b/config/binds.conf @@ -47,6 +47,8 @@ rr = :reply<Enter> rq = :reply -q<Enter> Rr = :reply -a<Enter> Rq = :reply -aq<Enter> +<C-k> = :prev-part<Enter> +<C-j> = :next-part<Enter> [compose] # Keybindings used when the embedded terminal is not selected in the compose diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go @@ -119,12 +119,13 @@ func NewMessageViewer(conf *config.AercConfig, if err != nil { goto handle_error } + switcher.selected = -1 for i, pv := range switcher.parts { pv.OnInvalidate(func(_ ui.Drawable) { switcher.Invalidate() }) // TODO: switch to user's preferred mimetype, if configured - if switcher.selected == 0 && pv.part.MIMEType != "multipart" { + if switcher.selected == -1 && pv.part.MIMEType != "multipart" { switcher.selected = i } } @@ -198,6 +199,34 @@ func (mv *MessageViewer) OnInvalidate(fn func(d ui.Drawable)) { }) } +func (mv *MessageViewer) PreviousPart() { + switcher := mv.switcher + for { + switcher.selected-- + if switcher.selected < 0 { + switcher.selected = len(switcher.parts) - 1 + } + if switcher.parts[switcher.selected].part.MIMEType != "multipart" { + break + } + } + mv.Invalidate() +} + +func (mv *MessageViewer) NextPart() { + switcher := mv.switcher + for { + switcher.selected++ + if switcher.selected >= len(switcher.parts) { + switcher.selected = 0 + } + if switcher.parts[switcher.selected].part.MIMEType != "multipart" { + break + } + } + mv.Invalidate() +} + func (ps *PartSwitcher) Invalidate() { ps.DoInvalidate(ps) } @@ -318,7 +347,7 @@ func NewPartViewer(conf *config.AercConfig, pv := &PartViewer{ filter: filter, - index: index, // TODO: Nested multipart does indicies differently + index: index, msg: msg, pager: pager, pagerin: pagerin,