Merge pull request #208425 from microsoft/tyriar/205744

Wait for cmd detection if running command at start up
This commit is contained in:
Daniel Imms 2024-03-22 08:40:37 -07:00 committed by GitHub
commit 712a3eefbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -824,10 +824,29 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
async runCommand(commandLine: string, shouldExecute: boolean): Promise<void> {
let commandDetection = this.capabilities.get(TerminalCapability.CommandDetection);
// Await command detection if the terminal is starting up
if (!commandDetection && (this._processManager.processState === ProcessState.Uninitialized || this._processManager.processState === ProcessState.Launching)) {
const store = new DisposableStore();
await Promise.race([
new Promise<void>(r => {
store.add(this.capabilities.onDidAddCapabilityType(e => {
if (e === TerminalCapability.CommandDetection) {
commandDetection = this.capabilities.get(TerminalCapability.CommandDetection);
r();
}
}));
}),
timeout(2000),
]);
store.dispose();
}
// Determine whether to send ETX (ctrl+c) before running the command. This should always
// happen unless command detection can reliably say that a command is being entered and
// there is no content in the prompt
if (this.capabilities.get(TerminalCapability.CommandDetection)?.hasInput !== false) {
if (commandDetection?.hasInput !== false) {
await this.sendText('\x03', false);
// Wait a little before running the command to avoid the sequences being echoed while the ^C
// is being evaluated