手动修改窗口大小问题

This commit is contained in:
liuzheng712
2016-04-05 10:53:35 +08:00
parent f65290ef38
commit 0499a7265a
5 changed files with 103 additions and 51 deletions

View File

@@ -56,7 +56,12 @@ NgApp.controller('TerminalRecordCtrl', function ($scope, $http) {
document.getElementById("beforeScrubberText").innerHTML = buildTimeString(time);
for (; pos < timelist.length; pos++) {
if (timelist[pos] * 1000 <= time) {
term.write(data[timelist[pos]]);
try{
var findResize = JSON.parse(data[timelist[pos]])['reszie'];
term.resize(findResize['cols'], findResize['rows'])
} catch (err) {
term.write(data[timelist[pos]]);
}
} else {
break;
}

View File

@@ -36,7 +36,7 @@ WSSHClient.prototype.connect = function (options) {
};
this._connection.onmessage = function (evt) {
try{
try {
options.onData(evt.data);
} catch (e) {
var data = JSON.parse(evt.data.toString());
@@ -55,6 +55,15 @@ WSSHClient.prototype.send = function (data) {
function openTerminal(options) {
var client = new WSSHClient();
var rowHeight, colWidth;
try {
rowHeight = localStorage.getItem('term-row');
colWidth = localStorage.getItem('term-col');
} catch (err) {
rowHeight = 24;
colWidth = 80
}
var term = new Terminal({
rows: rowHeight,
cols: colWidth,
@@ -66,7 +75,7 @@ function openTerminal(options) {
client.send(data)
});
$('.terminal').detach().appendTo('#term');
term.resize(80, 24);
//term.resize(colWidth, rowHeight);
term.write('Connecting...');
client.connect($.extend(options, {
onError: function (error) {
@@ -74,6 +83,7 @@ function openTerminal(options) {
},
onConnect: function () {
// Erase our connecting message
client.send({'resize': {'rows': rowHeight, 'cols': colWidth}});
term.write('\r');
},
onClose: function () {
@@ -83,20 +93,20 @@ function openTerminal(options) {
term.write(data);
}
}));
rowHeight = 0.0 + 1.00 * $('.terminal').height() / 24;
colWidth = 0.0 + 1.00 * $('.terminal').width() / 80;
//rowHeight = 0.0 + 1.00 * $('.terminal').height() / 24;
//colWidth = 0.0 + 1.00 * $('.terminal').width() / 80;
return {'term': term, 'client': client};
}
function resize() {
$('.terminal').css('width', window.innerWidth - 25);
console.log(window.innerWidth);
console.log(window.innerWidth - 10);
var rows = Math.floor(window.innerHeight / rowHeight) - 2;
var cols = Math.floor(window.innerWidth / colWidth) - 1;
return {rows: rows, cols: cols};
}
//function resize() {
// $('.terminal').css('width', window.innerWidth - 25);
// console.log(window.innerWidth);
// console.log(window.innerWidth - 10);
// var rows = Math.floor(window.innerHeight / rowHeight) - 2;
// var cols = Math.floor(window.innerWidth / colWidth) - 1;
//
// return {rows: rows, cols: cols};
//}
$(document).ready(function () {
var options = {};
@@ -112,5 +122,21 @@ $(document).ready(function () {
// term_client.client.send({'resize': {'rows': geom.rows, 'cols': geom.cols}});
// $('#ssh').show();
//}
try {
$('#term-row')[0].value = localStorage.getItem('term-row');
$('#term-col')[0].value = localStorage.getItem('term-col');
} catch (err) {
$('#term-row')[0].value = 24;
$('#term-col')[0].value = 80;
}
$('#col-row').click(function () {
var col = $('#term-col').val();
var row = $('#term-row').val();
localStorage.setItem('term-col', col);
localStorage.setItem('term-row', row);
term_client.term.resize(col, row);
term_client.client.send({'resize': {'rows': row, 'cols': col}});
$('#ssh').show();
})
});