Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
code: null
};
// Remove constants that indicate it's in CI.
// This is because Ink will only emit the last frame in CI.
const {
CI,
CONTINUOUS_INTEGRATION,
TRAVIS,
BUILD_NUMBER,
RUN_ID,
TRAVIS_PULL_REQUEST,
...env
} = process.env as any;
const spawned = (this.spawned = spawn(bin, command.split(' '), {
name: 'xterm-color',
cols: 80,
rows: 30,
encoding: 'utf-8',
cwd: this.cwd,
env
}));
spawned.on('data', data => {
this.output.stdout += data;
});
spawned.on('exit', code => {
this.output.closed = true;
this.output.code = code;
});
spawn(args, cwd, env) {
// Spawn the child process:
console.log("spawn", args[0], args.slice(1), cwd, env);
env['TERM'] = 'xterm-256color';
this.pty = PTY.spawn(args[0], args.slice(1), {
cols: this.view.terminal.cols,
rows: this.view.terminal.rows,
cwd: cwd,
env: env,
name: 'xterm-color',
});
this.startTime = new Date;
// Update the status (*Shellwords.join doesn't exist yet):
//this.view.log(args.join(' ') + ' (pgid ' + this.pty.pid + ')');
if (this.view.process) {
this.view.process.destroy();
}
runtimeArgs.push(...restOfScriptParams);
}
// To use our own commands in create-react, we need to tell the command that
// we're in a CI environment, or it will always append --watch
const env = process.env;
env.CI = "true";
if (platform() === "darwin") {
env.PATH = `${env.PATH}:/usr/local/bin`;
}
let stdoutCallback = (data: any) => {};
let onExitCallback = () => {};
let onCloseCallback = () => {};
const ptyProcess = pty.spawn(command, runtimeArgs, {
name: "xterm-color",
cols: 80,
rows: 30,
cwd: workspace.rootPath,
env
});
ptyProcess.on("data", data => {
let output = data;
if (data.includes("Test results written to")) {
output = data.substring(data.indexOf("Test results written to"));
}
stdoutCallback(output);
});
ptyProcess.on("exit", () => {
app.post('/terminals/:task_id', isUserAllowedToDebug, function(req, res) {
const task_id = req.params.task_id;
if(!task_id) {
res.send('You must provide a valid task id.');
return;
}
const term = pty.spawn('python3',
[MESOS_TASK_EXEC_DIR + '/exec.py', task_id], {
name: 'mesos-task-exec',
cwd: process.env.PWD,
env: process.env
});
console.log('User "%s" has opened a session in container "%s" (pid=%s)', req.user.cn, task_id, term.pid);
terminals[term.pid] = term;
logs[term.pid] = '';
ownersByPid[term.pid] = ownersByTaskId[task_id];
term.on('data', function(data) {
logs[term.pid] += data;
});
res.send(term.pid.toString());
res.end();
});
private setupPtyProcess(shellLaunchConfig: IShellLaunchConfig, options: pty.IPtyForkOptions): void {
const args = shellLaunchConfig.args || [];
this._logService.trace('IPty#spawn', shellLaunchConfig.executable, args, options);
const ptyProcess = pty.spawn(shellLaunchConfig.executable!, args, options);
this._ptyProcess = ptyProcess;
this._processStartupComplete = new Promise(c => {
this.onProcessReady(() => c());
});
ptyProcess.on('data', data => {
this._onProcessData.fire(data);
if (this._closeTimeout) {
clearTimeout(this._closeTimeout);
this._queueProcessExit();
}
});
ptyProcess.on('exit', code => {
this._exitCode = code;
this._queueProcessExit();
});
this._setupTitlePolling(ptyProcess);
constructor(options: IShellOptions) {
super();
this._process = pty.spawn(options.shell, [], {
name: 'xterm-256color',
cols: 9999,
rows: 999,
cwd: process.env.HOME,
env: process.env as any
});
this._process.on('data', this._onStdout.bind(this));
this._process.on('exit', this._onExit.bind(this));
}
function spawn(isPTY, command, args, options) {
let proc;
let stdin;
let stdout;
let stderr;
let exitPromise;
if (isPTY) {
proc = pty.spawn(command, args, options);
stdin = stdout = proc;
exitPromise = once(proc, 'exit');
} else {
proc = cp.spawn(command, args);
stdin = proc.stdin;
stdout = proc.stdout;
stderr = proc.stderr;
exitPromise = once(proc, 'close');
}
return { proc, stdin, stdout, stderr, exitPromise };
}
create(cwd = os.homedir()): Process {
const defaultShell = this._config.getDefaultShell();
const shell = defaultShell.shell;
const args = defaultShell.args;
const env = Object.assign({}, process.env, {
LANG: app.getLocale().replace('-', '_') + '.UTF-8',
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
TERM_PROGRAM: 'bterm'
});
const ps: Process = {
pty: pty.spawn(shell, args, {
cols: 80,
rows: 30,
cwd: cwd,
env: env
}),
input: new EventEmitter(),
output: new EventEmitter(),
resize: new EventEmitter<{ col: number, row: number }>(),
exit: new EventEmitter()
};
this.initializeEvents(ps);
return ps;
}
throw new Error(`${application.dir} is not a directory`);
if (!executable.match(/\//))
try {
await whichAsync(executable, {
path: envPath,
pathExt: env["PathExt"]
});
} catch (error) {
throw new Error(
`${error.message}: Cannot find executable ${executable} in PATH (${envPath})`
);
}
terminal = this._terminals[application.name] = {
pty: Pty.spawn(spawnCmd, spawnArgs, {
name: "xterm-color",
cols: _.min(this._sessions.map(s => s.terminalCols)) || 80,
rows: _.min(this._sessions.map(s => s.terminalRows)) || 24,
cwd: application.dir,
env: env
}),
history: ""
};
if (application.out) {
const outPath = Path.join(application.dir, application.out);
await mkdirpAsync(Path.dirname(outPath));
terminal.outStream = Fs.createWriteStream(null, {
fd: await openAsync(outPath, "a")
});
}
private setupTerminal(webSocket: WebSocket, request: http.IncomingMessage) {
const { cols, rows } = request.headers;
const defaultCols = 80;
const defaultRows = 24;
Utils.trace("Spawning pty");
const terminal = pty.spawn(this.shell, [], {
name: "xterm-color",
cols: parseInt(cols as string) || defaultCols,
rows: parseInt(rows as string) || defaultRows,
cwd: process.cwd(),
env: process.env as ProcessEnv
});
terminal.on("data", (data: string) => {
if (webSocket.readyState === WebSocket.OPEN) {
webSocket.send(data);
}
});
webSocket.on("message", (message: string) => {
this.handleMessage(message, terminal);
});