-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dual terminal support #56
Changes from all commits
c0a21c1
dd81f42
615321f
4815417
6ed127e
4a739ec
70c07c9
09ae919
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ | |
window.Jor1kGUI = (function () { | ||
'use strict'; | ||
|
||
function UARTDev(worker) { | ||
function UARTDev(worker, tty) { | ||
this.ReceiveChar = function (c) { | ||
if (worker.lastMouseDownTarget !== worker.fbcanvas) { | ||
worker.sendToWorker('tty0', c); | ||
worker.sendToWorker(tty, c); | ||
} | ||
}; | ||
} | ||
|
||
function Jor1kGUI(termId, imageurls, relayURL) { | ||
function Jor1kGUI(termId, termIdTwo, imageurls, relayURL) { | ||
this.urls = imageurls; | ||
|
||
this.worker = new Worker('jor1k/js/worker/worker.js'); | ||
|
@@ -35,6 +35,7 @@ window.Jor1kGUI = (function () { | |
this.sendToWorker('Reset'); | ||
this.sendToWorker('LoadAndStart', this.urls); | ||
this.term.PauseBlink(false); | ||
this.termTwo.PauseBlink(false); | ||
}; | ||
|
||
this.pause = function (pause) { | ||
|
@@ -48,25 +49,34 @@ window.Jor1kGUI = (function () { | |
this.sendToWorker('execute', 0); | ||
} | ||
this.term.PauseBlink(pause); | ||
this.termTwo.PauseBlink(pause); | ||
}; | ||
|
||
this.terminalcanvas = document.getElementById(termId); | ||
this.terminalcanvastwo = document.getElementById(termIdTwo); | ||
|
||
this.term = new Terminal(24, 80, termId); | ||
this.terminput = new TerminalInput(new UARTDev(this)); | ||
this.termTwo = new Terminal(24, 80, termIdTwo); | ||
this.terminput = new TerminalInput(new UARTDev(this, termId)); | ||
this.terminputtwo = new TerminalInput(new UARTDev(this, termIdTwo)); | ||
|
||
this.ignoreKeys = function () { | ||
//Simpler but not as general, return( document.activeElement.type==="textarea" || document.activeElement.type==='input'); | ||
return ((this.lastMouseDownTarget !== this.terminalcanvas)); | ||
return ((this.lastMouseDownTarget !== this.terminalcanvas) && (this.lastMouseDownTarget !== this.terminalcanvastwo)); | ||
}; | ||
|
||
var recordTarget = function (event) { | ||
this.lastMouseDownTarget = event.target; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change this? Based on your hosted test setup, currently what happens is when you switch to full screen on the first (left) terminal, the focus is set to the second terminal -- hence anything you type is sent to the second (right) terminal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I forgot to fix that. I'll get around to fixing that. Compilation is most likely because terminal one is using a different TTY device, I will look into that also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your latest commit fixed it. |
||
}.bind(this); | ||
|
||
// set the focus to the terminal after toggling full screen | ||
// TODO: implement terminal switching full screen | ||
SysViewModel.getInstance().ttyFullScreen.subscribe(function () { | ||
this.lastMouseDownTarget = this.terminalcanvas; | ||
if(SysViewModel.getInstance().isPrimaryTTY()) { | ||
this.lastMouseDownTarget = this.terminalcanvas; | ||
} else { | ||
this.lastMouseDownTarget = this.terminalcanvastwo; | ||
} | ||
}, this); | ||
|
||
if(document.addEventListener) { | ||
|
@@ -80,23 +90,35 @@ window.Jor1kGUI = (function () { | |
return true; | ||
} | ||
this.sendToWorker('keypress', {keyCode:event.keyCode, charCode:event.charCode}); | ||
return this.terminput.OnKeyPress(event); | ||
if(this.lastMouseDownTarget === this.terminalcanvas) { | ||
return this.terminput.OnKeyPress(event); | ||
} else if(this.lastMouseDownTarget === this.terminalcanvastwo) { | ||
return this.terminputtwo.OnKeyPress(event); | ||
} | ||
}.bind(this); | ||
|
||
document.onkeydown = function (event) { | ||
if(this.ignoreKeys()) { | ||
return true; | ||
} | ||
this.sendToWorker('keydown', {keyCode:event.keyCode, charCode:event.charCode}); | ||
return this.terminput.OnKeyDown(event); | ||
if(this.lastMouseDownTarget === this.terminalcanvas) { | ||
return this.terminput.OnKeyDown(event); | ||
} else if(this.lastMouseDownTarget === this.terminalcanvastwo) { | ||
return this.terminputtwo.OnKeyDown(event); | ||
} | ||
}.bind(this); | ||
|
||
document.onkeyup = function (event) { | ||
if(this.ignoreKeys()) { | ||
return true; | ||
} | ||
this.sendToWorker('keyup', {keyCode:event.keyCode, charCode:event.charCode}); | ||
return this.terminput.OnKeyUp(event); | ||
if(this.lastMouseDownTarget === this.terminalcanvas) { | ||
return this.terminput.OnKeyUp(event); | ||
} else if(this.lastMouseDownTarget === this.terminalcanvastwo) { | ||
return this.terminputtwo.OnKeyUp(event); | ||
} | ||
}.bind(this); | ||
|
||
this.ethernet = new Ethernet(relayURL); | ||
|
@@ -130,6 +152,9 @@ window.Jor1kGUI = (function () { | |
case 'tty0': | ||
this.term.PutChar(e.data.data); | ||
break; | ||
case 'tty1': | ||
this.termTwo.PutChar(e.data.data); | ||
break; | ||
case 'Stop': | ||
console.log('Received stop signal'); | ||
this.stop = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the
tty
parameter to theUARTDev
constructors be the literal strings'tty0'
and'tty1'
instead oftermId
andtermIdTwo
?The uart sends the command to the worker which only understands
'tty0'
and'tty1'
- it doesn't know about the HTML element ids. It just happens that the element ids are the strings'tty0'
and'tty1'
so everything works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was deliberate on my part, I prefer not to use hardcoded constants and it makes sense if you think of a terminal canvas 'attaching' to a UART for I/O.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point. However, the way I see it is that you are supposed to use the hardcoded constants. The jor1k codebase,
sys-runtime.js
andlive-edit.js
all use these string constants to refer to the ttys. These should ideally be global constants/enums or something instead of strings. If you want to use the element ids to refer to the ttys then the ids should be constants - the element ids shouldn't then be passed in as parameters to the Jor1kGUI constructor. What happens if the HTML programmer uses some different ids and passes them to the Jor1kGUI constructor? The very fact that the ids are accepted as params means that we cannot rely on them being the constants we expect them to be. If you want to get rid of the constants entirely, then you'll need to modify jor1k itself or somehow map from the term ids to the constants. This was just my opinion, what do you think?Anyway, no changes are required, I just merged in your code.