Skip to content

Commit 4285574

Browse files
authored
Merge pull request jupyter#3189 from cancan101/patch-2
Upgrade xterm.js to 3.1.0
2 parents 331a7a2 + 91794ec commit 4285574

File tree

8 files changed

+36
-77
lines changed

8 files changed

+36
-77
lines changed

bower.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
"requirejs-plugins": "~1.0.3",
2525
"text-encoding": "~0.1",
2626
"underscore": "components/underscore#~1.8.3",
27-
"xterm.js": "sourcelair/xterm.js#~2.9.2"
27+
"xterm.js": "https://unpkg.com/xterm@~3.1.0/dist/xterm.js",
28+
"xterm.js-css": "https://unpkg.com/xterm@~3.1.0/dist/xterm.css",
29+
"xterm.js-fit": "https://unpkg.com/xterm@~3.1.0/dist/addons/fit/fit.js"
2830
}
2931
}

notebook/static/terminal/js/main.js

+6-22
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ requirejs([
2929
var common_config = new configmod.ConfigSection('common', common_options);
3030
common_config.load();
3131

32+
// This makes the 'logout' button in the top right work.
3233
var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options);
3334

34-
// Test size: 25x80
35-
var termRowHeight = function(){ return 1.00 * $("#dummy-screen")[0].offsetHeight / 25;};
36-
// 1.02 here arrived at by trial and error to make the spacing look right
37-
var termColWidth = function() { return 1.02 * $("#dummy-screen-rows")[0].offsetWidth / 80;};
38-
3935
var base_url = utils.get_body_data('baseUrl').replace(/\/?$/, '/');
4036
var ws_path = utils.get_body_data('wsPath');
4137
var ws_url = utils.get_body_data('wsUrl');
@@ -45,31 +41,19 @@ requirejs([
4541
}
4642
ws_url = ws_url + base_url + ws_path;
4743

48-
var header = $("#header")[0];
49-
50-
function calculate_size() {
51-
var height = $(window).height() - header.offsetHeight;
52-
var width = $('#terminado-container').width();
53-
var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight())-1));
54-
var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth())-1));
55-
console.log("resize to :", rows , 'rows by ', cols, 'columns');
56-
return {rows: rows, cols: cols};
57-
}
58-
5944
page.show_header();
6045

61-
var size = calculate_size();
62-
var terminal = terminado.make_terminal($("#terminado-container")[0], size, ws_url);
46+
var terminal = terminado.make_terminal($("#terminado-container")[0], ws_url);
6347

6448
page.show_site();
6549

6650
utils.load_extensions_from_config(config);
6751
utils.load_extensions_from_config(common_config);
6852

