diff --git a/lib/client/terminal.js b/lib/client/terminal.js index 0c73b171..340cf6ac 100644 --- a/lib/client/terminal.js +++ b/lib/client/terminal.js @@ -1,7 +1,7 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; (function(CloudCmd, Util, DOM, CloudFunc) { 'use strict'; - + CloudCmd.Terminal = TerminalProto; function TerminalProto(CallBack) { @@ -10,6 +10,7 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; Element, MouseBinded, Term, + Cell, Key = CloudCmd.Key, ESC = Key.ESC, Images = DOM.Images, @@ -55,6 +56,12 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; style : 'height :100%' }); + Cell = DOM.anyload({ + name : 'div', + inner : ' ', + parent : Element + }); + DOM.cssSet({ id : 'terminal-css', inner : '#terminal, .terminal, #view {' + @@ -95,10 +102,7 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; function addListeners(callback) { var socket = CloudCmd.Socket, - size = { - cols: 80, - rows: 25 - }; + size = maxSize(); socket.on(CHANNEL, write); @@ -113,23 +117,29 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; /* when back to term * first simbol wasn't wrote */ - if (code !== ESC) - socket.emit(CHANNEL, data); + socket.emit(CHANNEL, data); } }); - //Term.resize(size.cols, size.rows); - //socket.emit(CHANNEL_RESIZE, size); + Term.on(CHANNEL_RESIZE, function() { + socket.emit(CHANNEL_RESIZE, size); + }); Util.exec(callback); } function maxSize() { - var w = Term.element.clientWidth - (Term.offsetWidth - Term.clientWidth), - h = Term.element.clientHeight - (Term.offsetHeight - Term.clientHeight), + var wSubs = Element.offsetWidth - Element.clientWidth, + w = Element.clientWidth - wSubs, - cols = Math.max(Math.floor(w), 10), - rows = Math.max(Math.floor(h), 10), + hSubs = Element.offsetHeight - Element.clientHeight, + h = Element.clientHeight - hSubs, + + x = Cell.clientWidth, + y = Cell.clientHeight, + + cols = Math.max(Math.floor(w / x), 10), + rows = Math.max(Math.floor(h / y), 10), size = { cols: cols,