Skip to content

Commit f254c1b

Browse files
committed
use bracketed paste mode when 3.13+ and !shellIntegration. THis means in PyREPL
1 parent 3ee255d commit f254c1b

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/client/common/configSettings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ export class PythonSettings implements IPythonSettings {
377377
launchArgs: [],
378378
activateEnvironment: true,
379379
activateEnvInCurrentTerminal: false,
380-
enableShellIntegration: false,
380+
shellIntegration: {
381+
enabled: false,
382+
},
381383
};
382384

383385
this.REPL = pythonSettings.get<IREPLSettings>('REPL')!;

src/client/common/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ export interface ITerminalSettings {
188188
readonly launchArgs: string[];
189189
readonly activateEnvironment: boolean;
190190
readonly activateEnvInCurrentTerminal: boolean;
191-
readonly enableShellIntegration: boolean;
191+
readonly shellIntegration: {
192+
enabled: boolean;
193+
};
192194
}
193195

194196
export interface IREPLSettings {

src/client/terminals/codeExecution/helper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
9999
const endLineVal = activeEditor?.selection?.end.line ?? 0;
100100
const emptyHighlightVal = activeEditor?.selection?.isEmpty ?? true;
101101
let smartSendSettingsEnabledVal = true;
102+
let shellIntegrationEnabled = false;
102103
const configuration = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
103104
if (configuration) {
104105
const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource());
105106
smartSendSettingsEnabledVal = pythonSettings.REPL.enableREPLSmartSend;
107+
shellIntegrationEnabled = pythonSettings.terminal.shellIntegration.enabled;
106108
}
107109

108110
const input = JSON.stringify({
@@ -125,6 +127,16 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
125127
await this.moveToNextBlock(lineOffset, activeEditor);
126128
}
127129

130+
// For new _pyrepl for Python3.13+ && !shellIntegration, we need to send code via bracketed paste mode.
131+
if (object.attach_bracket_paste && !shellIntegrationEnabled && _replType === ReplType.terminal) {
132+
let trimmedNormalized = object.normalized.replace(/\n$/, '');
133+
if (trimmedNormalized.endsWith(':\n')) {
134+
// In case where statement is unfinished via :, truncate so auto-indentation lands nicely.
135+
trimmedNormalized = trimmedNormalized.replace(/\n$/, '');
136+
}
137+
return `\u001b[200~${trimmedNormalized}\u001b[201~`;
138+
}
139+
128140
return parse(object.normalized);
129141
} catch (ex) {
130142
traceError(ex, 'Python: Failed to normalize code for execution in terminal');

0 commit comments

Comments
 (0)