1

是否可以控制 JQuery.Terminal 中的整个制表符完成功能?我想管理显示的自动完成。

例如,我想支持模板/正则表达式,以便我可以执行诸如“可视化活动 CAMPAIGN_NAME 其中 config = SOMETHING”之类的事情。我可以为所有这些编写自己的解析器和处理程序,但我不确定如何/在哪里插入它?

4

1 回答 1

1

在初始化设置中,需要确保没有设置完成属性(默认为false)。

然后,您需要拦截 keydown 函数并处理您感兴趣的键(在我的例子中是选项卡)。

在那里,您可以为自动完成逻辑提供自己的处理程序:

$('#terminal').terminal(function (command, term) 
        {
            // Command handlers
        },
        {
            keydown: function(event, term) {

            if (event.keyCode == 9) //Tab
            {
                // Call handler to handle your auto-completion logic

                // Sample to print stuff to the console and update the command
                term.echo("autocompletion commands...");
                term.set_command(term.get_command() + " completion text");

                // Tells the terminal to not handle the tab key
                return false;
            }
        }
    });
});
于 2014-10-15T18:52:42.420 回答