[GH-ISSUE #633] strange UI based on tview #464

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

Originally created by @zjkyz8 on GitHub (Aug 7, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/633

Hi guys,
I am new comer of tview, recently, I am working on a ssh bastion project.
I plan to use tview with tcell and ssh to draw a UI when user connect to ssh server, but I got a really strange ui like this:
image

Below is the code


func shell(s ssh.Session, version, gitSha, gitTag string) error {
	ptmx, tty, err := pty.Open()

	pty := &ptyOfTty{
		in:  ptmx,
		out: tty,
		sig: make(chan os.Signal),
		s:   s,
	}
	screen, err := tcell.NewTerminfoScreenFromTty(pty)
	// screen.Set
	if err != nil {
		return fmt.Errorf("%v\n", err)

	}
	if e := screen.Init(); e != nil {
		return fmt.Errorf("%v\n", e)
	}

	// go func() {
	// 	for win := range winCh {
	// 		pty.width = win.Width
	// 		pty.height = win.Height
	// 		pty.sig <- syscall.SIGWINCH
	// 	}
	// }()

	// go

	// go func() { _, _ = io.Copy(ptmx, s) }()
	// go func() { _, _ = io.Copy(s, ptmx) }()
	// go func() { _, _ = io.Copy(pty, s) }()
	// go func() { _, _ = io.Copy(s, pty) }()

	termLoop(screen, s)
	return nil
}


func termLoop(s tcell.Screen, sess ssh.Session) {
	app := tview.NewApplication()
	app.SetScreen(s)

	// newPrimitive := func(text string) tview.Primitive {
	// 	return tview.NewTextView().
	// 		SetTextAlign(tview.AlignCenter).
	// 		SetText(text)
	// }
	// menu := newPrimitive("Menu")
	// main := newPrimitive("Main content")
	// sideBar := newPrimitive("Side Bar")

	grid := tview.NewGrid().
		SetRows(2, 0, 1).
		SetColumns(0).
		SetBorders(true).
		AddItem(tview.NewGrid().SetRows(2, 1).AddItem(tview.NewTextView().SetTextAlign(tview.AlignLeft).SetText("welcome to"), 0, 0, 1, 1, 0, 0, false).AddItem(tview.NewTextView().SetTextAlign(tview.AlignLeft).SetText("快捷键"), 1, 0, 1, 1, 0, 0, false), 0, 0, 1, 3, 0, 0, false).
		AddItem(tview.NewTextView().SetTextAlign(tview.AlignLeft).SetText("当前22-58条,共60条"), 2, 0, 1, 3, 0, 0, false)

	// // Layout for screens narrower than 100 cells (menu and side bar are hidden).
	// grid.AddItem(menu, 0, 0, 0, 0, 0, 0, false).
	// 	AddItem(main, 1, 0, 1, 3, 0, 0, false).
	// 	AddItem(sideBar, 0, 0, 0, 0, 0, 0, false)

	// // Layout for screens wider than 100 cells.
	// grid.AddItem(menu, 1, 0, 1, 1, 0, 100, false).
	// 	AddItem(main, 1, 1, 1, 1, 0, 100, false).
	// 	AddItem(sideBar, 1, 2, 1, 1, 0, 100, false)

	// grid.SetBorderPadding(1, 1, 1, 1).SetBorderAttributes(tcell.AttrBold)

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

Can any one figure out the reason of this strange ui?
Thank you very much for your reply

Originally created by @zjkyz8 on GitHub (Aug 7, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/633 Hi guys, I am new comer of tview, recently, I am working on a ssh bastion project. I plan to use tview with tcell and ssh to draw a UI when user connect to ssh server, but I got a really strange ui like this: ![image](https://user-images.githubusercontent.com/1856389/128597404-5bf1caa0-bfc2-48df-930a-1d510ad128fa.png) Below is the code ```golang func shell(s ssh.Session, version, gitSha, gitTag string) error { ptmx, tty, err := pty.Open() pty := &ptyOfTty{ in: ptmx, out: tty, sig: make(chan os.Signal), s: s, } screen, err := tcell.NewTerminfoScreenFromTty(pty) // screen.Set if err != nil { return fmt.Errorf("%v\n", err) } if e := screen.Init(); e != nil { return fmt.Errorf("%v\n", e) } // go func() { // for win := range winCh { // pty.width = win.Width // pty.height = win.Height // pty.sig <- syscall.SIGWINCH // } // }() // go // go func() { _, _ = io.Copy(ptmx, s) }() // go func() { _, _ = io.Copy(s, ptmx) }() // go func() { _, _ = io.Copy(pty, s) }() // go func() { _, _ = io.Copy(s, pty) }() termLoop(screen, s) return nil } func termLoop(s tcell.Screen, sess ssh.Session) { app := tview.NewApplication() app.SetScreen(s) // newPrimitive := func(text string) tview.Primitive { // return tview.NewTextView(). // SetTextAlign(tview.AlignCenter). // SetText(text) // } // menu := newPrimitive("Menu") // main := newPrimitive("Main content") // sideBar := newPrimitive("Side Bar") grid := tview.NewGrid(). SetRows(2, 0, 1). SetColumns(0). SetBorders(true). AddItem(tview.NewGrid().SetRows(2, 1).AddItem(tview.NewTextView().SetTextAlign(tview.AlignLeft).SetText("welcome to"), 0, 0, 1, 1, 0, 0, false).AddItem(tview.NewTextView().SetTextAlign(tview.AlignLeft).SetText("快捷键"), 1, 0, 1, 1, 0, 0, false), 0, 0, 1, 3, 0, 0, false). AddItem(tview.NewTextView().SetTextAlign(tview.AlignLeft).SetText("当前22-58条,共60条"), 2, 0, 1, 3, 0, 0, false) // // Layout for screens narrower than 100 cells (menu and side bar are hidden). // grid.AddItem(menu, 0, 0, 0, 0, 0, 0, false). // AddItem(main, 1, 0, 1, 3, 0, 0, false). // AddItem(sideBar, 0, 0, 0, 0, 0, 0, false) // // Layout for screens wider than 100 cells. // grid.AddItem(menu, 1, 0, 1, 1, 0, 100, false). // AddItem(main, 1, 1, 1, 1, 0, 100, false). // AddItem(sideBar, 1, 2, 1, 1, 0, 100, false) // grid.SetBorderPadding(1, 1, 1, 1).SetBorderAttributes(tcell.AttrBold) if err := app.SetRoot(grid, true).SetFocus(grid).Run(); err != nil { panic(err) } ``` Can any one figure out the reason of this strange ui? Thank you very much for your reply
kerem closed this issue 2026-03-04 01:05:13 +03:00
Author
Owner

@rivo commented on GitHub (Aug 7, 2021):

Please check the FAQ, it's the only question there so far:

https://github.com/rivo/tview/wiki/FAQ

<!-- gh-comment-id:894686852 --> @rivo commented on GitHub (Aug 7, 2021): Please check the FAQ, it's the only question there so far: https://github.com/rivo/tview/wiki/FAQ
Author
Owner

@zjkyz8 commented on GitHub (Aug 8, 2021):

Thanks very much, That work for me. :)

<!-- gh-comment-id:894722840 --> @zjkyz8 commented on GitHub (Aug 8, 2021): Thanks very much, That work for me. :)
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#464
No description provided.