Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50650 views
1
// Copyright (c) IPython Development Team.
2
// Distributed under the terms of the Modified BSD License.
3
4
require([
5
'jquery',
6
'termjs',
7
'base/js/utils',
8
'base/js/page',
9
'services/config',
10
'terminal/js/terminado',
11
'custom/custom',
12
], function(
13
$,
14
termjs,
15
utils,
16
page,
17
configmod,
18
terminado
19
){
20
"use strict";
21
page = new page.Page();
22
23
var common_config = new configmod.ConfigSection('common',
24
{base_url: utils.get_body_data('baseUrl')});
25
common_config.load();
26
27
// Test size: 25x80
28
var termRowHeight = function(){ return 1.00 * $("#dummy-screen")[0].offsetHeight / 25;};
29
// 1.02 here arrived at by trial and error to make the spacing look right
30
var termColWidth = function() { return 1.02 * $("#dummy-screen-rows")[0].offsetWidth / 80;};
31
32
var base_url = utils.get_body_data('baseUrl');
33
var ws_path = utils.get_body_data('wsPath');
34
var ws_url = location.protocol.replace('http', 'ws') + "//" + location.host
35
+ base_url + ws_path;
36
37
var header = $("#header")[0]
38
function calculate_size() {
39
var height = $(window).height() - header.offsetHeight;
40
var width = $('#terminado-container').width();
41
var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight())-1));
42
var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth())-1));
43
console.log("resize to :", rows , 'rows by ', cols, 'columns');
44
return {rows: rows, cols: cols};
45
}
46
47
page.show_header();
48
49
var size = calculate_size();
50
var terminal = terminado.make_terminal($("#terminado-container")[0], size, ws_url);
51
52
page.show_site();
53
54
utils.load_extensions_from_config(common_config);
55
56
window.onresize = function() {
57
var geom = calculate_size();
58
terminal.term.resize(geom.cols, geom.rows);
59
terminal.socket.send(JSON.stringify(["set_size", geom.rows, geom.cols,
60
$(window).height(), $(window).width()]));
61
};
62
63
});
64
65