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

TypeScript readline.createInterface函数代码示例

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

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



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

示例1: uninstall

function uninstall() {
  const system = systemsById[systemId];
  if (system == null) {
    console.error(`System ${systemId} is not installed.`);
    process.exit(1);
  }

  if (pluginFullName == null) {
    const r1 = readline.createInterface({ input: process.stdin, output: process.stdout });
    r1.question(`Are you sure you want to uninstall the system ${systemId} ? (yes/no): `, (answer) => {
      if (answer === "yes") uninstallSystem(system.folderName);
      else process.exit(0);
    });

  } else {
    const [ pluginAuthor, pluginName ] = pluginFullName.split("/");
    if (builtInPluginAuthors.indexOf(pluginAuthor) !== -1) {
      console.error(`Built-in plugins can not be uninstalled.`);
      process.exit(1);
    }

    if (system.plugins[pluginAuthor] == null || system.plugins[pluginAuthor].indexOf(pluginName) === -1) {
      console.error(`Plugin ${pluginFullName} is not installed.`);
      process.exit(1);
    }

    const r1 = readline.createInterface({ input: process.stdin, output: process.stdout });
    r1.question(`Are you sure you want to uninstall the plugin ${pluginFullName} ? (yes/no): `, (answer) => {
      if (answer === "yes") uninstallPlugin(system.folderName, pluginAuthor);
      else process.exit(0);
    });
  }
}
开发者ID:alphafork,项目名称:Game-Engine-superpowers-core,代码行数:33,代码来源:index.ts


示例2: spawn

    runTask: (command: string, args: string[], config: TaskConfig) => {
      let loggerCategory = config.name;
      let logger = config.logger;

      logger.log(loggerCategory, `running command ${command} ${args.join(' ')}`);
      let task = spawn(command, args);

      let stdout = createInterface({ input: task.stdout });
      stdout.on('line', line => {
        line = strip(line);
        if (!line) {
          return;
        }
        let handled = false;
        if (config.handleOutput) {
          handled = config.handleOutput(line);
        }
        if (!handled) {
          logger.log(loggerCategory, line);
        }
      });

      let stderr = createInterface({ input: task.stderr });
      stderr.on('line', line => {
        line = strip(line);
        if (!line) {
          return;
        }
        let handled = false;
        if (config.handleError) {
          handled = config.handleError(line);
        }
        if (!handled) {
          logger.error(loggerCategory, line);
        }
      });

      let result = new Promise<void>((resolve, reject) => {
        task.on('close', (code: number) => {
          if (code === 0 || code === null) {
            resolve();
          } else {
            reject(`Process exited with code ${code}`);
          }
        });
      });

      return {
        result,
        kill: () => {
          kill(task.pid);
        }
      };
    }
开发者ID:AFASSoftware,项目名称:typescript-assistant,代码行数:54,代码来源:taskrunner.ts


示例3: uninstall

export default function uninstall(systemId: string, pluginFullName: string) {
  const system = utils.systemsById[systemId];
  if (system == null) utils.emitError(`System ${systemId} is not installed.`);

  if (pluginFullName == null) {
    if (system.isDev) utils.emitError(`System ${systemId} is a development version.`);

    if (utils.force) {
      uninstallSystem(system.folderName);
      return;
    }

    const r1 = readline.createInterface({ input: process.stdin, output: process.stdout });
    r1.question(`Are you sure you want to uninstall the system ${systemId}? (yes/no): `, (answer) => {
      if (answer === "yes") {
        console.log(`Uninstalling system ${systemId}...`);
        uninstallSystem(system.folderName);
      } else {
        console.log(`Uninstall canceled.`);
        process.exit(0);
      }
    });

  } else {
    const [ pluginAuthor, pluginName ] = pluginFullName.split("/");
    if (utils.builtInPluginAuthors.indexOf(pluginAuthor) !== -1) utils.emitError(`Built-in plugins can not be uninstalled.`);

    if (system.plugins[pluginAuthor] == null || system.plugins[pluginAuthor].indexOf(pluginName) === -1)
      utils.emitError(`Plugin ${pluginFullName} is not installed.`);

    let isDevFolder = true;
    try { fs.readdirSync(`${utils.systemsPath}/${system.folderName}/plugins/${pluginFullName}/.git`); } catch (err) { isDevFolder = false; }
    if (isDevFolder) utils.emitError(`Plugin ${pluginFullName} is a development version.`);

    if (utils.force) {
      uninstallPlugin(system.folderName, pluginFullName, pluginAuthor);
      return;
    }

    const r1 = readline.createInterface({ input: process.stdin, output: process.stdout });
    r1.question(`Are you sure you want to uninstall the plugin ${pluginFullName}? (yes/no): `, (answer) => {
      if (answer === "yes") {
        console.log(`Uninstalling plugin ${pluginFullName} from system ${systemId}...`);
        uninstallPlugin(system.folderName, pluginFullName, pluginAuthor);
      } else {
        console.log(`Uninstall canceled.`);
        process.exit(0);
      }
    });
  }
}
开发者ID:andy737,项目名称:superpowers-core,代码行数:51,代码来源:uninstall.ts


