Skip to content

EventError fired after suspended Screen resumes #480

@rivo

Description

@rivo

In the past, in tview, I hadn't handled the EventError event. But as one user reported, this gets fired when the user closes the terminal when the application is still running so it should be handled.

Now it turns out I'm getting EventError after a suspended screen resumes. Here's some code reproduce this:

package main

import (
	"fmt"
	"os"
	"os/exec"

	"github.com/gdamore/tcell/v2"
)

func main() {
	s, e := tcell.NewScreen()
	if e != nil {
		fmt.Fprintf(os.Stderr, "%v\n", e)
		os.Exit(1)
	}
	if e := s.Init(); e != nil {
		fmt.Fprintf(os.Stderr, "%v\n", e)
		os.Exit(1)
	}

	for {
		switch ev := s.PollEvent().(type) {
		case *tcell.EventError:
			s.Fini()
			panic(ev) // This fires with EOF after we return from vim.
		case *tcell.EventKey:
			if ev.Key() == tcell.KeyEscape {
				s.Fini()
				os.Exit(0)
			} else if ev.Rune() == 's' { // Press "s" to suspend and start vim.
				if err := s.Suspend(); err != nil {
					panic(err)
				}

				cmd := exec.Command("vim", "/tmp/foo")
				cmd.Stdout = os.Stdout
				cmd.Stdin = os.Stdin
				_ = cmd.Run()

				if err := s.Resume(); err != nil {
					panic(err)
				}
			}
		}
	}
}

Press s to suspend the screen and start vim. When you exit vim, the application panics with "EOF" after the EventError is handled. (It's not vim, this happens with any command.)

Any idea why this happens?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions