From 2293b76a6a4c9a8c1c544a1431dcd5d5aab21045 Mon Sep 17 00:00:00 2001 From: Robin Wilson Date: Fri, 24 Apr 2020 17:07:50 +0100 Subject: [PATCH 1/5] Added close button --- notebook_xterm/terminalclient.js | 1 + 1 file changed, 1 insertion(+) diff --git a/notebook_xterm/terminalclient.js b/notebook_xterm/terminalclient.js index ca13742..0fc054a 100644 --- a/notebook_xterm/terminalclient.js +++ b/notebook_xterm/terminalclient.js @@ -76,6 +76,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; } From db2072ea2cca7a8ffbb2751e2803e708f6d65d9b Mon Sep 17 00:00:00 2001 From: Robin Wilson Date: Fri, 24 Apr 2020 17:07:58 +0100 Subject: [PATCH 2/5] Add code to remove div when closed, so we can open another one --- notebook_xterm/terminalclient.js | 1 + 1 file changed, 1 insertion(+) diff --git a/notebook_xterm/terminalclient.js b/notebook_xterm/terminalclient.js index 0fc054a..c698229 100644 --- a/notebook_xterm/terminalclient.js +++ b/notebook_xterm/terminalclient.js @@ -170,6 +170,7 @@ TerminalClient.prototype.close = function() { console.log('Closing notebook_xterm.'); clearTimeout(this.termPollTimer); this.server_exec(PY_XTERM_INSTANCE + '.deleteTerminalServer()'); + $('#notebook_xterm').remove() this.closed = true; } // create the TerminalClient instance (only once!) From 209442c5da312c546659a51f90213406fb7bc37c Mon Sep 17 00:00:00 2001 From: Robin Wilson Date: Sun, 26 Apr 2020 22:07:49 +0100 Subject: [PATCH 3/5] Stop closing loop --- notebook_xterm/terminalclient.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notebook_xterm/terminalclient.js b/notebook_xterm/terminalclient.js index c698229..2378b78 100644 --- a/notebook_xterm/terminalclient.js +++ b/notebook_xterm/terminalclient.js @@ -167,11 +167,12 @@ 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()'); $('#notebook_xterm').remove() - this.closed = true; + } // create the TerminalClient instance (only once!) if (window.terminalClient) { From 34deb5c69a0d37e1d9c26225f37d0dd381ab4420 Mon Sep 17 00:00:00 2001 From: Robin Wilson Date: Mon, 27 Apr 2020 16:24:11 +0100 Subject: [PATCH 4/5] Use unique ID for each notebook_xterm div, so we can have multiple divs at a time --- notebook_xterm/terminalclient.js | 8 ++++---- notebook_xterm/xterm.py | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/notebook_xterm/terminalclient.js b/notebook_xterm/terminalclient.js index 2378b78..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, @@ -171,11 +172,10 @@ TerminalClient.prototype.close = function() { console.log('Closing notebook_xterm.'); clearTimeout(this.termPollTimer); this.server_exec(PY_XTERM_INSTANCE + '.deleteTerminalServer()'); - $('#notebook_xterm').remove() - + $("#" + 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..85b974c 100644 --- a/notebook_xterm/xterm.py +++ b/notebook_xterm/xterm.py @@ -5,6 +5,12 @@ from .terminalserver import TerminalServer from IPython.core.display import display, HTML from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic) +<<<<<<< HEAD +======= +import time +from base64 import b64encode +from uuid import uuid4 +>>>>>>> fb13e00... Use unique ID for each notebook_xterm div, so we can have multiple divs at a time JS_FILE_NAME = 'terminalclient.js' @@ -17,11 +23,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: From f81f4b473acf10fc1579b3dfe2ac95ad8ce71559 Mon Sep 17 00:00:00 2001 From: Robin Wilson Date: Tue, 28 Apr 2020 20:01:26 +0100 Subject: [PATCH 5/5] Fix incorrect merge --- notebook_xterm/xterm.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/notebook_xterm/xterm.py b/notebook_xterm/xterm.py index 85b974c..8080add 100644 --- a/notebook_xterm/xterm.py +++ b/notebook_xterm/xterm.py @@ -5,12 +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) -<<<<<<< HEAD -======= -import time from base64 import b64encode from uuid import uuid4 ->>>>>>> fb13e00... Use unique ID for each notebook_xterm div, so we can have multiple divs at a time JS_FILE_NAME = 'terminalclient.js'