The vscode.window.onDidWriteTerminalData
event cannot be used when publishing extensions for Visual Studio Code. Does anyone know of an alternative method to capture the text and changes from the built-in terminal to handle this information in a variable?
Searching in some places, I checked a Node.Js library called child_process
and imported it into my project.
After that, I declared a Promise to check the result of the exec method of this library.
It was possible to get the execution data and treat it using a regex to match a text or URL in the terminal.
Example:
function runApp(command) {
setApplicationProperties();
outputChannel.show();
let promise = new Promise(resolve => {
vscode.window.showInformationMessage(`Running App '${application_name}'...`);
let result = child.exec(command, {cwd: getWorkspaceDir()});
result.stdout.on("data", (data) => {
outputFilter = data;
infoCatcher = outputFilter.match(/\w.+/gi);
if (infoCatcher != null)
outputChannel.append(`${infoCatcher[0]}\n`);
urlCatcher = outputFilter.match(/(http|https)?:\/\/.+/gi);
if (urlCatcher != null)
vscode.env.openExternal(vscode.Uri.parse(urlCatcher[0]));
resolve();
});
});
return promise;
}