diff --git a/notebook_xterm/terminalclient.js b/notebook_xterm/terminalclient.js index ca13742..26e9061 100644 --- a/notebook_xterm/terminalclient.js +++ b/notebook_xterm/terminalclient.js @@ -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, @@ -76,6 +77,7 @@ TerminalClient.prototype.create_ui = function(elem) { }) this.titleText = $('
').html(INITIAL_TITLE).css({float: 'left'}).appendTo(this.titleBar); this.comIndicator = $('
').html('·').css({float: 'left', marginLeft: 10}).hide().appendTo(this.titleBar); + this.close_button = $('
').html('close').css({float: 'right'}).appendTo(this.titleBar); this.termArea = $('
').appendTo(this.wrap); return this.termArea; } @@ -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')) +} \ No newline at end of file diff --git a/notebook_xterm/xterm.py b/notebook_xterm/xterm.py index d7153a7..8080add 100644 --- a/notebook_xterm/xterm.py +++ b/notebook_xterm/xterm.py @@ -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' @@ -17,11 +19,18 @@ def xterm(self, line): with open(jsPath) as f: terminalClient_js = f.read() - markup = """ -
- - """.format(terminalClient_js) + unique_id = str(uuid4()) + markup = f""" +
+ + """ display(HTML(markup)) + ts = self.getTerminalServer() + + return self.getTerminalServer() def getTerminalServer(self): try: