Skip to content

Commit

Permalink
added chanmges from adamj9431#7
Browse files Browse the repository at this point in the history
  • Loading branch information
PipGrylls committed Jun 27, 2020
1 parent bac3cb7 commit 36b8760
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 6 additions & 3 deletions notebook_xterm/terminalclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function TerminalClient(elem) {
});

require(['xterm'], function(Terminal) {
this.div_id = elem.attr('id')
var termArea = this.create_ui(elem);
this.term = new Terminal({
rows: 25,
Expand Down Expand Up @@ -76,6 +77,7 @@ TerminalClient.prototype.create_ui = function(elem) {
})
this.titleText = $('<div>').html(INITIAL_TITLE).css({float: 'left'}).appendTo(this.titleBar);
this.comIndicator = $('<div>').html('&middot;').css({float: 'left', marginLeft: 10}).hide().appendTo(this.titleBar);
this.close_button = $('<div>').html('<a onclick="window.terminalClient.close()">close</a>').css({float: 'right'}).appendTo(this.titleBar);
this.termArea = $('<div>').appendTo(this.wrap);
return this.termArea;
}
Expand Down Expand Up @@ -166,13 +168,14 @@ TerminalClient.prototype.close = function() {
if (this.closed) {
return;
}
this.closed = true;
console.log('Closing notebook_xterm.');
clearTimeout(this.termPollTimer);
this.server_exec(PY_XTERM_INSTANCE + '.deleteTerminalServer()');
this.closed = true;
$("#" + this.div_id).remove()
}
// create the TerminalClient instance (only once!)
if (window.terminalClient) {
window.terminalClient.close()
delete window.terminalClient;
}
window.terminalClient = new TerminalClient($('#notebook_xterm'))
}
19 changes: 14 additions & 5 deletions notebook_xterm/xterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .terminalserver import TerminalServer
from IPython.core.display import display, HTML
from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic)
from base64 import b64encode
from uuid import uuid4

JS_FILE_NAME = 'terminalclient.js'

Expand All @@ -17,11 +19,18 @@ def xterm(self, line):
with open(jsPath) as f:
terminalClient_js = f.read()

markup = """
<div id="notebook_xterm"></div>
<script>{0}</script>
""".format(terminalClient_js)
unique_id = str(uuid4())
markup = f"""
<div id="notebook_xterm_{unique_id}"></div>
<script id="notebook_script">{terminalClient_js}
window.terminalClient = new TerminalClient($('#notebook_xterm_{unique_id}'))
</script>
"""
display(HTML(markup))
ts = self.getTerminalServer()

return self.getTerminalServer()

def getTerminalServer(self):
try:
Expand All @@ -33,4 +42,4 @@ def getTerminalServer(self):
def deleteTerminalServer(self):
if self.ts:
self.ts.close()
del self.ts
del self.ts

0 comments on commit 36b8760

Please sign in to comment.