Skip to content

Commit 39c3fce

Browse files
committed
🔨 Use verbose names and handlers for OSC 7 & OSC 9 sequences
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 7c528bc commit 39c3fce

File tree

1 file changed

+16
-40
lines changed

1 file changed

+16
-40
lines changed

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

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,8 @@ const enum ShellIntegrationOscPs {
4949
* Sequences pioneered by iTerm.
5050
*/
5151
ITerm = 1337,
52-
/**
53-
* Sequences by Cmder.
54-
*/
55-
Cmder = 9,
56-
/**
57-
* Sequences by unknown terminal (maybe a command, rather than an indentifier).
58-
*/
59-
Unknown7 = 7
52+
SetCwd = 7,
53+
SetWindowsFriendlyCwd = 9
6054
}
6155

6256
/**
@@ -174,16 +168,6 @@ const enum ITermOscPt {
174168
CurrentDir = 'CurrentDir'
175169
}
176170

177-
/**
178-
* Cmder sequences
179-
*/
180-
const enum CmderOscPt {
181-
/**
182-
* Reports current working directory (CWD). `OSC 9 ; 9 ; <cwd> ST`
183-
*/
184-
Code9 = '9'
185-
}
186-
187171
/**
188172
* The shell integration addon extends xterm by reading shell integration sequences and creating
189173
* capabilities and passing along relevant sequences to the capabilities. This is meant to
@@ -224,11 +208,11 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
224208
this.capabilities.add(TerminalCapability.PartialCommandDetection, new PartialCommandDetectionCapability(this._terminal));
225209
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.VSCode, data => this._handleVSCodeSequence(data)));
226210
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.ITerm, data => this._doHandleITermSequence(data)));
227-
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.Cmder, data => this._doHandleCmderSequence(data)));
228211
this._commonProtocolDisposables.push(
229212
xterm.parser.registerOscHandler(ShellIntegrationOscPs.FinalTerm, data => this._handleFinalTermSequence(data))
230213
);
231-
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.Unknown7, data => this._doHandleUnknownSequence(ShellIntegrationOscPs.Unknown7, data)));
214+
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.SetCwd, data => this._doHandleSetCwd(data)));
215+
this._register(xterm.parser.registerOscHandler(ShellIntegrationOscPs.SetWindowsFriendlyCwd, data => this._doHandleSetWindowsFriendlyCwd(data)));
232216
this._ensureCapabilitiesOrAddFailureTelemetry();
233217
}
234218

@@ -417,14 +401,15 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
417401
return false;
418402
}
419403

420-
private _doHandleCmderSequence(data: string): boolean {
404+
private _doHandleSetWindowsFriendlyCwd(data: string): boolean {
421405
if (!this._terminal) {
422406
return false;
423407
}
424408

425409
const [command, ...args] = data.split(';');
426410
switch (command) {
427-
case CmderOscPt.Code9:
411+
case '9':
412+
// Encountered `OSC 9 ; 9 ; <cwd> ST`
428413
if (args.length) {
429414
this._updateCwd(args[0]);
430415
}
@@ -435,29 +420,20 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
435420
return false;
436421
}
437422

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 {
423+
private _doHandleSetCwd(data: string): boolean {
445424
if (!this._terminal) {
446425
return false;
447426
}
448427

449428
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-
}
429+
430+
// Checking for: `OSC 7 ; scheme://cwd ST`
431+
if (command.startsWith('scheme://')) {
432+
// TODO: I'm not sure `scheme` here is literal or can be `file` or something else.
433+
// TODO: Possibly the path is URL-encoded, but I have no means to test it.
434+
const cwd = command.substring(9);
435+
this._updateCwd(cwd);
436+
return true;
461437
}
462438

463439
// Unrecognized sequence

0 commit comments

Comments
 (0)