aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
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 /widgets
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>
Diffstat (limited to 'widgets')
-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
4 files changed, 22 insertions, 18 deletions
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