What do these characters mean?(ANSI Code)

Viewed 48

It's the code I'm printing with node:

const m = `[38;5;1;48;5;16m TEST`
console.log(m)

output: enter image description here

It changes the text color. As you can see `` is a special char I don't understand(It's not being shown by the browser). How does it work?

enter image description here

Is there any alternative for ESC?

2 Answers

These are terminal control characters. They are often used e.g. for coloring the output. Some are non-printable. Backticks ` in your javascript example are called template literals.

As @puucee already mentions they are terminal control characters. I find it surprising that it says ESC[ in the code as that won't be escaped in normal node. I suspect that maybe your IDE is converting the "true" escape character to ESC. Node does not support octal escapes (such as \033), but hexadecimal escapes. That is, you string should usually be like this:

console.log('\x1b[38;5;1;48;5;16m TEST \x1b[0m')

Related