Skip to content

Commit da3a13a

Browse files
committed
Improve reliability of interrupt and log all events in trace
1 parent c238ded commit da3a13a

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/vs/platform/terminal/common/capabilities/commandDetection/promptInputModel.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import { throttle } from 'vs/base/common/decorators';
1414
import type { Terminal, IMarker, IBufferCell, IBufferLine, IBuffer } from '@xterm/headless';
1515

1616
const enum PromptInputState {
17-
Unknown,
18-
Input,
19-
Execute,
20-
Interrupt,
17+
Unknown = 0,
18+
Input = 1,
19+
Execute = 2,
2120
}
2221

2322
/**
@@ -94,6 +93,18 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
9493

9594
this._register(onCommandStart(e => this._handleCommandStart(e as { marker: IMarker })));
9695
this._register(onCommandExecuted(() => this._handleCommandExecuted()));
96+
97+
this.onDidStartInput(() => this._logCombinedStringIfTrace('PromptInputModel#onDidStartInput'));
98+
this.onDidChangeInput(() => this._logCombinedStringIfTrace('PromptInputModel#onDidChangeInput'));
99+
this.onDidFinishInput(() => this._logCombinedStringIfTrace('PromptInputModel#onDidFinishInput'));
100+
this.onDidInterrupt(() => this._logCombinedStringIfTrace('PromptInputModel#onDidInterrupt'));
101+
}
102+
103+
private _logCombinedStringIfTrace(message: string) {
104+
// Only generate the combined string if trace
105+
if (this._logService.getLevel() === LogLevel.Trace) {
106+
this._logService.trace(message, this.getCombinedString());
107+
}
97108
}
98109

99110
setContinuationPrompt(value: string): void {
@@ -136,7 +147,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
136147

137148
this._cursorIndex = -1;
138149
const event = this._createStateObject();
139-
if (this._state === PromptInputState.Interrupt) {
150+
if (this._lastUserInput !== '\u0003') {
140151
this._onDidInterrupt.fire(event);
141152
}
142153

@@ -216,15 +227,6 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
216227
this._logService.trace(`PromptInputModel#_sync: ${this.getCombinedString()}`);
217228
}
218229

219-
// Check for an interrupt, this is verified using both the last user input and the current
220-
// input.
221-
if (this._lastUserInput === '\u0003') { // ETX end of text (ctrl+c)
222-
if (this._value.endsWith('^C')) {
223-
this._state = PromptInputState.Interrupt;
224-
return;
225-
}
226-
}
227-
228230
if (this._value !== value || this._cursorIndex !== cursorIndex || this._ghostTextIndex !== ghostTextIndex) {
229231
this._value = value;
230232
this._cursorIndex = cursorIndex;

src/vs/platform/terminal/test/common/capabilities/commandDetection/promptInputModel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Terminal } from '@xterm/headless';
1414
import { notDeepStrictEqual, strictEqual } from 'assert';
1515
import { timeout } from 'vs/base/common/async';
1616

17-
suite.only('PromptInputModel', () => {
17+
suite('PromptInputModel', () => {
1818
const store = ensureNoDisposablesAreLeakedInTestSuite();
1919

2020
let promptInputModel: PromptInputModel;

0 commit comments

Comments
 (0)