1717// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919// SOFTWARE.
20- var CONSOLE_PUSH_COUNT = 50 ;
21- var CONSOLE_PUSH_FREQ = 200 ;
2220
23- const Console = ( function ( ) {
21+ var Console = ( function ( ) {
22+ var CONSOLE_PUSH_COUNT = 50 ;
23+ var CONSOLE_PUSH_FREQ = 200 ;
2424
2525 var terminalQueue ;
2626 var terminal ;
@@ -31,8 +31,10 @@ const Console = (function () {
3131 var memoryData ;
3232 var timeLabels ;
3333
34+ var $terminalNotify ;
35+
3436 function initConsole ( ) {
35- termianlQueue = [ ] ;
37+ terminalQueue = [ ] ;
3638 terminal = $ ( '#terminal' ) . terminal ( function ( command , term ) {
3739 Socket . emit ( 'send command' , command ) ;
3840 } , {
@@ -47,13 +49,25 @@ const Console = (function () {
4749 return false ;
4850 }
4951 } ) ;
52+
53+ $terminalNotify = $ ( '#terminalNotify' ) ;
54+ $terminalNotify . on ( 'click' , function ( ) {
55+ terminal . scroll_to_bottom ( ) ;
56+ $terminalNotify . addClass ( 'hidden' ) ;
57+ } )
58+
59+ terminal . on ( 'scroll' , function ( ) {
60+ if ( terminal . is_bottom ( ) ) {
61+ $terminalNotify . addClass ( 'hidden' ) ;
62+ }
63+ } )
5064 }
5165
5266 function initGraphs ( ) {
5367 var ctc = $ ( '#chart_cpu' ) ;
54- var timeLabels = [ ] ;
55- var cpuData = [ ] ;
56- var CPUChart = new Chart ( ctc , {
68+ timeLabels = [ ] ;
69+ cpuData = [ ] ;
70+ cpuChart = new Chart ( ctc , {
5771 type : 'line' ,
5872 data : {
5973 labels : timeLabels ,
@@ -62,17 +76,17 @@ const Console = (function () {
6276 label : "Percent Use" ,
6377 fill : false ,
6478 lineTension : 0.03 ,
65- backgroundColor : "#00A1CB " ,
66- borderColor : "#00A1CB " ,
79+ backgroundColor : "#3c8dbc " ,
80+ borderColor : "#3c8dbc " ,
6781 borderCapStyle : 'butt' ,
6882 borderDash : [ ] ,
6983 borderDashOffset : 0.0 ,
7084 borderJoinStyle : 'miter' ,
71- pointBorderColor : "rgba(75,192,192,1) " ,
85+ pointBorderColor : "#3c8dbc " ,
7286 pointBackgroundColor : "#fff" ,
7387 pointBorderWidth : 1 ,
7488 pointHoverRadius : 5 ,
75- pointHoverBackgroundColor : "rgba(75,192,192,1) " ,
89+ pointHoverBackgroundColor : "#3c8dbc " ,
7690 pointHoverBorderColor : "rgba(220,220,220,1)" ,
7791 pointHoverBorderWidth : 2 ,
7892 pointRadius : 1 ,
@@ -97,8 +111,8 @@ const Console = (function () {
97111 } ) ;
98112
99113 var ctm = $ ( '#chart_memory' ) ;
100- var memoryData = [ ] ;
101- var MemoryChart = new Chart ( ctm , {
114+ memoryData = [ ] ;
115+ memoryChart = new Chart ( ctm , {
102116 type : 'line' ,
103117 data : {
104118 labels : timeLabels ,
@@ -107,17 +121,17 @@ const Console = (function () {
107121 label : "Memory Use" ,
108122 fill : false ,
109123 lineTension : 0.03 ,
110- backgroundColor : "#01A4A4 " ,
111- borderColor : "#01A4A4 " ,
124+ backgroundColor : "#3c8dbc " ,
125+ borderColor : "#3c8dbc " ,
112126 borderCapStyle : 'butt' ,
113127 borderDash : [ ] ,
114128 borderDashOffset : 0.0 ,
115129 borderJoinStyle : 'miter' ,
116- pointBorderColor : "rgba(75,192,192,1) " ,
130+ pointBorderColor : "#3c8dbc " ,
117131 pointBackgroundColor : "#fff" ,
118132 pointBorderWidth : 1 ,
119133 pointHoverRadius : 5 ,
120- pointHoverBackgroundColor : "rgba(75,192,192,1) " ,
134+ pointHoverBackgroundColor : "#3c8dbc " ,
121135 pointHoverBorderColor : "rgba(220,220,220,1)" ,
122136 pointHoverBorderWidth : 2 ,
123137 pointRadius : 1 ,
@@ -158,6 +172,10 @@ const Console = (function () {
158172 updateServerPowerControls ( data . status ) ;
159173 } ) ;
160174
175+ Socket . on ( 'console' , function ( data ) {
176+ terminalQueue . push ( data . line ) ;
177+ } ) ;
178+
161179 Socket . on ( 'proc' , function ( proc ) {
162180 if ( cpuData . length > 10 ) {
163181 cpuData . shift ( ) ;
@@ -172,20 +190,25 @@ const Console = (function () {
172190 var m = new Date ( ) ;
173191 timeLabels . push ( $ . format . date ( new Date ( ) , 'HH:mm:ss' ) ) ;
174192
175- CPUChart . update ( ) ;
176- MemoryChart . update ( ) ;
193+ cpuChart . update ( ) ;
194+ memoryChart . update ( ) ;
177195 } ) ;
178196 }
179197
180198 function pushOutputQueue ( ) {
181- if ( termianlQueue . length > CONSOLE_PUSH_COUNT ) {
199+ if ( terminalQueue . length > CONSOLE_PUSH_COUNT ) {
182200 // console throttled warning show
183201 }
184202
185- if ( termianlQueue . length > 0 ) {
186- for ( var i = 0 ; i < CONSOLE_PUSH_COUNT && termianlQueue . length > 0 ; i ++ ) {
187- terminal . echo ( termianlQueue [ 0 ] ) ;
188- termianlQueue . shift ( ) ;
203+ if ( terminalQueue . length > 0 ) {
204+ for ( var i = 0 ; i < CONSOLE_PUSH_COUNT && terminalQueue . length > 0 ; i ++ ) {
205+ terminal . echo ( terminalQueue [ 0 ] ) ;
206+ terminalQueue . shift ( ) ;
207+ }
208+
209+ // Show
210+ if ( ! terminal . is_bottom ( ) ) {
211+ $terminalNotify . removeClass ( 'hidden' ) ;
189212 }
190213 }
191214
@@ -226,16 +249,16 @@ const Console = (function () {
226249 } ) ;
227250 } ,
228251
229- getTerminal : function ( ) {
252+ getTerminal : function ( ) {
230253 return terminal
231254 } ,
232255
233- getTerminalQueue : function ( ) {
256+ getTerminalQueue : function ( ) {
234257 return terminalQueue
235258 } ,
236259 }
237260
238- } ) ;
261+ } ) ( ) ;
239262
240263$ ( document ) . ready ( function ( ) {
241264 Console . init ( ) ;
0 commit comments