[GH-ISSUE #1085] Posible textarea error #787

Closed
opened 2026-03-04 01:07:45 +03:00 by kerem · 0 comments
Owner

Originally created by @manuelacgu on GitHub (Apr 14, 2025).
Original GitHub issue: https://github.com/rivo/tview/issues/1085

Hi, while checking the logs of my application, I noticed that sometimes I get the following error:
runtime error: index out of range [-1]

runtime error: index out of range [-1]
	/usr/local/go/src/runtime/panic.go:785 +0x132
github.com/rivo/tview.(*TextArea).replace(0xc000515b08, {0xcb5c, 0x0, 0xffffffffffffffff}, {0x0, 0x0, 0x0}, {0xc000d35b88, 0x2}, 0xff?)
	/go/pkg/mod/github.com/rivo/tview@v0.0.0-20250325173046-7b72abf45814/textarea.go:1083 +0x1192
github.com/rivo/tview.(*TextArea).Replace(0xc000515b08, 0xc000160870?, 0x13?, {0xc000d35b88, 0x2})
	/go/pkg/mod/github.com/rivo/tview@v0.0.0-20250325173046-7b72abf45814/textarea.go:635 +0xd1
github.com/rivo/tview.(*InputField).SetText(...)
	/go/pkg/mod/github.com/rivo/tview@v0.0.0-20250325173046-7b72abf45814/inputfield.go:158
github.com/inditex/cli-icarussaas/internal/ui/zones.(*DetailZone).UpdateInfoDetail(0xc00011e900, 0xc0002152b0)
	/github/workspace/code/internal/ui/zones/detail_zone.go:160 +0x465

It seems the bug happens when the application has been running for a long time, so to try to reproduce it, I created an infinite loop that keeps setting values in an input field. I haven’t been able to reproduce the crash, but I did observe a behavior that doesn’t seem quite right…

This value keeps growing endlessly...

Image

Image


import (
	"github.com/gdamore/tcell/v2"
	"github.com/inditex/cli-icarussaas/internal/ui/goroutines"
	"github.com/rivo/tview"
	"math/rand"
	"time"
)

func randomString(minLength, maxLength int) string {
	const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
	length := seededRand.Intn(maxLength-minLength+1) + minLength
	result := make([]byte, length)
	for i := range result {
		result[i] = charset[seededRand.Intn(len(charset))]
	}
	return string(result)
}

func main() {

	app := tview.NewApplication()
	inputField := tview.NewInputField().
		SetLabel("Enter a number: ").
		SetFieldWidth(20).SetLabelWidth(20).
		SetFieldTextColor(tcell.ColorGreen).
		SetAcceptanceFunc(tview.InputFieldMaxLength(50))

	q := func() {
		randomStr := randomString(10,30)
		inputField.SetText(randomStr)
		app.Draw()
	}

	duration := 100 * time.Millisecond
	errSchedule := goroutines.ScheduleTask(duration, q)
	if errSchedule != nil {
		panic(errSchedule)
	}

	if err := app.SetRoot(inputField, true).SetFocus(inputField).Run(); err != nil {
		panic(err)
	}
}
func init() {
	//Nothing to do
}

Is that behavior expected? Are you aware of the bug I’m referring to?

Originally created by @manuelacgu on GitHub (Apr 14, 2025). Original GitHub issue: https://github.com/rivo/tview/issues/1085 Hi, while checking the logs of my application, I noticed that sometimes I get the following error: runtime error: index out of range [-1] ``` runtime error: index out of range [-1] /usr/local/go/src/runtime/panic.go:785 +0x132 github.com/rivo/tview.(*TextArea).replace(0xc000515b08, {0xcb5c, 0x0, 0xffffffffffffffff}, {0x0, 0x0, 0x0}, {0xc000d35b88, 0x2}, 0xff?) /go/pkg/mod/github.com/rivo/tview@v0.0.0-20250325173046-7b72abf45814/textarea.go:1083 +0x1192 github.com/rivo/tview.(*TextArea).Replace(0xc000515b08, 0xc000160870?, 0x13?, {0xc000d35b88, 0x2}) /go/pkg/mod/github.com/rivo/tview@v0.0.0-20250325173046-7b72abf45814/textarea.go:635 +0xd1 github.com/rivo/tview.(*InputField).SetText(...) /go/pkg/mod/github.com/rivo/tview@v0.0.0-20250325173046-7b72abf45814/inputfield.go:158 github.com/inditex/cli-icarussaas/internal/ui/zones.(*DetailZone).UpdateInfoDetail(0xc00011e900, 0xc0002152b0) /github/workspace/code/internal/ui/zones/detail_zone.go:160 +0x465 ``` It seems the bug happens when the application has been running for a long time, so to try to reproduce it, I created an infinite loop that keeps setting values in an input field. I haven’t been able to reproduce the crash, but I did observe a behavior that doesn’t seem quite right… This value keeps growing endlessly... ![Image](https://github.com/user-attachments/assets/d8c1863b-7b8a-4aad-9455-111b20f55cde) ![Image](https://github.com/user-attachments/assets/02966c88-62f5-422a-8a2e-d32f1a00e859) ```package main import ( "github.com/gdamore/tcell/v2" "github.com/inditex/cli-icarussaas/internal/ui/goroutines" "github.com/rivo/tview" "math/rand" "time" ) func randomString(minLength, maxLength int) string { const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) length := seededRand.Intn(maxLength-minLength+1) + minLength result := make([]byte, length) for i := range result { result[i] = charset[seededRand.Intn(len(charset))] } return string(result) } func main() { app := tview.NewApplication() inputField := tview.NewInputField(). SetLabel("Enter a number: "). SetFieldWidth(20).SetLabelWidth(20). SetFieldTextColor(tcell.ColorGreen). SetAcceptanceFunc(tview.InputFieldMaxLength(50)) q := func() { randomStr := randomString(10,30) inputField.SetText(randomStr) app.Draw() } duration := 100 * time.Millisecond errSchedule := goroutines.ScheduleTask(duration, q) if errSchedule != nil { panic(errSchedule) } if err := app.SetRoot(inputField, true).SetFocus(inputField).Run(); err != nil { panic(err) } } func init() { //Nothing to do } ``` Is that behavior expected? Are you aware of the bug I’m referring to?
kerem closed this issue 2026-03-04 01:07:45 +03:00
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#787
No description provided.