0

I'm using the raw property to get formatted data from urls into the terminal, like this

$(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 });


});

I'm wondering, how do I get it so when links in result are clicked, they load their data into the terminal the same way command data is loaded, rather than opening a new browser tab?

Thanks!

1 Answers1

1

If you're using command that include URL or URI (for instance get foo.html or get https://example.com) you can use this:

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
});

if you have different logic for displaying the urls you may need to dipicate the code from interpreter inside click event handler.

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;
});
jcubic
  • 61,973
  • 54
  • 229
  • 402