TextView.GetRegionText() error when region contains color tags #69

Closed
opened 2021-07-11 19:17:10 +00:00 by bacardi55 · 1 comment

Hi,
Firt, a big thanks for the awesome work on cview!!

I think I found a bug with TextView.GetRegionText() (unless I'm doing something wrong) when a region contains color tags.

I created this simple code (based on the TextView demo) to reproduce:

package main

import (
	"code.rocketnine.space/tslocum/cview"
	"github.com/gdamore/tcell/v2"
)

const corporate = `["region-1"][red::]Leverage agile frameworks to provide a robust synopsis for high level overviews.[-:-:-]
Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition.
Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.[""]

["region-2"]Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.[""]

["region-3"]Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps.[""] Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line.

[yellow]Press Enter, then Tab/Backtab for word selections`

func main() {
	app := cview.NewApplication()
	app.EnableMouse(true)

	textView := cview.NewTextView()
	textView.SetDynamicColors(true)
	textView.SetRegions(true)
	textView.SetWordWrap(true)
	textView.SetBorder(true)
	textView.SetText(corporate)

	textView.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		var text string
		if event.Rune() == '1' {
			textView.Highlight("region-1")
			text = textView.GetRegionText("region-1")
		} else if event.Rune() == '2' {
			textView.Highlight("region-2")
			text = textView.GetRegionText("region-2")
		} else if event.Rune() == '3' {
			textView.Highlight("region-3")
			text = textView.GetRegionText("region-3")
		}

		textView.SetText(text)

		return nil
	})

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

I get the following error, while hitting 1, 2 or 3 (so I have the issue even if just 1 region has color tags):

panic: runtime error: index out of range [2] with length 2 [recovered]
	panic: runtime error: index out of range [2] with length 2

goroutine 1 [running]:
code.rocketnine.space/tslocum/cview.(*Application).Run.func1(0xc000110c80)
	/home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/application.go:299 +0x87
panic(0x56e700, 0xc0000bc000)
	/home/bacardi55/sdk/go1.16.4/src/runtime/panic.go:965 +0x1b9
code.rocketnine.space/tslocum/cview.(*TextView).GetRegionText(0xc000001200, 0x581443, 0x8, 0x0, 0x0)
	/home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/textview.go:701 +0x9bd
main.main.func1(0xc00009c000, 0xc00009e001)
	/home/bacardi55/workspace/perso/test-cview/main.go:39 +0x208
code.rocketnine.space/tslocum/cview.(*Box).WrapInputHandler.func1(0xc00009c000, 0xc00009e010)
	/home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/box.go:224 +0x7a
code.rocketnine.space/tslocum/cview.(*Application).Run.func3(0x563b40, 0xc00009c000)
	/home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/application.go:377 +0x3fe
code.rocketnine.space/tslocum/cview.(*Application).Run(0xc000110c80, 0x0, 0x0)
	/home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/application.go:458 +0x22f
main.main()
	/home/bacardi55/workspace/perso/test-cview/main.go:54 +0x213
exit status 2

If I change the corporate variable to:

const corporate = `["region-1"]Leverage agile frameworks to provide a robust synopsis for high level overviews.
Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition.
Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.[""]

["region-2"]Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.[""]

["region-3"]Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps.[""] Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line.

[yellow]Press Enter, then Tab/Backtab for word selections`

(Removing color tags in region 1)
Then it works as expected.

I'm using go 1.16.4
my go.mod contains:

╰─➤  cat go.mod
module test-cview

go 1.16

require (
	code.rocketnine.space/tslocum/cview v1.5.6
	github.com/gdamore/tcell/v2 v2.3.11
)

Let me know if I did something wrong or if you need more debug!

Hi, Firt, a big thanks for the awesome work on cview!! I think I found a bug with TextView.GetRegionText() (unless I'm doing something wrong) when a region contains color tags. I created this simple code (based on the TextView demo) to reproduce: ```golang package main import ( "code.rocketnine.space/tslocum/cview" "github.com/gdamore/tcell/v2" ) const corporate = `["region-1"][red::]Leverage agile frameworks to provide a robust synopsis for high level overviews.[-:-:-] Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.[""] ["region-2"]Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.[""] ["region-3"]Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps.[""] Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line. [yellow]Press Enter, then Tab/Backtab for word selections` func main() { app := cview.NewApplication() app.EnableMouse(true) textView := cview.NewTextView() textView.SetDynamicColors(true) textView.SetRegions(true) textView.SetWordWrap(true) textView.SetBorder(true) textView.SetText(corporate) textView.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { var text string if event.Rune() == '1' { textView.Highlight("region-1") text = textView.GetRegionText("region-1") } else if event.Rune() == '2' { textView.Highlight("region-2") text = textView.GetRegionText("region-2") } else if event.Rune() == '3' { textView.Highlight("region-3") text = textView.GetRegionText("region-3") } textView.SetText(text) return nil }) app.SetRoot(textView, true) if err := app.Run(); err != nil { panic(err) } } ``` I get the following error, while hitting 1, 2 or 3 (so I have the issue even if just 1 region has color tags): ``` panic: runtime error: index out of range [2] with length 2 [recovered] panic: runtime error: index out of range [2] with length 2 goroutine 1 [running]: code.rocketnine.space/tslocum/cview.(*Application).Run.func1(0xc000110c80) /home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/application.go:299 +0x87 panic(0x56e700, 0xc0000bc000) /home/bacardi55/sdk/go1.16.4/src/runtime/panic.go:965 +0x1b9 code.rocketnine.space/tslocum/cview.(*TextView).GetRegionText(0xc000001200, 0x581443, 0x8, 0x0, 0x0) /home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/textview.go:701 +0x9bd main.main.func1(0xc00009c000, 0xc00009e001) /home/bacardi55/workspace/perso/test-cview/main.go:39 +0x208 code.rocketnine.space/tslocum/cview.(*Box).WrapInputHandler.func1(0xc00009c000, 0xc00009e010) /home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/box.go:224 +0x7a code.rocketnine.space/tslocum/cview.(*Application).Run.func3(0x563b40, 0xc00009c000) /home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/application.go:377 +0x3fe code.rocketnine.space/tslocum/cview.(*Application).Run(0xc000110c80, 0x0, 0x0) /home/bacardi55/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.6/application.go:458 +0x22f main.main() /home/bacardi55/workspace/perso/test-cview/main.go:54 +0x213 exit status 2 ``` If I change the corporate variable to: ``` const corporate = `["region-1"]Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.[""] ["region-2"]Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.[""] ["region-3"]Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps.[""] Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line. [yellow]Press Enter, then Tab/Backtab for word selections` ``` (Removing color tags in region 1) Then it works as expected. I'm using go 1.16.4 my go.mod contains: ``` ╰─➤ cat go.mod module test-cview go 1.16 require ( code.rocketnine.space/tslocum/cview v1.5.6 github.com/gdamore/tcell/v2 v2.3.11 ) ``` Let me know if I did something wrong or if you need more debug!
tslocum added the
bug
label 2021-07-11 20:36:00 +00:00

Thanks for reporting this in detail.

Thanks for reporting this in detail.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
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: tslocum/cview#69
There is no content yet.