[GH-ISSUE #895] Long text in TextView #654

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

Originally created by @marek-kuticka on GitHub (Oct 3, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/895

Hi

what would be the best option to implement TextView component, inside some Flex container, or whatever, that contains scrollable text and I can keep focus at the end? something in sense of console logger.

I have bit struggles to getting this to work. would there be any example of this?

thx a lot

Marek

Originally created by @marek-kuticka on GitHub (Oct 3, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/895 Hi what would be the best option to implement TextView component, inside some Flex container, or whatever, that contains scrollable text and I can keep focus at the end? something in sense of console logger. I have bit struggles to getting this to work. would there be any example of this? thx a lot Marek
kerem closed this issue 2026-03-04 01:06:47 +03:00
Author
Owner

@rivo commented on GitHub (Oct 3, 2023):

You can call TextView.ScrollToEnd():

ScrollToEnd scrolls to the bottom left corner of the text if the text view is scrollable. Adding new rows to the end of the text view will cause it to scroll with the new data.

You can use TextView as a io.Writer and simply write your text to it (use SetChangedFunc() to redraw the text view). Make sure to also read the section on large texts.

<!-- gh-comment-id:1745661206 --> @rivo commented on GitHub (Oct 3, 2023): You can call [`TextView.ScrollToEnd()`](https://pkg.go.dev/github.com/rivo/tview#TextView.ScrollToEnd): > ScrollToEnd scrolls to the bottom left corner of the text if the text view is scrollable. _Adding new rows to the end of the text view will cause it to scroll with the new data._ You can use `TextView` as a `io.Writer` and simply write your text to it (use [`SetChangedFunc()`](https://pkg.go.dev/github.com/rivo/tview#TextView.SetChangedFunc) to redraw the text view). Make sure to also read the section on [large texts](https://pkg.go.dev/github.com/rivo/tview#hdr-Large_Texts).
Author
Owner

@marek-kuticka commented on GitHub (Oct 3, 2023):

thx, my question was rather aimed to adding text itself. what method is most suitable, and if TextView then handles the scroll by itself.

thx

<!-- gh-comment-id:1745666914 --> @marek-kuticka commented on GitHub (Oct 3, 2023): thx, my question was rather aimed to adding text itself. what method is most suitable, and if TextView then handles the scroll by itself. thx
Author
Owner

@rivo commented on GitHub (Oct 4, 2023):

No TextView will NOT automatically scroll when new content is written or appended.

Not true. TextView behaves exactly how it's described in the comment I quoted above. It will automatically scroll. It is not necessary to call ScrollToEnd() every time something is changed, like in the example @digitallyserviced posted. Once is enough.

@marek-kuticka Check out the following example which is how you could implement a continuous text stream (but again, please also look at the section about "Large Texts"):

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

	textView := tview.NewTextView().
		ScrollToEnd().
		SetChangedFunc(func() {
			app.Draw()
		})

	go func() {
		var i int
		for {
			fmt.Fprintf(textView, "%d\n", i)
			time.Sleep(10 * time.Millisecond)
			i++
		}
	}()

	if err := app.SetRoot(textView, true).Run(); err != nil {
		panic(err)
	}
}
<!-- gh-comment-id:1746343256 --> @rivo commented on GitHub (Oct 4, 2023): > No `TextView` will NOT automatically scroll when new content is written or appended. Not true. `TextView` behaves exactly how it's described in the comment I quoted above. It will automatically scroll. It is not necessary to call `ScrollToEnd()` every time something is changed, like in the example @digitallyserviced posted. Once is enough. @marek-kuticka Check out the following example which is how you could implement a continuous text stream (but again, please also look at the section about "Large Texts"): ```go func main() { app := tview.NewApplication() textView := tview.NewTextView(). ScrollToEnd(). SetChangedFunc(func() { app.Draw() }) go func() { var i int for { fmt.Fprintf(textView, "%d\n", i) time.Sleep(10 * time.Millisecond) i++ } }() if err := app.SetRoot(textView, true).Run(); err != nil { panic(err) } } ```
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#654
No description provided.