[GH-ISSUE #313] Refresh text #238

Closed
opened 2026-03-04 01:03:14 +03:00 by kerem · 2 comments
Owner

Originally created by @zhouke66 on GitHub (Jun 18, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/313

I need to refreshed textView every once in a while, but It can only be refreshed when a key is pressed.

For example:

`package main

import (
"fmt"
"github.com/rivo/tview"
"strings"
"time"
)

const corporate = [yellow]Leverage agile [red]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. 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. 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 := tview.NewApplication()
runFlex := tview.NewFlex().SetDirection(tview.FlexRow)
runView := tview.NewTextView().SetDynamicColors(true).SetRegions(true).
	SetWordWrap(true).SetChangedFunc(func() {
})
errView := tview.NewTextView().SetDynamicColors(true).SetRegions(true).
	SetWordWrap(true)
runView.SetTitle(" RUN ").SetBorder(true)
errView.SetTitle(" RESULT ").SetBorder(true)

runFlex.AddItem(runView, 0, 1, true).AddItem(errView, 0, 1, true)

go func() {
	for i, word := range strings.Split(corporate, " ") {
		if i%2 == 0 {
			fmt.Fprintf(runView, "%s ", word)
		} else {
			fmt.Fprintf(errView, "%s ", word)
		}
		time.Sleep(200 * time.Millisecond)
	}
}()

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

}
`

May I ask how to solve it?

Originally created by @zhouke66 on GitHub (Jun 18, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/313 I need to refreshed textView every once in a while, but It can only be refreshed when a key is pressed. For example: `package main import ( "fmt" "github.com/rivo/tview" "strings" "time" ) const corporate = `[yellow]Leverage agile [red]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. 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. 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 := tview.NewApplication() runFlex := tview.NewFlex().SetDirection(tview.FlexRow) runView := tview.NewTextView().SetDynamicColors(true).SetRegions(true). SetWordWrap(true).SetChangedFunc(func() { }) errView := tview.NewTextView().SetDynamicColors(true).SetRegions(true). SetWordWrap(true) runView.SetTitle(" RUN ").SetBorder(true) errView.SetTitle(" RESULT ").SetBorder(true) runFlex.AddItem(runView, 0, 1, true).AddItem(errView, 0, 1, true) go func() { for i, word := range strings.Split(corporate, " ") { if i%2 == 0 { fmt.Fprintf(runView, "%s ", word) } else { fmt.Fprintf(errView, "%s ", word) } time.Sleep(200 * time.Millisecond) } }() if err := app.SetRoot(runFlex, true).Run(); err != nil { panic(err) } } ` May I ask how to solve it?
kerem closed this issue 2026-03-04 01:03:14 +03:00
Author
Owner

@rivo commented on GitHub (Jun 18, 2019):

The solution to this is right in the example from which you copied your code:

github.com/rivo/tview@b62197ade4/demos/textview/main.go (L28-L30)

The changed callback is executed every time you write something to a TextView.

If you want to update on a different schedule, you can call Application.Draw() any time.

Let me know if this solves your problem.

<!-- gh-comment-id:503032394 --> @rivo commented on GitHub (Jun 18, 2019): The solution to this is right in the example from which you copied your code: https://github.com/rivo/tview/blob/b62197ade4121742db57ebd456b1f4d84f2b35dc/demos/textview/main.go#L28-L30 The `changed` callback is executed every time you write something to a `TextView`. If you want to update on a different schedule, you can call [`Application.Draw()`](https://godoc.org/github.com/rivo/tview#Application.Draw) any time. Let me know if this solves your problem.
Author
Owner

@zhouke66 commented on GitHub (Jun 18, 2019):

Thank you, the problem has been solved

<!-- gh-comment-id:503043909 --> @zhouke66 commented on GitHub (Jun 18, 2019): Thank you, the problem has been solved
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#238
No description provided.