[GH-ISSUE #499] Application.Stop() not working after call to Application.Suspend() #362

Closed
opened 2026-03-04 01:04:20 +03:00 by kerem · 2 comments
Owner

Originally created by @khughitt on GitHub (Sep 14, 2020).
Original GitHub issue: https://github.com/rivo/tview/issues/499

Overview

When attempting to call app.Stop() after a call to app.Suspend(), application continues running and appears to ignore/not fully process the call to app.Stop().

Interestingly, the first time I call a function which calls app.Suspend() and then app.Stop() (as in the example below), the application simply returns to it's normal running state.

If I then call the function a second time, after the Suspend function finishes, the app screen is cleared, but the application doesn't fully exit.

I have to then press cntl-c to finally exit the app completely.

To reproduce

package main

import (
	"github.com/rivo/tview"
	"os"
	"os/exec"
)

func main() {
	app := tview.NewApplication()

	form := tview.NewForm().
		AddButton("Launch Neovim & Exit", func() {
			app.Suspend(func() {
				cmd := exec.Command("nvim", "/tmp/foo")
				cmd.Stdout = os.Stdout
				cmd.Stdin = os.Stdin
				cmd.Run()
			})
			app.Stop()
		}).AddButton("Exit", func() {
		// uncomment empty callback below to prevent app.Stop() from working here, too
		// app.Suspend(func() {})
		app.Stop()
	})

	form.SetBorder(true)

	if err := app.SetRoot(form, true).SetFocus(form).Run(); err != nil {
		panic(err)
	}

}

System Info

Originally created by @khughitt on GitHub (Sep 14, 2020). Original GitHub issue: https://github.com/rivo/tview/issues/499 **Overview** When attempting to call `app.Stop()` after a call to `app.Suspend()`, application continues running and appears to ignore/not fully process the call to `app.Stop()`. Interestingly, the first time I call a function which calls `app.Suspend()` and then `app.Stop()` (as in the example below), the application simply returns to it's normal running state. If I then call the function a second time, after the Suspend function finishes, the app screen is cleared, but the application doesn't fully exit. I have to then press `cntl-c` to finally exit the app completely. **To reproduce** ```go package main import ( "github.com/rivo/tview" "os" "os/exec" ) func main() { app := tview.NewApplication() form := tview.NewForm(). AddButton("Launch Neovim & Exit", func() { app.Suspend(func() { cmd := exec.Command("nvim", "/tmp/foo") cmd.Stdout = os.Stdout cmd.Stdin = os.Stdin cmd.Run() }) app.Stop() }).AddButton("Exit", func() { // uncomment empty callback below to prevent app.Stop() from working here, too // app.Suspend(func() {}) app.Stop() }) form.SetBorder(true) if err := app.SetRoot(form, true).SetFocus(form).Run(); err != nil { panic(err) } } ``` **System Info** - Arch Linux 5.8.8 64-bit - Go 1.15.2 - [Termite](https://github.com/thestinger/termite) / [XTerm](https://invisible-island.net/xterm/)
kerem closed this issue 2026-03-04 01:04:20 +03:00
Author
Owner

@rivo commented on GitHub (Dec 4, 2020):

Thanks for letting me know. This should be fixed in the latest version. But you'll have to call app.Stop() in your suspend function, right after cmd.Run().

There is probably a way to make it work with the way your code is written. But I just spent quite a bit of time on this but couldn't make it work. Unfortunately, to suspend the application requires a whole bunch of trickery with the tcell.Screen object. The more I add to it, the more complex it gets and I'm afraid it will reopen old issues where Suspend() didn't work as expected. So I'll leave it the way it is for now.

<!-- gh-comment-id:738890093 --> @rivo commented on GitHub (Dec 4, 2020): Thanks for letting me know. This should be fixed in the latest version. But you'll have to call `app.Stop()` in your suspend function, right after `cmd.Run()`. There is probably a way to make it work with the way your code is written. But I just spent quite a bit of time on this but couldn't make it work. Unfortunately, to suspend the application requires a whole bunch of trickery with the `tcell.Screen` object. The more I add to it, the more complex it gets and I'm afraid it will reopen old issues where `Suspend()` didn't work as expected. So I'll leave it the way it is for now.
Author
Owner

@khughitt commented on GitHub (Dec 4, 2020):

Thanks for taking the time to look into it / provide a solution! It's no trouble to add a call to app.Stop(), so I'm completely fine with that and would rather you use your time on better things. Hope you have a great weekend!

<!-- gh-comment-id:738973648 --> @khughitt commented on GitHub (Dec 4, 2020): Thanks for taking the time to look into it / provide a solution! It's no trouble to add a call to `app.Stop()`, so I'm completely fine with that and would rather you use your time on better things. Hope you have a great weekend!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#362
No description provided.