Add support for 8/4 bit color and white terminals

This commit is contained in:
7cc5c4f330d47060 2024-07-30 17:14:41 -04:00
parent 9f99a1bbf1
commit 93c4835728
3 changed files with 203 additions and 24 deletions

View file

@ -5,7 +5,7 @@ const newercommands = require('./command.js').cmds
const rl = readln.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '\x1b[0m\x1b[38;5;15m> '
prompt: '\x1b[0m> '
})
rl.on('line', (l) => {
try {

View file

@ -1,36 +1,33 @@
const _lang = require('minecraft-data')('1.20.2').language
const _lang = require('minecraft-data')('1.20.2').language;
const settings = require('../settings.json');
const lang = Object.create(null) // Without constructor function
for (const i in _lang) {
lang[i] = _lang[i]
}
const consoleColors = {
dark_red: '\x1B[0m\x1B[38;2;170;0;0m',
red: '\x1B[0m\x1B[38;2;255;85;85m',
dark_green: '\x1B[0m\x1B[38;2;0;170;0m',
green: '\x1B[0m\x1B[38;2;85;255;85m',
gold: '\x1B[0m\x1B[38;2;255;170;0m',
yellow: '\x1B[0m\x1B[38;2;255;255;85m',
dark_blue: '\x1B[0m\x1B[38;2;0;0;170m',
blue: '\x1B[0m\x1B[38;2;85;85;255m',
dark_purple: '\x1B[0m\x1B[38;2;170;0;170m',
light_purple: '\x1B[0m\x1B[38;2;255;85;255m',
dark_aqua: '\x1B[0m\x1B[38;2;0;170;170m',
aqua: '\x1B[0m\x1B[38;2;85;255;255m',
black: '\x1B[0m\x1B[48;2;220;220;220m\x1B[38;2;0;0;0m',
gray: '\x1B[0m\x1B[38;2;170;170;170m',
dark_gray: '\x1B[0m\x1B[38;2;85;85;85m',
white: '\x1B[0m\x1B[38;2;255;255;255m',
reset: '\x1B[0m\x1B[38;2;255;255;255m'
const _consoleColors = require("./consolecolors.json");
let consoleColors;
let consoleColors24;
if(_consoleColors[settings.terminalMode]){
consoleColors=_consoleColors[settings.terminalMode].fourBit
consoleColors24=_consoleColors[settings.terminalMode].twentyFourBit
} else {
consoleColors=_consoleColors.none.fourBit
consoleColors24=_consoleColors.none.twentyFourBit
}
const hexColorParser = (color) => {
let out = '\x1B[0m'
if(!consoleColors24.enabled || consoleColors24.bit!==24){ //Non-24bit hex color parsing is not 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 (redChannel < 96 && greenChannel < 96 && blueChannel < 96) {
out += '\x1B[48;2;220;220;220m'
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 + `\x1B[38;2;${redChannel};${greenChannel};${blueChannel}m`
return out + `38;2;${redChannel};${greenChannel};${blueChannel}m`
}
const processColor = (col, rcol) => {
const out = ['', '']

182
util/consolecolors.json Normal file
View file

@ -0,0 +1,182 @@
{
"blackTerminal_24bit":{
"fourBit":{
"dark_red": "\u001B[0m\u001B[38;2;170;0;0m",
"red": "\u001B[0m\u001B[38;2;255;85;85m",
"dark_green": "\u001B[0m\u001B[38;2;0;170;0m",
"green": "\u001B[0m\u001B[38;2;85;255;85m",
"gold": "\u001B[0m\u001B[38;2;255;170;0m",
"yellow": "\u001B[0m\u001B[38;2;255;255;85m",
"dark_blue": "\u001B[0m\u001B[38;2;0;0;170m",
"blue": "\u001B[0m\u001B[38;2;85;85;255m",
"dark_purple": "\u001B[0m\u001B[38;2;170;0;170m",
"light_purple": "\u001B[0m\u001B[38;2;255;85;255m",
"dark_aqua": "\u001B[0m\u001B[38;2;0;170;170m",
"aqua": "\u001B[0m\u001B[38;2;85;255;255m",
"black": "\u001B[0m\u001B[48;2;220;220;220m\u001B[38;2;0;0;0m",
"gray": "\u001B[0m\u001B[38;2;170;170;170m",
"dark_gray": "\u001B[0m\u001B[38;2;85;85;85m",
"white": "\u001B[0m\u001B[38;2;255;255;255m",
"reset": "\u001B[0m\u001B[38;2;255;255;255m"
},
"twentyFourBit":{
"enabled": true,
"bit": 24,
"lightMode": false
}
},
"whiteTerminal_24bit":{
"fourBit":{
"dark_red": "\u001B[0m\u001B[38;2;170;0;0m",
"red": "\u001B[0m\u001B[38;2;255;85;85m",
"dark_green": "\u001B[0m\u001B[38;2;0;170;0m",
"green": "\u001B[0m\u001B[48;2;20;20;20m\u001B[38;2;85;255;85m",
"gold": "\u001B[0m\u001B[38;2;255;170;0m",
"yellow": "\u001B[0m\u001B[48;2;20;20;20m\u001B[38;2;255;255;85m",
"dark_blue": "\u001B[0m\u001B[38;2;0;0;170m",
"blue": "\u001B[0m\u001B[38;2;85;85;255m",
"dark_purple": "\u001B[0m\u001B[38;2;170;0;170m",
"light_purple": "\u001B[0m\u001B[38;2;255;85;255m",
"dark_aqua": "\u001B[0m\u001B[38;2;0;170;170m",
"aqua": "\u001B[0m\u001B[48;2;20;20;20m\u001B[38;2;85;255;255m",
"black": "\u001B[0m\u001B[38;2;0;0;0m",
"gray": "\u001B[0m\u001B[38;2;170;170;170m",
"dark_gray": "\u001B[0m\u001B[38;2;85;85;85m",
"white": "\u001B[0m\u001B[48;2;20;20;20m\u001B[38;2;255;255;255m",
"reset": "\u001B[0m\u001B[48;2;20;20;20m\u001B[38;2;255;255;255m"
},
"twentyFourBit":{
"enabled": true,
"bit": 24,
"lightMode": true
}
},
"blackTerminal_8bit":{
"fourBit":{
"dark_red": "\u001B[0m\u001B[38;5;1m",
"red": "\u001B[0m\u001B[38;5;9m",
"dark_green": "\u001B[0m\u001B[38;5;2m",
"green": "\u001B[0m\u001B[38;5;10m",
"gold": "\u001B[0m\u001B[38;5;3m",
"yellow": "\u001B[0m\u001B[38;5;11m",
"dark_blue": "\u001B[0m\u001B[38;5;4m",
"blue": "\u001B[0m\u001B[38;5;12m",
"dark_purple": "\u001B[0m\u001B[38;5;5m",
"light_purple": "\u001B[0m\u001B[38;5;13m",
"dark_aqua": "\u001B[0m\u001B[38;5;6m",
"aqua": "\u001B[0m\u001B[38;5;14m",
"black": "\u001B[0m\u001B[48;5;15m\u001B[38;5;0m",
"gray": "\u001B[0m\u001B[38;5;7m",
"dark_gray": "\u001B[0m\u001B[38;5;8m",
"white": "\u001B[0m\u001B[38;5;15m",
"reset": "\u001B[0m\u001B[38;5;15m"
},
"twentyFourBit":{
"enabled": true,
"bit": 8,
"lightMode": false
}
},
"whiteTerminal_8bit":{
"fourBit":{
"dark_red": "\u001B[0m\u001B[38;5;1m",
"red": "\u001B[0m\u001B[38;5;9m",
"dark_green": "\u001B[0m\u001B[38;5;2m",
"green": "\u001B[0m\u001B[48;5;0m\u001B[38;5;10m",
"gold": "\u001B[0m\u001B[38;5;3m",
"yellow": "\u001B[0m\u001B[48;5;0m\u001B[38;5;11m",
"dark_blue": "\u001B[0m\u001B[38;5;4m",
"blue": "\u001B[0m\u001B[38;5;12m",
"dark_purple": "\u001B[0m\u001B[38;5;5m",
"light_purple": "\u001B[0m\u001B[38;5;13m",
"dark_aqua": "\u001B[0m\u001B[38;5;6m",
"aqua": "\u001B[0m\u001B[48;5;0m\u001B[38;5;14m",
"black": "\u001B[0m\u001B[38;5;0m",
"gray": "\u001B[0m\u001B[38;5;7m",
"dark_gray": "\u001B[0m\u001B[38;5;8m",
"white": "\u001B[0m\u001B[48;5;0m\u001B[38;5;15m",
"reset": "\u001B[0m\u001B[48;5;0m\u001B[38;5;15m"
},
"twentyFourBit":{
"enabled": true,
"bit": 8,
"lightMode": true
}
},
"blackTerminal_4bit":{
"fourBit":{
"dark_red": "\u001B[0m\u001B[31m",
"red": "\u001B[0m\u001B[1;31m",
"dark_green": "\u001B[0m\u001B[32m",
"green": "\u001B[0m\u001B[1;32m",
"gold": "\u001B[0m\u001B[33m",
"yellow": "\u001B[0m\u001B[1;33m",
"dark_blue": "\u001B[0m\u001B[34m",
"blue": "\u001B[0m\u001B[1;34m",
"dark_purple": "\u001B[0m\u001B[35m",
"light_purple": "\u001B[0m\u001B[1;35m",
"dark_aqua": "\u001B[0m\u001B[36m",
"aqua": "\u001B[0m\u001B[1;36m",
"black": "\u001B[0m\u001B[0;1;47m\u001B[0;30m",
"gray": "\u001B[0m\u001B[0;37m",
"dark_gray": "\u001B[0m\u001B[0;1;30m",
"white": "\u001B[0m\u001B[0;1;37m",
"reset": "\u001B[0m\u001B[0;1;37m"
},
"twentyFourBit":{
"enabled": true,
"bit": 4,
"lightMode": false
}
},
"whiteTerminal_4bit":{
"fourBit":{
"dark_red": "\u001B[0m\u001B[31m",
"red": "\u001B[0m\u001B[1;31m",
"dark_green": "\u001B[0m\u001B[32m",
"green": "\u001B[0m\u001B[0;40m\u001B[1;32m",
"gold": "\u001B[0m\u001B[33m",
"yellow": "\u001B[0m\u001B[0;40m\u001B[1;33m",
"dark_blue": "\u001B[0m\u001B[34m",
"blue": "\u001B[0m\u001B[1;34m",
"dark_purple": "\u001B[0m\u001B[35m",
"light_purple": "\u001B[0m\u001B[1;35m",
"dark_aqua": "\u001B[0m\u001B[36m",
"aqua": "\u001B[0m\u001B[0;40m\u001B[1;36m",
"black": "\u001B[0m\u001B[0;30m",
"gray": "\u001B[0m\u001B[0;37m",
"dark_gray": "\u001B[0m\u001B[0;1;30m",
"white": "\u001B[0m\u001B[0;40m\u001B[1;37m",
"reset": "\u001B[0m\u001B[0;40m\u001B[1;37m"
},
"twentyFourBit":{
"enabled": true,
"bit": 4,
"lightMode": true
}
},
"none":{
"fourBit":{
"dark_red": "",
"red": "",
"dark_green": "",
"green": "",
"gold": "",
"yellow": "",
"dark_blue": "",
"blue": "",
"dark_purple": "",
"light_purple": "",
"dark_aqua": "",
"aqua": "",
"black": "",
"gray": "",
"dark_gray": "",
"white": "",
"reset": ""
},
"twentyFourBit":{
"enabled": false
}
}
}