aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-03-15 20:38:37 +0100
committerRobin Jarry <robin@jarry.cc>2023-04-01 01:01:07 +0200
commit088d63ce934c34e113a5b3154dfcf91b49132067 (patch)
treea743b7f5f563d7382ebde83cac5ba498b3f6b1e7
parentaec90650f63ff0195599dae817016db137964bcb (diff)
downloadaerc-088d63ce934c34e113a5b3154dfcf91b49132067.tar.gz
tabs: make sure to close tab content
Rework how tabs are closed. Change the aerc.RemoveTab and aerc.ReplaceTab functions to accept a new boolean argument. If true, make sure to close the tab content. Signed-off-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/compose/abort.go3
-rw-r--r--commands/compose/postpone.go2
-rw-r--r--commands/compose/send.go2
-rw-r--r--commands/msg/delete.go6
-rw-r--r--commands/msg/move.go8
-rw-r--r--commands/msg/reply.go5
-rw-r--r--commands/msgview/close.go3
-rw-r--r--commands/msgview/next.go2
-rw-r--r--commands/term.go2
-rw-r--r--commands/terminal/close.go2
-rw-r--r--commands/util.go4
-rw-r--r--lib/ui/interfaces.go4
-rw-r--r--lib/ui/tab.go4
-rw-r--r--widgets/account-wizard.go4
-rw-r--r--widgets/aerc.go19
-rw-r--r--widgets/msgviewer.go5
-rw-r--r--widgets/terminal.go12
17 files changed, 43 insertions, 44 deletions
diff --git a/commands/compose/abort.go b/commands/compose/abort.go
index 44711eb3..d6a81b57 100644
--- a/commands/compose/abort.go
+++ b/commands/compose/abort.go
@@ -26,8 +26,7 @@ func (Abort) Execute(aerc *widgets.Aerc, args []string) error {
}
composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
- aerc.RemoveTab(composer)
- composer.Close()
+ aerc.RemoveTab(composer, true)
return nil
}
diff --git a/commands/compose/postpone.go b/commands/compose/postpone.go
index cc709ff7..dad76877 100644
--- a/commands/compose/postpone.go
+++ b/commands/compose/postpone.go
@@ -84,7 +84,7 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
aerc.NewTab(composer, tabName)
}
- aerc.RemoveTab(composer)
+ aerc.RemoveTab(composer, false)
var buf bytes.Buffer
ctr := datacounter.NewWriterCounter(&buf)
err = composer.WriteMessage(header, ctr)
diff --git a/commands/compose/send.go b/commands/compose/send.go
index a5571e37..d43f28ea 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -145,7 +145,7 @@ func send(aerc *widgets.Aerc, composer *widgets.Composer, ctx sendCtx,
) {
// we don't want to block the UI thread while we are sending
// so we do everything in a goroutine and hide the composer from the user
- aerc.RemoveTab(composer)
+ aerc.RemoveTab(composer, false)
aerc.PushStatus("Sending...", 10*time.Second)
log.Debugf("send uri: %s", ctx.uri.String())
diff --git a/commands/msg/delete.go b/commands/msg/delete.go
index 9a07e509..6d3fb4a3 100644
--- a/commands/msg/delete.go
+++ b/commands/msg/delete.go
@@ -56,11 +56,11 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
mv, isMsgView := h.msgProvider.(*widgets.MessageViewer)
if isMsgView {
if !config.Ui.NextMessageOnDelete {
- aerc.RemoveTab(h.msgProvider)
+ aerc.RemoveTab(h.msgProvider, true)
} else {
// no more messages in the list
if next == nil {
- aerc.RemoveTab(h.msgProvider)
+ aerc.RemoveTab(h.msgProvider, true)
acct.Messages().Select(-1)
ui.Invalidate()
return
@@ -73,7 +73,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
return
}
nextMv := widgets.NewMessageViewer(acct, view)
- aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
+ aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject, true)
})
}
} else {
diff --git a/commands/msg/move.go b/commands/msg/move.go
index fc35c41b..e8661a61 100644
--- a/commands/msg/move.go
+++ b/commands/msg/move.go
@@ -93,12 +93,10 @@ func handleDone(
mv, isMsgView := h.msgProvider.(*widgets.MessageViewer)
switch {
case isMsgView && !config.Ui.NextMessageOnDelete:
- mv.Close()
- aerc.RemoveTab(h.msgProvider)
+ aerc.RemoveTab(h.msgProvider, true)
case isMsgView:
- mv.Close()
if next == nil {
- aerc.RemoveTab(h.msgProvider)
+ aerc.RemoveTab(h.msgProvider, true)
acct.Messages().Select(-1)
ui.Invalidate()
return
@@ -111,7 +109,7 @@ func handleDone(
return
}
nextMv := widgets.NewMessageViewer(acct, view)
- aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
+ aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject, true)
})
default:
if next == nil {
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 4fb5860a..2b9f5d4f 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -181,9 +181,8 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushError("Error: " + err.Error())
return err
}
- if (mv != nil) && closeOnReply {
- mv.Close()
- aerc.RemoveTab(mv)
+ if mv != nil && closeOnReply {
+ aerc.RemoveTab(mv, true)
}
if args[0] == "reply" {
diff --git a/commands/msgview/close.go b/commands/msgview/close.go
index 1fed0b7c..5e4f3e92 100644
--- a/commands/msgview/close.go
+++ b/commands/msgview/close.go
@@ -25,7 +25,6 @@ func (Close) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: close")
}
mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer)
- mv.Close()
- aerc.RemoveTab(mv)
+ aerc.RemoveTab(mv, true)
return nil
}
diff --git a/commands/msgview/next.go b/commands/msgview/next.go
index d4c02123..cc7a5479 100644
--- a/commands/msgview/next.go
+++ b/commands/msgview/next.go
@@ -53,7 +53,7 @@ func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
}
nextMv := widgets.NewMessageViewer(acct, view)
aerc.ReplaceTab(mv, nextMv,
- nextMsg.Envelope.Subject)
+ nextMsg.Envelope.Subject, true)
})
}
if nextMsg := store.Selected(); nextMsg != nil {
diff --git a/commands/term.go b/commands/term.go
index d6662fe1..5d0dd020 100644
--- a/commands/term.go
+++ b/commands/term.go
@@ -45,7 +45,7 @@ func TermCore(aerc *widgets.Aerc, args []string) error {
ui.Invalidate()
}
term.OnClose = func(err error) {
- aerc.RemoveTab(term)
+ aerc.RemoveTab(term, false)
if err != nil {
aerc.PushError(err.Error())
}
diff --git a/commands/terminal/close.go b/commands/terminal/close.go
index 1698e930..812266c0 100644
--- a/commands/terminal/close.go
+++ b/commands/terminal/close.go
@@ -25,6 +25,6 @@ func (Close) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: close")
}
term, _ := aerc.SelectedTabContent().(*widgets.Terminal)
- term.Close(nil)
+ term.Close()
return nil
}
diff --git a/commands/util.go b/commands/util.go
index 8b7060ec..7e21e167 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -38,12 +38,12 @@ func QuickTerm(aerc *widgets.Aerc, args []string, stdin io.Reader) (*widgets.Ter
if err != nil {
aerc.PushError(err.Error())
// remove the tab on error, otherwise it gets stuck
- aerc.RemoveTab(term)
+ aerc.RemoveTab(term, false)
} else {
aerc.PushStatus("Process complete, press any key to close.",
10*time.Second)
term.OnEvent = func(event tcell.Event) bool {
- aerc.RemoveTab(term)
+ aerc.RemoveTab(term, true)
return true
}
}
diff --git a/lib/ui/interfaces.go b/lib/ui/interfaces.go
index 757f81c9..a28c6c29 100644
--- a/lib/ui/interfaces.go
+++ b/lib/ui/interfaces.go
@@ -16,6 +16,10 @@ type Drawable interface {
Invalidate()
}
+type Closeable interface {
+ Close()
+}
+
type RootDrawable interface {
Initialize(ui *UI)
}
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index d336d646..b992a8a2 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -1,7 +1,6 @@
package ui
import (
- "io"
"sync"
"github.com/gdamore/tcell/v2"
@@ -116,9 +115,6 @@ func (tabs *Tabs) Replace(contentSrc Drawable, contentTarget Drawable, name stri
if tab.Content == contentSrc {
tabs.tabs[i] = replaceTab
tabs.selectPriv(i)
- if c, ok := contentSrc.(io.Closer); ok {
- c.Close()
- }
break
}
}
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index 60497f83..9ad814b5 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -570,14 +570,14 @@ func (wizard *AccountWizard) finish(tutorial bool) {
}
wizard.aerc.NewTab(term, "Tutorial")
term.OnClose = func(err error) {
- wizard.aerc.RemoveTab(term)
+ wizard.aerc.RemoveTab(term, false)
if err != nil {
wizard.aerc.PushError(err.Error())
}
}
}
- wizard.aerc.RemoveTab(wizard)
+ wizard.aerc.RemoveTab(wizard, false)
}
func (wizard *AccountWizard) imapUri() url.URL {
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 70083860..352bcadd 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -117,13 +117,8 @@ func NewAerc(
return
case *AccountWizard:
return
- case *Composer:
- aerc.RemoveTab(content)
- content.Close()
- case *Terminal:
- content.Close(nil)
- case *MessageViewer:
- aerc.RemoveTab(content)
+ default:
+ aerc.RemoveTab(content, true)
}
}
@@ -485,13 +480,19 @@ func (aerc *Aerc) NewTab(clickable ui.Drawable, name string) *ui.Tab {
return tab
}
-func (aerc *Aerc) RemoveTab(tab ui.Drawable) {
+func (aerc *Aerc) RemoveTab(tab ui.Drawable, closeContent bool) {
aerc.tabs.Remove(tab)
aerc.UpdateStatus()
+ if content, ok := tab.(ui.Closeable); ok && closeContent {
+ content.Close()
+ }
}
-func (aerc *Aerc) ReplaceTab(tabSrc ui.Drawable, tabTarget ui.Drawable, name string) {
+func (aerc *Aerc) ReplaceTab(tabSrc ui.Drawable, tabTarget ui.Drawable, name string, closeSrc bool) {
aerc.tabs.Replace(tabSrc, tabTarget, name)
+ if content, ok := tabSrc.(ui.Closeable); ok && closeSrc {
+ content.Close()
+ }
}
func (aerc *Aerc) MoveTab(i int, relative bool) {
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 0375dda9..f38b186a 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -390,11 +390,10 @@ func (mv *MessageViewer) Bindings() string {
}
}
-func (mv *MessageViewer) Close() error {
+func (mv *MessageViewer) Close() {
if mv.switcher != nil {
mv.switcher.Cleanup()
}
- return nil
}
func (ps *PartSwitcher) Invalidate() {
@@ -847,7 +846,7 @@ func (pv *PartViewer) Draw(ctx *ui.Context) {
func (pv *PartViewer) Cleanup() {
if pv.term != nil {
- pv.term.Close(nil)
+ pv.term.Close()
}
}
diff --git a/widgets/terminal.go b/widgets/terminal.go
index 9a2ebbef..0e31bf71 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -35,7 +35,11 @@ func NewTerminal(cmd *exec.Cmd) (*Terminal, error) {
return term, nil
}
-func (term *Terminal) Close(err error) {
+func (term *Terminal) Close() {
+ term.closeErr(nil)
+}
+
+func (term *Terminal) closeErr(err error) {
if term.closed {
return
}
@@ -62,7 +66,7 @@ func (term *Terminal) Destroy() {
}
// If we destroy, we don't want to call the OnClose callback
term.OnClose = nil
- term.Close(nil)
+ term.Close()
term.vterm = nil
term.destroyed = true
}
@@ -82,7 +86,7 @@ func (term *Terminal) Draw(ctx *ui.Context) {
attr := &syscall.SysProcAttr{Setsid: true, Setctty: true, Ctty: 1}
if err := term.vterm.StartWithAttrs(term.cmd, attr); err != nil {
log.Errorf("error running terminal: %v", err)
- term.Close(err)
+ term.closeErr(err)
return
}
term.running = true
@@ -152,7 +156,7 @@ func (term *Terminal) HandleEvent(ev tcell.Event) bool {
term.OnTitle(ev.Title())
}
case *tcellterm.EventClosed:
- term.Close(nil)
+ term.Close()
ui.QueueRedraw()
}
return false