Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support auto-answering the batch "Terminate batch job (Y/N)?" question #133524

Closed
Tyriar opened this issue Sep 21, 2021 · 1 comment · Fixed by #138886
Closed

Support auto-answering the batch "Terminate batch job (Y/N)?" question #133524

Tyriar opened this issue Sep 21, 2021 · 1 comment · Fixed by #138886
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes on-testplan terminal Integrated terminal issues windows VS Code on Windows issues
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Sep 21, 2021

When you hit ^C during batch scripts they will ask this "Terminate batch job (Y/N)?" question which is super annoying and often the process that the batch script was running has already been killed anyway.

Clink works around this by allowing configuring to auto answer the question and it's really nice. I put together a little prototype and it feels great:
recording (86)

The above was done by translating the terminal line to a string whenever process data comes in and checking if it contains that text. We would want to look into faster alternatives to that and to also ensure we don't answer twice for the same line (just in case):

	private _onProcessData(ev: IProcessDataEvent): void {
		const messageId = ++this._latestXtermWriteData;
		if (ev.trackCommit) {
			ev.writePromise = new Promise<void>(r => {
				this._xterm?.write(ev.data, () => {
					this._latestXtermParseData = messageId;
					this._processManager.acknowledgeDataEvent(ev.data.length);
					const line = this._xterm?.buffer.active.getLine(this._xterm.buffer.active.baseY + this._xterm.buffer.active.cursorY)?.translateToString(true);
					if (line && line.indexOf('Terminate batch job (Y/N)') >= 0) {
						this._processManager.write('Y\r').then(() => {
							this._onDidInputData.fire(this);
						});
					}
					r();
				});
			});
		} else {
			this._xterm?.write(ev.data, () => {
				this._latestXtermParseData = messageId;
				this._processManager.acknowledgeDataEvent(ev.data.length);
				const line = this._xterm?.buffer.active.getLine(this._xterm.buffer.active.baseY + this._xterm.buffer.active.cursorY)?.translateToString(true);
				if (line && line.indexOf('Terminate batch job (Y/N)') >= 0) {
					this._processManager.write('Y\r').then(() => {
						this._onDidInputData.fire(this);
					});
				}
			});
		}
	}
@Tyriar Tyriar added feature-request Request for new features or functionality terminal Integrated terminal issues windows VS Code on Windows issues labels Sep 21, 2021
@Tyriar Tyriar added this to the October 2021 milestone Sep 21, 2021
@Tyriar Tyriar modified the milestones: October 2021, On Deck Sep 21, 2021
@Tyriar
Copy link
Member Author

Tyriar commented Sep 21, 2021

Something this will also help with is I've got into the habit of pressing ctrl+c twice to workaround this but if I accidentally hit it 3 times it ends up interrupting PSReadline/starship and am left with a plain PS> prompt:

image

@Tyriar Tyriar modified the milestones: On Deck, January 2022 Dec 10, 2021
Tyriar added a commit that referenced this issue Dec 10, 2021
@Tyriar Tyriar added the on-release-notes Issue/pull request mentioned in release notes label Jan 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes on-testplan terminal Integrated terminal issues windows VS Code on Windows issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@Tyriar @hediet @meganrogge and others