[GH-ISSUE #670] Error in Modal example #491

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

Originally created by @abitrolly on GitHub (Nov 10, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/670

This example from https://github.com/rivo/tview/wiki/Modal

package main

import (
	"strings"

	"github.com/gdamore/tcell"
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()

	// Returns a new primitive which puts the provided primitive in the center and
	// sets its size to the given width and height.
	modal := func(p tview.Primitive, width, height int) tview.Primitive {
		return tview.NewFlex().
			AddItem(nil, 0, 1, false).
			AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
				AddItem(nil, 0, 1, false).
				AddItem(p, height, 1, false).
				AddItem(nil, 0, 1, false), width, 1, false).
			AddItem(nil, 0, 1, false)
	}

	background := tview.NewTextView().
		SetTextColor(tcell.ColorBlue).
		SetText(strings.Repeat("background ", 1000))

	box := tview.NewBox().
		SetBorder(true).
		SetTitle("Centered Box")

	pages := tview.NewPages().
		AddPage("background", background, true, true).
		AddPage("modal", modal(box, 40, 10), true, true)

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

Fails

✗ go run pages.go 
# command-line-arguments
./pages.go:26:15: cannot use "github.com/gdamore/tcell".ColorBlue (type "github.com/gdamore/tcell".Color) as type "github.com/gdamore/tcell/v2".Color in argument to tview.NewTextView().SetTextColor            
Originally created by @abitrolly on GitHub (Nov 10, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/670 This example from https://github.com/rivo/tview/wiki/Modal ```go package main import ( "strings" "github.com/gdamore/tcell" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() // Returns a new primitive which puts the provided primitive in the center and // sets its size to the given width and height. modal := func(p tview.Primitive, width, height int) tview.Primitive { return tview.NewFlex(). AddItem(nil, 0, 1, false). AddItem(tview.NewFlex().SetDirection(tview.FlexRow). AddItem(nil, 0, 1, false). AddItem(p, height, 1, false). AddItem(nil, 0, 1, false), width, 1, false). AddItem(nil, 0, 1, false) } background := tview.NewTextView(). SetTextColor(tcell.ColorBlue). SetText(strings.Repeat("background ", 1000)) box := tview.NewBox(). SetBorder(true). SetTitle("Centered Box") pages := tview.NewPages(). AddPage("background", background, true, true). AddPage("modal", modal(box, 40, 10), true, true) if err := app.SetRoot(pages, true).Run(); err != nil { panic(err) } } ``` Fails ``` ✗ go run pages.go # command-line-arguments ./pages.go:26:15: cannot use "github.com/gdamore/tcell".ColorBlue (type "github.com/gdamore/tcell".Color) as type "github.com/gdamore/tcell/v2".Color in argument to tview.NewTextView().SetTextColor ```
kerem closed this issue 2026-03-04 01:05:28 +03:00
Author
Owner

@abitrolly commented on GitHub (Nov 10, 2021):

@rivo what do you think about CI job that tries to scrape and go build all examples?

<!-- gh-comment-id:965052586 --> @abitrolly commented on GitHub (Nov 10, 2021): @rivo what do you think about CI job that tries to scrape and `go build` all examples?
Author
Owner

@rivo commented on GitHub (Nov 11, 2021):

This example from https://github.com/rivo/tview/wiki/Modal fails

It still had the old tcell version. Thanks, I fixed it.

what do you think about CI job that tries to scrape and go build all examples?

You mean the ones from the repo? I don't think that's necessary, my IDE automatically shows me if there are any compile errors. I wouldn't (wittingly) check anything in that doesn't compile.

The example you posted was from the wiki, which I have to update manually.

<!-- gh-comment-id:966023724 --> @rivo commented on GitHub (Nov 11, 2021): > This example from https://github.com/rivo/tview/wiki/Modal fails It still had the old `tcell` version. Thanks, I fixed it. > what do you think about CI job that tries to scrape and `go build` all examples? You mean the ones from the repo? I don't think that's necessary, my IDE automatically shows me if there are any compile errors. I wouldn't (wittingly) check anything in that doesn't compile. The example you posted was from the wiki, which I have to update manually.
Author
Owner

@abitrolly commented on GitHub (Nov 11, 2021):

Ok. Saves me some time I guess. Thanks. )

<!-- gh-comment-id:966143423 --> @abitrolly commented on GitHub (Nov 11, 2021): Ok. Saves me some time I guess. Thanks. )
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#491
No description provided.