Fix termpane not closing automatically after terminal job finished (#3386)

Fix regression caused by the fix 0de16334d3 ("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 b68461cf72 ("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.
This commit is contained in:
Dmytro Maluka
2024-07-15 09:35:50 +02:00
committed by GitHub
parent a10624cc33
commit 1f71667616
3 changed files with 19 additions and 2 deletions

View File

@@ -422,6 +422,7 @@ func DoEvent() {
b.AutoSave()
}
case <-shell.CloseTerms:
action.Tabs.CloseTerms()
case event = <-screen.Events:
case <-screen.DrawChan():
for len(screen.DrawChan()) > 0 {

View File

@@ -188,6 +188,17 @@ func (t *TabList) ResetMouse() {
}
}
// CloseTerms notifies term panes that a terminal job has finished.
func (t *TabList) CloseTerms() {
for _, tab := range t.List {
for _, p := range tab.Panes {
if tp, ok := p.(*TermPane); ok {
tp.HandleTermClose()
}
}
}
}
// Tabs is the global tab list
var Tabs *TabList

View File

@@ -159,9 +159,9 @@ func (t *TermPane) HandleEvent(event tcell.Event) {
if t.Status != shell.TTDone {
t.WriteString(event.EscSeq())
}
} else if e, ok := event.(*tcell.EventMouse); e != nil && (!ok || t.State.Mode(terminal.ModeMouseMask)) {
} else if e, ok := event.(*tcell.EventMouse); !ok || t.State.Mode(terminal.ModeMouseMask) {
// t.WriteString(event.EscSeq())
} else if e != nil {
} else {
x, y := e.Position()
v := t.GetView()
x -= v.X
@@ -188,7 +188,12 @@ func (t *TermPane) HandleEvent(event tcell.Event) {
t.mouseReleased = true
}
}
}
// HandleTermClose is called when a terminal has finished its job
// and should be closed. If that terminal is this termpane's terminal,
// HandleTermClose will close the terminal and the termpane itself.
func (t *TermPane) HandleTermClose() {
if t.Status == shell.TTClose {
t.Quit()
}