rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
11.17k stars 574 forks source link

Override themes for application individually #868

Closed HeavyBro1337 closed 8 months ago

HeavyBro1337 commented 1 year ago

Hello, I want to say right away that the package is fantastic and well-done! However, there's one quirk that I hope will be fixed in a new version.

The only limitation I encountered while using this package is styling, I am making a networked application which can use several instances of tview.Application and since tview.Styles is a global variable shared among other primitives, I can't really personalize the theme for each session.

The wiki didn't mention any style overriding (i.e. passing Theme struct as the parameter at very least).

image In this screenshot you can see default theme being used.

image When I execute this command, it is supposed to change theme at the current session by idea, however when somebody else joins, then the new theme is applied on that session. image

func applyTheme() {
    tview.Styles.BorderColor = tcell.ColorMaroon
    tview.Styles.PrimaryTextColor = tcell.ColorGold
    tview.Styles.PrimitiveBackgroundColor = tcell.ColorLightGreen
}

The code in question

digitallyserviced commented 1 year ago

@IvanKorchmit Maybe this could get you partly where you want to go...

This is something I had come up with to handle storing theme/style info in an external file. It could easily be hacked up to add a way to pull styles/themes from specific sources based on certain criteria.

Rather than rely on all your primitives pulling from the global Theme, apply styles to them using my theming thing here... Pull styles by name that can be differentiated by that, or by some additional criteria that is passed along and return something different.

The theming repo is mainly a registry for styles, and format strings that can be pulled and defined by name.

If you pair this with my fork of tview, you can also define borderStyle per Box and also for the [fg:bg:attr] style tags my Styler can be set globally, or per TextArea which will allow you to define style tags such as [titleBold] instead. Again, this will pull them from my theme registry thing here, and you can change how it chooses what styles to return. I am sorry I do not have any decent example code or anything just yet. But hopefully you can get the gist..

my theming registry deal...

https://github.com/digitallyserviced/tview-theming

the Styler functions you can define globally to hook into the style returned during [tag] styling

https://github.com/digitallyserviced/tview/blob/611a26b9bad195005135a6ce0215280c68d57903/util.go#L94

the TextView styler hooking to have specific textview stylers

https://github.com/digitallyserviced/tview/blob/611a26b9bad195005135a6ce0215280c68d57903/textview.go#L383

how i define styles in my theme.toml notice i use named tags as well as the standard [fg:bg:attr]

seedRolls = "[badgeText][::r] ﱬ  [blue:gray:-] %[2]d ROLLS [gray:red:-] %[1]d [-:-:-][red:purple:-] [white]⋯  [purple:blue:-][-:blue:-] %[3]d [blue:#303030:-]  [-:-:-]" # [:#303030:-]

and the whole fork with all sorts of extra shit

https://github.com/digitallyserviced/tview/tree/digitally

rivo commented 8 months ago

@IvanKorchmit You are correct. The way it currently works is that there is only one global theme which would apply to all applications if you used multiple. (I'm curious how you use multiple instances of Application, I have never seen that before.)

I have plans to allow for more detailed styling but as of now, I can't say when this will be available.

I'm closing this issue for now. If you feel that you need more help, please comment here or open a new issue.

HeavyBro1337 commented 8 months ago

@IvanKorchmit You are correct. The way it currently works is that there is only one global theme which would apply to all applications if you used multiple. (I'm curious how you use multiple instances of Application, I have never seen that before.)

I have plans to allow for more detailed styling but as of now, I can't say when this will be available.

I'm closing this issue for now. If you feel that you need more help, please comment here or open a new issue.

Hello, I'm using tview for multi-user dungeon framework via SSH and each session creates Application instance which is where it is used for rendering UI. I was curious to implement something like themes for different rooms (entering dungeon would result in a dark or gray themed UI for better experience)

rivo commented 8 months ago

Got it. Interesting. Well, as mentioned, this is currently not supported but there may be tools to facilitate this soon. (Again, I don't know how "soon".)

If you really need it, short of patching tview, you could think about starting separate processes for each session. But I don't know how complicated this is in your application.

HeavyBro1337 commented 8 months ago

Well, I'm totally fine, it would be nice to have that. I can definitely live without that!

On Sat, Apr 6, 2024, 15:49 rivo @.***> wrote:

Got it. Interesting. Well, as mentioned, this is currently not supported but there may be tools to facilitate this soon. (Again, I don't know how "soon".)

If you really need it, short of patching tview, you could think about starting separate processes for each session. But I don't know how complicated this is in your application.

— Reply to this email directly, view it on GitHub https://github.com/rivo/tview/issues/868#issuecomment-2041073654, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ3IYZK3HRTW3RRJDCGABJDY37VMTAVCNFSM6AAAAAA33QUSYGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGA3TGNRVGQ . You are receiving this because you were mentioned.Message ID: @.***>