Skip to content

Starting multiple screen sessions (lost key event) #194

@rivo

Description

@rivo

I need to temporarily exit a Screen session and then come back to it. From I can see, I can't reuse a Screen object on which Fini() has been called already. So I'm creating a new one. However, it seems that by doing that, one key event gets lost. The example below illustrates this. The first event after Init() is always a resize event. Then I hit a key so the second event is a key event. The main() function should thus exit after hitting a key two times. However, when you run it, it takes three key strokes to make it exit. (It's actually the second key stroke that is lost.)

Any idea why this happens? Also, in case starting multiple screen sessions is not a good idea, what would be a good way to go back to the previous terminal session temporarily?

Here's the code:

package main

import (
	"time"

	"github.com/gdamore/tcell"
)

// Program should exit after two key events. However, it takes three key strokes to
// stop it.
func main() {
	// First screen.
	screen, err := tcell.NewScreen()
	if err != nil {
		panic(err)
	}
	err = screen.Init()
	if err != nil {
		panic(err)
	}

	// Wait for input.
	screen.PollEvent() // Resize
	screen.PollEvent() // Key

	// Finish this screen.
	screen.Fini()

	// Go back for one second.
	time.Sleep(time.Second)

	// Second screen.
	screen, err = tcell.NewScreen()
	if err != nil {
		panic(err)
	}
	err = screen.Init()
	if err != nil {
		panic(err)
	}

	// Wait for input.
	screen.PollEvent() // Resize
	screen.PollEvent() // Key

	// Finish this screen.
	screen.Fini()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions