Skip to content

Commit 6b85ac7

Browse files
committed
🔨 Extract independent helper methods out of shellIntegrationAddon class
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent f236859 commit 6b85ac7

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
317317
case VSCodeOscPt.CommandLine: {
318318
let commandLine: string;
319319
if (args.length === 1) {
320-
commandLine = this._deserializeMessage(args[0]);
320+
commandLine = deserializeMessage(args[0]);
321321
} else {
322322
commandLine = '';
323323
}
@@ -341,7 +341,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
341341
return true;
342342
}
343343
case VSCodeOscPt.Property: {
344-
const { key, value } = this._parseKeyValueAssignment(args[0]);
344+
const { key, value } = parseKeyValueAssignment(args[0]);
345345
if (value === undefined) {
346346
return true;
347347
}
@@ -383,7 +383,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
383383
}
384384
default: {
385385
// Checking for known `<key>=<value>` pairs.
386-
const { key, value } = this._parseKeyValueAssignment(command);
386+
const { key, value } = parseKeyValueAssignment(command);
387387

388388
if (value === undefined) {
389389
// No '=' was found, so it's not a property assignment.
@@ -481,28 +481,29 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
481481
}
482482
return commandDetection;
483483
}
484+
}
484485

485-
private _deserializeMessage(message: string): string {
486-
let result = message.replace(/\\\\/g, '\\');
487-
const deserializeRegex = /\\x([0-9a-f]{2})/i;
488-
while (true) {
489-
const match = result.match(deserializeRegex);
490-
if (!match?.index || match.length < 2) {
491-
break;
492-
}
493-
result = result.slice(0, match.index) + String.fromCharCode(parseInt(match[1], 16)) + result.slice(match.index + 4);
486+
export function deserializeMessage(message: string): string {
487+
let result = message.replace(/\\\\/g, '\\');
488+
const deserializeRegex = /\\x([0-9a-f]{2})/i;
489+
while (true) {
490+
const match = result.match(deserializeRegex);
491+
if (!match?.index || match.length < 2) {
492+
break;
494493
}
495-
return result;
494+
result = result.slice(0, match.index) + String.fromCharCode(parseInt(match[1], 16)) + result.slice(match.index + 4);
496495
}
496+
return result;
497+
}
497498

498-
private _parseKeyValueAssignment(message: string): { key: string; value: string | undefined } {
499-
const [key, ...rawValues] = message.split('=');
500-
if (!rawValues.length) {
501-
return { key, value: undefined }; // No '=' was found.
502-
}
503-
const rawValue = rawValues.join('=');
504-
const value = this._deserializeMessage(rawValue);
505-
return { key, value };
499+
export function parseKeyValueAssignment(message: string): { key: string; value: string | undefined } {
500+
const deserialized = deserializeMessage(message);
501+
const separatorIndex = deserialized.indexOf('=');
502+
if (separatorIndex === -1) {
503+
return { key: deserialized, value: undefined }; // No '=' was found.
506504
}
505+
return {
506+
key: deserialized.substring(0, separatorIndex),
507+
value: deserialized.substring(1 + separatorIndex)
508+
};
507509
}
508-

0 commit comments

Comments
 (0)