Rubens Mariuzzo
Rubens Mariuzzo

Reputation: 29251

How to remove ansi code from output piped to VSCode?

As of November 2017 VSCode allow to pipe output directly to VSCode. I did tried with a few command until I got a bunch of ANSI codes which I'm not interested.

I'm running something like yarn info babel-core | code and getting this:

yarn info v0.24.6
{ name: [32m'babel-core'[39m,
  description: [32m'A placeholder package that bridges babel-core to @babel/core.'[39m,
  [32m'dist-tags'[39m: 
   { latest: [32m'6.26.0'[39m,
     old: [32m'5.8.38'[39m,
     next: [32m'7.0.0-beta.3'[39m,
     bridge: [32m'7.0.0-bridge.0'[39m },

I would like to that output without these ANSI codes.

Upvotes: 1

Views: 1756

Answers (2)

ScottWelker
ScottWelker

Reputation: 2094

Alternatively, plugins now exist, e.g. ANSI Colors, that once installed enable you to select ANSI text as the file's "language mode." You can then use VS Code's _Command Palette_ (Ctl-Sft-P) to preview the file (ANSI Text: Open Preview) with escape sequences respected, i.e. in color (and etc.)

Credit

Can I display a file with ANSI color escape sequences in Visual Studio Code?

Upvotes: -1

Rubens Mariuzzo
Rubens Mariuzzo

Reputation: 29251

If you NodeJS then you can globally install strip-ansi-cli which provides you the command: strip-ansi. It does exactly that.

For your case, you may use it as follow:

yarn info babel-core | strip-ansi | code

Happy coding!

Upvotes: 2

Related Questions