Skip to content
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ To display a terminal, type the [magic function](http://ipython.readthedocs.io/e
%xterm
```

To display a terminal and immediately run a command in it, just place the command after the `%xterm` call:
```
%xterm ls
```

## Tested Environments
+ [IBM Data Science Experience](https://datascience.ibm.com/)
+ Jupyter 4.3.0
Expand Down
2 changes: 2 additions & 0 deletions notebook_xterm/terminalclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function TerminalClient(elem) {
this.poll_server();
console.log('Starting notebook_xterm.');

this.server_exec(PY_TERMINAL_SERVER + '.initial_transmit()');

}.bind(this));
}

Expand Down
3 changes: 3 additions & 0 deletions notebook_xterm/terminalserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def __init__(self):
flags = fcntl(self.file, F_GETFL)
fcntl(self.file, F_SETFL, flags | os.O_NONBLOCK)

def initial_transmit(self):
self.transmit(base64.b64encode(self.initial_command))

def transmit(self,data):
# data in the "channel" is b64 encoded so that control characters
# don't get lost
Expand Down
9 changes: 8 additions & 1 deletion 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)
import time
from base64 import b64encode

JS_FILE_NAME = 'terminalclient.js'

Expand All @@ -19,9 +21,14 @@ def xterm(self, line):

markup = """
<div id="notebook_xterm"></div>
<script>{0}</script>
<script id="notebook_script">{0}</script>
""".format(terminalClient_js)
display(HTML(markup))
ts = self.getTerminalServer()
ts.initial_command = bytes(line, encoding="utf-8") + b"\r"

return self.getTerminalServer()
#ts.transmit(b64encode(b"ls"))

def getTerminalServer(self):
try:
Expand Down