[GH-ISSUE #550] Expose utils.printWithStyle function #405

Closed
opened 2026-03-04 01:04:40 +03:00 by kerem · 6 comments
Owner

Originally created by @dwillist on GitHub (Jan 14, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/550

It would be helpful to expose the printWithStyle function to let users set the style of a line.

Seems like from this issue you've considered this change.

Originally created by @dwillist on GitHub (Jan 14, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/550 It would be helpful to expose the [`printWithStyle`](https://github.com/rivo/tview/blob/c818a0c789ee6b8327cf55de5415109181f63bcb/util.go#L248) function to let users set the style of a line. Seems like from this [issue](https://github.com/rivo/tview/issues/131) you've considered this change.
kerem closed this issue 2026-03-04 01:04:41 +03:00
Author
Owner

@rivo commented on GitHub (Feb 17, 2021):

Actually, my comment in that issue was meant to advocate for the opposite: Keep these utility functions private. The problems with making them public are still relevant. I still have to modify them from time to time. In fact, the printWithStyle() function was just modified this week to allow for an improvement to the List primitive. As I said before, even Print() should be private (actually, it shouldn't even exist at all as it is now) but because of the backwards compatibility promise, I'm keeping it public. So it's unlikely that I'll make them public any time soon.

You mention changing the style of a line. Which line? How would you use printWithStyle() for that? It sounds to me like printWithStyle() would be a bit overkill to draw lines as its main complexity is in text alignment and handling colour tags etc. Maybe there's a more efficient way to do what you want to do.

<!-- gh-comment-id:780406776 --> @rivo commented on GitHub (Feb 17, 2021): Actually, [my comment in that issue](https://github.com/rivo/tview/issues/131#issuecomment-395961996) was meant to advocate for the opposite: Keep these utility functions private. The problems with making them public are still relevant. I still have to modify them from time to time. In fact, the `printWithStyle()` function was just modified this week to allow for an improvement to the `List` primitive. As I said before, even `Print()` should be private (actually, it shouldn't even exist at all as it is now) but because of the backwards compatibility promise, I'm keeping it public. So it's unlikely that I'll make them public any time soon. You mention changing the style of a line. Which line? How would you use `printWithStyle()` for that? It sounds to me like `printWithStyle()` would be a bit overkill to draw lines as its main complexity is in text alignment and handling colour tags etc. Maybe there's a more efficient way to do what you want to do.
Author
Owner

@rivo commented on GitHub (Apr 27, 2021):

Without any more information, I'll deny this one for now. You can reopen if you feel this needs more discussion.

<!-- gh-comment-id:827459341 --> @rivo commented on GitHub (Apr 27, 2021): Without any more information, I'll deny this one for now. You can reopen if you feel this needs more discussion.
Author
Owner

@tcurdt commented on GitHub (Jan 30, 2023):

Hm. I am conflicted about that argument, @rivo.
While agree it's important to keep the public interface clean...

I was hoping to rip out the List into my own package to turn it into a radio group control.
But the private utils make that a lot harder.

It does feel like having a "printing with styles" to be an essential part of allowing custom controls.
Otherwise everyone would have to re-implement that. And I'll be honest:
This function has so much stuff - I wouldn't even know where to start.

Doesn't that suggest it should become part of the public contract?

<!-- gh-comment-id:1409368104 --> @tcurdt commented on GitHub (Jan 30, 2023): Hm. I am conflicted about that argument, @rivo. While agree it's important to keep the public interface clean... I was hoping to rip out the `List` into my own package to turn it into a radio group control. But the private utils make that a lot harder. It does feel like having a "printing with styles" to be an essential part of allowing custom controls. Otherwise everyone would have to re-implement that. And I'll be honest: This function has so much stuff - I wouldn't even know where to start. Doesn't that suggest it should become part of the public contract?
Author
Owner

@rivo commented on GitHub (Apr 15, 2023):

This function has so much stuff - I wouldn't even know where to start.

I think this is the critical point: In your application, do you need all the stuff that printWithStyle() offers, specifically, what it offers over the already public Print() function?

The original question was about drawing lines which is really simple using Screen.SetContent() and doesn't require Unicode special character handling, text alignment, character skipping, string index calculation, color tag handling, width calculation, etc. I wonder if all of this is needed in your application.

On another note, radio buttons have been requested a few times already (see #839). I guess it's on the roadmap then.

<!-- gh-comment-id:1509794990 --> @rivo commented on GitHub (Apr 15, 2023): > This function has so much stuff - I wouldn't even know where to start. I think this is the critical point: In your application, do you need all the stuff that `printWithStyle()` offers, specifically, _what it offers over the already public `Print()` function_? The original question was about drawing lines which is really simple using [`Screen.SetContent()`](https://pkg.go.dev/github.com/gdamore/tcell/v2#Screen) and doesn't require Unicode special character handling, text alignment, character skipping, string index calculation, color tag handling, width calculation, etc. I wonder if all of this is needed in your application. On another note, radio buttons have been requested a few times already (see #839). I guess it's on the roadmap then.
Author
Owner

@tcurdt commented on GitHub (Apr 15, 2023):

TBH I wasn't even aware of Screen.SetContent() when writing that comment.
And I agree for (line) drawing that makes total sense to use.

The radio buttons on the other hand (or any custom control really) would probably benefit from using printWithStyle() over just Print(), no?

<!-- gh-comment-id:1509900605 --> @tcurdt commented on GitHub (Apr 15, 2023): TBH I wasn't even aware of `Screen.SetContent()` when writing that comment. And I agree for (line) drawing that makes total sense to use. The radio buttons on the other hand (or any custom control really) would probably benefit from using `printWithStyle()` over just `Print()`, no?
Author
Owner

@rivo commented on GitHub (Apr 16, 2023):

The difference between Print() and printWithStyle() is minimal. Unless you really need this specific extra feature that printWithStyle() offers, I'm quite sure you'll be fine with Print().

<!-- gh-comment-id:1510273607 --> @rivo commented on GitHub (Apr 16, 2023): The difference between `Print()` and `printWithStyle()` is minimal. Unless you really need this specific extra feature that `printWithStyle()` offers, I'm quite sure you'll be fine with `Print()`.
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#405
No description provided.