Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with implementing a tcell.Tty wrapping a websocket #541

Closed
tjhowse opened this issue Aug 14, 2022 · 1 comment
Closed

Issue with implementing a tcell.Tty wrapping a websocket #541

tjhowse opened this issue Aug 14, 2022 · 1 comment

Comments

@tjhowse
Copy link

tjhowse commented Aug 14, 2022

This isn't an issue with tcell, per se, but I thought this might be a good place to ask.

I'm working on a personal project that provides an interface to a tcell (tview, actually) application via websockets to xterm.js in a browser. I am hitting an issue stemming from a lack of understanding of how TTY screen buffer contents translate to printable characters. I have boiled down my implementation to a minimum demonstration here: https://github.com/tjhowse/websockettty

This demonstration excludes all the websocket stuff and just tries to print the screenbuffer to the local terminal.

Expectation:

╔═══Hi═══╗
║        ║
║        ║
║        ║
║        ║
║        ║
║        ║
║        ║
║        ║
╚════════╝

Reality:

??????????
??????????
??????????
??????????
??????????
??????????
??????????
??????????
??????????
??????????

Any help would be fantastic.

Cheers,
tjhowse.

@tjhowse
Copy link
Author

tjhowse commented Aug 14, 2022

OK. I think I've got to the bottom of this.

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'll raise an issue on the tview repo.

Cheers,
tjhowse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant