rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
11.17k stars 574 forks source link

non-scrollable TextView panics when too small #891

Closed rwos closed 1 year ago

rwos commented 1 year ago

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
rivo commented 1 year ago

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

rwos commented 1 year ago

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