Skip to content

Commit f04bd7d

Browse files
committed
First recorded test
1 parent 1e48847 commit f04bd7d

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
9393

9494
@debounce(50)
9595
private _sync() {
96+
this._syncNow();
97+
}
98+
99+
protected _syncNow() {
96100
if (this._state !== PromptInputState.Input) {
97101
return;
98102
}

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

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,61 @@ import type { ITerminalCommand } from 'vs/platform/terminal/common/capabilities/
1111

1212
// eslint-disable-next-line local/code-import-patterns, local/code-amd-node-module
1313
import { Terminal } from '@xterm/headless';
14+
import { strictEqual } from 'assert';
1415

15-
suite('RequestStore', () => {
16+
class TestPromptInputModel extends PromptInputModel {
17+
forceSync() {
18+
this._syncNow();
19+
}
20+
}
21+
22+
suite('PromptInputModel', () => {
1623
const store = ensureNoDisposablesAreLeakedInTestSuite();
17-
let promptInputModel: PromptInputModel;
24+
let promptInputModel: TestPromptInputModel;
1825
let xterm: Terminal;
1926
let onCommandStart: Emitter<ITerminalCommand>;
2027
let onCommandExecuted: Emitter<ITerminalCommand>;
2128

2229
setup(() => {
23-
xterm = new Terminal();
30+
xterm = new Terminal({ allowProposedApi: true });
2431
onCommandStart = new Emitter();
2532
onCommandExecuted = new Emitter();
26-
promptInputModel = store.add(new PromptInputModel(xterm, onCommandStart.event, onCommandExecuted.event, new NullLogService));
33+
promptInputModel = store.add(new TestPromptInputModel(xterm, onCommandStart.event, onCommandExecuted.event, new NullLogService));
34+
});
35+
36+
suite('recorded sessions', () => {
37+
async function replayEvents(events: string[]) {
38+
for (const e of events) {
39+
await new Promise<void>(r => xterm.write(e, r));
40+
}
41+
}
42+
43+
suite('Windows, pwsh 7.4.2, starship prompt', () => {
44+
test('input with ignored ghost text', async () => {
45+
await replayEvents([
46+
'[?25l]0;C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.2.0_x64__8wekyb3d8bbwe\pwsh.exe[?25h',
47+
'[?25l\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r[?25h',
48+
']633;P;IsWindows=True',
49+
']633;P;ContinuationPrompt=\x1b[38\x3b5\x3b8m∙\x1b[0m ',
50+
']633;A]633;P;Cwd=C:\x5cGithub\x5cmicrosoft\x5cvscode]633;B',
51+
'\n\r03:13:47  vscode   tyriar/prompt_input_model  $⇡  via  v18.18.2 \n\r❯ ',
52+
]);
53+
onCommandStart.fire({ marker: xterm.registerMarker() } as ITerminalCommand);
54+
promptInputModel.forceSync();
55+
strictEqual(promptInputModel.value, '');
56+
57+
await replayEvents([
58+
'[?25lfakecommand[?25h',
59+
'',
60+
'fo',
61+
'',
62+
'[?25lfoo[?25h',
63+
'',
64+
]);
65+
promptInputModel.forceSync();
66+
strictEqual(promptInputModel.value, 'foo');
67+
strictEqual(promptInputModel.cursorIndex, 3);
68+
});
69+
});
2770
});
2871
});

0 commit comments

Comments
 (0)