summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-07-14 18:29:56 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-23 22:00:25 +0200
commit171fefd2095132f49d84a4e9426fec0b293fa7ba (patch)
tree2a9bb3971b79c232ce32f10109d03fec6887e2ad /commands
parentc841f36513ffdaffbf4b68e5f108c97a45745092 (diff)
downloadaerc-171fefd2095132f49d84a4e9426fec0b293fa7ba.zip
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>
Diffstat (limited to 'commands')
-rw-r--r--commands/compose/postpone.go8
-rw-r--r--commands/compose/send.go8
-rw-r--r--commands/move-tab.go15
3 files changed, 16 insertions, 15 deletions
diff --git a/commands/compose/postpone.go b/commands/compose/postpone.go
index e1c0568..4b1e441 100644
--- a/commands/compose/postpone.go
+++ b/commands/compose/postpone.go
@@ -35,9 +35,13 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
if acct == nil {
return errors.New("No account selected")
}
- composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
+ tab := aerc.SelectedTab()
+ if tab == nil {
+ return errors.New("No tab selected")
+ }
+ composer, _ := tab.Content.(*widgets.Composer)
config := composer.Config()
- tabName := aerc.TabNames()[aerc.SelectedTabIndex()]
+ tabName := tab.Name
if config.Postpone == "" {
return errors.New("No Postpone location configured")
diff --git a/commands/compose/send.go b/commands/compose/send.go
index 776779e..cca1540 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -43,8 +43,12 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) > 1 {
return errors.New("Usage: send")
}
- composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
- tabName := aerc.TabNames()[aerc.SelectedTabIndex()]
+ tab := aerc.SelectedTab()
+ if tab == nil {
+ return errors.New("No selected tab")
+ }
+ composer, _ := tab.Content.(*widgets.Composer)
+ tabName := tab.Name
config := composer.Config()
if config.Outgoing == "" {
diff --git a/commands/move-tab.go b/commands/move-tab.go
index 4151bd7..8648ed3 100644
--- a/commands/move-tab.go
+++ b/commands/move-tab.go
@@ -34,18 +34,11 @@ func (MoveTab) Execute(aerc *widgets.Aerc, args []string) error {
return fmt.Errorf("failed to parse index argument: %v", err)
}
- i := aerc.SelectedTabIndex()
- l := aerc.NumTabs()
-
- if strings.HasPrefix(joinedArgs, "+") {
- i = (i + n) % l
- } else if strings.HasPrefix(joinedArgs, "-") {
- i = (((i + n) % l) + l) % l
- } else {
- i = n
+ var relative bool
+ if strings.HasPrefix(joinedArgs, "+") || strings.HasPrefix(joinedArgs, "-") {
+ relative = true
}
-
- aerc.MoveTab(i)
+ aerc.MoveTab(n, relative)
return nil
}