Theia API Documentation v1.65.0
    Preparing search index...

    Shell integration-powered capabilities owned by a terminal.

    interface TerminalShellIntegration {
        cwd: undefined | Uri;
        executeCommand(commandLine: string): TerminalShellExecution;
        executeCommand(executable: string, args: string[]): TerminalShellExecution;
    }
    Index

    Properties

    Methods

    Properties

    cwd: undefined | Uri

    The current working directory of the terminal. This Uri may represent a file on another machine (eg. ssh into another machine). This requires the shell integration to support working directory reporting.

    Methods

    • Execute a command, sending ^C as necessary to interrupt any running command if needed.

      Parameters

      • commandLine: string

        The command line to execute, this is the exact text that will be sent to the terminal.

      Returns TerminalShellExecution

      // Execute a command in a terminal immediately after being created
      const myTerm = window.createTerminal();
      window.onDidChangeTerminalShellIntegration(async ({ terminal, shellIntegration }) => {
      if (terminal === myTerm) {
      const execution = shellIntegration.executeCommand('echo "Hello world"');
      window.onDidEndTerminalShellExecution(event => {
      if (event.execution === execution) {
      console.log(`Command exited with code ${event.exitCode}`);
      }
      }
      }));
      // Fallback to sendText if there is no shell integration within 3 seconds of launching
      setTimeout(() => {
      if (!myTerm.shellIntegration) {
      myTerm.sendText('echo "Hello world"');
      // Without shell integration, we can't know when the command has finished or what the
      // exit code was.
      }
      }, 3000);
      // Send command to terminal that has been alive for a while
      const commandLine = 'echo "Hello world"';
      if (term.shellIntegration) {
      const execution = shellIntegration.executeCommand({ commandLine });
      window.onDidEndTerminalShellExecution(event => {
      if (event.execution === execution) {
      console.log(`Command exited with code ${event.exitCode}`);
      }
      } else {
      term.sendText(commandLine);
      // Without shell integration, we can't know when the command has finished or what the
      // exit code was.
      }
    • Execute a command, sending ^C as necessary to interrupt any running command if needed.

      Note This is not guaranteed to work as shell integration must be activated. Check whether TerminalShellExecution.exitCode is rejected to verify whether it was successful.

      Parameters

      • executable: string
      • args: string[]

        Arguments to launch the executable with which will be automatically escaped based on the executable type.

      Returns TerminalShellExecution

      // Execute a command in a terminal immediately after being created
      const myTerm = window.createTerminal();
      window.onDidActivateTerminalShellIntegration(async ({ terminal, shellIntegration }) => {
      if (terminal === myTerm) {
      const command = shellIntegration.executeCommand({
      command: 'echo',
      args: ['Hello world']
      });
      const code = await command.exitCode;
      console.log(`Command exited with code ${code}`);
      }
      }));
      // Fallback to sendText if there is no shell integration within 3 seconds of launching
      setTimeout(() => {
      if (!myTerm.shellIntegration) {
      myTerm.sendText('echo "Hello world"');
      // Without shell integration, we can't know when the command has finished or what the
      // exit code was.
      }
      }, 3000);
      // Send command to terminal that has been alive for a while
      const commandLine = 'echo "Hello world"';
      if (term.shellIntegration) {
      const command = term.shellIntegration.executeCommand({
      command: 'echo',
      args: ['Hello world']
      });
      const code = await command.exitCode;
      console.log(`Command exited with code ${code}`);
      } else {
      term.sendText(commandLine);
      // Without shell integration, we can't know when the command has finished or what the
      // exit code was.
      }