MCPcopy Index your code
hub / github.com/devcontainers/cli / plainExecAsPtyExec

Function plainExecAsPtyExec

src/spec-common/commonUtils.ts:382–424  ·  view source on GitHub ↗
(plain: ExecFunction, allowInheritTTY: boolean)

Source from the content-addressed store, hash-verified

380}
381
382export function plainExecAsPtyExec(plain: ExecFunction, allowInheritTTY: boolean): PtyExecFunction {
383 return async function (params: PtyExecParameters): Promise<PtyExec> {
384 const p = await plain({
385 ...params,
386 stdio: allowInheritTTY && params.output !== nullLog ? [
387 process.stdin.isTTY ? 'inherit' : 'pipe',
388 process.stdout.isTTY ? 'inherit' : 'pipe',
389 process.stderr.isTTY ? 'inherit' : 'pipe',
390 ] : undefined,
391 });
392 const onDataEmitter = new NodeEventEmitter<string>();
393 if (p.stdout) {
394 const stdoutDecoder = new StringDecoder();
395 p.stdout.on('data', data => onDataEmitter.fire(stdoutDecoder.write(data)));
396 p.stdout.on('close', () => {
397 const end = stdoutDecoder.end();
398 if (end) {
399 onDataEmitter.fire(end);
400 }
401 });
402 }
403 if (p.stderr) {
404 const stderrDecoder = new StringDecoder();
405 p.stderr.on('data', data => onDataEmitter.fire(stderrDecoder.write(data)));
406 p.stderr.on('close', () => {
407 const end = stderrDecoder.end();
408 if (end) {
409 onDataEmitter.fire(end);
410 }
411 });
412 }
413 return {
414 onData: onDataEmitter.event,
415 write: p.stdin ? p.stdin.write.bind(p.stdin) : undefined,
416 resize: () => {},
417 exit: p.exit.then(({ code, signal }) => ({
418 code: typeof code === 'number' ? code : undefined,
419 signal: typeof signal === 'string' ? processSignals[signal] : undefined,
420 })),
421 terminate: p.terminate.bind(p),
422 };
423 };
424}
425
426async function findLocalWindowsExecutable(command: string, cwd = process.cwd(), env: Record<string, string | undefined>, output: Log): Promise<string> {
427 if (process.platform !== 'win32') {

Callers 2

dockerPtyExecFunctionFunction · 0.90
plainPtyExecFunction · 0.85

Calls 3

fireMethod · 0.95
onMethod · 0.80
writeMethod · 0.65

Tested by

no test coverage detected