當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript readline.createInterface函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。