var term;
function runFakeTerminal() {
	term = new Terminal();
	term.open(document.getElementById('terminal'));
	myws.send(JSON.stringify(mytm));
	mytm.code="201";
	if (term._initialized) {return}
		term._initialized = true;
		mytm.Data = ''; let historyLineData = []; let last = 0;
		term.onData(async key => {
	if (key.charCodeAt(0) === 13) {//enter
		if (mytm.Data !== '') {historyLineData.push(mytm.Data);last = historyLineData.length - 1}
		myws.send(JSON.stringify(mytm));mytm.Data = ''
    } else if (key.charCodeAt(0) === 127) {//del
	if (term._core.buffer.x > 2) {mytm.Data = mytm.Data.slice(0, -1);term.write('\b \b')}
    } else if (key === '\u001b[A') { let len = 0 //up
		if (historyLineData.length > 0) {len = historyLineData.length + 1}
		if (last < len && last > 0) {
		for (let i = 0; i < mytm.Data.length; i++) {
			if (term._core.buffer.x > 0) {term.write('\b \b')}
        }
        let text = historyLineData[last - 1];term.write(text);mytm.Data = text;last--
		}
    } else if (key === '\u001b[B') {let lent = 0; //down
		if (historyLineData.length > 0) {lent = historyLineData.length - 1}
		if (last < lent && last > -1) {
        for (let i = 0; i < mytm.Data.length; i++) {
          if (term._core.buffer.x > 0) {term.write('\b \b')}
        }
        let text = historyLineData[last + 1];term.write(text);mytm.Data = text;last++
		}
    } else {mytm.Data += key;term.write(key)}
  });
}
function writeterm(msg){term.write(msg)}
function closeterminal(){
	term.dispose();mytm.Data="";mytm.code="203";myws.send(JSON.stringify(mytm))
}