示例4: uninstall

export default function uninstall(systemId: string, pluginFullName: string) {
  const localSystem = utils.systemsById[systemId];
  if (localSystem == null) utils.emitError(`System ${systemId} is not installed.`);

  if (pluginFullName == null) {
    // Uninstall system
    if (localSystem.isDev) utils.emitError(`System ${systemId} is a development version.`);

    if (utils.force) {
      uninstallSystem(localSystem.folderName);
      return;
    }

    const r1 = readline.createInterface({ input: process.stdin, output: process.stdout });
    r1.question(`Are you sure you want to uninstall the system ${systemId}? (yes/no): `, (answer) => {
      if (answer === "yes") {
        console.log(`Uninstalling system ${systemId}...`);
        uninstallSystem(localSystem.folderName);
      } else {
        console.log(`Uninstall canceled.`);
        process.exit(0);
      }
    });

  } else {
    // Uninstall plugin
    const [ authorName, pluginName ] = pluginFullName.split("/");
    if (utils.builtInPluginAuthors.indexOf(authorName) !== -1) utils.emitError(`Built-in plugins can not be uninstalled.`);

    const localPlugin = localSystem.plugins[authorName] != null ? localSystem.plugins[authorName][pluginName] : null;
    if (localPlugin == null) utils.emitError(`Plugin ${pluginFullName} is not installed.`);

    if (localPlugin.isDev) utils.emitError(`Plugin ${pluginFullName} is a development version.`);

    if (utils.force) {
      uninstallPlugin(localSystem.folderName, pluginFullName, authorName);
      return;
    }

    const r1 = readline.createInterface({ input: process.stdin, output: process.stdout });
    r1.question(`Are you sure you want to uninstall the plugin ${pluginFullName}? (yes/no): `, (answer) => {
      if (answer === "yes") {
        console.log(`Uninstalling plugin ${pluginFullName} from system ${systemId}...`);
        uninstallPlugin(localSystem.folderName, pluginFullName, authorName);
      } else {
        console.log(`Uninstall canceled.`);
        process.exit(0);
      }
    });
  }
}
开发者ID:Pangoraw,项目名称:superpowers-core,代码行数:51,代码来源:uninstall.ts


示例5: loadTimeFile

 function loadTimeFile(cb: (fd: TimePair[], p: string[]) => void, params: string[]){
   var clockfile, currentDeep, fileData, rd;
   clockfile = config.clockfile;
   if (!clockfile || !fs.existsSync(clockfile)) {
     println("You need to set the environment variable CLOCKFILE (pointing to an existing file)");
     process.exit(1);
   }
   currentDeep = 0;
   fileData = [];
   rd = readline.createInterface({
     input: fs.createReadStream(clockfile),
     output: process.stdout,
     terminal: false
   });
   rd.on('line', function(line){
     var l;
     l = parseLine(line, currentDeep);
     fileData.push(l);
     if (l.deep) {
       currentDeep = l.deep;
     }
   });
   rd.on('close', function(){
     cb(fileData, params);
   });
 };
开发者ID:jramb,项目名称:punch,代码行数:26,代码来源:punch.ts


