Snippet with ANSI terminal escape color codes in VSCODE

247 views Asked by At

im trying to create a custom snippet in order to use console.log() and I'm using some Ascii code because I want to make the the first logged value yellow.

So my problem is that the snippets.json file from VSCode in not able to read \x1b[33m%s\x1b[0m.

enter image description here

I would like to know if there is a way to be able to read the Ascii code from the snippets.json file.

https://voidcanvas.com/make-console-log-output-colorful-and-stylish-in-browser-node/

 "Print to console": {
        "prefix": "lg",
        "body": [
             "console.log("\x1b[33m%s\x1b[0m",'$1', $2);",
        ],
        "description": "Log output to console"
     }
1

There are 1 answers

0
rioV8 On BEST ANSWER

You have to escape the " and \

"Print to console": {
  "prefix": "lg",
  "body": [
       "console.log(\"\\x1b[33m%s\\x1b[0m\", '$1', $2);",
  ],
  "description": "Log output to console"
}