Qix- / color-convert

Plain color conversion functions in JavaScript
MIT License
746 stars 96 forks source link

Add `ansi256` → `ansi16` #93

Open Richienb opened 3 years ago

Richienb commented 3 years ago

Output in Windows Terminal:

Grid of colours with an ansi256 code and a corresponding ansi16 code

Fixes #92, Fixes #89

Qix- commented 3 years ago

Thanks - could you add tests that check the result of ansi256.ansi16() to rgb.ansi16(ansi256.rgb()) to make sure it's as expected?

Something like:

for (let i = 0; i < 8; i++) {
    assert( cc.ansi256.ansi16(i) === (i + 30) );
}

for (let i = 8; i < 16; i++) {
    assert( cc.ansi256.ansi16(i) === (i + 90) );
}

for (let i = 16; i < 256; i++) {
    assert( cc.ansi256.ansi16(i) === cc.rgb.ansi16(cc.ansi256.rgb(i)) );
}
Richienb commented 3 years ago

Couldn't get the third test to work but the other 2 passed fine.