示例6: Promise

        return new Promise((resolve) => {
            const io = this.io;
            const output = io.output;

            const options: readline.ReadLineOptions = {
                completer: (line: string) => {
                    const hits = question.getCompletions(line);
                    return [hits, line];
                },
                input: io.input.getStream(),
                terminal: output.isDecorated(),
            };

            if (!question.isHidden()) {
                options.output = output.getStream();
            }

            const rl = readline.createInterface(options);

            rl.question(question.getPrompt(), (answer) => {
                resolve(answer || "");

                rl.close();
            });
        });
开发者ID:sirian,项目名称:node-component-console,代码行数:25,代码来源:QuestionHelper.ts


示例7: dynamicRequire

virtualConnectionServer.createInterface(server).on('connection', (connection: Duplex) => {
    readline.createInterface(connection, null).on('line', line => {
        try {
            // Get a reference to the function to invoke
            const invocation = JSON.parse(line) as RpcInvocation;
            const invokedModule = dynamicRequire(path.resolve(process.cwd(), invocation.moduleName));
            const invokedFunction = invocation.exportedFunctionName ? invokedModule[invocation.exportedFunctionName] : invokedModule;

            // Actually invoke it, passing the callback followed by any supplied args
            const invocationCallback = (errorValue, successValue) => {
                connection.end(JSON.stringify({
                    result: successValue,
                    errorMessage: errorValue && (errorValue.message || errorValue),
                    errorDetails: errorValue && (errorValue.stack || null)
                }));
            };
            invokedFunction.apply(null, [invocationCallback].concat(invocation.args));
        } catch (ex) {
            connection.end(JSON.stringify({
                errorMessage: ex.message,
                errorDetails: ex.stack
            }));
        }
    });
});
开发者ID:Niaro,项目名称:JavaScriptServices,代码行数:25,代码来源:SocketNodeInstanceEntryPoint.ts


示例8: require

  .then(user => {
    if (!user) {
      console.error('User unknown.')
      process.exit(-1)
    }

    const readline = require('readline')
    const Writable = require('stream').Writable
    const mutableStdout = new Writable({
      write: function (chunk, encoding, callback) {
        callback()
      }
    })
    const rl = readline.createInterface({
      input: process.stdin,
      output: mutableStdout,
      terminal: true
    })

    console.log('New password?')
    rl.on('line', function (password) {
      user.password = password

      user.save()
        .then(() => console.log('User password updated.'))
        .catch(err => console.error(err))
        .finally(() => process.exit(0))
    })
  })
开发者ID:jiang263,项目名称:PeerTube,代码行数:29,代码来源:reset-password.ts


示例9:

	return new Promise<string>((resolve) => {
		const rl = readLine.createInterface(process.stdin, process.stdout);
		rl.question(message, (ans) => {
			resolve(ans);
			rl.close();
		});
	});
开发者ID:Frost-Dev,项目名称:Frost,代码行数:7,代码来源:ConsoleMenu.ts


示例10: read

    public static read(filePath: string, featureSize:number, callback: Function, complete: Function = null): void {
        const options: Object = { encoding: 'utf8', highWaterMark: 256 };
        const stream: fs.ReadStream = fs.createReadStream(filePath, options);
        const rl: readline.ReadLine = readline.createInterface(stream, null);
        
        rl.on('line', (line: string) => {
            const fields: string[] = line.split(/[\s:]/);
            const label: number = fields[0].charAt(0) == '+' ? +1 : -1;
            const len: number = fields.length;
            let x: Feature | Float32Array = null;
            if (featureSize != null && featureSize > 0) {
                x = new Float32Array(featureSize).fill(0.0);
                for (let i = 1; i < len; i += 2) {
                    let index: number = parseInt(fields[i]) - 1;
                    let value: number = parseFloat(fields[i + 1]);
                    x[index] = value;
                }
            } else {
                x = [];
                for (let i = 1; i < len; i += 2) {
                    let index: number = parseInt(fields[i]) - 1;
                    let value: number = parseFloat(fields[i + 1]);
                    let element = { index, value };
                    x.push(element);
                }
            }
            callback(x, label);
        });

        rl.on('close', () => {
            if (complete instanceof Function) {
                complete();
            }
        });
    }
开发者ID:wellflat,项目名称:imageprocessing-labs,代码行数:35,代码来源:data_loader.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript readline.cursorTo函数代码示例发布时间:2022-05-25
下一篇:
TypeScript readline.clearScreenDown函数代码示例发布时间: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