cs-education / sysbuild

A system programming learning environment in the browser
https://cs-education.github.io/sys/
Other
36 stars 35 forks source link

Terminal output capture does not differentiate between terminals #96

Closed wchill closed 9 years ago

wchill commented 9 years ago

The putCharListener in sys-runtime.js:20 currently does not differentiate between the outputs of the two terminals. This means that if both terminals are being used simultaneously, a race condition will occur and the captured output will be garbage.

wchill commented 9 years ago

Part of the problem is in terminal.js, lines 464 and 521.

464:  document.dispatchEvent(new CustomEvent("jor1k_terminal_put_char", { detail: { character: "\n" }}));
521:  document.dispatchEvent(new CustomEvent("jor1k_terminal_put_char", { detail: { character: String.fromCharCode(c) }}));

This is a straightforward fix; just pass in a terminal ID when constructing the Terminal and use that as part of the event name (example: jor1k_terminal_put_char_tty0). Then register two putCharListeners listening on both terminal devices and update any usage of the original putCharListener.

anant-singh commented 9 years ago

But wouldn't this require a mod in jor1k's code since terminal.js is their file, so maybe you should open up this issue in their repo also.

wchill commented 9 years ago

jor1k actually revamped their terminal code (https://github.com/s-macke/jor1k/blob/master/js/plugins/terminal-macke.js) and it's structured completely differently. So this fix should be implemented in our jor1k fork (sysbuild-stable branch) for the time being.

neelabhg commented 9 years ago

I'm very close to upgrading jor1k (issue #51), in which case we can have our own custom terminal implementation.

wchill commented 9 years ago

Just to be sure, is putCharListener being used anywhere? I suspect it's used to parse gcc's output, but I'm not entirely sure.

anant-singh commented 9 years ago

It is used to update the status for the vm and compiler also. There are some custom listeners that wait for these events such as the compile button, so they are directly tied to putcharlistener's output