Skip to content
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

Allow multiple terminals in one notebook #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))
}
17 changes: 13 additions & 4 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 Down