function setareacontent(content:string):void{ //this appends to the bottom of the console and scrolls to the bottom make sure we start typing at the bottom var console = document.getElementById("console"); if (console != null) { console.innerHTML = content; console.scrollTop = console.scrollHeight; } } function addareacontent(content:string):void{ //this appends to the bottom of the console and scrolls to the bottom make sure we start typing at the bottom var console = document.getElementById("console"); if (console != null) { console.innerHTML += content; console.scrollTop = console.scrollHeight; } } function resizeit():void{ let con = $("#console"); let windowx = $("window"); let consolecont = $("#consolecont"); if (con != null && windowx != null && con != undefined&& windowx != undefined&&consolecont != null&&consolecont!=undefined) { let winheight = windowx.height(); let conoffset = con.offset(); if (winheight != undefined && conoffset != undefined){ consolecont.css('height', winheight - 10); let height = (winheight - conoffset.top)*0.96; $('#console').css('height', height); $('#rows').val(winheight - conoffset.top - 10); } } else{ console.log("error"); } } $(function(){ //fit console to screen //$('#console').css('height', $(window).height() - $('#console').offset().top - 10); //account for the input box let host = 'ws://127.0.0.1:8480'; var socket = io.connect(host) resizeit(); //resize it on window resize //$(window).resize(function(){ $(window).on('resize', function(){ resizeit(); }); //on key press on any part of html page //$("#console").keyup(function(e){ $("#console").on('keyup', function(e){ //if enter key is pressed //get the input e.preventDefault(); //resolve e.code to char let key = e.which; //send to server via socket if connected if (key == 8){ socket.emit('keypress', key); } }); // $("#console").keypress(function(e){ $("#console").on('keypress', function(e){ //if enter key is pressed //get the input e.preventDefault(); //resolve e.code to char let key = e.which; //send to server via socket if connected socket.emit('keypress', key); }); //connect to the server //on connect socket.on('connect', function(){ setareacontent("Connected to server"); }); //on disconnect socket.on('disconnect', function(){ setareacontent("Disconnected from server"); }); //on error socket.on('error', function(err:any){ setareacontent("Error: " + err); }); //on message socket.on('buffer', function(msg:any){ setareacontent(msg); }); socket.on('bufferx', function(msg:any){ addareacontent(msg); }); }) function flash(){ //if u+2800 is present in the console then replace it with 2588 let console = document.getElementById("console"); if (console != null) { if(console.innerHTML.indexOf("\u2800") > -1){ console.innerHTML = console.innerHTML.replace("\u2800", "\u2588"); } else{ console.innerHTML = console.innerHTML.replace("\u2588", "\u2800"); } } } setInterval(flash, 500);