Bladeren bron

Add a terminal example

Steven Silvester 9 jaren geleden
bovenliggende
commit
09e601b56e

+ 149 - 0
examples/terminal/index.css

@@ -0,0 +1,149 @@
+/*-----------------------------------------------------------------------------
+| Copyright (c) Jupyter Development Team.
+| Distributed under the terms of the Modified BSD License.
+|----------------------------------------------------------------------------*/
+.jp-TerminalWidget {
+  min-width: 50px;
+  min-height: 500px;
+}
+
+.jp-TerminalWidget-body {
+  padding: 0.5em;
+}
+
+
+/*-----------------------------------------------------------------------------
+| Copyright (c) 2014-2015, PhosphorJS Contributors
+|
+| Distributed under the terms of the BSD 3-Clause License.
+|
+| The full license is in the file LICENSE, distributed with this software.
+|----------------------------------------------------------------------------*/
+body {
+  margin: 0;
+  padding: 0;
+  background: #F5F6F7;
+  overflow: hidden;
+}
+
+
+#main {
+  position: absolute;
+  top: 10px;
+  left: 10px;
+  right: 10px;
+  bottom: 10px;
+}
+
+
+.p-DockTabPanel {
+  padding-right: 2px;
+  padding-bottom: 2px;
+}
+
+
+.p-DockTabPanel > .p-StackedPanel {
+  padding: 10px;
+  background: white;
+  border: 1px solid #C0C0C0;
+  border-top: none;
+  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
+}
+
+
+.p-DockPanel-overlay {
+  background: rgba(255, 255, 255, 0.6);
+  border: 1px dashed black;
+}
+
+
+.p-DockPanel-overlay.p-mod-root-top,
+.p-DockPanel-overlay.p-mod-root-left,
+.p-DockPanel-overlay.p-mod-root-right,
+.p-DockPanel-overlay.p-mod-root-bottom,
+.p-DockPanel-overlay.p-mod-root-center {
+  border-width: 2px;
+}
+
+
+.p-TabBar {
+  min-height: 24px;
+  max-height: 24px;
+}
+
+
+.p-TabBar-header {
+  display: none;
+}
+
+
+.p-TabBar-footer {
+  flex: 0 0 1px;
+  background: #C0C0C0;
+}
+
+
+.p-TabBar-content {
+  min-width: 0;
+  align-items: flex-end;
+}
+
+
+.p-TabBar-tab {
+  flex: 0 1 125px;
+  min-height: 20px;
+  max-height: 20px;
+  min-width: 35px;
+  margin-left: -1px;
+  border: 1px solid #C0C0C0;
+  border-bottom: none;
+  padding: 0px 10px;
+  background: #E5E5E5;
+  font: 12px Helvetica, Arial, sans-serif;
+}
+
+
+.p-TabBar-tab:first-child {
+  margin-left: 0;
+}
+
+
+.p-TabBar-tab.p-mod-current {
+  min-height: 23px;
+  max-height: 23px;
+  background: white;
+  transform: translateY(1px);
+}
+
+
+.p-TabBar-tab:hover:not(.p-mod-current) {
+  background: #F0F0F0;
+}
+
+
+.p-TabBar-tabIcon,
+.p-TabBar-tabText,
+.p-TabBar-tabCloseIcon {
+  line-height: 20px;
+}
+
+
+.p-TabBar-tab.p-mod-closable > .p-TabBar-tabCloseIcon {
+  margin-left: 4px;
+}
+
+
+.p-TabBar-tab.p-mod-closable > .p-TabBar-tabCloseIcon:before {
+  content: '\f00d';
+  font-family: FontAwesome;
+}
+
+
+.p-TabBar-tab.p-mod-drag-image {
+  min-height: 23px;
+  max-height: 23px;
+  min-width: 125px;
+  border: none;
+  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
+  transform: translateX(-40%) translateY(-58%);
+}

+ 13 - 0
examples/terminal/index.html

@@ -0,0 +1,13 @@
+<!doctype html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <link rel="stylesheet" type="text/css" href="index.css">
+    <title>Jupyter Terminal Demo</title>
+  </head>
+  <body>
+    <script id='jupyter-config-data' type="application/json">{ "wsUrl": "{{ws_url}}" }</script>
+    <script src="build/bundle.js"></script>
+
+  </body>
+</html>

+ 84 - 0
examples/terminal/main.py

