Parsa_Gholipour
Parsa_Gholipour

Reputation: 950

What do these characters mean?(ANSI Code)

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?

Upvotes: 1

Views: 224

Answers (2)

Naphat Amundsen
Naphat Amundsen

Reputation: 1623

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')

Upvotes: 1

puucee
puucee

Reputation: 36

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.

Upvotes: 1

Related Questions