Skip to content

Commit 1093fe0

Browse files
committed
🎁 Add support for Cmder CWD seq: OSC 9 ; 9 ; <cwd> ST
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 43f7d43 commit 1093fe0

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ const enum ShellIntegrationOscPs {
4848
/**
4949
* Sequences pioneered by iTerm.
5050
*/
51-
ITerm = 1337
51+
ITerm = 1337,
52+
/**
53+
* Sequences by Cmder.
54+
*/
55+
Cmder = 9
5256
}
5357

5458
/**
@@ -166,6 +170,16 @@ const enum ITermOscPt {
166170
CurrentDir = 'CurrentDir'
167171
}
168172

173+
/**
174+
* Cmder sequences
175+
*/
176+
const enum CmderOscPt {
177+
/**
178+
* Reports current working directory (CWD). `OSC 9 ; 9 ; <cwd> ST`
179+
*/
180+
Code9 = '9'
181+
}
182+
169183
/**
170184
* The shell integration addon extends xterm by reading shell integration sequences and creating
171185
* capabilities and passing along relevant sequences to the capabilities. This is meant to
@@ -206,6 +220,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
206220
this.capabilities.add(TerminalCapability.PartialCommandDetection, new PartialCommandDetectionCapability(this._terminal));
207221
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.VSCode, data => this._handleVSCodeSequence(data)));
208222
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.ITerm, data => this._doHandleITermSequence(data)));
223+
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.Cmder, data => this._doHandleCmderSequence(data)));
209224
this._commonProtocolDisposables.push(
210225
xterm.parser.registerOscHandler(ShellIntegrationOscPs.FinalTerm, data => this._handleFinalTermSequence(data))
211226
);
@@ -343,7 +358,6 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
343358
case 'Cwd': {
344359
// TODO: Ideally we would also support the following to supplement our own:
345360
// - OSC 7 ; scheme://cwd ST (Unknown origin)
346-
// - OSC 9 ; 9 ; <cwd> ST (cmder)
347361
this._updateCwd(value);
348362
return true;
349363
}
@@ -400,6 +414,24 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
400414
return false;
401415
}
402416

417+
private _doHandleCmderSequence(data: string): boolean {
418+
if (!this._terminal) {
419+
return false;
420+
}
421+
422+
const [command, ...args] = data.split(';');
423+
switch (command) {
424+
case CmderOscPt.Code9:
425+
if (args.length) {
426+
this._updateCwd(args[0]);
427+
}
428+
return true;
429+
}
430+
431+
// Unrecognized sequence
432+
return false;
433+
}
434+
403435
serialize(): ISerializedCommandDetectionCapability {
404436
if (!this._terminal || !this.capabilities.has(TerminalCapability.CommandDetection)) {
405437
return {

0 commit comments

Comments
 (0)