[GH-ISSUE #558] List does not unselect items when navigating #410

Closed
opened 2026-03-04 01:04:44 +03:00 by kerem · 7 comments
Owner

Originally created by @njkleiner on GitHub (Jan 29, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/558

I'm running the following code, adapted from the flex and list demos.

package main

import (
    "github.com/gdamore/tcell/v2"
    "github.com/rivo/tview"
)

func main() {
    app := tview.NewApplication()

    channels := tview.NewList()
    channels.
        SetBackgroundColor(tcell.ColorDefault).SetBorder(true).SetTitle("").SetBorderPadding(0, 0, 1, 1)
    channels.
        AddItem("Channel A", "", 0, nil).AddItem("Channel B", "", 0, nil).
        ShowSecondaryText(false).SetMainTextColor(tcell.ColorDefault).SetSelectedTextColor(tcell.ColorDefault)

    items := tview.NewBox().SetBorder(true).SetTitle("").SetBackgroundColor(tcell.ColorDefault)

    content := tview.NewFlex().
        AddItem(channels, 0, 1, true).
        AddItem(items, 0, 5, false)

    if err := app.SetRoot(content, true).EnableMouse(true).Run(); err != nil {
        panic(err)
    }
}

When I navigate to the second item using the arrow keys, the first one stays selected. Once the second item is selected too, they both stay selected and further navigating the list does nothing.

The behavior I would have expected is for the list to work normally (i.e., only select one item at a time). I'm not sure what I'm doing wrong, because I don't think what I'm doing is much different from the list demo, which works as expected.

Originally created by @njkleiner on GitHub (Jan 29, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/558 I'm running the following code, adapted from the flex and list demos. ```go package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() channels := tview.NewList() channels. SetBackgroundColor(tcell.ColorDefault).SetBorder(true).SetTitle("").SetBorderPadding(0, 0, 1, 1) channels. AddItem("Channel A", "", 0, nil).AddItem("Channel B", "", 0, nil). ShowSecondaryText(false).SetMainTextColor(tcell.ColorDefault).SetSelectedTextColor(tcell.ColorDefault) items := tview.NewBox().SetBorder(true).SetTitle("").SetBackgroundColor(tcell.ColorDefault) content := tview.NewFlex(). AddItem(channels, 0, 1, true). AddItem(items, 0, 5, false) if err := app.SetRoot(content, true).EnableMouse(true).Run(); err != nil { panic(err) } } ``` When I navigate to the second item using the arrow keys, the first one stays selected. Once the second item is selected too, they both stay selected and further navigating the list does nothing. The behavior I would have expected is for the list to work normally (i.e., only select one item at a time). I'm not sure what I'm doing wrong, because I don't think what I'm doing is much different from the list demo, which works as expected.
kerem closed this issue 2026-03-04 01:04:45 +03:00
Author
Owner

@SoMuchForSubtlety commented on GitHub (Feb 13, 2021):

I just encountered this issue myself. Looks it was introduced with this commit. github.com/rivo/tview@d7d44cb0d2

@rivo can you shine some light on the reason behind this?

<!-- gh-comment-id:778635071 --> @SoMuchForSubtlety commented on GitHub (Feb 13, 2021): I just encountered this issue myself. Looks it was introduced with this commit. https://github.com/rivo/tview/commit/d7d44cb0d26e6f45c3591e8f1c29956cb8a3deee @rivo can you shine some light on the reason behind this?
Author
Owner

@rivo commented on GitHub (Feb 17, 2021):

Please don't use tcell.ColorDefault. It basically means "transparent" so it has pretty much no effect and therefore leads to strange side effects such as this one.

<!-- gh-comment-id:780474141 --> @rivo commented on GitHub (Feb 17, 2021): Please don't use [`tcell.ColorDefault`](https://pkg.go.dev/github.com/gdamore/tcell#Color). It basically means "transparent" so it has pretty much no effect and therefore leads to strange side effects such as this one.
Author
Owner

@njkleiner commented on GitHub (Feb 17, 2021):

Please don't use tcell.ColorDefault.

The reason why I used ColorDefault was because I use a terminal with a white background. Is there a different (preferred) way to reset the colors to a "light mode"?

<!-- gh-comment-id:780479777 --> @njkleiner commented on GitHub (Feb 17, 2021): > Please don't use [`tcell.ColorDefault`](https://pkg.go.dev/github.com/gdamore/tcell#Color). The reason why I used `ColorDefault` was because I use a terminal with a white background. Is there a different (preferred) way to reset the colors to a "light mode"?
Author
Owner

@rivo commented on GitHub (Feb 17, 2021):

I understand. This has come up multiple times as many people assume ColorDefault means something like ColorTerminalBackground.

I'm currently not aware of any way to use the terminal's theme colours. There was some related work done in https://github.com/gdamore/tcell/issues/314 but the attached commit isn't in the main branch so I don't know what the status is. (There are also no further comments in that issue.)

<!-- gh-comment-id:780488809 --> @rivo commented on GitHub (Feb 17, 2021): I understand. This has come up multiple times as many people assume `ColorDefault` means something like `ColorTerminalBackground`. I'm currently not aware of any way to use the terminal's theme colours. There was some related work done in https://github.com/gdamore/tcell/issues/314 but the attached commit isn't in the main branch so I don't know what the status is. (There are also no further comments in that issue.)
Author
Owner

@SoMuchForSubtlety commented on GitHub (Feb 17, 2021):

I changed the behaviour in this commit github.com/SoMuchForSubtlety/tview@c4de038979

Now tview respects the terminal background colour and things like transparent terminals work
image
Before my patch it looked like this (note that the TextView borders are still transparent)
image

<!-- gh-comment-id:780543674 --> @SoMuchForSubtlety commented on GitHub (Feb 17, 2021): I changed the behaviour in this commit https://github.com/SoMuchForSubtlety/tview/commit/c4de038979df4f0c2f1891d71511b37cbb703bd3 Now tview respects the terminal background colour and things like transparent terminals work ![image](https://user-images.githubusercontent.com/15961647/108207989-bf79e780-7128-11eb-8b10-ddd1e3f673fa.png) Before my patch it looked like this (note that the `TextView` borders are still transparent) ![image](https://user-images.githubusercontent.com/15961647/108208322-30210400-7129-11eb-8296-b3c73c3870cf.png)
Author
Owner

@rivo commented on GitHub (Feb 17, 2021):

I realize I looked at the wrong tcell documentation and maybe my previous comment is not accurate anymore.

I will look at this again.

<!-- gh-comment-id:780568268 --> @rivo commented on GitHub (Feb 17, 2021): I realize I looked at the wrong `tcell` documentation and maybe my previous comment is not accurate anymore. I will look at this again.
Author
Owner

@rivo commented on GitHub (Apr 27, 2021):

Coming back to this, in your application, you can now set the general background colour to your terminal's default as follows:

tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault

However, tcell doesn't provide any equivalent for the default text colour. So if you only make this one change, the text colour in your light terminal will still be white. Of course, you can set it to black:

tview.Styles.PrimaryTextColor = tcell.ColorBlack

But then it's black even on dark terminals.

Overall, I don't see a way to make it adapt to different terminal themes.

<!-- gh-comment-id:827552611 --> @rivo commented on GitHub (Apr 27, 2021): Coming back to this, in your application, you can now set the general background colour to your terminal's default as follows: ```go tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault ``` However, `tcell` doesn't provide any equivalent for the default text colour. So if you only make this one change, the text colour in your light terminal will still be white. Of course, you can set it to black: ```go tview.Styles.PrimaryTextColor = tcell.ColorBlack ``` But then it's black even on dark terminals. Overall, I don't see a way to make it adapt to different terminal themes.
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#410
No description provided.