Tag: readline

createInterface在terminal中双击打印

当使用readline接口时,标准input的所有内容都被打印两次到stdout: var rl = require('readline'); var i = rl.createInterface(process.stdin, process.stdout); 当我运行这个代码时,我在terminal中input的所有内容都是重复的。 打字'你好世界'收益率: hheelloo wwoorrlldd 我猜这是有道理的,因为readline模块是为了将inputpipe道输出到输出。 但是它不是也用来创build命令行界面吗? 我很困惑,我该怎么使用它。 帮帮我?

如何使用readlinebuild议使用tab完成文件?

在Bash shell中,我可以使用tab-completion来使用build议的文件和目录名称。 我怎样才能实现这与nodejs和readline ? 例子: /<Tab>应该build议/root/ , /bin/等 /et<Tab>应该完成到/etc/ 。 fo<Tab>应该完成foobar假设这样的文件存在于当前目录中。 我正在考虑使用globbing(pattern search_term.replace(/[?*]/g, "\\$&") + "*" ),但是有没有可能忽视的库? 这是我目前使用glob的方法,在使用//<Tab>时会被破坏,因为它返回规范化的名称,并且可能还有一些其他的特性: function command_completion(line) { var hits; // likely broken, one does not simply escape a glob char var pat = line.replace(/[?*]/g, "\\$&") + "*"; // depends: glob >= 3.0 var glob = require("glob").sync; hits = glob(pat, { silent: […]

我怎样才能同步使用readline?

我只是试图等待用户input密码,然后使用它,然后继续我的代码的其余部分。 错误是Cannot read property 'then' of undefined 。 let rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question('Password: ', password => { rl.close(); return decrypt(password); }).then(data =>{ console.log(data); }); function decrypt( password ) { return new Promise((resolve) => { //do stuff resolve(data); }); }

如何在Node.js中逐行读取child_process?

我正在尝试做一个Node.js脚本来分析磁盘使用情况。 为此,我掏出了du ,但我无法弄清楚如何逐行读取subprocess的输出。 以下是我迄今为止所尝试的: var spawn = require("child_process").spawn, rl = require('readline'), du = spawn('du', ['/home']); linereader = rl.createInterface(du.stdout, du.stdin); // Read line by line. //du.stdout.on('data', function (data) { linereader.on('line', function (data) { console.log(data); }); du.stdout.on('data'只是读取数据块,而readline应该按行分割它的input,而不是,而是我得到完全相同的数据(du.stdout返回一个缓冲区,但调用.toString()它给了我与linereader相同的数据)。

Node.js readline缺less文件的最后一行?

我试图读取一个文本文件asynchronous和​​逐行Node.js下。 我有以下CoffeeScript代码: readline = require 'readline' fs = require 'fs' #——————————————————————– lines_of = ( route, handler ) -> #………………………………………………………… stream = readline.createInterface input: fs.createReadStream route output: process.stdout terminal: false #………………………………………………………… stream.on 'close', -> handler null, null #………………………………………………………… stream.on 'error', ( error ) -> handler error #………………………………………………………… stream.on 'line', ( line ) -> handler null, line […]

Node.js多行input

我想提示用户input,让用户input多行文本,在每行之间敲入回车,然后按CTRL + D或类似的东西终止input。 使用“按键”,我可以捕捉EOF,但是我将不得不手动处理所有回显,退格处理,terminal转义序列等。 如果我可以使用“readline”会好得多,但是用“按键”拦截CTRL + D(EOF),但我不知道该怎么去做。

在控制台上简单的node.js readline

我想教学生如何使用JavaScript进行编程。 我不想引入新的学生回电或任何其他复杂的程序结构。 查看Node.js,用于标准input的readline使用callback。 对于简单的input数据,然后做一个计算,我想一个简单的等价于像Python或其他类似语言的input具有: width = input("Width? ") height = input("Height? ") area = width * height print("Area is",area) 有什么方法可以用JavaScript来做到这一点?

清除Node.js readlineshell中的terminal窗口

我有一个用Coffeescript编写的简单的readline shell: rl = require 'readline' cli = rl.createInterface process.stdin, process.stdout, null cli.setPrompt "hello> " cli.on 'line', (line) -> console.log line cli.prompt() cli.prompt() 运行这将显示一个提示: $ coffee cli.coffee hello> 我希望能够Ctrl-L清除屏幕。 这可能吗? 我也注意到,我无法在节点或咖啡 REPL中Ctrl-L 。 我在Ubuntu 11.04上运行。

节点“readline”模块没有“结束”事件 – 当没有更多的行时,我该怎么做?

阅读readline模块的官方文档 ,没有像其他stream一样的end事件。 试 reader.on('end', cb); 不起作用。 一旦没有更多的行被读取,我怎样才能运行一个callback?

如何从node.js打开terminal应用程序?

我希望能够从terminal上运行的node.js程序打开Vim ,创build一些内容,保存并退出Vim ,然后抓取文件的内容。 我正在尝试做这样的事情: filename = '/tmp/tmpfile-' + process.pid editor = process.env['EDITOR'] ? 'vi' spawn editor, [filename], (err, stdout, stderr) -> text = fs.readFileSync filename console.log text 但是,当这个运行,它只是挂起terminal。 我也试着用exec得到相同的结果。 更新: 这个过程很复杂,因为这个过程是通过在readline运行的提示符下键入的命令启动的。 我完全将我最新版本的相关部分提取到一个文件中。 这是完整的: {spawn} = require 'child_process' fs = require 'fs' tty = require 'tty' rl = require 'readline' cli = rl.createInterface process.stdin, process.stdout, null […]