about summary refs log tree commit diff stats
Commit message (Collapse)AuthorAgeFilesLines
* implemented focus on enterwindow on titlebarsarg@10ksloc.org2006-08-022-2/+2
|
* applied Sanders patches (numlock2)arg@10ksloc.org2006-08-025-26/+40
|
* reverting to old resize policyarg@10ksloc.org2006-08-022-21/+32
|
* new resize stuff (using XConfigureWindow instead of XSendEvent)arg@10ksloc.org2006-08-022-32/+21
|
* renamed WM_PROTOCOL_DELWIN into PROTODELWINarg@10ksloc.org2006-08-013-3/+3
|
* renamed ARRANGE into DEFMODEarg@10ksloc.org2006-08-013-4/+3
|
* small fixes to dwm.htmlarg@10ksloc.org2006-08-011-6/+6
|
* simplified READMEarg@10ksloc.org2006-08-011-4/+1
|
* removed 1 missing LOCarg@10ksloc.org2006-08-011-1/+0
|
* removed 5LOCarg@10ksloc.org2006-08-012-15/+10
|
* removed artefacts of single-linked list (thanx to Jukka, I must have been mad)arg@10ksloc.org2006-08-012-9/+4
|
* cleaned config.*h to prevent some confusionarg@10ksloc.org2006-08-013-6/+5
|
* saved 2LOCarg@10ksloc.org2006-08-011-4/+2
|
* uppercasing all define'd values (uppercase-prefixed should only be enum ↵arg@10ksloc.org2006-08-014-16/+16
| | | | field qualifiers)
* fixed config.h filesarg@10ksloc.org2006-08-012-4/+2
|
* centralized/externalized configuration to config.harg@10ksloc.org2006-08-019-107/+172
|
* applied Cedric's NumLock patcharg@10ksloc.org2006-08-011-1/+17
|
* applied Jukkas prev/next patch with XK_{h,l}arg@10ksloc.org2006-08-013-0/+18
|
* applied Sanders patchesarg@10ksloc.org2006-08-018-58/+42
|
* committed a patch which fixes the hints of Jukkaarg@10ksloc.org2006-08-014-40/+14
|
* updated htmlarg@10ksloc.org2006-07-211-1/+1
|
* Added tag 0.5 for changeset 22213b9a2114167ee8ba019a012e27da0422a61aarg@10ksloc.org2006-07-211-0/+1
|
* prepared 0.5 0.5arg@10ksloc.org2006-07-211-3/+9
|
* some cleanups/fixes inspired by Jukka Salmi's feedbackarg@10ksloc.org2006-07-214-13/+7
|
* simplified main.c, switching back to single urxvt usagearg@10ksloc.org2006-07-212-28/+14
|
* s/sleep 5/sleep 2/arg@10ksloc.org2006-07-211-1/+1
|
* changed the status info README hint (more simple now, no extra script necessary)arg@10ksloc.org2006-07-211-7/+1
|
* s/0.5/0.6/ - my steps are wider than the realityarg@10ksloc.org2006-07-212-2/+2
|
* applied sanders maxfix patcharg@10ksloc.org2006-07-211-2/+2
|
* added a note how to achieve status info in the bararg@10ksloc.org2006-07-211-1/+17
|
* preparing 0.6 which will be available in the evening after sanders patch approx.arg@10ksloc.org2006-07-212-21/+8
|
* sanitization of several clunky stuff, removed heretag (rarely of use), ↵arg@10ksloc.org2006-07-214-48/+40
| | | | simplified pop(), changed shortcuts to always contain MODKEY
* applied sanders no_sizehints for tiled mode patch (thx!)arg@10ksloc.org2006-07-202-11/+11
|
* serious mistake in pop() (forgot to set c->prev to NULL on pop)arg@10ksloc.org2006-07-201-0/+1
|
* using double-linked list in order to get correct prev focus handlingarg@10ksloc.org2006-07-204-21/+45
|
* added yet another CUTOMIZE tagarg@10ksloc.org2006-07-201-0/+2
|
* cleaned the CUSTOMIZE flagsarg@10ksloc.org2006-07-203-5/+9
|
* made status bar drawing more robust, implemented togglemax and togglemode, ↵arg@10ksloc.org2006-07-205-33/+59
| | | | works quite well
* cleaned up codearg@10ksloc.org2006-07-208-85/+78
|
* Added tag 0.4 for changeset eb3165734f00fe7f7da8aeebaed00e60a57caac9arg@10ksloc.org2006-07-201-0/+1
|
* prepared 0.4 0.4arg@10ksloc.org2006-07-202-4/+10
|
* using O3 instead of Os, binary size still < 40kbarg@10ksloc.org2006-07-201-1/+1
|
* fixed version in man pagearg@10ksloc.org2006-07-201-1/+1
|
* yet another html patcharg@10ksloc.org2006-07-201-5/+5
|
* updated htmlarg@10ksloc.org2006-07-201-5/+5
|
* makefile now sets permissions for executables and man pagesarg@10ksloc.org2006-07-201-0/+6
|
* removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling ↵arg@10ksloc.org2006-07-204-114/+85
| | | | remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
* implemented regexp matching for rulesarg@10ksloc.org2006-07-194-32/+40
|
* applied Jukka's patch with s/ModKeyMask/MODKEY/garg@10ksloc.org2006-07-194-24/+25
|
* removed TODO, because dwm is nearly finishedarg@10ksloc.org2006-07-191-1/+0
|
                                                     
 
package account

import (
	"errors"
	"fmt"
	"strconv"
	"strings"

	"git.sr.ht/~sircmpwn/aerc/widgets"
)

type NextPrevMsg struct{}

func init() {
	register(NextPrevMsg{})
}

func (NextPrevMsg) Aliases() []string {
	return []string{"next", "next-message", "prev", "prev-message"}
}

func (NextPrevMsg) Complete(aerc *widgets.Aerc, args []string) []string {
	return nil
}

func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
	n, pct, err := ParseNextPrevMessage(args)
	if err != nil {
		return err
	}
	acct := aerc.SelectedAccount()
	if acct == nil {
		return errors.New("No account selected")
	}
	return ExecuteNextPrevMessage(args, acct, pct, n)
}

func ParseNextPrevMessage(args []string) (int, bool, error) {
	if len(args) > 2 {
		return 0, false, nextPrevMessageUsage(args[0])
	}
	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 0, false, nextPrevMessageUsage(args[0])
		}
	}
	return n, pct, nil
}

func ExecuteNextPrevMessage(args []string, acct *widgets.AccountView, pct bool, n int) error {
	if pct {
		n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0))
	}
	if args[0] == "prev-message" || args[0] == "prev" {
		store := acct.Store()
		if store != nil {
			store.NextPrev(-n)
			acct.Messages().Scroll()
		}
	} else {
		store := acct.Store()
		if store != nil {
			store.NextPrev(n)
			acct.Messages().Scroll()
		}
	}
	return nil
}

func nextPrevMessageUsage(cmd string) error {
	return fmt.Errorf("Usage: %s [<n>[%%]]", cmd)
}