0

Just as the question says.

I am writing a node.js application and I want the app to be able to determine how it will output status text based off what terminal is in use, the integrated terminal or an external one.

The readline package clearline and cursorto and stdout in general does not seem to work in the vscode terminal, so, no single line updating status messages.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
John Sohn
  • 100
  • 1
  • 9
  • I would expect, but haven't verified, that the TERM env var should tell you the capabilities on the terminal node is running in, e.g., in a console: `process.env.TERM == 'xterm-256color'` – Christian Fritz Apr 03 '21 at 17:40
  • nope and unfortunately the vscode specific environment variables don't house any insight either, even when I choose the external console option in the launch config. – John Sohn Apr 04 '21 at 01:06

2 Answers2

1

The VSCode integrated terminal sets the TERM_PROGRAM environment variable to vscode. [1]

You can check this in node.js: [2]

process.env.TERM_PROGRAM == "vscode"
Gavin S. Yancey
  • 1,216
  • 1
  • 13
  • 34
0

The env var "VSCODE_INSPECTOR_OPTIONS" only exists when using VS to run your code. Perfect way to decide outputs.

if (!process.env.VSCODE_INSPECTOR_OPTIONS) {
      process.stdout.on('data', (data) => {
        console.log('processMgr:', `${data}`);
      });
      process.stderr.on('data', (data) => {
        console.error('processMgr:', `${data}`);
      });
    }