[GH-ISSUE #314] Set transparent background for TreeView #240

Closed
opened 2026-03-04 01:03:14 +03:00 by kerem · 8 comments
Owner

Originally created by @robinmitra on GitHub (Jun 19, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/314

Context

I'm trying to set the background colour of a TreeView widget to be transparent (i.e. the default terminal background).

I've gone through the documentation and past issues but was unable to find a solution which works properly. The following code does make the background transparent, but selecting a different node completely messes up the background colour.

tree.SetBackgroundColor(tcell.ColorDefault)

The following images should explain the issue better:

default-background

For reference, this is how the same tree looks like without setting the background colour to default like done above (if you look closely, you can basically see how the tree background is black, but the edges of my terminal are dark blue, which is made apparent by the fact that my terminal has padding added):

without-default-background

Question

How do I set the background colour of a TreeView to be transparent? Am I doing this wrong?

Originally created by @robinmitra on GitHub (Jun 19, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/314 ### Context I'm trying to set the background colour of a TreeView widget to be transparent (i.e. the default terminal background). I've gone through the documentation and past issues but was unable to find a solution which works properly. The following code does make the background transparent, but selecting a different node completely messes up the background colour. ```go tree.SetBackgroundColor(tcell.ColorDefault) ``` The following images should explain the issue better: ![default-background](https://user-images.githubusercontent.com/3193694/59791441-05ced180-92ca-11e9-862a-6c9edf06baac.gif) For reference, this is how the same tree looks like without setting the background colour to default like done above (if you look closely, you can basically see how the tree background is black, but the edges of my terminal are dark blue, which is made apparent by the fact that my terminal has padding added): ![without-default-background](https://user-images.githubusercontent.com/3193694/59791656-842b7380-92ca-11e9-8c1c-db22dab0ed1a.gif) ### Question How do I set the background colour of a TreeView to be transparent? Am I doing this wrong?
kerem closed this issue 2026-03-04 01:03:14 +03:00
Author
Owner

@rivo commented on GitHub (Jul 10, 2019):

The `tcell.ColorDefault´ description says:

ColorDefault is used to leave the Color unchanged from whatever system or teminal default may exist.

So the background colour doesn't get cleared when you use tcell.ColorDefault. This is why you're seeing those effects. I would advise against using that value. tview needs to clear the background and it needs a concrete colour for that.

I actually don't know how you can find out what your terminal's default background colour is and whether this is exposed to applications at all. I would suggest asking about that over at the tcell project and letting us know here when you have an answer.

<!-- gh-comment-id:510025991 --> @rivo commented on GitHub (Jul 10, 2019): The `tcell.ColorDefault´ description says: > ColorDefault is used to leave the Color unchanged from whatever system or teminal default may exist. So the background colour doesn't get cleared when you use `tcell.ColorDefault`. This is why you're seeing those effects. I would advise against using that value. `tview` needs to clear the background and it needs a concrete colour for that. I actually don't know how you can find out what your terminal's default background colour is and whether this is exposed to applications at all. I would suggest asking about that over at the `tcell` project and letting us know here when you have an answer.
Author
Owner

@robinmitra commented on GitHub (Jul 18, 2019):

Thanks for looking into it, I've asked a question in the tcell project.

<!-- gh-comment-id:512911952 --> @robinmitra commented on GitHub (Jul 18, 2019): Thanks for looking into it, I've asked a [question](https://github.com/gdamore/tcell/issues/292) in the `tcell` project.
Author
Owner

@gdamore commented on GitHub (Jul 18, 2019):

I actually think for some terminals we should be able to clear the background color to the default background color. For example, XTerm supports the notion of resetting that.

<!-- gh-comment-id:512916020 --> @gdamore commented on GitHub (Jul 18, 2019): I actually think for some terminals we should be able to clear the background color to the default background color. For example, XTerm supports the notion of resetting that.
Author
Owner

@rivo commented on GitHub (Jul 21, 2019):

I understand (except maybe on Windows) there is no way to find out what the default colour is. Maybe we can clear a screen to the default background colour on some terminals. But we do want to avoid clearing and redrawing the entire screen each time something changes.

So all in all, my feeling is that there is no acceptable solution at the moment.

<!-- gh-comment-id:513558203 --> @rivo commented on GitHub (Jul 21, 2019): I understand (except maybe on Windows) there is no way to find out what the default colour is. Maybe we can clear a screen to the default background colour on some terminals. But we do want to avoid clearing and redrawing the entire screen each time something changes. So all in all, my feeling is that there is no acceptable solution at the moment.
Author
Owner

@rivo commented on GitHub (Aug 29, 2019):

Will close for now as we don't know of any good solution to this.

<!-- gh-comment-id:526219105 --> @rivo commented on GitHub (Aug 29, 2019): Will close for now as we don't know of any good solution to this.
Author
Owner

@gdamore commented on GitHub (Aug 29, 2019):

Actually, I think this might be a bug in tcell. Some terminals have escape sequences to set the default color on a cell -- we aren't using those, but simply assuming that Default means no change to whatever is already there.

I'm not sure what the best semantic here is though -- people might be relying on the current semantic.

<!-- gh-comment-id:526222907 --> @gdamore commented on GitHub (Aug 29, 2019): Actually, I think this might be a bug in tcell. Some terminals have escape sequences to *set* the default color on a cell -- we aren't using those, but simply assuming that Default means no change to whatever is already there. I'm not sure what the best semantic here is though -- people might be relying on the current semantic.
Author
Owner

@rivo commented on GitHub (Aug 29, 2019):

If there was something like tcell.ColorBackground (for the terminal's default background colour, often black) and tcell.ColorForeground (for the terminal's default foreground color, often white), that would be quite nice as it wouldn't force a specific theme on everyone. Of course, tcell.ColorDefault would still exist, it would still mean "don't change the color".

<!-- gh-comment-id:526261131 --> @rivo commented on GitHub (Aug 29, 2019): If there was something like `tcell.ColorBackground` (for the terminal's default background colour, often black) and `tcell.ColorForeground` (for the terminal's default foreground color, often white), that would be quite nice as it wouldn't force a specific theme on everyone. Of course, `tcell.ColorDefault` would still exist, it would still mean "don't change the color".
Author
Owner

@blefevre commented on GitHub (Jan 24, 2020):

While waiting for some progress on https://github.com/gdamore/tcell/issues/314 which will hopefully address this, I was able to workaround the issue of using tcell.ColorDefault by clearing the screen before each draw:

app := tview.NewApplication()
app.SetBeforeDrawFunc(func(screen tcell.Screen) bool {
	screen.Clear()
	return false
})
<!-- gh-comment-id:578180467 --> @blefevre commented on GitHub (Jan 24, 2020): While waiting for some progress on https://github.com/gdamore/tcell/issues/314 which will hopefully address this, I was able to workaround the issue of using `tcell.ColorDefault` by clearing the screen before each draw: ```go app := tview.NewApplication() app.SetBeforeDrawFunc(func(screen tcell.Screen) bool { screen.Clear() return false }) ```
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#240
No description provided.