How ansi work

This commit is contained in:
Yaode_owo 2024-07-18 08:47:10 -04:00
parent 8fe3efac35
commit 69188b3e66

13
toAnsi/toAnsi.js Normal file
View file

@ -0,0 +1,13 @@
message = '§#123456' // §#RRGGBB
const hexRegex = /§#?([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})/ // find §#??????
while (message.search(hexRegex) !== -1) {
const hexCodes = hexRegex.exec(message)
const red = parseInt(hexCodes[1], 16) // converts the hexadecimal strings to decimal values.
const green = parseInt(hexCodes[2], 16) // The function replaces the hexadecimal color code with an ANSI escape sequence that sets the text color using RGB values.
const blue = parseInt(hexCodes[3], 16) // from google
message = message.replace(hexRegex, `\u001b[38;2;${red};${green};${blue}m`)
message = '\x1B[0m' + message + "Text Message" + '\x1B[0m' // reset + color + "Text" + reset
}
console.log(message)