Skip to content

Commit e935155

Browse files
committed
webrepl.html: Automatically resize the terminal to fill the window.
The terminal widget is resized depending on the size of its containing window. The minimum size is 80x24 characters and the maximum is 150x80 (these numbers can be tuned if needed). There is also a small margin on the right side and the bottom.
1 parent 85557fb commit e935155

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Diff for: webrepl.html

+14-3
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,28 @@
5454
var ws;
5555
var connected = false;
5656

57+
function calculate_size(win) {
58+
var cols = Math.max(80, Math.min(150, (win.innerWidth - 40) / 7)) | 0;
59+
var rows = Math.max(24, Math.min(80, (win.innerHeight - 180) / 12)) | 0;
60+
return [cols, rows];
61+
}
62+
5763
(function() {
5864
window.onload = function() {
65+
var size = calculate_size(self);
5966
term = new Terminal({
60-
cols: 80,
61-
rows: 24,
67+
cols: size[0],
68+
rows: size[1],
6269
useStyle: true,
6370
screenKeys: true,
6471
cursorBlink: false
6572
});
6673
term.open(document.getElementById("term"));
67-
}
74+
};
75+
window.addEventListener('resize', function() {
76+
var size = calculate_size(self);
77+
term.resize(size[0], size[1]);
78+
});
6879
}).call(this);
6980

7081
function button_click() {

0 commit comments

Comments
 (0)