Commit 4ae2a336 by Sheng

Added resize_terminal function to wssh

parent e0cc2091
...@@ -30,19 +30,10 @@ jQuery(function($){ ...@@ -30,19 +30,10 @@ jQuery(function($){
} }
function resize_term(term, sock) { wssh.window_size = function() {
var geometry = current_geometry(), var geo = current_geometry();
cols = geometry.cols, console.log('Current window size: ' + geo.cols + ',' + geo.rows);
rows = geometry.rows; };
// console.log([cols, rows]);
// console.log(term.geometry);
if (cols !== term.geometry[0] || rows !== term.geometry[1]) {
console.log('resizing term');
term.resize(cols, rows);
sock.send(JSON.stringify({'resize': [cols, rows]}));
}
}
function callback(msg) { function callback(msg) {
...@@ -67,10 +58,15 @@ jQuery(function($){ ...@@ -67,10 +58,15 @@ jQuery(function($){
console.log(url); console.log(url);
console.log('The deault encoding of your server is ' + encoding); console.log('The deault encoding of your server is ' + encoding);
wssh.sock = sock; // wssh.sock = sock;
wssh.term = term; // wssh.term = term;
var test_decoder; var test_decoder;
function resize_terminal (term) {
var geometry = current_geometry();
term.on_resize(geometry.cols, geometry.rows);
}
wssh.set_encoding = function (new_encoding) { wssh.set_encoding = function (new_encoding) {
try { try {
test_decoder = new window.TextDecoder(new_encoding); test_decoder = new window.TextDecoder(new_encoding);
...@@ -90,6 +86,34 @@ jQuery(function($){ ...@@ -90,6 +86,34 @@ jQuery(function($){
console.log('Reset encoding to ' + msg.encoding); console.log('Reset encoding to ' + msg.encoding);
}; };
wssh.resize_terminal = function (raw_cols, raw_rows) {
// for console use
var cols = parseInt(raw_cols, 10),
rows = parseInt(raw_rows, 10),
valid_args = false;
if (cols > 0 && rows > 0) {
var geometry = current_geometry();
if (cols <= geometry.cols && rows <= geometry.rows) {
valid_args = true;
}
}
if (!valid_args) {
console.log('Invalid arguments: ' + raw_cols + ',' + raw_rows);
} else {
term.on_resize(cols, rows);
}
};
term.on_resize = function (cols, rows) {
if (cols !== this.geometry[0] || rows !== this.geometry[1]) {
console.log('Resizing terminal size to: ' + cols + ',' + rows);
this.resize(cols, rows);
sock.send(JSON.stringify({'resize': [cols, rows]}));
}
};
term.on('data', function(data) { term.on('data', function(data) {
// console.log(data); // console.log(data);
sock.send(JSON.stringify({'data': data})); sock.send(JSON.stringify({'data': data}));
...@@ -110,7 +134,7 @@ jQuery(function($){ ...@@ -110,7 +134,7 @@ jQuery(function($){
// console.log(text); // console.log(text);
term.write(text); term.write(text);
if (!term.resized) { if (!term.resized) {
resize_term(term, sock); resize_terminal(term);
term.resized = true; term.resized = true;
} }
}; };
...@@ -125,12 +149,14 @@ jQuery(function($){ ...@@ -125,12 +149,14 @@ jQuery(function($){
sock.onclose = function(e) { sock.onclose = function(e) {
console.log(e); console.log(e);
term.destroy(); term.destroy();
wssh.term = undefined;
wssh.sock = undefined;
$('.container').show(); $('.container').show();
status.text(e.reason); status.text(e.reason);
btn.prop('disabled', false); btn.prop('disabled', false);
}; };
$(window).resize(function(){
resize_terminal(term);
});
} }
...@@ -165,14 +191,5 @@ jQuery(function($){ ...@@ -165,14 +191,5 @@ jQuery(function($){
contentType: false, contentType: false,
processData: false processData: false
}); });
}); });
$(window).resize(function(){
if (wssh.term && wssh.sock) {
resize_term(wssh.term, wssh.sock);
}
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment