[GH-ISSUE #52] An example of how to use Print or PrintSimple #39

Closed
opened 2026-03-04 01:01:19 +03:00 by kerem · 1 comment
Owner

Originally created by @njones on GitHub (Feb 6, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/52

I'm trying to write some text into a NewBox, and I can't figure out how to do this.

The documentation explains how Print is used to write to a box, but the function takes a tcell.Screen which is an interface the Box struct doesn't conform to. Maybe, the example of how to create and use a Box can be expanded to include some text as well?

Originally created by @njones on GitHub (Feb 6, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/52 I'm trying to write some text into a `NewBox`, and I can't figure out how to do this. The documentation explains how `Print` is used to write to a box, but the function takes a `tcell.Screen` which is an interface the `Box` struct doesn't conform to. Maybe, the example of how to create and use a `Box` can be expanded to include some text as well?
kerem closed this issue 2026-03-04 01:01:19 +03:00
Author
Owner

@rivo commented on GitHub (Feb 7, 2018):

Hi, Box by itself doesn't allow you to write text into it. It's really just a box with a border and a title and it's used as the superclass for all other primitives.

If you want to add text, you should use TextView. Because TextView implements the io.Writer interface, you can simply print to it:

t := tview.NewTextView()
fmt.Fprintln(t, "Hello, World!")

The Print() functions in the package are used to write directly to a tcell.Screen but this is useful only if you decide to implement your own Primitive where you would implement the Draw() function. For most applications, this is probably not necessary.

<!-- gh-comment-id:363691779 --> @rivo commented on GitHub (Feb 7, 2018): Hi, `Box` by itself doesn't allow you to write text into it. It's really just a box with a border and a title and it's used as the superclass for all other primitives. If you want to add text, you should use `TextView`. Because `TextView` implements the `io.Writer` interface, you can simply print to it: ```go t := tview.NewTextView() fmt.Fprintln(t, "Hello, World!") ``` The `Print()` functions in the package are used to write directly to a `tcell.Screen` but this is useful only if you decide to implement your own `Primitive` where you would implement the `Draw()` function. For most applications, this is probably not necessary.
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#39
No description provided.