[GH-ISSUE #756] A screen passed via Application.SetScreen() before Application.Run() is not initialised. #553

Closed
opened 2026-03-04 01:05:58 +03:00 by kerem · 1 comment
Owner

Originally created by @tjhowse on GitHub (Aug 14, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/756

func withWebsocketTty(initScreen bool) {
	// Make a WebsocketTty object
	tty := websockettty.WebsocketTty{}
	// Look up a terminfo definition should work
	ti, err := tcell.LookupTerminfo("tmux")
	if err != nil {
		log.Fatal(err)
	}
	// Build a tcell.Screen object
	screen, err := tcell.NewTerminfoScreenFromTtyTerminfo(&tty, ti)
	if err != nil {
		log.Fatal(err)
	}
	if initScreen {
		screen.Init()
	}
	// if !screen.CanDisplay('=', false) {
	// 	log.Fatal("Your terminal cannot display the equals sign")
	// }
	// Build a tview application
	app := tview.NewApplication()
	box := tview.NewBox().SetBorder(true).SetTitle("Hi")
	app.SetRoot(box, true)

	// Start the application running in the background.
	app.SetScreen(screen)
	go app.Run()
	// Crudely give it some time to draw.
	time.Sleep(time.Millisecond * 100)

	fmt.Printf("%s", tty.Screenbuffer)
}

This function only prints the expected output if initScreen is true. The docs on SetScreen says Init() need not be called on a screen before passing it to the app: https://github.com/rivo/tview/blob/master/application.go#L172

I will raise a PR shortly.

Originally created by @tjhowse on GitHub (Aug 14, 2022). Original GitHub issue: https://github.com/rivo/tview/issues/756 ```go func withWebsocketTty(initScreen bool) { // Make a WebsocketTty object tty := websockettty.WebsocketTty{} // Look up a terminfo definition should work ti, err := tcell.LookupTerminfo("tmux") if err != nil { log.Fatal(err) } // Build a tcell.Screen object screen, err := tcell.NewTerminfoScreenFromTtyTerminfo(&tty, ti) if err != nil { log.Fatal(err) } if initScreen { screen.Init() } // if !screen.CanDisplay('=', false) { // log.Fatal("Your terminal cannot display the equals sign") // } // Build a tview application app := tview.NewApplication() box := tview.NewBox().SetBorder(true).SetTitle("Hi") app.SetRoot(box, true) // Start the application running in the background. app.SetScreen(screen) go app.Run() // Crudely give it some time to draw. time.Sleep(time.Millisecond * 100) fmt.Printf("%s", tty.Screenbuffer) } ``` This function only prints the expected output if `initScreen` is true. The docs on SetScreen says Init() need not be called on a screen before passing it to the app: https://github.com/rivo/tview/blob/master/application.go#L172 I will raise a PR shortly.
kerem closed this issue 2026-03-04 01:05:58 +03:00
Author
Owner

@rivo commented on GitHub (Nov 13, 2022):

Indeed, that's a case that was overlooked. Thanks for the fix.

<!-- gh-comment-id:1312765769 --> @rivo commented on GitHub (Nov 13, 2022): Indeed, that's a case that was overlooked. Thanks for the fix.
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#553
No description provided.