[GH-ISSUE #859] respect terminal colors #624

Closed
opened 2026-03-04 01:06:32 +03:00 by kerem · 11 comments
Owner

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.

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.
kerem closed this issue 2026-03-04 01:06:33 +03:00
Author
Owner

@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?

<!-- gh-comment-id:1606833868 --> @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?
Author
Owner

@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.

<!-- gh-comment-id:1606959186 --> @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](https://pkg.go.dev/github.com/rivo/tview#Theme) but it will not be automatic.
Author
Owner

@rivo commented on GitHub (Jun 27, 2023):

I'll get @gdamore from tcell in the loop here as this is really a tcell topic and not tview. If this is ever supported at some point by tcell, it will be supported by tview as well.

<!-- gh-comment-id:1608825204 --> @rivo commented on GitHub (Jun 27, 2023): I'll get @gdamore from [`tcell`](https://github.com/gdamore/tcell) in the loop here as this is really a `tcell` topic and not `tview`. If this is ever supported at some point by `tcell`, it will be supported by `tview` as well.
Author
Owner

@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.

<!-- gh-comment-id:1608861298 --> @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.
Author
Owner

@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 as tcell supports this, I can implement it in tview, too. In short, tview does not interact with the terminal directly so any solution to this tcell's responsibility to implement.

<!-- gh-comment-id:1694373264 --> @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 as `tcell` supports this, I can implement it in `tview`, too. In short, `tview` does not interact with the terminal directly so any solution to this `tcell`'s responsibility to implement.
Author
Owner

@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.

<!-- gh-comment-id:1694380100 --> @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.
Author
Owner

@gdamore commented on GitHub (Aug 26, 2023):

The first 16 colors in tcell are:

        ColorBlack = ColorValid + iota
        ColorMaroon
        ColorGreen
        ColorOlive
        ColorNavy
        ColorPurple
        ColorTeal
        ColorSilver
        ColorGray
        ColorRed
        ColorLime
        ColorYellow
        ColorBlue
        ColorFuchsia
        ColorAqua
        ColorWhite

And they have values:

        ColorBlack:                0x000000,
        ColorMaroon:               0x800000,
        ColorGreen:                0x008000,
        ColorOlive:                0x808000,
        ColorNavy:                 0x000080,
        ColorPurple:               0x800080,
        ColorTeal:                 0x008080,
        ColorSilver:               0xC0C0C0,
        ColorGray:                 0x808080,
        ColorRed:                  0xFF0000,
        ColorLime:                 0x00FF00,
        ColorYellow:               0xFFFF00,
        ColorBlue:                 0x0000FF,
        ColorFuchsia:              0xFF00FF,
        ColorAqua:                 0x00FFFF,
        ColorWhite:                0xFFFFFF,

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.

<!-- gh-comment-id:1694380925 --> @gdamore commented on GitHub (Aug 26, 2023): The first 16 colors in tcell are: ``` ColorBlack = ColorValid + iota ColorMaroon ColorGreen ColorOlive ColorNavy ColorPurple ColorTeal ColorSilver ColorGray ColorRed ColorLime ColorYellow ColorBlue ColorFuchsia ColorAqua ColorWhite ``` And they have values: ``` ColorBlack: 0x000000, ColorMaroon: 0x800000, ColorGreen: 0x008000, ColorOlive: 0x808000, ColorNavy: 0x000080, ColorPurple: 0x800080, ColorTeal: 0x008080, ColorSilver: 0xC0C0C0, ColorGray: 0x808080, ColorRed: 0xFF0000, ColorLime: 0x00FF00, ColorYellow: 0xFFFF00, ColorBlue: 0x0000FF, ColorFuchsia: 0xFF00FF, ColorAqua: 0x00FFFF, ColorWhite: 0xFFFFFF, ``` 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.
Author
Owner

@rivo commented on GitHub (Aug 26, 2023):

I just had a look at this in iTerm on macOS. The colour preferences have two sections:

image

If I change the "ANSI Colors" on the right hand side, the tview application 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, tview should look as expected.

<!-- gh-comment-id:1694386155 --> @rivo commented on GitHub (Aug 26, 2023): I just had a look at this in iTerm on macOS. The colour preferences have two sections: ![image](https://github.com/rivo/tview/assets/480930/3f563a04-136a-48fc-b4df-890c09aaf825) If I change the "ANSI Colors" on the right hand side, the `tview` application 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, `tview` should look as expected.
Author
Owner

@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.

theme := tview.Theme{
	PrimitiveBackgroundColor:    tcell.ColorDefault,
	ContrastBackgroundColor:     tcell.ColorDefault,
	MoreContrastBackgroundColor: tcell.ColorDefault,
	BorderColor:                 tcell.ColorDefault,
	TitleColor:                  tcell.ColorDefault,
	GraphicsColor:               tcell.ColorDefault,
	PrimaryTextColor:            tcell.ColorDefault,
	SecondaryTextColor:          tcell.ColorDefault,
	TertiaryTextColor:           tcell.ColorDefault,
	InverseTextColor:            tcell.ColorDefault,
	ContrastSecondaryTextColor:  tcell.ColorDefault,
}
tview.Styles = theme
<!-- gh-comment-id:1848992716 --> @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. ```go theme := tview.Theme{ PrimitiveBackgroundColor: tcell.ColorDefault, ContrastBackgroundColor: tcell.ColorDefault, MoreContrastBackgroundColor: tcell.ColorDefault, BorderColor: tcell.ColorDefault, TitleColor: tcell.ColorDefault, GraphicsColor: tcell.ColorDefault, PrimaryTextColor: tcell.ColorDefault, SecondaryTextColor: tcell.ColorDefault, TertiaryTextColor: tcell.ColorDefault, InverseTextColor: tcell.ColorDefault, ContrastSecondaryTextColor: tcell.ColorDefault, } tview.Styles = theme ```
Author
Owner

@alvaroarenas commented on GitHub (Feb 23, 2025):

theme := tview.Theme{
PrimitiveBackgroundColor: tcell.ColorDefault,
ContrastBackgroundColor: tcell.ColorDefault,
MoreContrastBackgroundColor: tcell.ColorDefault,
BorderColor: tcell.ColorDefault,
TitleColor: tcell.ColorDefault,
GraphicsColor: tcell.ColorDefault,
PrimaryTextColor: tcell.ColorDefault,
SecondaryTextColor: tcell.ColorDefault,
TertiaryTextColor: tcell.ColorDefault,
InverseTextColor: tcell.ColorDefault,
ContrastSecondaryTextColor: tcell.ColorDefault,
}

Great trick. Solved my issue

<!-- gh-comment-id:2676759539 --> @alvaroarenas commented on GitHub (Feb 23, 2025): > theme := tview.Theme{ > PrimitiveBackgroundColor: tcell.ColorDefault, > ContrastBackgroundColor: tcell.ColorDefault, > MoreContrastBackgroundColor: tcell.ColorDefault, > BorderColor: tcell.ColorDefault, > TitleColor: tcell.ColorDefault, > GraphicsColor: tcell.ColorDefault, > PrimaryTextColor: tcell.ColorDefault, > SecondaryTextColor: tcell.ColorDefault, > TertiaryTextColor: tcell.ColorDefault, > InverseTextColor: tcell.ColorDefault, > ContrastSecondaryTextColor: tcell.ColorDefault, > } Great trick. Solved my issue
Author
Owner

@dbohdan commented on GitHub (Sep 21, 2025):

Because tcell.ColorDefault is the zero value for Color, you can shorten this to:

theme := tview.Theme{}
tview.Styles = theme

However, keep in mine that with this trick (and its longer version) text selection in a TextArea will be invisible. You can make it visible using SetSelectedStyle. The most established and arguably the most theme-neutral style for selected text is inverse. The following code applies it:

// With a zero theme, selectedStyle must differ from tcell.StyleDefault, or selection will be invisible.
selectedStyle := tcell.StyleDefault.Reverse(true)
textArea := tview.NewTextArea().SetSelectedStyle(selectedStyle)
<!-- gh-comment-id:3316216373 --> @dbohdan commented on GitHub (Sep 21, 2025): Because `tcell.ColorDefault` is the [zero value for `Color`](https://github.com/gdamore/tcell/blob/340fa4f8f86b00bada44cf10483a39b2162e44cb/color.go#L39), you can shorten this to: ```go theme := tview.Theme{} tview.Styles = theme ``` However, keep in mine that with this trick (and its longer version) text selection in a `TextArea` will be invisible. You can make it visible using `SetSelectedStyle`. The most established and arguably the most theme-neutral style for selected text is [inverse](https://terminalguide.namepad.de/attr/7/). The following code applies it: ```go // With a zero theme, selectedStyle must differ from tcell.StyleDefault, or selection will be invisible. selectedStyle := tcell.StyleDefault.Reverse(true) textArea := tview.NewTextArea().SetSelectedStyle(selectedStyle) ```
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#624
No description provided.