##// END OF EJS Templates
Terminal basically working...
Thomas Kluyver -
Show More
@@ -0,0 +1,7 b''
1 /*This file contains any manual css for this page that needs to override the global styles.
2 This is only required when different pages style the same element differently. This is just
3 a hack to deal with our current css styles and no new styling should be added in this file.*/
4
5 #terminado-container {
6 margin: 8px;
7 }
@@ -0,0 +1,39 b''
1 define ([], function() {
2 function make_terminal(element, size, ws_url) {
3 var ws = new WebSocket(ws_url);
4 var term = new Terminal({
5 cols: size.cols,
6 rows: size.rows,
7 screenKeys: true,
8 useStyle: true
9 });
10 ws.onopen = function(event) {
11 ws.send(JSON.stringify(["set_size", size.rows, size.cols,
12 window.innerHeight, window.innerWidth]));
13 term.on('data', function(data) {
14 ws.send(JSON.stringify(['stdin', data]));
15 });
16
17 term.on('title', function(title) {
18 document.title = title;
19 });
20
21 term.open(element);
22
23 ws.onmessage = function(event) {
24 json_msg = JSON.parse(event.data);
25 switch(json_msg[0]) {
26 case "stdout":
27 term.write(json_msg[1]);
28 break;
29 case "disconnect":
30 term.write("\r\n\r\n[CLOSED]\r\n");
31 break;
32 }
33 };
34 };
35 return {socket: ws, term: term};
36 }
37
38 return {make_terminal: make_terminal};
39 });
@@ -4,9 +4,50 b''
4 require([
4 require([
5 'jquery',
5 'jquery',
6 'termjs',
6 'termjs',
7 'base/js/utils',
8 'base/js/page',
9 'terminal/js/terminado',
7 'custom/custom',
10 'custom/custom',
8 ], function(
11 ], function(
9 $,
12 $,
10 termjs){
13 termjs,
14 utils,
15 page,
16 terminado
17 ){
18 page = new page.Page();
19 // Test size: 25x80
20 var termRowHeight = 1.00 * $("#dummy-screen")[0].offsetHeight / 25;
21 var termColWidth = 1.02 * $("#dummy-screen-rows")[0].offsetWidth / 80;
22 $("#dummy-screen").hide();
23
24 var base_url = utils.get_body_data('baseUrl');
25 var ws_url = location.protocol.replace('http', 'ws') + "//" + location.host
26 + base_url + "terminal/websocket";
27
28 var header = $("#header")[0]
29 function calculate_size() {
30 height = window.innerHeight - header.offsetHeight;
31 width = window.innerWidth;
32 var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight)-1));
33 var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth)-1));
34 console.log("resize:", termRowHeight, termColWidth, height, width,
35 rows, cols);
36 return {rows: rows, cols: cols};
37 }
38
39 page.show_header();
40
41 size = calculate_size();
42 var terminal = terminado.make_terminal($("#terminado-container")[0], size, ws_url);
43
44 page.show_site();
45
46 window.onresize = function() {
47 var geom = calculate_size();
48 terminal.term.resize(geom.cols, geom.rows);
49 terminal.socket.send(JSON.stringify(["set_size", geom.rows, geom.cols,
50 window.innerHeight, window.innerWidth]));
51 };
11
52
12 });
53 });
@@ -2,6 +2,10 b''
2
2
3 {% block title %}{{page_title}}{% endblock %}
3 {% block title %}{{page_title}}{% endblock %}
4
4
5 {% block stylesheet %}
6 {{super()}}
7 <link rel="stylesheet" href="{{ static_url("terminal/css/override.css") }}" type="text/css" />
8 {% endblock %}
5
9
6 {% block params %}
10 {% block params %}
7
11
@@ -12,15 +16,43 b' data-base-url="{{base_url}}"'
12
16
13 {% block site %}
17 {% block site %}
14
18
15 <div id="ipython-main-app" class="container">
19 <div id="terminado-container"></div>
16
17 <div id="terminado-container"/>
18
19 </div>
20
20
21 {% endblock %}
21 {% endblock %}
22
22
23 {% block script %}
23 {% block script %}
24
25 <!-- Hack: this needs to be outside the display:none block, so we can measure
26 its size in JS in setting up the page. It is still invisible. Putting in
27 the script block gets it outside the initially undisplayed region. -->
28 <!-- test size: 25x80 -->
29 <pre id="dummy-screen" style="visibility:hidden; border: white solid 5px; font-family: &quot;DejaVu Sans Mono&quot;, &quot;Liberation Mono&quot;, monospace; font-size: 11px;">0
30 1
31 2
32 3
33 4
34 5
35 6
36 7
37 8
38 9
39 0
40 1
41 2
42 3
43 4
44 5
45 6
46 7
47 8
48 9
49 0
50 1
51 2
52 3
53 <span id="dummy-screen-rows" style="visibility:hidden;">01234567890123456789012345678901234567890123456789012345678901234567890123456789</span>
54 </pre>
55
24 {{super()}}
56 {{super()}}
25
57
26 <script src="{{ static_url("terminal/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
58 <script src="{{ static_url("terminal/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
@@ -4,9 +4,9 b''
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 from tornado import web
6 from tornado import web
7 import terminado
7 from ..base.handlers import IPythonHandler
8 from ..base.handlers import IPythonHandler
8
9
9
10 class TerminalHandler(IPythonHandler):
10 class TerminalHandler(IPythonHandler):
11 """Render the tree view, listing notebooks, clusters, etc."""
11 """Render the tree view, listing notebooks, clusters, etc."""
12 @web.authenticated
12 @web.authenticated
@@ -21,4 +21,6 b' class TerminalHandler(IPythonHandler):'
21
21
22 default_handlers = [
22 default_handlers = [
23 (r"/terminal", TerminalHandler),
23 (r"/terminal", TerminalHandler),
24 (r"/terminal/websocket", terminado.TermSocket,
25 {'term_manager': terminado.SingleTermManager(shell_command=['bash'])}),
24 ]
26 ]
General Comments 0
You need to be logged in to leave comments. Login now