visual-studio-codecommand-line-interfacevscode-extensions

How to use Terminal API to listen to all terminal commands/output in VS Code?


I want to listen to terminal output from extension, such as tsc -w and catch the moment if the output contains similar text:

Found 1 error. Watching for file changes.

Or the error exit code or something like that. Is it possible to do with old API or Proposed API?

Tried:

terminal.onDidWriteData(data => {
    console.log('onDidWriteData: ', data.trim());
});

It just outputs autogenerated rubbish like:

Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.


Solution

  • Looks like it is deprecated in insiders edition. Try using window.onDidWriteTerminalData:

    window.onDidWriteTerminalData(event => console.log(event.data.trim()))
    

    Reference