[GH-ISSUE #891] non-scrollable TextView panics when too small #649

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

Originally created by @rwos on GitHub (Sep 27, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/891

this is the smallest app that reliably reproduces this for me (in my real app I have the text view in a dynamically-sized flex item and it crashes when the terminal window is made too small):

package main

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

func main() {
	app := tview.NewApplication()
	textView := tview.NewTextView()
	textView.SetText("hello")
	textView.SetBorder(true)
	textView.SetScrollable(false)
	flex := tview.NewFlex().SetDirection(tview.FlexRow).
		AddItem(textView, 1, 0, false)
	if err := app.SetRoot(flex, true).SetFocus(flex).Run(); err != nil {
		panic(err)
	}
}

crashes with

$ go run .
panic: runtime error: index out of range [1] with length 1 [recovered]
	panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1()
	/Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/application.go:251 +0x4d
panic({0x113f0c0, 0xc00009c018})
	/usr/local/Cellar/go/1.20.4/libexec/src/runtime/panic.go:884 +0x213
github.com/rivo/tview.(*TextView).Draw(0xc00018c000, {0x117b010, 0xc00018e000})
	/Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/textview.go:1263 +0xab1
github.com/rivo/tview.(*Flex).Draw(0xc000076840, {0x117b010?, 0xc00018e000})
	/Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/flex.go:196 +0x34b
github.com/rivo/tview.(*Application).draw(0xc000188000)
	/Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/application.go:612 +0x15a
github.com/rivo/tview.(*Application).Run(0xc000188000)
	/Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/application.go:257 +0x13e
main.main()
	/Users/richard/src/work/tview-crash/main.go:15 +0x213
exit status 2
Originally created by @rwos on GitHub (Sep 27, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/891 this is the smallest app that reliably reproduces this for me (in my real app I have the text view in a dynamically-sized flex item and it crashes when the terminal window is made too small): ```go package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() textView := tview.NewTextView() textView.SetText("hello") textView.SetBorder(true) textView.SetScrollable(false) flex := tview.NewFlex().SetDirection(tview.FlexRow). AddItem(textView, 1, 0, false) if err := app.SetRoot(flex, true).SetFocus(flex).Run(); err != nil { panic(err) } } ``` crashes with ``` $ go run . panic: runtime error: index out of range [1] with length 1 [recovered] panic: runtime error: index out of range [1] with length 1 goroutine 1 [running]: github.com/rivo/tview.(*Application).Run.func1() /Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/application.go:251 +0x4d panic({0x113f0c0, 0xc00009c018}) /usr/local/Cellar/go/1.20.4/libexec/src/runtime/panic.go:884 +0x213 github.com/rivo/tview.(*TextView).Draw(0xc00018c000, {0x117b010, 0xc00018e000}) /Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/textview.go:1263 +0xab1 github.com/rivo/tview.(*Flex).Draw(0xc000076840, {0x117b010?, 0xc00018e000}) /Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/flex.go:196 +0x34b github.com/rivo/tview.(*Application).draw(0xc000188000) /Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/application.go:612 +0x15a github.com/rivo/tview.(*Application).Run(0xc000188000) /Users/richard/src/go/pkg/mod/github.com/rivo/tview@v0.0.0-20230927091330-c961b0f0b9c5/application.go:257 +0x13e main.main() /Users/richard/src/work/tview-crash/main.go:15 +0x213 exit status 2 ```
kerem closed this issue 2026-03-04 01:06:46 +03:00
Author
Owner

@rivo commented on GitHub (Sep 28, 2023):

Thanks for letting me know. The latest commit should fix this.

<!-- gh-comment-id:1738487196 --> @rivo commented on GitHub (Sep 28, 2023): Thanks for letting me know. The latest commit should fix this.
Author
Owner

@rwos commented on GitHub (Sep 28, 2023):

Wow that was fast, seems fixed on my end, perfect, thank you!

<!-- gh-comment-id:1738802701 --> @rwos commented on GitHub (Sep 28, 2023): Wow that was fast, seems fixed on my end, perfect, thank you!
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#649
No description provided.