@@ -0,0 +1,84 @@
+"""
+Copyright (c) Jupyter Development Team.
+Distributed under the terms of the Modified BSD License.
+"""
+import re
+import subprocess
+import sys
+import threading
+import tornado.web
+
+PORT = 8765
+
+
+class MainPageHandler(tornado.web.RequestHandler):
+
+    def initialize(self, ws_url):
+        self.ws_url = ws_url
+
+    def get(self):
+        return self.render("index.html", static=self.static_url,
+                           ws_url=self.ws_url)
+
+
+def main(argv):
+
+    url = "http://localhost:%s" % PORT
+
+    nb_command = [sys.executable, '-m', 'notebook', '--no-browser', '--debug',
+                  '--NotebookApp.allow_origin="%s"' % url]
+    nb_server = subprocess.Popen(nb_command, stderr=subprocess.STDOUT,
+                                 stdout=subprocess.PIPE)
+
+    # wait for notebook server to start up
+    while 1:
+        line = nb_server.stdout.readline().decode('utf-8').strip()
+        if not line:
+            continue
+        print(line)
+        if 'Jupyter Notebook is running at:' in line:
+            host = re.search('http(.*?)$', line).groups()[0]
+            ws_url = 'ws' + host
+            break
+
+    while 1:
+        line = nb_server.stdout.readline().decode('utf-8').strip()
+        if not line:
+            continue
+        print(line)
+        if 'Control-C' in line:
+            break
+
+    def print_thread():
+        while 1:
+            line = nb_server.stdout.readline().decode('utf-8').strip()
+            if not line:
+                continue
+            print(line)
+    thread = threading.Thread(target=print_thread)
+    thread.setDaemon(True)
+    thread.start()
+
+    handlers = [
+        (r"/", MainPageHandler, {'ws_url': ws_url}),
+        (r'/(.*)', tornado.web.StaticFileHandler,
+         {'path': '.'}),
+    ]
+
+    app = tornado.web.Application(handlers, static_path='build',
+                                  template_path='.',
+                                  compiled_template_cache=False)
+
+    app.listen(PORT, 'localhost')
+    loop = tornado.ioloop.IOLoop.instance()
+    print('Browse to http://localhost:%s' % PORT)
+    try:
+        loop.start()
+    except KeyboardInterrupt:
+        print(" Shutting down on SIGINT")
+    finally:
+        nb_server.kill()
+        loop.close()
+
+if __name__ == '__main__':
+    main(sys.argv)

+ 24 - 0
examples/terminal/package.json

@@ -0,0 +1,24 @@
+{
+  "private": true,
+  "name": "terminal-example",
+  "dependencies": {
+    "phosphor-dockpanel": "^0.9.6",
+    "jupyter-js-ui": "file:../.."
+  },
+  "scripts": {
+    "build": "tsc --project src && webpack --config webpack.conf.js",
+    "clean": "rimraf build && rimraf node_modules",
+    "postinstall": "npm dedupe",
+    "update": "rimraf node_modules/jupyter-js-ui && npm install",
+    "watch:src": "watch 'npm run build' src --wait 5",
+    "watch": "concurrently 'npm run watch:src' 'python main.py'"
+  },
+  "devDependencies": {
+    "concurrently": "^2.0.0",
+    "css-loader": "^0.23.1",
+    "rimraf": "^2.5.2",
+    "style-loader": "^0.13.0",
+    "watch": "^0.17.1",
+    "webpack": "^1.12.14"
+  }
+}

+ 35 - 0
examples/terminal/src/index.ts

@@ -0,0 +1,35 @@
+/*-----------------------------------------------------------------------------
+| Copyright (c) 2014-2015, Jupyter Development Team.
+|
+| Distributed under the terms of the Modified BSD License.
+|----------------------------------------------------------------------------*/
+'use strict';
+
+import {
+  DockPanel
+} from 'phosphor-dockpanel';
+
+
+import {
+  TerminalWidget
+} from 'jupyter-js-ui/lib/terminal';
+
+
+function main(): void {
+  let term1 = new TerminalWidget({ background: 'black',
+                                  color: 'white'});
+  let term2 = new TerminalWidget({ background: 'white',
+                                  color: 'black'});
+
+  let dock = new DockPanel();
+  dock.insertTabBefore(term1);
+  dock.insertTabBefore(term2);
+
+  dock.attach(document.body);
+  dock.id = 'main';
+
+  window.onresize = () => dock.fit();
+}
+
+
+window.onload = main;

+ 15 - 0
examples/terminal/src/tsconfig.json

@@ -0,0 +1,15 @@
+{
+  "compilerOptions": {
+    "noImplicitAny": true,
+    "noEmitOnError": true,
+    "module": "commonjs",
+    "moduleResolution": "node",
+    "target": "ES5",
+    "outDir": "../build"
+  },
+  "files": [
+    "../../../src/typings/term.js/term.js.d.ts",
+    "../../../src/typings/es6-promise.d.ts",
+    "index.ts"
+  ]
+}

+ 17 - 0
examples/terminal/webpack.conf.js

@@ -0,0 +1,17 @@
+
+module.exports = {
+  entry: './build/index.js',
+  output: {
+    path: './build',
+    filename: 'bundle.js'
+  },
+  node: {
+    fs: "empty"
+  },
+  bail: true,
+  module: {
+    loaders: [
+      { test: /\.css$/, loader: 'style-loader!css-loader' },
+    ]
+  }
+}