• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript node-pty.spawn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中node-pty.spawn函数的典型用法代码示例。如果您正苦于以下问题:TypeScript spawn函数的具体用法?TypeScript spawn怎么用?TypeScript spawn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了spawn函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: login

 public static login(socket: SocketIO.Socket): Promise<string> {
   const term = spawn(
     '/usr/bin/env',
     ['node', `${__dirname}/buffer.js`],
     xterm
   );
   let buf = '';
   return new Promise((resolve, reject) => {
     term.on('exit', () => {
       resolve(buf);
     });
     term.on('data', data => {
       socket.emit('data', data);
     });
     socket
       .on('input', (input: string) => {
         term.write(input);
         buf = /\177/.exec(input) ? buf.slice(0, -1) : buf + input;
       })
       .on('disconnect', () => {
         term.kill();
         reject();
       });
   });
 }
开发者ID:krishnasrinivas,项目名称:wetty,代码行数:25,代码来源:term.ts


示例2: spawn

 public static spawn(socket: SocketIO.Socket, args: string[]): void {
   const term = spawn('/usr/bin/env', args, xterm);
   const address = args[0] === 'ssh' ? args[1] : 'localhost';
   events.spawned(term.pid, address);
   socket.emit('login');
   term.on('exit', code => {
     events.exited(code, term.pid);
     socket.emit('logout');
     socket
       .removeAllListeners('disconnect')
       .removeAllListeners('resize')
       .removeAllListeners('input');
   });
   term.on('data', data => {
     socket.emit('data', data);
   });
   socket
     .on('resize', ({ cols, rows }) => {
       term.resize(cols, rows);
     })
     .on('input', input => {
       if (!isUndefined(term)) term.write(input);
     })
     .on('disconnect', () => {
       const { pid } = term;
       term.kill();
       events.exited(0, pid);
     });
 }
开发者ID:krishnasrinivas,项目名称:wetty,代码行数:29,代码来源:term.ts


示例3: init_term

  async function init_term() {
    const args: string[] = [];

    if (options.args != null) {
      for (let arg of options.args) {
        if (typeof arg === "string") {
          args.push(arg);
        }
      }
    } else {
      const init_filename: string = console_init_filename(path);
      if (await exists(init_filename)) {
        args.push("--init-file");
        args.push(path_split(init_filename).tail);
      }
    }

    const s = path_split(path);
    const env = merge({ COCALC_TERMINAL_FILENAME: s.tail }, process.env);
    if (options.env != null) {
      merge(env, options.env);
    }

    const command = options.command ? options.command : "/bin/bash";
    const cwd = s.head;

    try {
      terminals[name].history = (await callback(readFile, path)).toString();
    } catch (err) {
      console.log(`failed to load ${path} from disk`);
    }
    const term = spawn(command, args, { cwd, env });
    logger.debug("terminal", "init_term", name, "pid=", term.pid, "args", args);
    terminals[name].term = term;

    const save_history_to_disk = throttle(async () => {
      try {
        await callback(writeFile, path, terminals[name].history);
      } catch (err) {
        console.log(`failed to save ${path} to disk`);
      }
    }, 15000);

    term.on("data", function(data): void {
      //logger.debug("terminal: term --> browsers", name, data);
      handle_backend_messages(data);
      terminals[name].history += data;
      save_history_to_disk();
      const n = terminals[name].history.length;
      if (n >= MAX_HISTORY_LENGTH) {
        logger.debug("terminal data -- truncating");
        terminals[name].history = terminals[name].history.slice(
          n - MAX_HISTORY_LENGTH / 2
        );
        const last = terminals[name].last_truncate_time;
        const now = new Date().valueOf();
        terminals[name].last_truncate_time = now;
        logger.debug("terminal", now, last, now - last, truncate_thresh_ms);
        if (now - last <= truncate_thresh_ms) {
          // getting a huge amount of data quickly.
          if (!terminals[name].truncating) {
            channel.write({ cmd: "burst" });
          }
          terminals[name].truncating += data.length;
          setTimeout(check_if_still_truncating, check_interval_ms);
          if (terminals[name].truncating >= 5 * MAX_HISTORY_LENGTH) {
            // only start sending control+c if output has been completely stuck
            // being truncated several times in a row -- it has to be a serious non-stop burst...
            term.write("\u0003");
          }
          return;
        } else {
          terminals[name].truncating = 0;
        }
      }
      if (!terminals[name].truncating) {
        channel.write(data);
      }
    });

    let backend_messages_state: "NONE" | "READING" = "NONE";
    let backend_messages_buffer: string = "";
    function reset_backend_messages_buffer(): void {
      backend_messages_buffer = "";
      backend_messages_state = "NONE";
    }
    function handle_backend_messages(data: string): void {
      /* parse out messages like this:
            \x1b]49;"valid JSON string here"\x07
         and format and send them via our json channel.
         NOTE: such messages also get sent via the
         normal channel, but ignored by the client.
      */
      if (backend_messages_state === "NONE") {
        const i = data.indexOf("\x1b");
        if (i === -1) {
          return; // nothing to worry about
        }
        backend_messages_state = "READING";
        backend_messages_buffer = data.slice(i);
//.........这里部分代码省略.........
开发者ID:DrXyzzy,项目名称:smc,代码行数:101,代码来源:server.ts


示例4: parseInt

	name: string;
	cwd: string;
	cols?: number;
	rows?: number;
}

const options: IOptions = {
	name: shellName,
	cwd
};
if (cols && rows) {
	options.cols = parseInt(cols, 10);
	options.rows = parseInt(rows, 10);
}

const ptyProcess = pty.spawn(shell, args, options);

let closeTimeout: number;
let exitCode: number;

// Allow any trailing data events to be sent before the exit event is sent.
// See https://github.com/Tyriar/node-pty/issues/72
function queueProcessExit() {
	if (closeTimeout) {
		clearTimeout(closeTimeout);
	}
	closeTimeout = setTimeout(function () {
		ptyProcess.kill();
		process.exit(exitCode);
	}, 250);
}
开发者ID:liunian,项目名称:vscode,代码行数:31,代码来源:terminalProcess.ts



注:本文中的node-pty.spawn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript node-rest-client.Client类代码示例发布时间:2022-05-25
下一篇:
TypeScript node-pipe2.pipe2函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap