diff options
| author | Drew DeVault <sir@cmpwn.com> | 2019-03-15 21:41:18 -0400 | 
|---|---|---|
| committer | Drew DeVault <sir@cmpwn.com> | 2019-03-15 21:41:39 -0400 | 
| commit | e780c6ee96ae086fc668aadcd61fb1777d1cbe43 (patch) | |
| tree | 53a4f8b7809563de114b0f870a89a3bb029b1268 | |
| parent | ef6178a12ae5ef7070711f5cc2f2114dfd015dcd (diff) | |
Implement :next-message n%
| -rw-r--r-- | commands/next-message.go | 11 | ||||
| -rw-r--r-- | widgets/msglist.go | 6 | 
2 files changed, 16 insertions, 1 deletions
diff --git a/commands/next-message.go b/commands/next-message.go index 86cd678..81725c0 100644 --- a/commands/next-message.go +++ b/commands/next-message.go @@ -4,6 +4,7 @@ import (  	"errors"  	"fmt"  	"strconv" +	"strings"  	"git.sr.ht/~sircmpwn/aerc2/widgets"  ) @@ -14,7 +15,7 @@ func init() {  }  func nextPrevMessageUsage(cmd string) error { -	return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) +	return errors.New(fmt.Sprintf("Usage: %s [<n>[%]]", cmd))  }  func NextPrevMessage(aerc *widgets.Aerc, args []string) error { @@ -24,14 +25,22 @@ func NextPrevMessage(aerc *widgets.Aerc, args []string) error {  	var (  		n   int = 1  		err error +		pct bool  	)  	if len(args) > 1 { +		if strings.HasSuffix(args[1], "%") { +			pct = true +			args[1] = args[1][:len(args[1])-1] +		}  		n, err = strconv.Atoi(args[1])  		if err != nil {  			return nextPrevMessageUsage(args[0])  		}  	}  	acct := aerc.SelectedAccount() +	if pct { +		n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0)) +	}  	for ; n > 0; n-- {  		if args[0] == "prev-message" {  			acct.Messages().Prev() diff --git a/widgets/msglist.go b/widgets/msglist.go index 0fb919d..cf9a772 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -13,6 +13,7 @@ import (  type MessageList struct {  	conf         *config.AercConfig  	logger       *log.Logger +	height       int  	onInvalidate func(d ui.Drawable)  	selected     int  	spinner      *Spinner @@ -45,6 +46,7 @@ func (ml *MessageList) Invalidate() {  }  func (ml *MessageList) Draw(ctx *ui.Context) { +	ml.height = ctx.Height()  	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)  	if ml.store == nil { @@ -91,6 +93,10 @@ func (ml *MessageList) Draw(ctx *ui.Context) {  	}  } +func (ml *MessageList) Height() int { +	return ml.height +} +  func (ml *MessageList) SetStore(store *lib.MessageStore) {  	ml.store = store  	if store != nil {  | 
