Dr *_*Kay 13 javascript shell node.js
我在node.js中寻找这个功能,但我还没有找到它.
我可以自己实施吗?据我所知,node.js在启动时没有加载任何文件(就像Bash那样.bashrc),我没有注意到以任何方式覆盖shell提示符.
有没有办法在不编写自定义shell的情况下实现它?
你可以修补REPL:
var repl = require('repl').start()
var _complete = repl.complete
repl.complete = function(line) {
...
_complete.apply(this, arguments)
}
Run Code Online (Sandbox Code Playgroud)
仅作为参考.
readlinemodule具有readline.createInterface(options)接受可选completer功能的方法,该功能使选项卡完成.
function completer(line) {
var completions = '.help .error .exit .quit .q'.split(' ')
var hits = completions.filter(function(c) { return c.indexOf(line) == 0 })
// show all completions if none found
return [hits.length ? hits : completions, line]
}
Run Code Online (Sandbox Code Playgroud)
和
function completer(linePartial, callback) {
callback(null, [['123'], linePartial]);
}
Run Code Online (Sandbox Code Playgroud)
链接到api文档:http://nodejs.org/api/readline.html#readline_readline_createinterface_options
| 归档时间: |
|
| 查看次数: |
2977 次 |
| 最近记录: |