2011-08-17 71 views
11

我在node.js中寻找这个功能,我没有找到它。
我可以自己实施吗?据我所知,node.js不会在启动时加载任何文件(如Bash与.bashrc一样),我也没有注意到有任何方法可以覆盖shell提示符。如何在node.js shell中实现选项卡完成?

有没有一种方法来实现它,而无需编写自定义外壳?

+0

AFAIK不存在用于所述V8终端自动填充选项。但是,也许像[with-readline](http://www.greenend.org.uk/rjk/2005/withreadline.html)这样的工具对您有所帮助。 – brandizzi

回答

9

你可以猴子修补REPL:

var repl = require('repl').start() 
var _complete = repl.complete 
repl.complete = function(line) { 
    ... 
    _complete.apply(this, arguments) 
} 
4

只是作为参考。

readline模块有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] 
} 

​​

链接到API文档:http://nodejs.org/api/readline.html#readline_readline_createinterface_options