Skip to content

Commit 7c528bc

Browse files
committed
🎁 Add support for unkown CWD seq: OSC 7 ; scheme://cwd ST
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 1093fe0 commit 7c528bc

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ const enum ShellIntegrationOscPs {
5252
/**
5353
* Sequences by Cmder.
5454
*/
55-
Cmder = 9
55+
Cmder = 9,
56+
/**
57+
* Sequences by unknown terminal (maybe a command, rather than an indentifier).
58+
*/
59+
Unknown7 = 7
5660
}
5761

5862
/**
@@ -224,6 +228,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
224228
this._commonProtocolDisposables.push(
225229
xterm.parser.registerOscHandler(ShellIntegrationOscPs.FinalTerm, data => this._handleFinalTermSequence(data))
226230
);
231+
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.Unknown7, data => this._doHandleUnknownSequence(ShellIntegrationOscPs.Unknown7, data)));
227232
this._ensureCapabilitiesOrAddFailureTelemetry();
228233
}
229234

@@ -356,8 +361,6 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
356361
}
357362
switch (key) {
358363
case 'Cwd': {
359-
// TODO: Ideally we would also support the following to supplement our own:
360-
// - OSC 7 ; scheme://cwd ST (Unknown origin)
361364
this._updateCwd(value);
362365
return true;
363366
}
@@ -432,6 +435,35 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
432435
return false;
433436
}
434437

438+
/**
439+
* Some escape sequences are not well known/documented, so we handle them in
440+
* an ad-hoc/one-off manner. Also, note that in some cases the `ident` value
441+
* itself acts like a command (not an terminal/emulator identifier). So, it
442+
* seems logical to have a slack method that deals with such cases.
443+
*/
444+
private _doHandleUnknownSequence(ident: number, data: string): boolean {
445+
if (!this._terminal) {
446+
return false;
447+
}
448+
449+
const [command] = data.split(';');
450+
switch (ident) {
451+
case ShellIntegrationOscPs.Unknown7: {
452+
// Checking for: `OSC 7 ; scheme://cwd ST`
453+
if (command.startsWith('scheme://')) {
454+
// TODO: I'm not sure `scheme` here is literal or can be `file` or something else.
455+
// TODO: Possibly the path is URL-encoded, but I have no means to test it.
456+
const cwd = command.substring(9);
457+
this._updateCwd(cwd);
458+
return true;
459+
}
460+
}
461+
}
462+
463+
// Unrecognized sequence
464+
return false;
465+
}
466+
435467
serialize(): ISerializedCommandDetectionCapability {
436468
if (!this._terminal || !this.capabilities.has(TerminalCapability.CommandDetection)) {
437469
return {

0 commit comments

Comments
 (0)