mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #1142] [Question] Changing the tview.Styles (theme) at runtime #827
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#827
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ramonvermeulen on GitHub (Jan 8, 2026).
Original GitHub issue: https://github.com/rivo/tview/issues/1142
Hi @rivo,
First, thank you for developing tview! It's been a great experience building a TUI application with it.
I'm currently implementing a theme picker in my application that allows users to switch themes at runtime. I'm using the
Themestruct for this purpose, and I'm updating it at runtime with the user's selected theme from a registry.E.g.:
Unfortunately, this doesn't automatically update all primitives in the tview application. As the documentation for
Themenotes:Two approaches I considered were:
a) Rebuilding all primitives when changing the theme
This would work since all primitives would be reinitialized, but it seems like a heavy operation for just changing themes.
b) Notifying all primitives to update their theme
I implemented this approach by introducing a
theme.Manager:Example of the theme.Manager
My current approach is to register each primitive with the manager in its initializer function. The manager then calls ApplyToPrimitive on all registered primitives when the theme changes. This works, but I'm wondering if this is the best approach to solve this problem, or if there's a better solution within tview itself?
One potential solution could be to add an
ApplyTheme(theme *tview.Theme)method to eitherApplicationorPages. I'm not sure if this is feasible, but I think theoretically it should be possible to traverse the entire primitive tree and apply theme settings to each primitive.If you think this feature has potential, please let me know. I'd be happy to explore whether this is feasible to implement and open a PR.