aerc/commands/move-tab.go
Robin Jarry 171fefd209 tabs: make fields private
The Tabs object exposes an array of Tab objects and the current selected
index in that array. The these two fields are sometimes modified in
goroutines, which can lead to data races causing fatal out of bounds
accesses on the tab array.

Hide these fields as private API. Expose only what needs to be seen from
the outside. This will prepare for protecting concurrent access with
a lock in the next commit.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Koni Marti <koni.marti@gmail.com>
2022-07-23 22:00:25 +02:00

44 lines
778 B
Go

package commands
import (
"fmt"
"strconv"
"strings"
"git.sr.ht/~rjarry/aerc/widgets"
)
type MoveTab struct{}
func init() {
register(MoveTab{})
}
func (MoveTab) Aliases() []string {
return []string{"move-tab"}
}
func (MoveTab) Complete(aerc *widgets.Aerc, args []string) []string {
return nil
}
func (MoveTab) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) == 1 {
return fmt.Errorf("Usage: %s [+|-]<index>", args[0])
}
joinedArgs := strings.Join(args[1:], "")
n, err := strconv.Atoi(joinedArgs)
if err != nil {
return fmt.Errorf("failed to parse index argument: %v", err)
}
var relative bool
if strings.HasPrefix(joinedArgs, "+") || strings.HasPrefix(joinedArgs, "-") {
relative = true
}
aerc.MoveTab(n, relative)
return nil
}