69-
window.onresize = function() {
70-
var geom = calculate_size();
71-
terminal.term.resize(geom.cols, geom.rows);
72-
terminal.socket.send(JSON.stringify(["set_size", geom.rows, geom.cols,
53+
window.onresize = function() {
54+
terminal.term.fit();
55+
// send the new size to the server so that it can trigger a resize in the running process.
56+
terminal.socket.send(JSON.stringify(["set_size", terminal.term.rows, terminal.term.cols,
7357
$(window).height(), $(window).width()]));
7458
};
7559

notebook/static/terminal/js/terminado.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
define (["xterm"], function(Terminal) {
1+
define (["xterm", "xtermjs-fit"], function(Terminal, fit) {
22
"use strict";
3-
function make_terminal(element, size, ws_url) {
3+
function make_terminal(element, ws_url) {
44
var ws = new WebSocket(ws_url);
5-
var term = new Terminal({
6-
cols: size.cols,
7-
rows: size.rows
8-
});
5+
Terminal.applyAddon(fit);
6+
var term = new Terminal();
97
ws.onopen = function(event) {
10-
ws.send(JSON.stringify(["set_size", size.rows, size.cols,
11-
window.innerHeight, window.innerWidth]));
128
term.on('data', function(data) {
139
ws.send(JSON.stringify(['stdin', data]));
1410
});
@@ -18,7 +14,11 @@ define (["xterm"], function(Terminal) {
1814
});
1915

2016
term.open(element);
21-
17+
term.fit();
18+
// send the terminal size to the server.
19+
ws.send(JSON.stringify(["set_size", term.rows, term.cols,
20+
window.innerHeight, window.innerWidth]));
21+
2222
ws.onmessage = function(event) {
2323
var json_msg = JSON.parse(event.data);
2424
switch(json_msg[0]) {

notebook/static/terminal/less/terminal.less

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515
padding: @code_padding;
1616
border-radius: @border-radius-base;
1717
.box-shadow(@global-shadow-dark);
18+
line-height: 1em;
19+
font-size: @notebook_font_size;
1820

19-
&, dummy-screen {
20-
line-height: 1em;
21-
font-size: @notebook_font_size;
22-
}
23-
2421
.xterm-rows {
2522
padding: 10px;
2623
}
@@ -31,7 +28,12 @@
3128
background: white;
3229
}
3330

31+
.terminado-container-container {
32+
padding-top: @page-header-padding;
33+
height: 100%;
34+
}
35+
3436
#terminado-container {
35-
margin-top: @page-header-padding;
37+
height: 100%;
3638
}
3739
}

notebook/templates/page.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'jquery-ui': 'components/jquery-ui/ui/minified/jquery-ui.min',
4343
moment: 'components/moment/min/moment-with-locales',
4444
codemirror: 'components/codemirror',
45-
termjs: 'components/xterm.js/dist/xterm',
45+
termjs: 'components/xterm.js/xterm',
4646
typeahead: 'components/jquery-typeahead/dist/jquery.typeahead.min',
4747
},
4848
map: { // for backward compatibility

notebook/templates/terminal.html

+4-35
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,21 @@
1515
{% block stylesheet %}
1616
{{super()}}
1717
<link rel="stylesheet" href="{{ static_url("terminal/css/override.css") }}" type="text/css" />
18-
<link rel="stylesheet" href="{{static_url("components/xterm.js/dist/xterm.css") }}" type="text/css" />
18+
<link rel="stylesheet" href="{{static_url("components/xterm.js-css/index.css") }}" type="text/css" />
1919
{% endblock %}
2020

2121
{% block headercontainer %}
2222
<span id="save_widget" class="save_widget"></span>
2323
{% endblock headercontainer %}
2424

2525
{% block site %}
26-
<div id="terminado-container" class="container"></div>
26+
<div class="terminado-container-container">
27+
<div id="terminado-container" class="container"></div>
28+
</div>
2729
{% endblock %}
2830

2931
{% block script %}
3032

31-
<!-- Hack: this needs to be outside the display:none block, so we can measure
32-
its size in JS in setting up the page. It is still invisible. Putting in
33-
the script block gets it outside the initially undisplayed region. -->
34-
<!-- test size: 25x80 -->
35-
<div style='position:absolute; left:-1000em'>
36-
<pre id="dummy-screen" style="border: solid 5px white;" class="terminal">0
37-
1
38-
2
39-
3
40-
4
41-
5
42-
6
43-
7
44-
8
45-
9
46-
0
47-
1
48-
2
49-
3
50-
4
51-
5
52-
6
53-
7
54-
8
55-
9
56-
0
57-
1
58-
2
59-
3
60-
<span id="dummy-screen-rows" style="">01234567890123456789012345678901234567890123456789012345678901234567890123456789</span>
61-
</pre>
62-
</div>
63-
6433
{{super()}}
6534

6635
<script src="{{ static_url("terminal/js/main.min.js") }}" type="text/javascript" charset="utf-8"></script>

setupbase.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ def find_package_data():
157157
pjoin(components, "underscore", "underscore-min.js"),
158158
pjoin(components, "moment", "moment.js"),
159159
pjoin(components, "moment", "min", "*.js"),
160-
pjoin(components, "xterm.js", "dist", "xterm.js"),
161-
pjoin(components, "xterm.js", "dist", "xterm.css"),
160+
pjoin(components, "xterm.js", "index.js"),
161+
pjoin(components, "xterm.js-css", "index.css"),
162+
pjoin(components, "xterm.js-fit", "index.js"),
162163
pjoin(components, "text-encoding", "lib", "encoding.js"),
163164
])
164165

tools/build-main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ var rjs_config = {
2424
"jquery-ui": 'components/jquery-ui/ui/minified/jquery-ui.min',
2525
moment: 'components/moment/min/moment-with-locales',
2626
codemirror: 'components/codemirror',
27-
xterm: 'components/xterm.js/dist/xterm',
27+
xterm: 'components/xterm.js/index',
28+
'xtermjs-fit': 'components/xterm.js-fit/index',
2829
typeahead: 'components/jquery-typeahead/dist/jquery.typeahead',
2930
contents: 'empty:',
3031
custom: 'empty:',

0 commit comments

Comments
 (0)