2

I successfully installed the terminal on a test page and want to highlight parentheses that match, something like this:
http://profgra.org/lycee/calcul.html
So I already have a working solution that I now need to hook to the terminal.
My first idea was to see if I could grab the term content, using the keypress option:

keypress: function(e) {
   console.log(term.html());
}

But the content always lacks the last letter typed. Any idea to fix this? Or any other direction to try?

Thanks reading.

jcubic
  • 61,973
  • 54
  • 229
  • 402
Gra
  • 1,542
  • 14
  • 28
  • If you modify html it will be removed on refresh. If you want to highlight parentheses only inside command line you can use `term.get_command()` to grab current command, but you will not be able to set the class for the text because I've removed formatting from command line. – jcubic May 24 '14 at 04:20

1 Answers1

0

keypress first execute user function then insert the text, so you can try to delay the action:

keypress: function(e, term) {
    setTimeout(function() {
        console.log(term.html());
    }, 10);
}

Insetead of setTimeout you can also use jQuery Timers that's included with terminal file.

jcubic
  • 61,973
  • 54
  • 229
  • 402
  • Thanks. It works great for me but what would be the advantage to use jQuery here? Better cross-browser compatibility? – Gra May 24 '14 at 12:40
  • @Gra jQuery timers have more functions then builtin setTimeout, but for this case I don't see a reason why not to just use setTimeout. I was just saying that terminal include that plugin, just as side note. – jcubic May 24 '14 at 13:59