Add support for 8-bit color parsing
This commit is contained in:
parent
354250c506
commit
d2726ef746
2 changed files with 69 additions and 45 deletions
|
@ -11,21 +11,45 @@ if (_consoleColors[settings.terminalMode]) {
|
|||
consoleColors = _consoleColors.none.fourBit
|
||||
consoleColors24 = _consoleColors.none.twentyFourBit
|
||||
}
|
||||
|
||||
const process8bitColorChannel = (value)=>{
|
||||
if(value < 65) return 0
|
||||
if(value < 115) return 1
|
||||
if(value < 155) return 2
|
||||
if(value < 195) return 3
|
||||
if(value < 235) return 4
|
||||
return 5
|
||||
}
|
||||
const hexColorParser = (color) => {
|
||||
if (!consoleColors24.enabled || consoleColors24.bit !== 24) { // Hex color parsing to the 8 bit and 4 bit modes has not been implemented yet
|
||||
if (!consoleColors24.enabled || consoleColors24.bit === 4) { // Hex color parsing to the 4 bit mode has not been implemented yet
|
||||
return ''
|
||||
}
|
||||
let out = '\x1B[0;'
|
||||
const redChannel = Number(`0x${color.slice(1, 3)}`)
|
||||
const greenChannel = Number(`0x${color.slice(3, 5)}`)
|
||||
const blueChannel = Number(`0x${color.slice(5, 7)}`)
|
||||
if (!consoleColors24.lightMode && redChannel < 64 && greenChannel < 64 && blueChannel < 64) {
|
||||
out += '48;2;220;220;220;'
|
||||
} else if (consoleColors24.lightMode && ((redChannel > 192 && greenChannel > 192 && blueChannel > 192) || greenChannel > 160)) {
|
||||
out += '48;2;0;0;0;'
|
||||
if(consoleColors24.bit == 24){
|
||||
let out = '\x1B[0;'
|
||||
const redChannel = Number(`0x${color.slice(1, 3)}`)
|
||||
const greenChannel = Number(`0x${color.slice(3, 5)}`)
|
||||
const blueChannel = Number(`0x${color.slice(5, 7)}`)
|
||||
if (!consoleColors24.lightMode && redChannel < 64 && greenChannel < 64 && blueChannel < 64) {
|
||||
out += '48;2;220;220;220;'
|
||||
} else if (consoleColors24.lightMode && ((redChannel > 192 && greenChannel > 192 && blueChannel > 192) || greenChannel > 160)) {
|
||||
out += '48;2;0;0;0;'
|
||||
}
|
||||
return out + `38;2;${redChannel};${greenChannel};${blueChannel}m`
|
||||
} else if(consoleColors24.bit == 8){
|
||||
let out = '\x1B[0;'
|
||||
const redChannel = Number(`0x${color.slice(1, 3)}`)
|
||||
const greenChannel = Number(`0x${color.slice(3, 5)}`)
|
||||
const blueChannel = Number(`0x${color.slice(5, 7)}`)
|
||||
if (!consoleColors24.lightMode && redChannel < 65 && greenChannel < 65 && blueChannel < 65) {
|
||||
out += '48;5;253;'
|
||||
} else if (consoleColors24.lightMode && ((redChannel > 194 && greenChannel > 194 && blueChannel > 194) || greenChannel > 154)) {
|
||||
out += '48;5;16;'
|
||||
}
|
||||
let redOut = process8bitColorChannel(redChannel);
|
||||
let greenOut = process8bitColorChannel(greenChannel);
|
||||
let blueOut = process8bitColorChannel(blueChannel);
|
||||
let colorValue = 16 + 36 * redOut + 6 * greenOut + blueOut
|
||||
return out + `38;5;${colorValue}m`
|
||||
}
|
||||
return out + `38;2;${redChannel};${greenChannel};${blueChannel}m`
|
||||
}
|
||||
|
||||
const processColor = (col, rcol) => {
|
||||
|
|
|
@ -53,23 +53,23 @@
|
|||
},
|
||||
"blackTerminal_8bit":{
|
||||
"fourBit":{
|
||||
"dark_red": "\u001B[0;38;5;1m",
|
||||
"red": "\u001B[0;38;5;9m",
|
||||
"dark_green": "\u001B[0;38;5;2m",
|
||||
"green": "\u001B[0;38;5;10m",
|
||||
"gold": "\u001B[0;38;5;3m",
|
||||
"yellow": "\u001B[0;38;5;11m",
|
||||
"dark_blue": "\u001B[0;38;5;4m",
|
||||
"blue": "\u001B[0;38;5;12m",
|
||||
"dark_purple": "\u001B[0;38;5;5m",
|
||||
"light_purple": "\u001B[0;38;5;13m",
|
||||
"dark_aqua": "\u001B[0;38;5;6m",
|
||||
"aqua": "\u001B[0;38;5;14m",
|
||||
"black": "\u001B[0;48;5;15;38;5;0m",
|
||||
"gray": "\u001B[0;38;5;7m",
|
||||
"dark_gray": "\u001B[0;38;5;8m",
|
||||
"white": "\u001B[0;38;5;15m",
|
||||
"reset": "\u001B[0;38;5;15m"
|
||||
"dark_red": "\u001B[0;38;5;124m",
|
||||
"red": "\u001B[0;38;5;203m",
|
||||
"dark_green": "\u001B[0;38;5;34m",
|
||||
"green": "\u001B[0;38;5;83m",
|
||||
"gold": "\u001B[0;38;5;214m",
|
||||
"yellow": "\u001B[0;38;5;227m",
|
||||
"dark_blue": "\u001B[0;38;5;19m",
|
||||
"blue": "\u001B[0;38;5;63m",
|
||||
"dark_purple": "\u001B[0;38;5;127m",
|
||||
"light_purple": "\u001B[0;38;5;207m",
|
||||
"dark_aqua": "\u001B[0;38;5;37m",
|
||||
"aqua": "\u001B[0;38;5;87m",
|
||||
"black": "\u001B[0;48;5;253;38;5;16m",
|
||||
"gray": "\u001B[0;38;5;145m",
|
||||
"dark_gray": "\u001B[0;38;5;59m",
|
||||
"white": "\u001B[0;38;5;231m",
|
||||
"reset": "\u001B[0;38;5;231m"
|
||||
},
|
||||
"twentyFourBit":{
|
||||
"enabled": true,
|
||||
|
@ -79,23 +79,23 @@
|
|||
},
|
||||
"whiteTerminal_8bit":{
|
||||
"fourBit":{
|
||||
"dark_red": "\u001B[0;38;5;1m",
|
||||
"red": "\u001B[0;38;5;9m",
|
||||
"dark_green": "\u001B[0;38;5;2m",
|
||||
"green": "\u001B[0;48;5;0;38;5;10m",
|
||||
"gold": "\u001B[0;38;5;3m",
|
||||
"yellow": "\u001B[0;48;5;0;38;5;11m",
|
||||
"dark_blue": "\u001B[0;38;5;4m",
|
||||
"blue": "\u001B[0;38;5;12m",
|
||||
"dark_purple": "\u001B[0;38;5;5m",
|
||||
"light_purple": "\u001B[0;38;5;13m",
|
||||
"dark_aqua": "\u001B[0;38;5;6m",
|
||||
"aqua": "\u001B[0;48;5;0;38;5;14m",
|
||||
"black": "\u001B[0;38;5;0m",
|
||||
"gray": "\u001B[0;38;5;7m",
|
||||
"dark_gray": "\u001B[0;38;5;8m",
|
||||
"white": "\u001B[0;48;5;0;38;5;15m",
|
||||
"reset": "\u001B[0;48;5;0;38;5;15m"
|
||||
"dark_red": "\u001B[0;38;5;124m",
|
||||
"red": "\u001B[0;38;5;203m",
|
||||
"dark_green": "\u001B[0;38;5;34m",
|
||||
"green": "\u001B[0;48;5;16;38;5;83m",
|
||||
"gold": "\u001B[0;38;5;214m",
|
||||
"yellow": "\u001B[0;48;5;16;38;5;227m",
|
||||
"dark_blue": "\u001B[0;38;5;19m",
|
||||
"blue": "\u001B[0;38;5;63m",
|
||||
"dark_purple": "\u001B[0;38;5;127m",
|
||||
"light_purple": "\u001B[0;38;5;207m",
|
||||
"dark_aqua": "\u001B[0;38;5;37m",
|
||||
"aqua": "\u001B[0;48;5;16;38;5;87m",
|
||||
"black": "\u001B[0;38;5;16m",
|
||||
"gray": "\u001B[0;38;5;145m",
|
||||
"dark_gray": "\u001B[0;38;5;59m",
|
||||
"white": "\u001B[0;48;5;16;38;5;231m",
|
||||
"reset": "\u001B[0;48;5;16;38;5;231m"
|
||||
},
|
||||
"twentyFourBit":{
|
||||
"enabled": true,
|
||||
|
|
Loading…
Add table
Reference in a new issue