How to use the node-pty.fork function in node-pty

To help you get started, we’ve selected a few node-pty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rse / blessed-xterm / blessed-xterm.js View on Github external
/*  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")
        })
github IonicaBizau / web-term / lib / index.js View on Github external
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") {
github moonrailgun / devbox / src / renderer / components / Deprecated / SSHEmulator.vue View on Github external
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()

node-pty

Fork pseudoterminals in Node.JS

MIT
Latest version published 2 years ago

Package Health Score

82 / 100
Full package analysis