Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* termine old PTY */
if (this.pty)
this.terminate()
/* establish environment */
env = Object.assign({},
process.env,
typeof this.options.env === "object" ? this.options.env : {},
typeof env === "object" ? env : {}
)
if ( env.TERM === undefined
|| !(typeof env.TERM === "string" && env.TERM.match(/^xterm(?:-.+)?$/)))
env.TERM = "xterm"
/* create new PTY */
this.pty = Pty.fork(shell, args, {
name: "xterm",
cols: this.width - this.iwidth,
rows: this.height - this.iheight,
cwd: cwd || this.options.cwd || process.cwd(),
env: env
})
/* process data on PTY */
this.pty.on("data", (data) => {
this.write(data)
if (data instanceof Buffer)
data = data.toString()
if (data.match(/\x07/))
this.emit("beep")
})
constructor (options) {
this.terminal = null;
WebTerm.sockets.push(options.socket);
// Default shell
options.shell = deffy(options.shell, process.env.SHELL || "bash");
if (options.ptyOptions && options.ptyOptions.env && options.inheritEnv !== false) {
options.ptyOptions.env = ul.merge(options.ptyOptions.env, process.env);
}
// Create the terminal
this.terminal = pty.fork(options.shell, [], ul.merge({
cols: options.cols
, rows: options.rows
, cwd: options.cwd || ul.home()
}, options.ptyOptions));
// Terminal -> Socket
this.terminal.on("data", data => options.socket.emit("data", data));
// Close terminal
this.terminal.on("close", () => {
options.socket.emit("kill");
this.kill();
});
// Handle the start app
if (typeof options.start === "string") {
init () {
Terminal.applyAddon(fit)
this.term = new Terminal({})
this.term.open(this.$refs.terminal)
let shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash'
this.ptyProcess = pty.fork(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 10,
cwd: process.env.HOME,
env: process.env
})
this.ptyProcess.on('data', (data) => {
this.term.write(data)
})
this.term.on('data', (data) => {
this.ptyProcess.write(data)
})
this.resize()