[GH-ISSUE #160] redraw on grid not working (user typo) #127

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

Originally created by @alvarolm on GitHub (Aug 30, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/160

First of all, thanks for all the hard work !

Maybe I'm missing something but desn't seems to the redraw the textview.
fmt.Fprintf returns nil, checked with delve btw, any ideas ?

package main

import (
	"fmt"
	"time"

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

func main() {

	gui := tview.NewApplication()

	display := tview.NewPages()

	logs := tview.NewTextView().
		//SetWrap(true).
		//SetScrollable(true).
		//SetDynamicColors(true).
		SetChangedFunc(func() { gui.Draw() })

	go func() {
		var i = 0
		for {
			fmt.Fprintf(logs, "%d", i)
			time.Sleep(500 * time.Millisecond)
			i++
		}
	}()

	command := tview.NewInputField()

	grid := tview.NewGrid().
		SetRows(0, 3, 3).
		SetColumns(0).
		SetBorders(true).
		AddItem(display, 0, 0, 1, 1, 0, 0, false).
		AddItem(logs, 1, 0, 1, 1, 0, 0, false).
		AddItem(command, 2, 0, 1, 1, 0, 0, false)

	gui.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		switch event.Key() {
		case tcell.KeyEscape:
			gui.Stop()
		}
		return event
	})

	if err := gui.SetRoot(grid, true).SetFocus(grid).Run(); err != nil {
		panic(err)
	}

}

Update: made a typo, just fixed, now its working fine, sorry.

Originally created by @alvarolm on GitHub (Aug 30, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/160 First of all, thanks for all the hard work ! Maybe I'm missing something but desn't seems to the redraw the textview. fmt.Fprintf returns nil, checked with delve btw, any ideas ? ``` package main import ( "fmt" "time" "github.com/gdamore/tcell" "github.com/rivo/tview" ) func main() { gui := tview.NewApplication() display := tview.NewPages() logs := tview.NewTextView(). //SetWrap(true). //SetScrollable(true). //SetDynamicColors(true). SetChangedFunc(func() { gui.Draw() }) go func() { var i = 0 for { fmt.Fprintf(logs, "%d", i) time.Sleep(500 * time.Millisecond) i++ } }() command := tview.NewInputField() grid := tview.NewGrid(). SetRows(0, 3, 3). SetColumns(0). SetBorders(true). AddItem(display, 0, 0, 1, 1, 0, 0, false). AddItem(logs, 1, 0, 1, 1, 0, 0, false). AddItem(command, 2, 0, 1, 1, 0, 0, false) gui.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch event.Key() { case tcell.KeyEscape: gui.Stop() } return event }) if err := gui.SetRoot(grid, true).SetFocus(grid).Run(); err != nil { panic(err) } } ``` Update: made a typo, just fixed, now its working fine, sorry.
kerem closed this issue 2026-03-04 01:02:12 +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#127
No description provided.