0

我最近一直在研究一个使用 jquery 终端插件的电子应用程序。我正在使用插件的 cmd 功能,并希望在给出命令时传递一个参数,然后打印两个参数。我的整个 renderer.js 文件如下所示:

var pre = $('pre');
var body = $('body');
function scroll_to_bottom() {
  var sHeight = body.prop('scrollHeight');
  body.scrollTop(sHeight);
}
var cmd = $('#some_id').cmd({
  prompt: ' ',
  width: '100%',
  commands: function(command, argd) {
    var html = pre.html();
    if (html) { html += '\n'; }
    var message = "you've typed " + 
        "<span style=\"color:white\">" + command + " " + argd
        "</span>";
    pre.html(html + '> ' + command + '\n' + message);
    scroll_to_bottom();
    
  }
});
4

1 回答 1

0

cmd 插件仅接受单个参数,即您键入的整个命令。为了获得命令和参数,您需要解析将从回调中获得的字符串:

var cmd = $('#some_id').cmd({
  prompt: ' ',
  width: '100%',
  commands: function(command) {
    var cmd = $.terminal.parse_command(command);
    // cmd.name == name of the command
    // cmd.args == array of arguments
    // cmd.rest == rest of the command as string
  }
});
于 2021-11-30T16:30:48.963 回答