我希望能够Vim从终端中运行的node.js程序打开,创建一些内容,保存并退出Vim,然后抓取文件的内容.
我正在尝试做这样的事情:
filename = '/tmp/tmpfile-' + process.pid
editor = process.env['EDITOR'] ? 'vi'
spawn editor, [filename], (err, stdout, stderr) ->
text = fs.readFileSync filename
console.log text
Run Code Online (Sandbox Code Playgroud)
但是,当它运行时,它只是挂起终端.
我也试过了exec,得到了同样的结果.
更新:
由于在readline运行的提示符下键入的命令启动了此过程,因此这很复杂.我完全将我最新版本的相关部分提取到文件中.这是完整的:
{spawn} = require 'child_process'
fs = require 'fs'
tty = require 'tty'
rl = require 'readline'
cli = rl.createInterface process.stdin, process.stdout, null
cli.prompt()
filename = '/tmp/tmpfile-' + process.pid
proc = spawn 'vim', [filename]
#cli.pause()
process.stdin.resume()
indata = (c) ->
proc.stdin.write c
process.stdin.on 'data', …Run Code Online (Sandbox Code Playgroud) 给定一组对象:
{
key: "a",
value: 42
},
{
key: "d",
value: 28
},
{
key: "c",
value: 92
},
{
key: "b",
value: 87
}
和一组键:
["c", "a", "b", "d"]
Run Code Online (Sandbox Code Playgroud)
是否有ECMAScript函数或第三方JavaScript库,允许您在一行/函数调用中排序第一个对象数组,以匹配第二个数组中指定的键的顺序,结果是:
{
key: "c",
value: 92
},
{
key: "a",
value: 42
},
{
key: "b",
value: 87
},
{
key: "d",
value: 28
}
提供功能或算法的其他问题:
相似/相关问题:
我有一个用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()
Run Code Online (Sandbox Code Playgroud)
运行此命令会显示提示:
$ coffee cli.coffee
hello>
Run Code Online (Sandbox Code Playgroud)
我希望能够点击Ctrl-L清除屏幕.这可能吗?
我也注意到,我不能打Ctrl-L在任一节点或咖啡 REPLs无论是.
我在Ubuntu 11.04上运行.
coffeescript ×2
node.js ×2
readline ×2
arrays ×1
javascript ×1
jquery ×1
sorting ×1
terminal ×1
vim ×1