Skip to content

Commit 1f71667

Browse files
authored
Fix termpane not closing automatically after terminal job finished (zyedidia#3386)
Fix regression caused by the fix 0de1633 ("micro: Don't forward nil events into the sub event handler"): even if the terminal was started with `wait` set to false, it is not closed immediately after it finished its job, instead it shows "Press enter to close". The reason is that since the commit b68461c ("Terminal plugin callback support") the termpane code has been (slightly hackily) relying on nil events as notifications to close the terminal after it finished its job. So fix this by introducing a separate CloseTerms() function for notifying termpanes about that, decoupled from HandleEvent() which is for tcell events only.
1 parent a10624c commit 1f71667

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

cmd/micro/micro.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ func DoEvent() {
422422
b.AutoSave()
423423
}
424424
case <-shell.CloseTerms:
425+
action.Tabs.CloseTerms()
425426
case event = <-screen.Events:
426427
case <-screen.DrawChan():
427428
for len(screen.DrawChan()) > 0 {

internal/action/tab.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ func (t *TabList) ResetMouse() {
188188
}
189189
}
190190

191+
// CloseTerms notifies term panes that a terminal job has finished.
192+
func (t *TabList) CloseTerms() {
193+
for _, tab := range t.List {
194+
for _, p := range tab.Panes {
195+
if tp, ok := p.(*TermPane); ok {
196+
tp.HandleTermClose()
197+
}
198+
}
199+
}
200+
}
201+
191202
// Tabs is the global tab list
192203
var Tabs *TabList
193204

internal/action/termpane.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ func (t *TermPane) HandleEvent(event tcell.Event) {
159159
if t.Status != shell.TTDone {
160160
t.WriteString(event.EscSeq())
161161
}
162-
} else if e, ok := event.(*tcell.EventMouse); e != nil && (!ok || t.State.Mode(terminal.ModeMouseMask)) {
162+
} else if e, ok := event.(*tcell.EventMouse); !ok || t.State.Mode(terminal.ModeMouseMask) {
163163
// t.WriteString(event.EscSeq())
164-
} else if e != nil {
164+
} else {
165165
x, y := e.Position()
166166
v := t.GetView()
167167
x -= v.X
@@ -188,7 +188,12 @@ func (t *TermPane) HandleEvent(event tcell.Event) {
188188
t.mouseReleased = true
189189
}
190190
}
191+
}
191192

193+
// HandleTermClose is called when a terminal has finished its job
194+
// and should be closed. If that terminal is this termpane's terminal,
195+
// HandleTermClose will close the terminal and the termpane itself.
196+
func (t *TermPane) HandleTermClose() {
192197
if t.Status == shell.TTClose {
193198
t.Quit()
194199
}

0 commit comments

Comments
 (0)