Skip to content

Commit 04065df

Browse files
committed
allowInheritTTY only for text output
1 parent c64e4d3 commit 04065df

File tree

12 files changed

+24
-21
lines changed

12 files changed

+24
-21
lines changed

src/spec-common/cliHost.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ export enum FileTypeBitmask {
5454
SymbolicLink = 64
5555
}
5656

57-
export async function getCLIHost(localCwd: string, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>): Promise<CLIHost> {
57+
export async function getCLIHost(localCwd: string, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>, allowInheritTTY: boolean): Promise<CLIHost> {
5858
const exec = plainExec(localCwd);
59-
const ptyExec = await plainPtyExec(localCwd, loadNativeModule);
59+
const ptyExec = await plainPtyExec(localCwd, loadNativeModule, allowInheritTTY);
6060
return createLocalCLIHostFromExecFunctions(localCwd, exec, ptyExec, connectLocal);
6161
}
6262

src/spec-common/commonUtils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,11 @@ export function plainExec(defaultCwd: string | undefined): ExecFunction {
316316
};
317317
}
318318

319-
export async function plainPtyExec(defaultCwd: string | undefined, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>): Promise<PtyExecFunction> {
319+
export async function plainPtyExec(defaultCwd: string | undefined, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>, allowInheritTTY: boolean): Promise<PtyExecFunction> {
320320
const pty = await loadNativeModule<typeof ptyType>('node-pty');
321321
if (!pty) {
322322
const plain = plainExec(defaultCwd);
323-
return plainExecAsPtyExec(plain);
323+
return plainExecAsPtyExec(plain, allowInheritTTY);
324324
}
325325

326326
return async function (params: PtyExecParameters): Promise<PtyExec> {
@@ -370,15 +370,15 @@ export async function plainPtyExec(defaultCwd: string | undefined, loadNativeMod
370370
};
371371
}
372372

373-
export function plainExecAsPtyExec(plain: ExecFunction): PtyExecFunction {
373+
export function plainExecAsPtyExec(plain: ExecFunction, allowInheritTTY: boolean): PtyExecFunction {
374374
return async function (params: PtyExecParameters): Promise<PtyExec> {
375375
const p = await plain({
376376
...params,
377-
stdio: [
377+
stdio: allowInheritTTY && params.output !== nullLog ? [
378378
process.stdin.isTTY ? 'inherit' : 'pipe',
379379
process.stdout.isTTY ? 'inherit' : 'pipe',
380380
process.stderr.isTTY ? 'inherit' : 'pipe',
381-
],
381+
] : undefined,
382382
});
383383
const onDataEmitter = new NodeEventEmitter<string>();
384384
if (p.stdout) {

src/spec-common/injectHeadless.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface ResolverParameters {
5353
getLogLevel: () => LogLevel;
5454
onDidChangeLogLevel: Event<LogLevel>;
5555
loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>;
56+
allowInheritTTY: boolean;
5657
shutdowns: (() => Promise<void>)[];
5758
backgroundTasks: (Promise<void> | (() => Promise<void>))[];
5859
persistedFolder: string; // A path where config can be persisted and restored at a later time. Should default to tmpdir() folder if not provided.

src/spec-node/devContainers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export async function createDockerParams(options: ProvisionOptions, disposables:
105105

106106
const appRoot = undefined;
107107
const cwd = options.workspaceFolder || process.cwd();
108-
const cliHost = await getCLIHost(cwd, loadNativeModule);
108+
const allowInheritTTY = options.logFormat === 'text';
109+
const cliHost = await getCLIHost(cwd, loadNativeModule, allowInheritTTY);
109110
const sessionId = crypto.randomUUID();
110111

111112
const common: ResolverParameters = {
@@ -130,6 +131,7 @@ export async function createDockerParams(options: ProvisionOptions, disposables:
130131
getLogLevel: () => options.logLevel,
131132
onDidChangeLogLevel: () => ({ dispose() { } }),
132133
loadNativeModule,
134+
allowInheritTTY,
133135
shutdowns: [],
134136
backgroundTasks: [],
135137
persistedFolder: persistedFolder || await getCacheFolder(cliHost), // Fallback to tmp folder, even though that isn't 'persistent'

src/spec-node/devContainersSpecCLI.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async function provision({
205205
const providedIdLabels = idLabel ? Array.isArray(idLabel) ? idLabel as string[] : [idLabel] : undefined;
206206

207207
const cwd = workspaceFolder || process.cwd();
208-
const cliHost = await getCLIHost(cwd, loadNativeModule);
208+
const cliHost = await getCLIHost(cwd, loadNativeModule, logFormat === 'text');
209209
const secretsP = readSecretsFromFile({ secretsFile, cliHost });
210210

211211
const options: ProvisionOptions = {
@@ -786,7 +786,7 @@ async function doRunUserCommands({
786786
const overrideConfigFile = overrideConfig ? URI.file(path.resolve(process.cwd(), overrideConfig)) : undefined;
787787

788788
const cwd = workspaceFolder || process.cwd();
789-
const cliHost = await getCLIHost(cwd, loadNativeModule);
789+
const cliHost = await getCLIHost(cwd, loadNativeModule, logFormat === 'text');
790790
const secretsP = readSecretsFromFile({ secretsFile, cliHost });
791791

792792
const params = await createDockerParams({
@@ -954,7 +954,7 @@ async function readConfiguration({
954954
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined;
955955
const overrideConfigFile = overrideConfig ? URI.file(path.resolve(process.cwd(), overrideConfig)) : undefined;
956956
const cwd = workspaceFolder || process.cwd();
957-
const cliHost = await getCLIHost(cwd, loadNativeModule);
957+
const cliHost = await getCLIHost(cwd, loadNativeModule, logFormat === 'text');
958958
const extensionPath = path.join(__dirname, '..', '..');
959959
const sessionStart = new Date();
960960
const pkg = getPackageConfig();
@@ -1082,7 +1082,7 @@ async function outdated({
10821082
try {
10831083
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg);
10841084
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined;
1085-
const cliHost = await getCLIHost(workspaceFolder, loadNativeModule);
1085+
const cliHost = await getCLIHost(workspaceFolder, loadNativeModule, logFormat === 'text');
10861086
const extensionPath = path.join(__dirname, '..', '..');
10871087
const sessionStart = new Date();
10881088
const pkg = getPackageConfig();

src/spec-node/featuresCLI/package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async function featuresPackage({
3131
const pkg = getPackageConfig();
3232

3333
const cwd = process.cwd();
34-
const cliHost = await getCLIHost(cwd, loadNativeModule);
34+
const cliHost = await getCLIHost(cwd, loadNativeModule, true);
3535
const output = createLog({
3636
logLevel: mapLogLevel(inputLogLevel),
3737
logFormat: 'text',

src/spec-node/featuresCLI/publish.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function featuresPublish({
4040
const pkg = getPackageConfig();
4141

4242
const cwd = process.cwd();
43-
const cliHost = await getCLIHost(cwd, loadNativeModule);
43+
const cliHost = await getCLIHost(cwd, loadNativeModule, true);
4444
const output = createLog({
4545
logLevel: mapLogLevel(inputLogLevel),
4646
logFormat: 'text',

src/spec-node/featuresCLI/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async function featuresTest({
9292
};
9393

9494
const cwd = process.cwd();
95-
const cliHost = await getCLIHost(cwd, loadNativeModule);
95+
const cliHost = await getCLIHost(cwd, loadNativeModule, true);
9696
const pkg = getPackageConfig();
9797

9898
const logLevel = mapLogLevel(inputLogLevel);

src/spec-node/templatesCLI/publish.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function templatesPublish({
4141
const pkg = getPackageConfig();
4242

4343
const cwd = process.cwd();
44-
const cliHost = await getCLIHost(cwd, loadNativeModule);
44+
const cliHost = await getCLIHost(cwd, loadNativeModule, true);
4545
const output = createLog({
4646
logLevel: mapLogLevel(inputLogLevel),
4747
logFormat: 'text',

src/spec-node/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export async function createContainerProperties(params: DockerResolverParameters
380380
const [, user, , group] = /([^:]*)(:(.*))?/.exec(containerUser) as (string | undefined)[];
381381
const containerEnv = envListToObj(containerInfo.Config.Env);
382382
const remoteExec = dockerExecFunction(params, containerId, containerUser);
383-
const remotePtyExec = await dockerPtyExecFunction(params, containerId, containerUser, common.loadNativeModule);
383+
const remotePtyExec = await dockerPtyExecFunction(params, containerId, containerUser, common.loadNativeModule, common.allowInheritTTY);
384384
const remoteExecAsRoot = dockerExecFunction(params, containerId, 'root');
385385
return getContainerProperties({
386386
params: common,

src/spec-shutdown/dockerUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ export function dockerExecFunction(params: DockerCLIParameters | PartialExecPara
325325
};
326326
}
327327

328-
export async function dockerPtyExecFunction(params: PartialPtyExecParameters | DockerResolverParameters, containerName: string, user: string | undefined, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>): Promise<PtyExecFunction> {
328+
export async function dockerPtyExecFunction(params: PartialPtyExecParameters | DockerResolverParameters, containerName: string, user: string | undefined, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>, allowInheritTTY: boolean): Promise<PtyExecFunction> {
329329
const pty = await loadNativeModule<typeof ptyType>('node-pty');
330330
if (!pty) {
331331
const plain = dockerExecFunction(params, containerName, user);
332-
return plainExecAsPtyExec(plain);
332+
return plainExecAsPtyExec(plain, allowInheritTTY);
333333
}
334334

335335
return async function (execParams: PtyExecParameters): Promise<PtyExec> {

src/test/testUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface ExecPtyResult {
7777
}
7878

7979
export async function shellPtyExec(command: string, options: { stdin?: string } = {}): Promise<ExecPtyResult> {
80-
const ptyExec = await plainPtyExec(undefined, loadNativeModule);
80+
const ptyExec = await plainPtyExec(undefined, loadNativeModule, true);
8181
return runCommand({
8282
ptyExec,
8383
cmd: '/bin/sh',
@@ -147,7 +147,7 @@ export const testSubstitute: SubstituteConfig = value => {
147147
export const output = makeLog(createPlainLog(text => process.stdout.write(text), () => LogLevel.Trace));
148148

149149
export async function createCLIParams(hostPath: string) {
150-
const cliHost = await getCLIHost(hostPath, loadNativeModule);
150+
const cliHost = await getCLIHost(hostPath, loadNativeModule, true);
151151
const dockerComposeCLI = dockerComposeCLIConfig({
152152
exec: cliHost.exec,
153153
env: cliHost.env,

0 commit comments

Comments
 (0)