@@ -11,18 +11,61 @@ import type { ITerminalCommand } from 'vs/platform/terminal/common/capabilities/
11
11
12
12
// eslint-disable-next-line local/code-import-patterns, local/code-amd-node-module
13
13
import { Terminal } from '@xterm/headless' ;
14
+ import { strictEqual } from 'assert' ;
14
15
15
- suite ( 'RequestStore' , ( ) => {
16
+ class TestPromptInputModel extends PromptInputModel {
17
+ forceSync ( ) {
18
+ this . _syncNow ( ) ;
19
+ }
20
+ }
21
+
22
+ suite ( 'PromptInputModel' , ( ) => {
16
23
const store = ensureNoDisposablesAreLeakedInTestSuite ( ) ;
17
- let promptInputModel : PromptInputModel ;
24
+ let promptInputModel : TestPromptInputModel ;
18
25
let xterm : Terminal ;
19
26
let onCommandStart : Emitter < ITerminalCommand > ;
20
27
let onCommandExecuted : Emitter < ITerminalCommand > ;
21
28
22
29
setup ( ( ) => {
23
- xterm = new Terminal ( ) ;
30
+ xterm = new Terminal ( { allowProposedApi : true } ) ;
24
31
onCommandStart = new Emitter ( ) ;
25
32
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[2J[m[H]0;C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.2.0_x64__8wekyb3d8bbwe\pwsh.exe[?25h' ,
47
+ '[?25l[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K\n\r[K[H[?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
+ '[34m\n\r[38;2;17;17;17m[44m03:13:47 [34m[41m [38;2;17;17;17mvscode [31m[43m [38;2;17;17;17m tyriar/prompt_input_model [33m[46m [38;2;17;17;17m$⇡ [36m[49m [mvia [32m[1m v18.18.2 \n\r❯[m ' ,
52
+ ] ) ;
53
+ onCommandStart . fire ( { marker : xterm . registerMarker ( ) } as ITerminalCommand ) ;
54
+ promptInputModel . forceSync ( ) ;
55
+ strictEqual ( promptInputModel . value , '' ) ;
56
+
57
+ await replayEvents ( [
58
+ '[?25l[93mf[97m[2m[3makecommand[3;4H[?25h' ,
59
+ '[m' ,
60
+ '[93mfo[9X' ,
61
+ '[m' ,
62
+ '[?25l[93m[3;3Hfoo[?25h' ,
63
+ '[m' ,
64
+ ] ) ;
65
+ promptInputModel . forceSync ( ) ;
66
+ strictEqual ( promptInputModel . value , 'foo' ) ;
67
+ strictEqual ( promptInputModel . cursorIndex , 3 ) ;
68
+ } ) ;
69
+ } ) ;
27
70
} ) ;
28
71
} ) ;
0 commit comments