0

我正在使用 raw 属性将格式化数据从 url 获取到终端,就像这样

$(function() {
var save_state = [];
var terminal = $('#term').terminal(function(command, term) {

        term.pause();

        url = ...;
        $.get(url, function(result) {
            term.echo(result, {raw:true}).resume();

        });

}, { prompt: '>>', name: 'test', outputLimit: 1000 });


});

我想知道,我如何得到它,所以当点击结果中的链接时,它们会将数据加载到终端中,就像加载命令数据一样,而不是打开一个新的浏览器选项卡?

谢谢!

4

1 回答 1

1

如果您使用的命令包含 URL 或 URI(例如get foo.htmlget https://example.com),您可以使用以下命令:

terminal.on('click', '.terminal-output > div:not(.exception) a', function() {
   // if you don't use `true` it will show the command like if you type it
   // instead of `get` you can use any command you have that will
   // fetch the url and display it on the terminal
   terminal.exec('get ' + $(this).attr('href'), true);
   return false; // prevent following the link
});

如果您有不同的逻辑来显示 url,您可能需要在 click 事件处理程序中从解释器中提取代码。

terminal.on('click', '.terminal-output > div:not(.exception) a', function() {
    // duplicated code from your interpreter
    term.pause();
    var url = $(this).attr('href');
    $.get(url, function(result) {
        term.echo(result, {raw:true}).resume();
    });
    return false;
});
于 2018-10-18T07:00:04.067 回答