mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 13:55:51 +03:00
[GH-ISSUE #859] respect terminal colors #624
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#624
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 @boyter on GitHub (Jun 21, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/859
To start, this is a fantastic library and I love it to bits. Thank you so much for having created it.
I had a look through issues, the documentation and a few other places but was unable to find an answer to this.
Is it possible to have tview respect someones existing terminal colors and use those in the display?
I am running into the issue where its in "dark" mode where the persons terminal has a white background. Its a similar question for colors for display and such.
I had a look at https://github.com/gdamore/tcell and it looks like that might support it, but I don't have enough knowledge over it to say one way or the other.
@boyter commented on GitHub (Jun 26, 2023):
Yes confusing. Actually I must confess I still am.
I guess what I would need to know, is given a tview application how do I set it up to respect the user's preferences?
I create the tview application like so https://github.com/boyter/cs/blob/master/tui.go#L250 and set colours based on the above (other than one I am going to replace), but I am not sure what else I need to do here. Also how does one refer to the colours correctly inside coloured content where you use
[red]or[white]for example?@rivo commented on GitHub (Jun 26, 2023):
This is discussed in one of two questions in the FAQ: https://github.com/rivo/tview/wiki/FAQ In short, it's not possible to determine a user's color settings.
You can offer your users a choice of a few predefined themes but it will not be automatic.
@rivo commented on GitHub (Jun 27, 2023):
I'll get @gdamore from
tcellin the loop here as this is really atcelltopic and nottview. If this is ever supported at some point bytcell, it will be supported bytviewas well.@boyter commented on GitHub (Jun 27, 2023):
Cool. I don't mind putting in the work to support this myself, or indeed adding themes to have it mostly work across the board but ideally something that is applied across everything would be better, even if its just an example to follow from that perhaps we can setup for people to follow should they want to do this.
@rivo commented on GitHub (Aug 26, 2023):
I'm closing this issue now. If there is anything left to discuss regarding this topic, please open an issue with
tcell. As soon astcellsupports this, I can implement it intview, too. In short,tviewdoes not interact with the terminal directly so any solution to thistcell's responsibility to implement.@gdamore commented on GitHub (Aug 26, 2023):
tcell does respect colors, if you ask it to. However, if you use the low order color names, or convert the color to a palette color (via the PaletteColor function), then it will respect user preferences set up in the terminal.
So the application developer has complete control to decide whether to strictly enforce and control color (via RGB colors) or to use palette colors.
The default for the first 16 colors (actually the first 256 colors) is to respect the palette of the user.
@gdamore commented on GitHub (Aug 26, 2023):
The first 16 colors in tcell are:
And they have values:
Note that these values may be different than what you've chosen, as some actual terminals represent these somewhat differently. But if you want to use the palette/theme of the user, then stick to these color values.
@rivo commented on GitHub (Aug 26, 2023):
I just had a look at this in iTerm on macOS. The colour preferences have two sections:
If I change the "ANSI Colors" on the right hand side, the
tviewapplication will automatically change accordingly. On the other hand, if I make changes on the left hand side for "Basic Colors", it has no effect. (I don't know what these "basic colours" refer to in the context of a terminal.)The "Color Presets..." dialog opens up a number of predefined themes from which I can choose one. Some of them change the ANSI colour palette, others don't.
So I guess it's all really a matter of how a terminal colour theme is defined. If "Light Mode" also changes the ANSI palette,
tviewshould look as expected.@2minchul commented on GitHub (Dec 10, 2023):
I have found a way.
I've discovered a neat little trick.
By inserting the following code before
tview.NewApplication(), you can ensure that all the fields in tview are set to your terminal's default color scheme.@alvaroarenas commented on GitHub (Feb 23, 2025):
Great trick. Solved my issue
@dbohdan commented on GitHub (Sep 21, 2025):
Because
tcell.ColorDefaultis the zero value forColor, you can shorten this to:However, keep in mine that with this trick (and its longer version) text selection in a
TextAreawill be invisible. You can make it visible usingSetSelectedStyle. The most established and arguably the most theme-neutral style for selected text is inverse. The following code applies it: