opened
walles
username_0
Hi!

In 1.x, `tcell.Color(74)` used to return a value matching `tcell.Color74.`

In 2.0, those values are different.

Is this something I should worry about?

  Regards /Johan

# Repro
```go
package main

import (
	"fmt"
	"strconv"

	"github.com/username_1/tcell"
)

func main() {
	colorValue := tcell.Color(74)

	fmt.Printf("Created color value: %s\n", strconv.FormatInt(int64(colorValue), 16))
	fmt.Printf("Constant color value: %s\n", strconv.FormatInt(int64(tcell.Color74), 16))
	if colorValue == tcell.Color74 {
		fmt.Println("Equal, good.")
	} else {
		fmt.Println("Not equal, bad!")
	}
}
```
In 2.0, color constants don't match created colors
issue
closed
gdamore
username_1
issue
created
gdamore
username_1
You should not worry about it.   The numeric value of the color includes a bit indicating that the color is "valid".  The low order bits are still 74 (or whatever).

The reason for adding in an extra high order bit is so that we can treat 0 (normally black) as an uninitialized value.

The numeric values are "private" -- if you want the actual RGB value, you can ask for it.  We don't give you the palette index as a value -- mostly because we didn't see a need for that, but if you want to have that I'm sure its an API we could provide.
comment
created
gdamore
username_1
(These changes in the color handling were why tcell was bumped to v2 btw...)
comment
created
walles
username_0
So I have a function returning different colors depending on its input, and I want to test it.

Currently the test looks like this, and it works on 1.4 and fails on 2.0:
https://github.com/username_0/moar/blob/a174d861801c4c206c116635638d430c08361c19/m/ansiTokenizer_test.go#L93-L99

```go
func TestConsumeCompositeColorHappy(t *testing.T) {
	// 8 bit color
	// Example from: https://github.com/username_0/moar/issues/14
	newIndex, color, err := consumeCompositeColor([]string{"38", "5", "74"}, 0)
	assert.NilError(t, err)
	assert.Equal(t, newIndex, 3)
	assert.Equal(t, *color, tcell.Color74)
```

What would be the best way for me to phrase this test with tcell 2.0?
comment
created
walles
username_0
@username_1 should I turn my last comment here into a new ticket, do you want to re-open this one or something else?

I would *like* to re-open this issue until it has been hashed out, but I don't have permissions to do so.
comment
created
gdamore
username_1
Wait a minute -- you're trying to assert that this color (tcell.Color74) has a specific numeric value?  That specifically is not part of our public API.

However.... if you want to get the TrueColor value of tcell.Color74, you can do that via a call to the colors RGB() or Hex() methods.  That will give you a value.  Maybe that will resolve what you want?
comment
created
gdamore
username_1
Specifically try "tcell.Color74.Hex()" to get the 24 bit value, or tcell.Color74.RGB() to return the red, green, blue components.  Admittedly when using palette colors this is based on the published default palette of xterm, which may or may not match what folks have configured.  (Generally palette entries above >= 16 are rarely if ever modified by themes, but the lower 16 entries are frequently changed via themes.)
comment
created
gdamore
username_1
Btw, if you need to create a color a specific RGB value, you should use NewRGBColor().  It will create the precise value, or as close a match as we can using the palette if direct RGB colors are not supported by the terminal.
comment
created
walles
username_0
Well, verifying that my color has a specific numeric value is *exactly* what I want to do.

# Background
In this case, [moar](https://github.com/username_0/moar) is a pager.

And the test case outlined above is for verifying that it converts an input ANSI escape sequence requesting color 74 to `tcell.Color74`.

Since this is a pager, it should display the same thing as `cat` would, but with paging.

So **I can't convert to RGB**, that would make `moar` display the wrong things, by not following the terminal theming.
comment
created
walles
username_0
@username_1 any opinions about this use case? ^
comment
created
gdamore
username_1
The colors starting at index 1 will have the same offset.  So compare the difference to color1 if you need that verification. 

Alternatively just compare the RGB values which should be good enough for your self tests.
comment
created
walles
username_0
Given that I have a variable containing the number `74`, what do you think would be the best way for me to turn that into `tcell.Color74`?

I have [a workaround](https://github.com/username_0/moar/blob/08db9e9cd6232ca0c13c7b434d69c6d16321fd5d/m/ansiTokenizer.go#L426-L432) for how to do that, but it doesn't feel great, so I'd like to know what you think would be the best way.
comment
created
gdamore
username_1
Take 73 (74-1) and add it to Color1.
comment
created
gdamore
username_1
Maybe I should add a method to create a color from a palette index.
comment